diff --git a/app/coffeescripts/bundles/roster.coffee b/app/coffeescripts/bundles/roster.coffee index 4a01c010f09..85ca95aa23b 100644 --- a/app/coffeescripts/bundles/roster.coffee +++ b/app/coffeescripts/bundles/roster.coffee @@ -22,7 +22,8 @@ require [ 'compiled/collections/UserCollection' 'compiled/collections/SectionCollection' 'compiled/views/courses/RosterView' -], ($, _, UserCollection, SectionCollection, RosterView) -> + 'jst/courses/Roster' +], ($, _, UserCollection, SectionCollection, RosterView, roster) -> # Load environment course = ENV.context_asset_string.split('_')[1] @@ -31,36 +32,29 @@ require [ include: ['avatar_url', 'enrollments', 'email'] per_page: 50 - # Cache elements - $studentList = $('.student_roster .user_list') - $teacherList = $('.teacher_roster .user_list') + sections = new SectionCollection(ENV.SECTIONS) + columns = + students: $('.roster .student_roster') + teachers: $('.roster .teacher_roster') - # Create views - sections = new SectionCollection(ENV.SECTIONS) - students = new UserCollection - teachers = new UserCollection + for roster_data in ENV.COURSE_ROSTERS + users = new UserCollection + users.url = url + users.sections = sections + users.roles = roster_data['roles'] - _.each [students, teachers], (c) -> - c.url = url - c.sections = sections + usersOptions = add: false, data: _.extend({}, fetchOptions, enrollment_role: roster_data['roles']) - studentOptions = add: false, data: _.extend({}, fetchOptions, enrollment_type: 'student') - teacherOptions = add: false, data: _.extend({}, fetchOptions, enrollment_type: ['teacher', 'ta']) + column = columns[roster_data['column']] + html = roster + title: roster_data['title'] + column.append(html) + list = column.find('.user_list').last() - studentView = new RosterView - collection: students - el: $studentList - fetchOptions: studentOptions - teacherView = new RosterView - collection: teachers - el: $teacherList - fetchOptions: teacherOptions - - # Add events - students.on('reset', studentView.render, studentView) - teachers.on('reset', teacherView.render, teacherView) - - # Fetch roster - studentView.$el.disableWhileLoading(students.fetch(studentOptions)) - teacherView.$el.disableWhileLoading(teachers.fetch(teacherOptions)) + usersView = new RosterView + collection: users + el: list + fetchOptions: usersOptions + users.on('reset', usersView.render, usersView) + usersView.$el.disableWhileLoading(users.fetch(usersOptions)) \ No newline at end of file diff --git a/app/coffeescripts/views/courses/RosterView.coffee b/app/coffeescripts/views/courses/RosterView.coffee index 5e0f18a3e64..3d187cae03b 100644 --- a/app/coffeescripts/views/courses/RosterView.coffee +++ b/app/coffeescripts/views/courses/RosterView.coffee @@ -83,7 +83,11 @@ define [ # # Return an array of section names. getSections: (user) -> - sections = _.map user.get('enrollments'), (enrollment) => + enrollments = _.filter(user.get('enrollments'), ((enrollment) -> + _.contains(@roles, enrollment.role)) + , @collection) + + sections = _.map enrollments, (enrollment) => @collection.sections.find (section) -> enrollment.course_section_id == section.id _.uniq(_.map(sections, (section) -> section.get('name'))) diff --git a/app/controllers/context_controller.rb b/app/controllers/context_controller.rb index ca8fa542c6f..6ea4c3eb6bd 100644 --- a/app/controllers/context_controller.rb +++ b/app/controllers/context_controller.rb @@ -304,12 +304,32 @@ class ContextController < ApplicationController if @context.is_a?(Course) sections = @context.course_sections(:select => 'id, name') js_env :SECTIONS => sections.map { |s| { :id => s.id, :name => s.name } } + + all_roles = Role.custom_roles_and_counts_for_course(@context, @current_user) + header_rosters = [ + {:title => t('roster.students', 'Students'), :roles => ['StudentEnrollment'], :column => 'students'}, + {:title => t('roster.teachers', 'Teachers'), :roles => ['TeacherEnrollment'], :column => 'teachers'}, + {:title => t('roster.tas', 'TAs'), :roles => ['TaEnrollment'], :column => 'teachers'} + ] + @display_rosters = [] + + header_rosters.each do |hr| + base_roles = all_roles.select{|r| hr[:roles].include?(r[:base_role_name])} + @display_rosters << hr if base_roles.find{|br| br[:count] && br[:count] > 0}.present? + + base_roles.each do |br| + br[:custom_roles].select{|cr| cr[:count] && cr[:count] > 0}.each do |cr| + @display_rosters << {:title => cr[:label], :roles => [cr[:name]], :column => hr[:column]} + end + end + end + elsif @context.is_a?(Group) @users = @context.participating_users.order_by_sortable_name.uniq @primary_users = { t('roster.group_members', 'Group Members') => @users } if course = @context.context.try(:is_a?, Course) && @context.context - @secondary_users = { t('roster.teachers', 'Teachers & TAs') => course.instructors.order_by_sortable_name.uniq } + @secondary_users = { t('roster.teachers_and_tas', 'Teachers & TAs') => course.instructors.order_by_sortable_name.uniq } end end diff --git a/app/stylesheets/roster.scss b/app/stylesheets/roster.scss index 028b1b80d33..5c44337f6b0 100644 --- a/app/stylesheets/roster.scss +++ b/app/stylesheets/roster.scss @@ -4,7 +4,7 @@ min-width: 515px; overflow: hidden; - .users-wrapper { + .users-column-wrapper { float: left; margin-right: 2%; width: 47%; diff --git a/app/views/context/roster.html.erb b/app/views/context/roster.html.erb index 6c3b53525b0..32c0fa41c8a 100644 --- a/app/views/context/roster.html.erb +++ b/app/views/context/roster.html.erb @@ -10,23 +10,20 @@ <% if @context.is_a?(Course) %>