summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-09-01 17:37:06 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-09-01 17:37:06 -0700
commitdd5a0be56a05e55e71843e37d02581b9424bbc6c (patch)
treeef644ecd249134604939929e4cbe0b7dba1122b3 /src
parentba05f378d217316ebb3c92b69fdf48585be46825 (diff)
Adding video completion tracking to frontend
Diffstat (limited to 'src')
-rw-r--r--src/com/p4square/grow/frontend/ErrorPage.java3
-rw-r--r--src/com/p4square/grow/frontend/TrainingPageResource.java69
-rw-r--r--src/com/p4square/grow/frontend/VideosResource.java15
-rw-r--r--src/templates/templates/nav.ftl2
4 files changed, 20 insertions, 69 deletions
diff --git a/src/com/p4square/grow/frontend/ErrorPage.java b/src/com/p4square/grow/frontend/ErrorPage.java
index b57cc49..721b477 100644
--- a/src/com/p4square/grow/frontend/ErrorPage.java
+++ b/src/com/p4square/grow/frontend/ErrorPage.java
@@ -31,6 +31,9 @@ public class ErrorPage extends WriterRepresentation {
public static final ErrorPage RENDER_ERROR =
new ErrorPage("Error rendering page.");
+ public static final ErrorPage BACKEND_ERROR =
+ new ErrorPage("Error communicating with backend.");
+
private static Template cTemplate = null;
private final String mMessage;
diff --git a/src/com/p4square/grow/frontend/TrainingPageResource.java b/src/com/p4square/grow/frontend/TrainingPageResource.java
index 459eb9a..ad7ea8d 100644
--- a/src/com/p4square/grow/frontend/TrainingPageResource.java
+++ b/src/com/p4square/grow/frontend/TrainingPageResource.java
@@ -65,7 +65,7 @@ public class TrainingPageResource extends FreeMarkerPageResource {
}
/**
- * Return a page with a survey question.
+ * Return a page of videos.
*/
@Override
protected Representation get() {
@@ -121,76 +121,11 @@ public class TrainingPageResource extends FreeMarkerPageResource {
} catch (Exception e) {
cLog.fatal("Could not render page: " + e.getMessage(), e);
setStatus(Status.SERVER_ERROR_INTERNAL);
- return null;
+ return ErrorPage.RENDER_ERROR;
}
}
/**
- * Record a survey answer and redirect to the next question.
- */
- @Override
- protected Representation post(Representation entity) {
- return null;
- /*final Form form = new Form(entity);
- final String answerId = form.getFirstValue("answer");
-
- if (mQuestionId == null || answerId == null || answerId.length() == 0) {
- // Something is wrong.
- setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
- return null;
- }
-
- try {
- // Find the question
- Map questionData = null;
- {
- JsonResponse response = backendGet("/assessment/question/" + mQuestionId);
- if (!response.getStatus().isSuccess()) {
- // User is answering a question which doesn't exist
- setStatus(Status.CLIENT_ERROR_NOT_FOUND);
- return null;
- }
-
- questionData = response.getMap();
- }
-
- // Store answer
- {
- Map<String, String> answer = new HashMap<String, String>();
- answer.put("answerId", answerId);
- JsonResponse response = backendPut("/accounts/" + mUserId +
- "/assessment/answers/" + mQuestionId, answer);
-
- if (!response.getStatus().isSuccess()) {
- // Something went wrong talking to the backend, error out.
- cLog.fatal("Error recording survey answer " + response.getStatus());
- setStatus(Status.SERVER_ERROR_INTERNAL);
- return null;
- }
- }
-
- // Find the next question or finish the assessment.
- String nextPage = mConfig.getString("dynamicRoot", "");
- {
- String nextQuestionId = (String) questionData.get("nextQuestion");
- if (nextQuestionId == null) {
- nextPage += "/account/assessment/results";
- } else {
- nextPage += "/account/assessment/question/" + nextQuestionId;
- }
- }
-
- getResponse().redirectSeeOther(nextPage);
- return null;
-
- } catch (Exception e) {
- cLog.fatal("Could not render page: " + e.getMessage(), e);
- setStatus(Status.SERVER_ERROR_INTERNAL);
- return null;
- }*/
- }
-
- /**
* @return The backend endpoint URI
*/
private String getBackendEndpoint() {
diff --git a/src/com/p4square/grow/frontend/VideosResource.java b/src/com/p4square/grow/frontend/VideosResource.java
index cdb2fb4..caf8dc1 100644
--- a/src/com/p4square/grow/frontend/VideosResource.java
+++ b/src/com/p4square/grow/frontend/VideosResource.java
@@ -4,6 +4,7 @@
package com.p4square.grow.frontend;
+import java.util.HashMap;
import java.util.Map;
import freemarker.template.Template;
@@ -62,7 +63,7 @@ public class VideosResource extends ServerResource {
JsonResponse response = backendGet("/training/" + mChapter + "/videos/" + mVideoId);
if (response.getStatus().isSuccess()) {
- return new JacksonRepresentation<Map>(response.getMap());
+ return new JacksonRepresentation<Map>(response.getMap());
} else {
setStatus(response.getStatus());
@@ -81,6 +82,18 @@ public class VideosResource extends ServerResource {
*/
@Override
protected Representation post(Representation entity) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("completed", "t");
+ JsonResponse response = backendPut("/accounts/" + mUserId + "/training/videos/" + mVideoId, data);
+
+ if (!response.getStatus().isSuccess()) {
+ // Something went wrong talking to the backend, error out.
+ cLog.fatal("Error recording completed video " + response.getStatus());
+ setStatus(Status.SERVER_ERROR_INTERNAL);
+ return ErrorPage.BACKEND_ERROR;
+ }
+
+ setStatus(Status.SUCCESS_NO_CONTENT);
return null;
}
diff --git a/src/templates/templates/nav.ftl b/src/templates/templates/nav.ftl
index 54074d5..07148eb 100644
--- a/src/templates/templates/nav.ftl
+++ b/src/templates/templates/nav.ftl
@@ -1,6 +1,6 @@
<#macro navLink href>
<li><a
- <#if currentPage!"" == href>
+ <#if (currentPage!"") == href>
class="current"
</#if>
href="${href}"><#nested></a></li>