Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incrementing and decrementing the data so that 0s display now as 1s #139

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions test/controllers/admin_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ defmodule Skillswheel.AdminControllerTest do
end

test "/admin" do
assert AdminController.all_survey_data() == [
actual =
AdminController.all_survey_data()
|> Enum.map(&(Map.delete(&1, "Date")))
expected = [
%{"Child Name" => "First Last",
"Date" => "20/3/17",
"Group Name" => "Group 1",
"Managing Feelings" => 5,
"Non-Verbal Communication" => 5,
Expand All @@ -95,6 +97,8 @@ defmodule Skillswheel.AdminControllerTest do
"Teaching Assistant" => "My Name",
"Verbal Communication" => 5,
"Year" => "2"}]

assert actual == expected
end
end
end
12 changes: 11 additions & 1 deletion web/controllers/survey_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ defmodule Skillswheel.SurveyController do

alias Skillswheel.{Student, Survey}

defp increment(string) do
case string do
"0" -> "1"
"1" -> "2"
"2" -> "3"
"3" -> "4"
_ -> string
end
end

def create_survey(conn, %{"student_id" => student_id, "survey" => survey}, _user) do
attrs
= survey
|> Map.new(fn {key, val} -> {String.to_atom(key), val} end)
|> Map.new(fn {key, val} -> {String.to_atom(key), increment(val)} end)
|> Map.delete(:student_id)

student = Repo.get!(Student, student_id)
Expand Down
10 changes: 9 additions & 1 deletion web/templates/student/show.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@
]);
}

function decrement(survey) {
return survey.map(function (obj) {
obj.answer = parseInt(obj.answer) - 1
return obj;
});
}

var format_surveys = surveys
.map(relevant_keys)
.map(format)
.map(order);
.map(order)
.map(decrement);

// draw in all the wheels to the wheels-container
format_surveys.forEach(function (survey, i) {
Expand Down