Skip to content

Commit 56272d6

Browse files
authored
Merge pull request #1115 from concord-consortium/186748228-add-hide-question-numbers-setting
feat: Added setting to hide question numbers per activity or per sequence [PT-#186748228]
2 parents db80396 + 62bdaa3 commit 56272d6

File tree

11 files changed

+72
-9
lines changed

11 files changed

+72
-9
lines changed

app/models/lightweight_activity.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LightweightActivity < ActiveRecord::Base
3030
:time_to_complete, :is_locked, :notes, :thumbnail_url, :project_id,
3131
:portal_run_count, :layout, :editor_mode, :publication_hash, :copied_from_id,
3232
:student_report_enabled, :show_submit_button, :project, :background_image,
33-
:glossary_id, :hide_read_aloud, :font_size
33+
:glossary_id, :hide_read_aloud, :font_size, :hide_question_numbers
3434

3535
belongs_to :user # Author
3636
belongs_to :changed_by, :class_name => 'User'
@@ -111,6 +111,7 @@ def to_hash
111111
student_report_enabled: student_report_enabled,
112112
show_submit_button: show_submit_button,
113113
hide_read_aloud: hide_read_aloud,
114+
hide_question_numbers: hide_question_numbers,
114115
font_size: font_size
115116
}
116117
end
@@ -158,6 +159,7 @@ def export(host)
158159
:background_image,
159160
:defunct,
160161
:hide_read_aloud,
162+
:hide_question_numbers,
161163
:font_size ])
162164
activity_json[:version] = 2
163165
activity_json[:project] = self.project ? self.project.export : nil
@@ -224,6 +226,7 @@ def self.import(activity_json_object,new_owner,imported_activity_url=nil,helper=
224226
import_activity.imported_activity_url = imported_activity_url
225227
import_activity.is_official = activity_json_object[:is_official]
226228
import_activity.hide_read_aloud = activity_json_object[:hide_read_aloud]
229+
import_activity.hide_question_numbers = activity_json_object[:hide_question_numbers]
227230
import_activity.font_size = activity_json_object[:font_size]
228231
import_activity.project = Project.find_or_create(activity_json_object[:project]) if activity_json_object[:project]
229232
self.link_glossaries_on_import(activity_json_object, import_activity)

app/models/sequence.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Sequence < ActiveRecord::Base
22

33
attr_accessible :description, :title, :project_id, :defunct,
44
:user_id, :logo, :display_title, :thumbnail_url, :abstract, :publication_hash,
5-
:project, :background_image, :hide_read_aloud, :font_size, :layout_override
5+
:project, :background_image, :hide_read_aloud, :font_size, :layout_override, :hide_question_numbers
66

77
include Publishable # defines methods to publish to portals
88
include PublicationStatus # defines publication status scopes and helpers
@@ -57,6 +57,7 @@ def to_hash
5757
display_title: display_title,
5858
thumbnail_url: thumbnail_url,
5959
hide_read_aloud: hide_read_aloud,
60+
hide_question_numbers: hide_question_numbers,
6061
font_size: font_size,
6162
layout_override: layout_override
6263
}
@@ -104,6 +105,7 @@ def export(host)
104105
:background_image,
105106
:defunct,
106107
:hide_read_aloud,
108+
:hide_question_numbers,
107109
:font_size,
108110
:layout_override
109111
])
@@ -216,6 +218,7 @@ def self.extract_from_hash(sequence_json_object)
216218
title: sequence_json_object[:title],
217219
background_image: sequence_json_object[:background_image],
218220
hide_read_aloud: sequence_json_object[:hide_read_aloud],
221+
hide_question_numbers: sequence_json_object[:hide_question_numbers],
219222
font_size: sequence_json_object[:font_size],
220223
layout_override: sequence_json_object[:layout_override]
221224
}

app/views/lightweight_activities/_form.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
= f.check_box :hide_read_aloud
99
= f.label :hide_read_aloud, "Hide Read-Aloud Toggle"
1010
.hint Check this box if you do not want the "Tap text to listen" toggle to appear on this activity.
11+
.field
12+
= f.check_box :hide_question_numbers
13+
= f.label :hide_question_numbers, "Hide Question Numbers"
14+
.hint Check this box if you do not want question numbers to appear to the student in this activity.
1115
.field
1216
= f.label :layout, "Activity Layout"
1317
= f.select :layout, options_for_select(LightweightActivity::LAYOUT_OPTIONS, @activity.layout)

app/views/sequences/_form.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
= f.check_box :hide_read_aloud
2828
= f.label :hide_read_aloud, "Hide Read-Aloud Toggle"
2929
.hint Check this box if you do not want the "Tap text to listen" toggle to appear on activities in this sequence.
30+
.field
31+
= f.check_box :hide_question_numbers
32+
= f.label :hide_question_numbers, "Hide Question Numbers"
33+
.hint Check this box if you do not want question numbers to appear to the student in activities in this sequence.
3034
.field
3135
= f.label :layout_override, "Activity Layout Override"
3236
= f.select :layout_override, options_for_select(LightweightActivity::LAYOUT_OVERRIDE_OPTIONS, @sequence.layout_override)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddHideQuestionNumbers < ActiveRecord::Migration
2+
def change
3+
add_column :lightweight_activities, :hide_question_numbers, :boolean, default: false
4+
add_column :sequences, :hide_question_numbers, :boolean, default: false
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20231129130443) do
14+
ActiveRecord::Schema.define(:version => 20240103135547) do
1515

1616
create_table "admin_events", :force => true do |t|
1717
t.string "kind"
@@ -456,6 +456,7 @@
456456
t.string "migration_status", :default => "not_migrated"
457457
t.boolean "hide_read_aloud", :default => false
458458
t.string "font_size", :default => "normal"
459+
t.boolean "hide_question_numbers", :default => false
459460
end
460461

461462
add_index "lightweight_activities", ["changed_by_id"], :name => "index_lightweight_activities_on_changed_by_id"
@@ -750,6 +751,7 @@
750751
t.boolean "hide_read_aloud", :default => false
751752
t.string "font_size", :default => "normal"
752753
t.integer "layout_override", :default => 0
754+
t.boolean "hide_question_numbers", :default => false
753755
end
754756

755757
add_index "sequences", ["project_id"], :name => "index_sequences_on_project_id"

spec/import_examples/valid_lightweight_activity_import_v2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"background_image": "",
33
"defunct": false,
44
"hide_read_aloud": true,
5+
"hide_question_numbers": true,
56
"font_size": "large",
67
"description": "<p>Contains all page layout formats</p>",
78
"editor_mode": 0,

spec/models/lightweight_activity_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let(:thumbnail_url) { "http://fake.url.com/image" }
55
let(:author) { FactoryGirl.create(:author) }
66
let(:glossary) { nil }
7-
let(:act_opts) { {thumbnail_url: thumbnail_url, glossary: glossary, hide_read_aloud: true, font_size: "large"} }
7+
let(:act_opts) { {thumbnail_url: thumbnail_url, glossary: glossary, hide_read_aloud: true, hide_question_numbers: true, font_size: "large"} }
88
let(:activity) {
99
activity = FactoryGirl.create(:activity, act_opts)
1010
activity.user = author
@@ -188,6 +188,7 @@
188188
layout: activity.layout,
189189
editor_mode: activity.editor_mode,
190190
hide_read_aloud: activity.hide_read_aloud,
191+
hide_question_numbers: activity.hide_question_numbers,
191192
font_size: activity.font_size,
192193
}
193194
expect(activity.to_hash).to eq(expected)
@@ -230,6 +231,9 @@
230231
it 'includes the hide_read_aloud setting' do
231232
expect(export["hide_read_aloud"]).to eq(true)
232233
end
234+
it 'includes the hide_question_numbers setting' do
235+
expect(export["hide_question_numbers"]).to eq(true)
236+
end
233237
it 'includes the font_size setting' do
234238
expect(export["font_size"]).to eq("large")
235239
end
@@ -291,6 +295,7 @@
291295
expect(activity.glossary_id).to eq(glossary.id)
292296
expect(dup.glossary_id).to eq(activity.glossary_id)
293297
expect(dup.hide_read_aloud).to eq(activity.hide_read_aloud)
298+
expect(dup.hide_question_numbers).to eq(activity.hide_question_numbers)
294299
expect(dup.font_size).to eq(activity.font_size)
295300
end
296301

@@ -451,6 +456,7 @@
451456
expect(act.pages.count).to eq(json[:pages].length)
452457
expect(act.glossary_id).to eq(nil)
453458
expect(act.hide_read_aloud).to eq(true)
459+
expect(act.hide_question_numbers).to eq(true)
454460
expect(act.font_size).to eq("large")
455461
end
456462

spec/models/sequence_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
end
196196

197197
describe '#to_hash' do
198-
let(:sequence_opts) { {hide_read_aloud: true, font_size: "large", layout_override: 2} }
198+
let(:sequence_opts) { {hide_read_aloud: true, hide_question_numbers: true, font_size: "large", layout_override: 2} }
199199
it 'returns a hash with relevant values for sequence duplication' do
200200
expected = {
201201
title: sequence.title,
@@ -207,6 +207,7 @@
207207
display_title: sequence.display_title,
208208
thumbnail_url: sequence.thumbnail_url,
209209
hide_read_aloud: true,
210+
hide_question_numbers: true,
210211
font_size: "large",
211212
layout_override: 2,
212213
}
@@ -215,12 +216,13 @@
215216
end
216217

217218
describe '#export' do
218-
let(:sequence_opts) { {hide_read_aloud: true, font_size: "large", layout_override: 2} }
219+
let(:sequence_opts) { {hide_read_aloud: true, hide_question_numbers: true, font_size: "large", layout_override: 2} }
219220
let(:host) { 'http://test.host' }
220221
it 'returns json of a sequence' do
221222
sequence_json = JSON.parse(sequence.export(host))
222223
expect(sequence_json['activities'].length).to eq(sequence.activities.count)
223224
expect(sequence_json['hide_read_aloud']).to eq(true)
225+
expect(sequence_json['hide_question_numbers']).to eq(true)
224226
expect(sequence_json['font_size']).to eq("large")
225227
expect(sequence_json['layout_override']).to eq(2)
226228
end
@@ -251,9 +253,10 @@
251253
let(:thumbnail_url) { "https://concord.org/sunflower.jpg" }
252254
let(:title) { "title" }
253255
let(:hide_read_aloud) { true }
256+
let(:hide_question_numbers) { true }
254257
let(:font_size) { "large" }
255258
let(:layout_override) { 2 }
256-
let(:sequence_opts) { {logo: logo, thumbnail_url: thumbnail_url, title: title, hide_read_aloud: hide_read_aloud, font_size: font_size, layout_override: layout_override} }
259+
let(:sequence_opts) { {logo: logo, thumbnail_url: thumbnail_url, title: title, hide_read_aloud: hide_read_aloud, hide_question_numbers: hide_question_numbers, font_size: font_size, layout_override: layout_override} }
257260
let(:owner) { FactoryGirl.create(:user) }
258261
let(:host) { 'http://test.host' }
259262

@@ -263,6 +266,7 @@
263266
expect(imported.thumbnail_url).to eq(thumbnail_url)
264267
expect(imported.logo).to eq(logo)
265268
expect(imported.hide_read_aloud).to eq(hide_read_aloud)
269+
expect(imported.hide_question_numbers).to eq(hide_question_numbers)
266270
expect(imported.font_size).to eq(font_size)
267271
expect(imported.layout_override).to eq(layout_override)
268272
end

spec/views/lightweight_activities/edit.html.haml_spec.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ def official_checkbox
1010
def hide_read_aloud_checkbox
1111
'//*[@id="lightweight_activity_hide_read_aloud"]'
1212
end
13+
def hide_question_numbers_checkbox
14+
'//*[@id="lightweight_activity_hide_question_numbers"]'
15+
end
1316
def font_size_select
1417
'//*[@id="lightweight_activity_font_size"]'
1518
end
1619

1720
describe "lightweight_activities/edit" do
1821

19-
let(:activity) { stub_model(LightweightActivity, :id => 1, :name => 'Activity name', :defunct => false, :hide_read_aloud => false, :font_size => "normal") }
22+
let(:activity) { stub_model(LightweightActivity, :id => 1, :name => 'Activity name', :defunct => false, :hide_read_aloud => false, :hide_question_numbers => false, :font_size => "normal") }
2023
let(:user) { stub_model(User, :is_admin => false) }
2124

2225
before(:each) do
@@ -56,13 +59,39 @@ def font_size_select
5659

5760
context "when the current user is not an admin" do
5861
let (:user) { stub_model(User, :is_admin => false)}
59-
it "should show the checkbox" do
62+
it "should not show the checkbox" do
6063
render
6164
expect(rendered).to have_xpath hide_read_aloud_checkbox
6265
end
6366
end
6467
end
6568

69+
describe "hide_question_numbers checkbox" do
70+
context "when the current user is an admin" do
71+
let (:user) { stub_model(User, :is_admin => true)}
72+
it "should show the checkbox" do
73+
render
74+
expect(rendered).to have_xpath hide_question_numbers_checkbox
75+
end
76+
end
77+
78+
context "when the current user is an author" do
79+
let (:user) { stub_model(User, :is_author => true)}
80+
it "should show the checkbox" do
81+
render
82+
expect(rendered).to have_xpath hide_question_numbers_checkbox
83+
end
84+
end
85+
86+
context "when the current user is not an admin or author" do
87+
let (:user) { stub_model(User, :is_admin => false, :is_author => false)}
88+
it "should not show the checkbox" do
89+
render
90+
expect(rendered).to have_xpath hide_question_numbers_checkbox
91+
end
92+
end
93+
end
94+
6695
describe "font_size select" do
6796
context "when the current user is an admin" do
6897
let (:user) { stub_model(User, :is_admin => true)}

spec/views/sequences/edit.html.haml_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
assert_select "input#sequence_title", :name => "sequence[title]"
2020
assert_select "textarea#sequence_description", :name => "sequence[description]"
2121
assert_select "input#sequence_hide_read_aloud", :name => "sequence[hide_read_aloud]"
22+
assert_select "input#sequence_hide_question_numbers", :name => "sequence[hide_question_numbers]"
2223
assert_select "select#sequence_font_size", :name => "sequence[font_size]"
2324
end
2425
end

0 commit comments

Comments
 (0)