diff options
| -rw-r--r-- | src/com/p4square/grow/frontend/ErrorPage.java | 3 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/TrainingPageResource.java | 69 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/VideosResource.java | 15 | ||||
| -rw-r--r-- | src/templates/templates/nav.ftl | 2 | ||||
| -rw-r--r-- | web/scripts/growth.js | 2 | 
5 files changed, 21 insertions, 70 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 6c89ac9..6615295 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 fed315b..e85ecd4 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> diff --git a/web/scripts/growth.js b/web/scripts/growth.js index 9aae3aa..4bc7e5b 100644 --- a/web/scripts/growth.js +++ b/web/scripts/growth.js @@ -178,7 +178,7 @@ function reportVideoComplete(data)      $.ajax({          type: "POST", -        url: location.href + "/videos/" + videoId + ".json", +        url: location.href + "/videos/" + data.id + ".json",          dataType: "json",          data: {'completed':'true'}      }).error(function(jqXHR, error) {  | 
