Add students and add relations to selected_course plugin.
This commit is contained in:
parent
bf2b6b2d32
commit
ceac6ff879
|
@ -42,7 +42,8 @@ class PersonalCoursesController < ApplicationController
|
|||
"course_multimedia_file",
|
||||
"course_material_file",
|
||||
"course_supplement_file",
|
||||
"course_evaluation_file"
|
||||
"course_evaluation_file",
|
||||
"students"
|
||||
]
|
||||
|
||||
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
module Admin::CoursesHelper
|
||||
def page_for_course(course_object)
|
||||
page = nil
|
||||
pages = Page.where(:module=>"course")
|
||||
|
||||
page = pages.first if page.nil?
|
||||
request.protocol+(request.host_with_port+page.url+'/'+course_object.to_param).gsub('//','/') rescue "/"
|
||||
page = Page.where(:module=>"personal_course").first
|
||||
("/#{I18n.locale}"+page.url+'/'+course_object.to_param).gsub('//','/') rescue "#"
|
||||
end
|
||||
|
||||
def get_data_for_excel(year_start,year_end)
|
||||
|
|
|
@ -8,7 +8,7 @@ class Course
|
|||
field :title, as: :slug_title, type: String, localize: true
|
||||
field :objective, localize: true
|
||||
field :year, type: Integer
|
||||
|
||||
field :student_ids, type: Array, default: []
|
||||
has_many :course_syllabus_files, :dependent => :destroy, :autosave => true
|
||||
has_many :course_progress_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
|
||||
|
||||
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)
|
||||
|
||||
fields_to_show = [
|
||||
|
@ -111,6 +131,8 @@ class Course
|
|||
when "authors"
|
||||
path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#'
|
||||
value = "<a href='#{path}'>#{self.member_profile.name}</a>"
|
||||
when "students"
|
||||
value = self.display_students
|
||||
else
|
||||
value = self.send(field) rescue ""
|
||||
end
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
</div>
|
||||
</td>
|
||||
<td><%= course.member_profile.name rescue "" %></td>
|
||||
<td><%= course.display_students rescue "" %></td>
|
||||
</tr>
|
||||
<% end %>
|
|
@ -65,7 +65,7 @@
|
|||
<!-- File -->
|
||||
<%
|
||||
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["html"] = add_attribute("form_file", f, file.pluralize.to_sym)
|
||||
hash["count"] = @course.send(file.pluralize).count rescue 0
|
||||
|
@ -109,6 +109,9 @@
|
|||
<li>
|
||||
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#students" data-toggle="tab"><%= t("personal_course.students") %></a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Module -->
|
||||
|
@ -133,7 +136,7 @@
|
|||
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
|
||||
<div class="controls">
|
||||
<% 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>
|
||||
|
||||
|
@ -176,6 +179,14 @@
|
|||
</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>
|
||||
<!-- Form Actions -->
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<th class="span1"><%= t('personal_course.year') %></th>
|
||||
<th class="span7"><%= t('module_name.courses') %></th>
|
||||
<th class="span1"><%= t("personal_plugins.author") %></th>
|
||||
<th class="span2"><%= t("personal_course.students") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody_writing_journals" class="sort-holder">
|
||||
|
|
|
@ -4,6 +4,7 @@ en:
|
|||
courses: Courses
|
||||
course: Course
|
||||
personal_course:
|
||||
students: Students
|
||||
year: Year
|
||||
title: Course Title
|
||||
objective: Objective
|
||||
|
|
|
@ -4,6 +4,7 @@ zh_tw:
|
|||
courses: 教學資料
|
||||
course: 教學資料
|
||||
personal_course:
|
||||
students: 學生
|
||||
year: 年度
|
||||
title: 課程名稱
|
||||
objective: 課程目標
|
||||
|
|
Loading…
Reference in New Issue