Add students and add relations to selected_course plugin.

This commit is contained in:
BoHung Chiu 2020-09-15 17:02:43 +08:00
parent bf2b6b2d32
commit ceac6ff879
8 changed files with 46 additions and 11 deletions

View File

@ -42,7 +42,8 @@ class PersonalCoursesController < ApplicationController
"course_multimedia_file", "course_multimedia_file",
"course_material_file", "course_material_file",
"course_supplement_file", "course_supplement_file",
"course_evaluation_file" "course_evaluation_file",
"students"
] ]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}

View File

@ -1,10 +1,7 @@
module Admin::CoursesHelper module Admin::CoursesHelper
def page_for_course(course_object) def page_for_course(course_object)
page = nil page = Page.where(:module=>"personal_course").first
pages = Page.where(:module=>"course") ("/#{I18n.locale}"+page.url+'/'+course_object.to_param).gsub('//','/') rescue "#"
page = pages.first if page.nil?
request.protocol+(request.host_with_port+page.url+'/'+course_object.to_param).gsub('//','/') rescue "/"
end end
def get_data_for_excel(year_start,year_end) def get_data_for_excel(year_start,year_end)

View File

@ -8,7 +8,7 @@ class Course
field :title, as: :slug_title, type: String, localize: true field :title, as: :slug_title, type: String, localize: true
field :objective, localize: true field :objective, localize: true
field :year, type: Integer field :year, type: Integer
field :student_ids, type: Array, default: []
has_many :course_syllabus_files, :dependent => :destroy, :autosave => true has_many :course_syllabus_files, :dependent => :destroy, :autosave => true
has_many :course_progress_files, :dependent => :destroy, :autosave => true has_many :course_progress_files, :dependent => :destroy, :autosave => true
has_many :course_activity_files, :dependent => :destroy, :autosave => true has_many :course_activity_files, :dependent => :destroy, :autosave => true
@ -31,7 +31,27 @@ class Course
accepts_nested_attributes_for :course_evaluation_files, :allow_destroy => true accepts_nested_attributes_for :course_evaluation_files, :allow_destroy => true
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc') } scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc') }
before_save do |record|
if !record.student_ids.empty?
selected_course = SelectedCourse rescue nil
if selected_course
record.student_ids.each do |student_id|
selected_course = SelectedCourse.where(:member_profile_id => student_id,:course_id=>self.id).first
if selected_course.nil?
SelectedCourse.create(:member_profile => MemberProfile.find(student_id) , :course_id=>self.id , :year=>self.year,:course_title_translations=>self.title_translations,:course_objective_translations=>self.objective_translations) rescue nil
else
selected_course.update(:year=>self.year,:course_title_translations=>self.title_translations,:course_objective_translations=>self.objective_translations)
end
end
end
end
end
def students
return MemberProfile.where(:id.in=>self.student_ids)
end
def display_students
return MemberProfile.where(:id.in=>self.student_ids).map{|m| m.name}.join(", ")
end
def self.get_plugin_datas_to_member(datas) def self.get_plugin_datas_to_member(datas)
fields_to_show = [ fields_to_show = [
@ -111,6 +131,8 @@ class Course
when "authors" when "authors"
path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#'
value = "<a href='#{path}'>#{self.member_profile.name}</a>" value = "<a href='#{path}'>#{self.member_profile.name}</a>"
when "students"
value = self.display_students
else else
value = self.send(field) rescue "" value = self.send(field) rescue ""
end end

View File

@ -11,5 +11,6 @@
</div> </div>
</td> </td>
<td><%= course.member_profile.name rescue "" %></td> <td><%= course.member_profile.name rescue "" %></td>
<td><%= course.display_students rescue "" %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -65,7 +65,7 @@
<!-- File --> <!-- File -->
<% <%
files_hash = {} files_hash = {}
["course_syllabus_file", "course_progress_file", "course_activity_file", "course_multimedia_file", "course_material_file", "course_supplement_file", "course_evaluation_file"].each do |file| ["selected_course_syllabus_file", "selected_course_progress_file", "selected_course_activity_file", "selected_course_multimedia_file", "selected_course_material_file", "selected_course_supplement_file", "selected_course_evaluation_file"].each do |file|
hash = {} hash = {}
hash["html"] = add_attribute("form_file", f, file.pluralize.to_sym) hash["html"] = add_attribute("form_file", f, file.pluralize.to_sym)
hash["count"] = @course.send(file.pluralize).count rescue 0 hash["count"] = @course.send(file.pluralize).count rescue 0
@ -109,6 +109,9 @@
<li> <li>
<a href="#status" data-toggle="tab"><%= t(:status) %></a> <a href="#status" data-toggle="tab"><%= t(:status) %></a>
</li> </li>
<li>
<a href="#students" data-toggle="tab"><%= t("personal_course.students") %></a>
</li>
</ul> </ul>
<!-- Module --> <!-- Module -->
@ -133,7 +136,7 @@
<label class="control-label muted"><%= t("personal_plugins.author") %></label> <label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls"> <div class="controls">
<% members = !@course.member_profile.nil? ? @course.member_profile.to_a : [] %> <% members = !@course.member_profile.nil? ? @course.member_profile.to_a : [] %>
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[member_profile_id]', email_members: members} %> <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[member_profile_id]', email_members: members,index:'0',select_name:'member_profile_id'} %>
</div> </div>
</div> </div>
@ -176,6 +179,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="tab-pane fade" id="students">
<div class="control-group">
<label class="control-label muted"><%= t("personal_course.students") %></label>
<div class="controls" data-toggle="buttons-checkbox">
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[student_ids][]', email_members: @course.students,index:'1',select_name:'student_ids'} %>
</div>
</div>
</div>
</div> </div>
</div> </div>
<!-- Form Actions --> <!-- Form Actions -->

View File

@ -4,6 +4,7 @@
<th class="span1"><%= t('personal_course.year') %></th> <th class="span1"><%= t('personal_course.year') %></th>
<th class="span7"><%= t('module_name.courses') %></th> <th class="span7"><%= t('module_name.courses') %></th>
<th class="span1"><%= t("personal_plugins.author") %></th> <th class="span1"><%= t("personal_plugins.author") %></th>
<th class="span2"><%= t("personal_course.students") %></th>
</tr> </tr>
</thead> </thead>
<tbody id="tbody_writing_journals" class="sort-holder"> <tbody id="tbody_writing_journals" class="sort-holder">

View File

@ -4,6 +4,7 @@ en:
courses: Courses courses: Courses
course: Course course: Course
personal_course: personal_course:
students: Students
year: Year year: Year
title: Course Title title: Course Title
objective: Objective objective: Objective

View File

@ -4,6 +4,7 @@ zh_tw:
courses: 教學資料 courses: 教學資料
course: 教學資料 course: 教學資料
personal_course: personal_course:
students: 學生
year: 年度 year: 年度
title: 課程名稱 title: 課程名稱
objective: 課程目標 objective: 課程目標