Browse Source

Make course member list more compact

Frans Bergman 7 years ago
parent
commit
a39b9f3aab

+ 2 - 0
app/models/course_participation.rb

@@ -8,4 +8,6 @@ class CourseParticipation < ApplicationRecord
 
   scope :teachers, -> { where(role: :teacher) }
   scope :students, -> { where(role: :student) }
+
+  default_scope { order(role: :desc) }
 end

+ 1 - 1
app/views/course_participations/_form.html.erb

@@ -1,8 +1,8 @@
 <%= bootstrap_form_for(@course.course_participations.build, html: { class: "form-inline" }) do |f| %>
   <%= render 'shared/error_messages', object: f.object %>
   <%= f.hidden_field :course_id, value: @course.id %>
-  <%= f.hidden_field :role, value: role %>
 
+  <%= f.select :role, collection: CourseParticipation.roles.keys.to_a %>
   <%= f.select :user_id, options_for_select(User.where.not(id: @course.users.map(&:id)).map{ |user| [user.name, user.id] }) %>
 
   <%= f.submit "Add user", class: "btn btn-primary" %>

+ 8 - 5
app/views/courses/_participants_panel.html.erb

@@ -1,17 +1,20 @@
 <div class="panel panel-primary">
   <div class="panel-heading">
-    <%= role.to_s.capitalize.pluralize %>
+    Course Members
   </div>
   <table class="panel-body table table-striped table-bordered table-hover">
     <tbody>
-      <% for user in users %>
+      <% for course_participation in @course.course_participations %>
         <tr>
           <td>
-            <%= render user %>
+            <%= render course_participation.user %>
+          </td>
+          <td>
+            <%= course_participation.role.to_s.capitalize %>
           </td>
           <% if current_user.is_administrator_at?(@course.school) || current_user.admin? %>
             <td>
-              <%= form_for @course.course_participations.find_by(user_id: user.id), html: { method: :delete } do |f| %>
+              <%= form_for course_participation, html: { method: :delete } do |f| %>
                 <%= f.submit "Remove", class: "btn btn-danger" %>
               <% end %>
             </td>
@@ -22,7 +25,7 @@
   </table>
   <div class="panel-footer">
     <% if current_user.is_administrator_at?(@course.school) || current_user.admin? %>
-      <%= render partial: 'course_participations/form', locals: { role: role } %>
+      <%= render partial: 'course_participations/form' %>
     <% end %>
   </div>
 </div>

+ 1 - 2
app/views/courses/show.html.erb

@@ -6,8 +6,7 @@
 </div>
 <div class="row">
   <div class="col-md-6">
-    <%= render partial: 'participants_panel', locals: { users: @course.users.merge(CourseParticipation.teachers), role: :teacher } %>
-    <%= render partial: 'participants_panel', locals: { users: @course.users.merge(CourseParticipation.students), role: :student } %>
+    <%= render partial: 'participants_panel' %>
     <div class="panel panel-default">
       <div class="panel-heading">
         Lectures