Skip to content

Commit b410b5f

Browse files
Improved Assessment Configurability in Ground Control (#1093)
* rename hasTokenCounter to hasVotingFeature under assessmentConfig * Added hasVotingFeatures to assessment config * Added hasVotingFeature to assessmentConfig * Added hasTokenCounter and hasVotingFeatures to assessments * hasTokenCounter and hasVotingFeatures to be updated to ones in assessment config when uploaded * Added hasTokenCounter and hasVotingFeatures to be shown when assessment is requested * Added hasTokenCounter into swaggers * Changed test cases to include hasVotingFeatures and hasTokenCounter * Added a way to change hasTokenCounter and hasVotingFeatures from the frontEnd * fixed format * fixed format * fixed alias format * added new test case to ensure hasTokenCounter and hasVotingFeatures can be changed * Seperated nil checks to be for indivudual field instead --------- Co-authored-by: Richard Dominick <[email protected]>
1 parent 5edaa6a commit b410b5f

15 files changed

+167
-9
lines changed

lib/cadet/assessments/assessment.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ defmodule Cadet.Assessments.Assessment do
3333
field(:reading, :string)
3434
field(:password, :string, default: nil)
3535
field(:max_team_size, :integer, default: 1)
36+
field(:has_token_counter, :boolean, default: false)
37+
field(:has_voting_features, :boolean, default: false)
3638

3739
belongs_to(:config, AssessmentConfig)
3840
belongs_to(:course, Course)
@@ -43,7 +45,7 @@ defmodule Cadet.Assessments.Assessment do
4345

4446
@required_fields ~w(title open_at close_at number course_id config_id max_team_size)a
4547
@optional_fields ~w(reading summary_short summary_long
46-
is_published story cover_picture access password)a
48+
is_published story cover_picture access password has_token_counter has_voting_features)a
4749
@optional_file_fields ~w(mission_pdf)a
4850

4951
def changeset(assessment, params) do

lib/cadet/courses/assessment_config.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defmodule Cadet.Courses.AssessmentConfig do
1313
field(:show_grading_summary, :boolean, default: true)
1414
field(:is_manually_graded, :boolean, default: true)
1515
field(:has_token_counter, :boolean, default: false)
16+
field(:has_voting_features, :boolean, default: false)
1617
# used by frontend to determine display styles
1718
field(:early_submission_xp, :integer, default: 0)
1819
field(:hours_before_early_xp_decay, :integer, default: 0)
@@ -24,7 +25,7 @@ defmodule Cadet.Courses.AssessmentConfig do
2425

2526
@required_fields ~w(course_id)a
2627
@optional_fields ~w(order type early_submission_xp
27-
hours_before_early_xp_decay show_grading_summary is_manually_graded has_token_counter)a
28+
hours_before_early_xp_decay show_grading_summary is_manually_graded has_voting_features has_token_counter)a
2829

2930
def changeset(assessment_config, params) do
3031
assessment_config

lib/cadet/jobs/xml_parser.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ defmodule Cadet.Updater.XMLParser do
55

66
use Cadet, [:display]
77

8+
import Ecto.Query
89
import SweetXml
910

10-
alias Cadet.Assessments
11+
alias Cadet.{Repo, Courses.AssessmentConfig, Assessments}
1112

1213
require Logger
1314

@@ -80,6 +81,11 @@ defmodule Cadet.Updater.XMLParser do
8081

8182
close_at = Timex.shift(open_at, days: 7)
8283

84+
assessment_config =
85+
AssessmentConfig
86+
|> where(id: ^assessment_config_id)
87+
|> Repo.one()
88+
8389
assessment_params =
8490
xml
8591
|> xpath(
@@ -99,6 +105,8 @@ defmodule Cadet.Updater.XMLParser do
99105
|> Map.put(:close_at, close_at)
100106
|> Map.put(:course_id, course_id)
101107
|> Map.put(:config_id, assessment_config_id)
108+
|> Map.put(:has_token_counter, assessment_config.has_token_counter)
109+
|> Map.put(:has_voting_features, assessment_config.has_voting_features)
102110
|> (&if(&1.access === "public",
103111
do: Map.put(&1, :password, nil),
104112
else: &1

lib/cadet_web/admin_controllers/admin_assessments_controller.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ defmodule CadetWeb.AdminAssessmentsController do
8383
close_at = params |> Map.get("closeAt")
8484
is_published = params |> Map.get("isPublished")
8585
max_team_size = params |> Map.get("maxTeamSize")
86+
has_token_counter = params |> Map.get("hasTokenCounter")
87+
has_voting_features = params |> Map.get("hasVotingFeatures")
8688

8789
updated_assessment =
8890
if is_nil(is_published) do
@@ -98,6 +100,20 @@ defmodule CadetWeb.AdminAssessmentsController do
98100
Map.put(updated_assessment, :max_team_size, max_team_size)
99101
end
100102

103+
updated_assessment =
104+
if is_nil(has_token_counter) do
105+
updated_assessment
106+
else
107+
Map.put(updated_assessment, :has_token_counter, has_token_counter)
108+
end
109+
110+
updated_assessment =
111+
if is_nil(has_voting_features) do
112+
updated_assessment
113+
else
114+
Map.put(updated_assessment, :has_voting_features, has_voting_features)
115+
end
116+
101117
with {:ok, assessment} <- check_dates(open_at, close_at, updated_assessment),
102118
{:ok, _nil} <- Assessments.update_assessment(assessment_id, assessment) do
103119
text(conn, "OK")

lib/cadet_web/admin_views/admin_assessments_view.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ defmodule CadetWeb.AdminAssessmentsView do
2828
isPublished: :is_published,
2929
questionCount: :question_count,
3030
gradedCount: &(&1.graded_count || 0),
31-
maxTeamSize: :max_team_size
31+
maxTeamSize: :max_team_size,
32+
hasVotingFeatures: :has_voting_features,
33+
hasTokenCounter: :has_token_counter
3234
})
3335
end
3436

@@ -44,6 +46,7 @@ defmodule CadetWeb.AdminAssessmentsView do
4446
number: :number,
4547
reading: :reading,
4648
longSummary: :summary_long,
49+
hasTokenCounter: :has_token_counter,
4750
missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}),
4851
questions:
4952
&Enum.map(&1.questions, fn question ->

lib/cadet_web/admin_views/admin_courses_view.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule CadetWeb.AdminCoursesView do
1212
displayInDashboard: :show_grading_summary,
1313
isManuallyGraded: :is_manually_graded,
1414
earlySubmissionXp: :early_submission_xp,
15+
hasVotingFeatures: :has_voting_features,
1516
hasTokenCounter: :has_token_counter,
1617
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
1718
})

lib/cadet_web/controllers/assessments_controller.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ defmodule CadetWeb.AssessmentsController do
174174
required: true
175175
)
176176

177+
hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?")
178+
177179
maxXp(
178180
:integer,
179181
"The maximum XP for this assessment",
@@ -216,6 +218,7 @@ defmodule CadetWeb.AssessmentsController do
216218
story(:string, "The story that should be shown for this assessment")
217219
reading(:string, "The reading for this assessment")
218220
longSummary(:string, "Long summary", required: true)
221+
hasTokenCounter(:boolean, "Does the assessment have Token Counter enabled?")
219222
missionPDF(:string, "The URL to the assessment pdf")
220223

221224
questions(Schema.ref(:Questions), "The list of questions for this assessment")

lib/cadet_web/views/assessments_view.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ defmodule CadetWeb.AssessmentsView do
2929
isPublished: :is_published,
3030
questionCount: :question_count,
3131
gradedCount: &(&1.graded_count || 0),
32-
maxTeamSize: :max_team_size
32+
maxTeamSize: :max_team_size,
33+
hasVotingFeatures: :has_voting_features,
34+
hasTokenCounter: :has_token_counter
3335
})
3436
end
3537

@@ -45,6 +47,7 @@ defmodule CadetWeb.AssessmentsView do
4547
number: :number,
4648
reading: :reading,
4749
longSummary: :summary_long,
50+
hasTokenCounter: :has_token_counter,
4851
missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}),
4952
questions:
5053
&Enum.map(&1.questions, fn question ->

lib/cadet_web/views/user_view.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ defmodule CadetWeb.UserView do
125125
type: :type,
126126
displayInDashboard: :show_grading_summary,
127127
isManuallyGraded: :is_manually_graded,
128+
hasVotingFeatures: :has_voting_features,
128129
hasTokenCounter: :has_token_counter,
129130
earlySubmissionXp: :early_submission_xp,
130131
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Cadet.Repo.Migrations.AddHasTokenCounterToggleToAssessment do
2+
use Ecto.Migration
3+
4+
def up do
5+
alter table(:assessments) do
6+
add(:has_token_counter, :boolean, null: false, default: false)
7+
add(:has_voting_features, :boolean, null: false, default: false)
8+
end
9+
end
10+
11+
def down do
12+
alter table(:assessments) do
13+
remove(:has_token_counter)
14+
remove(:has_voting_features)
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)