tweak group category creation UI
fold "I'll create groups myself" into "create 0 groups now" for self sign-up categories Change-Id: I562f5f303da52fa6e7bcbdc2ce1fb7b071bb8342 Reviewed-on: https://gerrit.instructure.com/6143 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
718f9f34ea
commit
21be362b0d
|
@ -116,7 +116,7 @@ class GroupsController < ApplicationController
|
|||
if authorized_action(@context, @current_user, :manage_groups)
|
||||
@group_category = @context.group_categories.build
|
||||
if populate_group_category_from_params
|
||||
create_default_groups_in_category if params[:category][:split_groups] == "1"
|
||||
create_default_groups_in_category
|
||||
flash[:notice] = t('notices.create_category_success', 'Category was successfully created.')
|
||||
render :json => [@group_category.as_json, @group_category.groups.map{ |g| g.as_json(:include => :users) }].to_json
|
||||
end
|
||||
|
@ -347,9 +347,12 @@ class GroupsController < ApplicationController
|
|||
end
|
||||
|
||||
def create_default_groups_in_category
|
||||
distribute_students = params[:category][:enable_self_signup] != "1"
|
||||
count = params[:category][:group_count].to_i
|
||||
self_signup = params[:category][:enable_self_signup] == "1"
|
||||
distribute_students = !self_signup && params[:category][:split_groups] == "1"
|
||||
return unless self_signup || distribute_students
|
||||
|
||||
count_field = self_signup ? :create_group_count : :split_group_count
|
||||
count = params[:category][count_field].to_i
|
||||
count = 0 if count < 0
|
||||
count = @context.students.length if distribute_students && count > @context.students.length
|
||||
return if count.zero?
|
||||
|
|
|
@ -42,13 +42,19 @@
|
|||
<tr>
|
||||
<td style="vertical-align: top; padding: 0.5em;"><%= before_label :group_structure, "Group Structure" %></td>
|
||||
<td style="padding: 0.5em;">
|
||||
<input type="radio" name="category[split_groups]" id="category_split_groups" value="1"/>
|
||||
<%= t :group_structure, "*Create* %{number_of_groups} groups now",
|
||||
:number_of_groups => '<input type="text" name="category[group_count]" style="width: 25px;"/>'.html_safe,
|
||||
:wrapper => '<label for="category_split_groups">\1</label>' %><br/>
|
||||
<span id="spread_students" style="padding-left: 2em;"><%= t :group_structure_footnote, "(Students will be split equally among these groups.)" %><br/></span>
|
||||
<input type="radio" name="category[split_groups]" id="category_no_groups" value="0" checked="true"/>
|
||||
<label for="category_no_groups"><%= t 'labels.manually_create_groups', "I'll create groups manually" %></label>
|
||||
<div id="group_structure_standard_subcontainer">
|
||||
<input type="radio" name="category[split_groups]" id="category_split_groups" value="1"/>
|
||||
<%= t :group_structure_standard, "*Split students into* %{number_of_groups} *equal groups*",
|
||||
:number_of_groups => '<input type="text" name="category[split_group_count]" id="category_split_group_count" style="width: 25px;"/>'.html_safe,
|
||||
:wrapper => '<label for="category_split_groups">\1</label>' %><br/>
|
||||
<input type="radio" name="category[split_groups]" id="category_no_groups" value="0" checked="true"/>
|
||||
<label for="category_no_groups"><%= t 'labels.manually_create_groups', "I'll create groups manually" %></label>
|
||||
</div>
|
||||
<div id="group_structure_self_signup_subcontainer" style="display:none;">
|
||||
<%= t :group_structure_self_signup, "*Create* %{number_of_groups} *groups now*",
|
||||
:number_of_groups => '<input type="text" name="category[create_group_count]" id="category_create_group_count" value="0" style="width: 25px;"/>'.html_safe,
|
||||
:wrapper => '<label for="category_create_group_count">\1</label>' %><br/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
@ -613,17 +613,18 @@ I18n.scoped('groups', function(I18n){
|
|||
$("#add_category_form #category_enable_self_signup").change(function() {
|
||||
var self_signup = $(this).prop('checked')
|
||||
$("#add_category_form #category_restrict_self_signup").prop('disabled', !self_signup);
|
||||
if (!self_signup && $("#add_category_form #category_restrict_self_signup").prop('checked')) {
|
||||
$("#add_category_form #group_structure_standard_subcontainer").showIf(!self_signup);
|
||||
$("#add_category_form #group_structure_self_signup_subcontainer").showIf(self_signup);
|
||||
if (!self_signup) {
|
||||
$("#add_category_form #category_restrict_self_signup").prop('checked', false);
|
||||
}
|
||||
$("#add_category_form #spread_students").showIf(!self_signup);
|
||||
});
|
||||
$("#edit_category_form #category_enable_self_signup").change(function() {
|
||||
var self_signup = $(this).prop('checked');
|
||||
var heterogenous = $(this).parents('.group_category').find('.heterogenous').text() == 'true';
|
||||
var disable_restrict = !self_signup || heterogenous;
|
||||
$("#edit_category_form #category_restrict_self_signup").prop('disabled', disable_restrict);
|
||||
if (disable_restrict && $("#edit_category_form #category_restrict_self_signup").prop('checked')) {
|
||||
if (disable_restrict) {
|
||||
$("#edit_category_form #category_restrict_self_signup").prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -106,7 +106,7 @@ describe GroupsController do
|
|||
e4 = @course.enroll_student(user_model)
|
||||
e5 = @course.enroll_student(user_model)
|
||||
e6 = @course.enroll_student(user_model)
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :group_count => 2, :split_groups => '1'}
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :split_group_count => 2, :split_groups => '1'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
groups = assigns[:group_category].groups
|
||||
|
@ -118,7 +118,7 @@ describe GroupsController do
|
|||
it "should give the new groups the right group_category" do
|
||||
course_with_teacher_logged_in(:active_all => true)
|
||||
student_in_course
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :group_count => 1, :split_groups => '1'}
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :split_group_count => 1, :split_groups => '1'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
assigns[:group_category].groups[0].group_category.name.should == "Study Groups"
|
||||
|
@ -148,6 +148,46 @@ describe GroupsController do
|
|||
response.should be_success
|
||||
assigns[:group_category].name.should == "Study Groups"
|
||||
end
|
||||
|
||||
it "should respect enable_self_signup" do
|
||||
course_with_teacher_logged_in(:active_all => true)
|
||||
student_in_course
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :enable_self_signup => '1'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
assigns[:group_category].should be_self_signup
|
||||
assigns[:group_category].should be_unrestricted_self_signup
|
||||
end
|
||||
|
||||
it "should use create_group_count when self-signup" do
|
||||
course_with_teacher_logged_in(:active_all => true)
|
||||
student_in_course
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :enable_self_signup => '1', :create_group_count => '3'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
assigns[:group_category].groups.size.should == 3
|
||||
end
|
||||
|
||||
it "should not distribute students when self-signup" do
|
||||
course_with_teacher_logged_in(:active_all => true)
|
||||
student_in_course
|
||||
student_in_course
|
||||
student_in_course
|
||||
student_in_course
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :enable_self_signup => '1', :create_category_count => '2'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
assigns[:group_category].groups.all?{ |g| g.users.should be_empty }
|
||||
end
|
||||
|
||||
it "should respect restrict_self_signup" do
|
||||
course_with_teacher_logged_in(:active_all => true)
|
||||
student_in_course
|
||||
post 'create_category', :course_id => @course.id, :category => {:name => "Study Groups", :enable_self_signup => '1', :restrict_self_signup => '1'}
|
||||
response.should be_success
|
||||
assigns[:group_category].should_not be_nil
|
||||
assigns[:group_category].should be_restricted_self_signup
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT update_category" do
|
||||
|
|
|
@ -306,11 +306,11 @@ describe "manage_groups selenium tests" do
|
|||
|
||||
# submit new category form
|
||||
driver.find_element(:css, ".add_category_link").click
|
||||
driver.find_elements(:css, "#add_category_form input[type=text]").first.clear
|
||||
driver.find_elements(:css, "#add_category_form input[type=text]").first.send_keys("New Category")
|
||||
driver.find_element(:css, "#category_no_groups").click
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").clear
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").send_keys("New Category")
|
||||
driver.find_element(:css, "#category_split_groups").click
|
||||
driver.find_elements(:css, "#add_category_form input[type=text]").second.send_keys("1")
|
||||
driver.find_element(:css, "#category_split_group_count").clear
|
||||
driver.find_element(:css, "#category_split_group_count").send_keys("1")
|
||||
driver.find_element(:css, "#add_category_form").submit
|
||||
wait_for_ajax_requests
|
||||
wait_for_ajaximations
|
||||
|
@ -324,6 +324,71 @@ describe "manage_groups selenium tests" do
|
|||
find_with_jquery("#sidebar_category_#{new_category.id} #sidebar_group_#{new_group.id}").should_not be_nil
|
||||
end
|
||||
|
||||
it "should honor enable_self_signup when adding a category" do
|
||||
course_with_teacher_logged_in
|
||||
@course.enroll_student(john = user_model(:name => "John Doe"))
|
||||
|
||||
get "/courses/#{@course.id}/groups"
|
||||
|
||||
# submit new category form
|
||||
driver.find_element(:css, ".add_category_link").click
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").clear
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").send_keys("New Category")
|
||||
driver.find_element(:css, "#add_category_form #category_enable_self_signup").click
|
||||
driver.find_element(:css, "#add_category_form").submit
|
||||
wait_for_ajax_requests
|
||||
wait_for_ajaximations
|
||||
|
||||
new_category = @course.group_categories.find_by_name('New Category')
|
||||
new_category.should_not be_nil
|
||||
new_category.should be_self_signup
|
||||
new_category.should be_unrestricted_self_signup
|
||||
end
|
||||
|
||||
it "should honor restrict_self_signup when adding a self signup category" do
|
||||
course_with_teacher_logged_in
|
||||
@course.enroll_student(john = user_model(:name => "John Doe"))
|
||||
|
||||
get "/courses/#{@course.id}/groups"
|
||||
|
||||
# submit new category form
|
||||
driver.find_element(:css, ".add_category_link").click
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").clear
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").send_keys("New Category")
|
||||
driver.find_element(:css, "#add_category_form #category_enable_self_signup").click
|
||||
driver.find_element(:css, "#add_category_form #category_restrict_self_signup").click
|
||||
driver.find_element(:css, "#add_category_form").submit
|
||||
wait_for_ajax_requests
|
||||
wait_for_ajaximations
|
||||
|
||||
new_category = @course.group_categories.find_by_name('New Category')
|
||||
new_category.should_not be_nil
|
||||
new_category.should be_self_signup
|
||||
new_category.should be_restricted_self_signup
|
||||
end
|
||||
|
||||
it "should honor create_group_count when adding a self signup category" do
|
||||
course_with_teacher_logged_in
|
||||
@course.enroll_student(john = user_model(:name => "John Doe"))
|
||||
|
||||
get "/courses/#{@course.id}/groups"
|
||||
|
||||
# submit new category form
|
||||
driver.find_element(:css, ".add_category_link").click
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").clear
|
||||
driver.find_element(:css, "#add_category_form input[type=text]").send_keys("New Category")
|
||||
driver.find_element(:css, "#add_category_form #category_enable_self_signup").click
|
||||
driver.find_element(:css, "#category_create_group_count").clear
|
||||
driver.find_element(:css, "#category_create_group_count").send_keys("2")
|
||||
driver.find_element(:css, "#add_category_form").submit
|
||||
wait_for_ajax_requests
|
||||
wait_for_ajaximations
|
||||
|
||||
new_category = @course.group_categories.find_by_name('New Category')
|
||||
new_category.should_not be_nil
|
||||
new_category.groups.size.should == 2
|
||||
end
|
||||
|
||||
it "should preserve group to category association when editing a group" do
|
||||
course_with_teacher_logged_in
|
||||
|
||||
|
|
Loading…
Reference in New Issue