From 45634dc9934813bd88aebf58f39e82bf0254a7d6 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 1 Oct 2013 22:21:19 -0700 Subject: Adding message banner --- src/com/p4square/grow/backend/GrowBackend.java | 3 + .../grow/backend/resources/BannerResource.java | 66 ++++++++++++++++++++++ src/templates/macros/common-page.ftl | 1 + src/templates/pages/index.html.ftl | 1 + src/templates/templates/banner.ftl | 6 ++ web/scripts/growth.js | 2 + web/style.css | 8 +++ 7 files changed, 87 insertions(+) create mode 100644 src/com/p4square/grow/backend/resources/BannerResource.java create mode 100644 src/templates/templates/banner.ftl diff --git a/src/com/p4square/grow/backend/GrowBackend.java b/src/com/p4square/grow/backend/GrowBackend.java index 7da6fff..533cf09 100644 --- a/src/com/p4square/grow/backend/GrowBackend.java +++ b/src/com/p4square/grow/backend/GrowBackend.java @@ -17,6 +17,7 @@ import com.p4square.grow.config.Config; import com.p4square.grow.backend.db.CassandraDatabase; import com.p4square.grow.backend.resources.AccountResource; +import com.p4square.grow.backend.resources.BannerResource; import com.p4square.grow.backend.resources.SurveyResource; import com.p4square.grow.backend.resources.SurveyResultsResource; import com.p4square.grow.backend.resources.TrainingRecordResource; @@ -64,6 +65,8 @@ public class GrowBackend extends Application { router.attach("/accounts/{userId}/training/videos/{videoId}", TrainingRecordResource.class); + // Misc. + router.attach("/banner", BannerResource.class); return router; } diff --git a/src/com/p4square/grow/backend/resources/BannerResource.java b/src/com/p4square/grow/backend/resources/BannerResource.java new file mode 100644 index 0000000..4551777 --- /dev/null +++ b/src/com/p4square/grow/backend/resources/BannerResource.java @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.backend.resources; + +import java.io.IOException; + +import org.restlet.data.Status; +import org.restlet.resource.ServerResource; +import org.restlet.representation.Representation; +import org.restlet.representation.StringRepresentation; + +import org.apache.log4j.Logger; + +import com.p4square.grow.backend.GrowBackend; +import com.p4square.grow.backend.db.CassandraDatabase; + +/** + * Fetches or sets the banner string. + * + * @author Jesse Morgan + */ +public class BannerResource extends ServerResource { + private static final Logger LOG = Logger.getLogger(BannerResource.class); + + private CassandraDatabase mDb; + + @Override + public void doInit() { + super.doInit(); + + final GrowBackend backend = (GrowBackend) getApplication(); + mDb = backend.getDatabase(); + } + + /** + * Handle GET Requests. + */ + @Override + protected Representation get() { + String result = mDb.getKey("strings", "banner"); + + if (result == null || result.length() == 0) { + result = "{}"; + } + + return new StringRepresentation(result); + } + + /** + * Handle PUT requests + */ + @Override + protected Representation put(Representation entity) { + try { + mDb.putKey("strings", "banner", entity.getText()); + setStatus(Status.SUCCESS_NO_CONTENT); + + } catch (IOException e) { + setStatus(Status.SERVER_ERROR_INTERNAL); + } + + return null; + } +} diff --git a/src/templates/macros/common-page.ftl b/src/templates/macros/common-page.ftl index 512128b..94cc5e3 100644 --- a/src/templates/macros/common-page.ftl +++ b/src/templates/macros/common-page.ftl @@ -12,6 +12,7 @@
+ <#include "/templates/banner.ftl"> <#include "/templates/header.ftl"> <#nested> diff --git a/src/templates/pages/index.html.ftl b/src/templates/pages/index.html.ftl index 94eaec3..1b59509 100644 --- a/src/templates/pages/index.html.ftl +++ b/src/templates/pages/index.html.ftl @@ -12,6 +12,7 @@
+ <#include "/templates/banner.ftl">

diff --git a/src/templates/templates/banner.ftl b/src/templates/templates/banner.ftl new file mode 100644 index 0000000..3a2d23b --- /dev/null +++ b/src/templates/templates/banner.ftl @@ -0,0 +1,6 @@ +<#assign bannerResult = get("bannerData", "riap://component/backend/banner")> +<#if bannerResult.succeeded == true> + <#if (bannerData.html!"") != ""> + + + diff --git a/web/scripts/growth.js b/web/scripts/growth.js index 6571273..de10d45 100644 --- a/web/scripts/growth.js +++ b/web/scripts/growth.js @@ -76,6 +76,8 @@ $(document).ready(function() if (video != null) { video.removeAttribute("controls"); } + + $("#banner").slideDown(); }); function notice(msg) diff --git a/web/style.css b/web/style.css index b6a83f0..0343038 100644 --- a/web/style.css +++ b/web/style.css @@ -44,6 +44,14 @@ blockquote { clear: both; } +#banner { + padding: 0.5em; + border-bottom: outset 2px; + background: #FFFF91; + font-size: 90%; + display: none; +} + header { background: white; margin: 0 auto 0 auto; -- cgit v1.2.3