diff --git a/app/controllers/admin/selected_courses_controller.rb b/app/controllers/admin/selected_courses_controller.rb
index 298dd12..08a012d 100644
--- a/app/controllers/admin/selected_courses_controller.rb
+++ b/app/controllers/admin/selected_courses_controller.rb
@@ -2,6 +2,7 @@ class Admin::SelectedCoursesController < OrbitMemberController
include Admin::SelectedCoursesHelper
layout "member_plugin"
before_action :set_course, only: [:show, :edit , :update, :destroy]
+ before_action :set_course_assignment, only: [:new_assignment, :edit_assignment , :update_assignment]
before_action :set_plugin
before_action :get_settings,:only => [:new, :edit, :setting]
@@ -11,7 +12,32 @@ class Admin::SelectedCoursesController < OrbitMemberController
def index
@selected_courses = SelectedCourse.order_by(:created_at=>'desc').page(params[:page]).per(10)
end
-
+ def show_assignments
+ @course_assignments = CourseAssignment.where(:course_id=>params[:id]).enabled_for_student.page(params[:page]).per(10)
+ @course = Course.find(params[:id]) rescue nil
+ @member_profile = MemberProfile.where(:uid=>params[:member_profile_uid]).first
+ end
+ def edit_assignment
+ @student_assignment = StudentAssignment.find(params[:id])
+ end
+ def update_assignment
+ @student_assignment = StudentAssignment.find(params[:id])
+ @student_assignment.update_attributes(student_assignment_params)
+ @student_assignment.save
+ redirect_to params[:referer_url]
+ end
+ def new_assignment
+ @student_assignment = StudentAssignment.new
+ end
+ def create_assignment
+ #render :html => params and return
+ student_assignment = StudentAssignment.create(student_assignment_params)
+ redirect_to params[:referer_url]
+ end
+ def destroy_assignment
+ @student_assignment.destroy
+ redirect_to course_assignments_admin_courses_path(:page => params[:page])
+ end
def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@selected_course = SelectedCourse.new
@@ -93,13 +119,12 @@ class Admin::SelectedCoursesController < OrbitMemberController
end
private
-
+ def student_assignment_params
+ student_assignment_params = params.require(:student_assignment).permit!
+ return student_assignment_params
+ end
def selected_course_params
- selected_course_params = params.require(:selected_course).permit!
- if selected_course_params["member_profile_id"].nil?
- selected_course_params["member_profile_id"] = nil
- end
- return selected_course_params
+ params.require(:selected_course).permit!
end
def intro_params
@@ -117,13 +142,34 @@ class Admin::SelectedCoursesController < OrbitMemberController
def set_course
path = request.path.split('/')
- if path.last.include? '-'
- uid = path[-1].split("-").last
- uid = uid.split("?").first
- else
- uid = path[-2].split("-").last
- uid = uid.split("?").first
- end
- @selected_course = SelectedCourse.find_by(:uid => uid) rescue SelectedCourse.find(params[:id])
+ if params[:uid].nil?
+ if path.last.include? '-'
+ uid = path[-1].split("-").last
+ uid = uid.split("?").first
+ else
+ uid = path[-2].split("-").last
+ uid = uid.split("?").first
+ end
+ else
+ uid = params[:uid]
+ end
+ @selected_course = SelectedCourse.find_by(:uid => uid) rescue SelectedCourse.find(params[:id])
+ end
+ def set_course_assignment
+ path = request.path.split('/')
+ if params[:uid].nil?
+ if path.last.include? '-'
+ uid = path[-1].split("-").last
+ uid = uid.split("?").first
+ else
+ uid = path[-2].split("-").last
+ uid = uid.split("?").first
+ end
+ else
+ uid = params[:uid]
+ end
+ @course_assignment = CourseAssignment.find_by(:uid => uid) rescue CourseAssignment.find(params[:id])
+ @closed = (@course_assignment.deadline < DateTime.now) rescue false
+ @member_profile = MemberProfile.where(:uid=>params[:member_profile_uid]).first
end
end
\ No newline at end of file
diff --git a/app/models/student_assignment.rb b/app/models/student_assignment.rb
new file mode 100644
index 0000000..5227cff
--- /dev/null
+++ b/app/models/student_assignment.rb
@@ -0,0 +1,19 @@
+class StudentAssignment
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Slug
+ field :assignment_content, as: :slug_title, type: String, localize: true, default: ""
+ has_many :student_assignment_files, :dependent => :destroy, :autosave => true
+ accepts_nested_attributes_for :student_assignment_files, :allow_destroy => true
+ belongs_to :course_assignment
+ belongs_to :member_profile
+ def display_created_at
+ self.created_at.strftime("%Y-%m-%d %H:%M")
+ end
+ def display_updated_at
+ self.updated_at.strftime("%Y-%m-%d %H:%M")
+ end
+ def display_student_assignment_files
+ self.student_assignment_files.map{|f| "#{f.title} "}.join(" ").html_safe
+ end
+end
\ No newline at end of file
diff --git a/app/models/student_assignment_file.rb b/app/models/student_assignment_file.rb
new file mode 100644
index 0000000..a29dc76
--- /dev/null
+++ b/app/models/student_assignment_file.rb
@@ -0,0 +1,12 @@
+class StudentAssignmentFile
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :title, localize: true
+ field :description, localize: true
+ field :should_destroy, :type => Boolean
+
+ mount_uploader :file, AssetUploader
+
+ belongs_to :student_assignment
+end
\ No newline at end of file
diff --git a/app/views/admin/selected_courses/_form_assignment.html.erb b/app/views/admin/selected_courses/_form_assignment.html.erb
new file mode 100644
index 0000000..c165187
--- /dev/null
+++ b/app/views/admin/selected_courses/_form_assignment.html.erb
@@ -0,0 +1,236 @@
+<% # encoding: utf-8 %>
+<% content_for :page_specific_css do %>
+ <%= stylesheet_link_tag "lib/main-forms" %>
+ <%= stylesheet_link_tag "lib/fileupload" %>
+ <%= stylesheet_link_tag "lib/main-list" %>
+ <%= stylesheet_link_tag "lib/main-form-col2" %>
+
+<% end %>
+<% content_for :page_specific_javascript do %>
+ <%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
+ <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
+ <%= javascript_include_tag "lib/bootstrap-fileupload" %>
+ <%= javascript_include_tag "lib/file-type" %>
+ <%= javascript_include_tag "lib/module-area" %>
+<% end %>
+<% if @student_assignment.new_record? %>
+ <%= f.hidden_field :course_assignment_id,:value=>@course_assignment.id.to_s %>
+<% end %>
+
+ <%= @course_assignment.course.title rescue "" %>-<%= @course_assignment.name rescue "" %>
+
+
+
+
+
+ <% ["course_attachment"].each do |file| %>
+
+
<%= t("personal_course.#{file}") %>
+
+ <%= @course_assignment.send("display_"+file.pluralize.gsub('course_','')) rescue "" %>
+
+
+ <% end %>
+
+
+
+ <%= t("personal_course.assign_date") %>
+
+
+
+
+ <%= @course_assignment.display_assign_date %>
+
+
+
+
+
+ <%= t("personal_course.deadline") %>
+
+
+
+ <%= @course_assignment.display_deadline %>
+
+
+
+
+
+
+
+ <%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %>
+
+ <% if !@closed %>
+ <%= f.submit t('submit'), class: 'btn btn-primary' %>
+ <%= link_to t('cancel'), request.referer, :class=>"btn" %>
+ <% else %>
+ <%= link_to t('personal_selected_course.back'), request.referer, :class=>"btn" %>
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/selected_courses/_selected_courses.html.erb b/app/views/admin/selected_courses/_selected_courses.html.erb
index c608904..dff9d39 100644
--- a/app/views/admin/selected_courses/_selected_courses.html.erb
+++ b/app/views/admin/selected_courses/_selected_courses.html.erb
@@ -2,6 +2,7 @@
<% host_url = protocol+(request.host_with_port) %>
<% @selected_courses.each do |selected_course| %>
+ <% member_profile = selected_course.member_profile %>
<%= selected_course.year %>
<%= link_to selected_course.course_title, page_for_selected_course(selected_course), target: "blank"%>
@@ -11,6 +12,13 @@
<%= link_to t(:delete_), admin_selected_course_path(id: selected_course.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %>
+
+ <% if member_profile.present? %>
+ <%= link_to CourseAssignment.where(:course_id=>selected_course.course_id).enabled_for_student.count,show_assignments_admin_selected_courses_path(:id=> selected_course.course_id,:member_profile_name=> member_profile.name,:member_profile_uid=> member_profile.uid) %>
+ <% else %>
+ 0
+ <% end %>
+
<% course_url = selected_course.course_url %>
<% if selected_course.course %>
@@ -22,6 +30,6 @@
<%=selected_course.other_course_url%>
<% end %>
- <%= selected_course.member_profile.name rescue "" %>
+ <%= member_profile.name rescue "" %>
<% end %>
\ No newline at end of file
diff --git a/app/views/admin/selected_courses/edit_assignment.html.erb b/app/views/admin/selected_courses/edit_assignment.html.erb
new file mode 100644
index 0000000..8b589f1
--- /dev/null
+++ b/app/views/admin/selected_courses/edit_assignment.html.erb
@@ -0,0 +1,5 @@
+<%= form_for @student_assignment, url: update_assignment_admin_selected_courses_path(:name=>@course_assignment.name,:uid=>@course_assignment.uid), html: {class: "form-horizontal main-forms previewable"} do |f| %>
+
+ <%= render partial: 'form_assignment', locals: {f: f} %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/selected_courses/index.html.erb b/app/views/admin/selected_courses/index.html.erb
index 7f001bf..d1229d7 100644
--- a/app/views/admin/selected_courses/index.html.erb
+++ b/app/views/admin/selected_courses/index.html.erb
@@ -2,7 +2,8 @@
<%= t('personal_selected_course.year') %>
- <%= t('module_name.selected_courses') %>
+ <%= t('personal_selected_course.name') %>
+ <%= t('personal_selected_course.course_assignment') %>
<%= t("personal_selected_course.course_url") %>
<%= t("personal_selected_course.course_student") %>
diff --git a/app/views/admin/selected_courses/new_assignment.html.erb b/app/views/admin/selected_courses/new_assignment.html.erb
new file mode 100644
index 0000000..b057a54
--- /dev/null
+++ b/app/views/admin/selected_courses/new_assignment.html.erb
@@ -0,0 +1,5 @@
+<%= form_for @student_assignment, url: create_assignment_admin_selected_courses_path, html: {class: "form-horizontal main-forms previewable"} do |f| %>
+
+ <%= render partial: 'form_assignment', locals: {f: f} %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/selected_courses/show_assignments.html.erb b/app/views/admin/selected_courses/show_assignments.html.erb
new file mode 100644
index 0000000..4b1b4d3
--- /dev/null
+++ b/app/views/admin/selected_courses/show_assignments.html.erb
@@ -0,0 +1,93 @@
+<%=t("personal_selected_course.assignment_delivery_area")%>-<%=@course.title rescue "" %>
+
+
+
+ <%= t("personal_course.name") %>
+ <%= t("personal_course.detail") %>
+ <%= t("personal_course.course_attachment") %>
+
+ <%= t("personal_course.assign_date") %>
+
+
+
+
+
+
<%= t("personal_course.assign_date_hint") %>
+
+
+
+
+
+
+ <%= t("personal_course.deadline") %>
+
+
+
+
+
+
<%= t("personal_course.deadline_hint") %>
+
+
+
+
+
+ <%= t("personal_selected_course.status") %>
+
+
+
+ <% @course_assignments.each do |course_assignment| %>
+ <% student_assignment = StudentAssignment.where(:course_assignment_id=> course_assignment.id,:member_profile_id=>@member_profile.id).first %>
+ <% closed = (course_assignment.deadline < DateTime.now) rescue false %>
+
+
+ <%= course_assignment.name %>
+
+ <% if !closed %>
+
+ <% if student_assignment.nil? %>
+ <%= link_to t('new_'), new_assignment_admin_selected_courses_path(:uid=>course_assignment.uid,:name=>course_assignment.name,:page => params[:page]) %>
+ <% else %>
+ <%= link_to t('edit'), edit_assignment_admin_selected_courses_path(:uid=>course_assignment.uid,:name=>course_assignment.name,:page => params[:page],:id=>student_assignment.id) %>
+ <% end %>
+
+ <% else %>
+
<%=t('personal_selected_course.closed')%>
+
+ <% if student_assignment.nil? %>
+ <%= link_to t('personal_selected_course.view'), new_assignment_admin_selected_courses_path(:uid=>course_assignment.uid,:name=>course_assignment.name,:page => params[:page]) %>
+ <% else %>
+ <%= link_to t('personal_selected_course.view'), edit_assignment_admin_selected_courses_path(:uid=>course_assignment.uid,:name=>course_assignment.name,:page => params[:page],:id=>student_assignment.id) %>
+ <% end %>
+
+ <% end %>
+
+
+ <%= course_assignment.detail %>
+ <%= course_assignment.display_attachments %>
+ <%= course_assignment.display_assign_date %>
+ <%= course_assignment.display_deadline %>
+ <%= student_assignment.nil? ? "#{t("personal_selected_course.not_yet_deliver")} ".html_safe : ("#{t("personal_selected_course.already_deliver")} "+"#{t('personal_selected_course.last_updated_date')}:#{student_assignment.display_updated_at} ").html_safe %>
+
+ <% end %>
+
+
+
+
+
+ <%#= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_assignment_admin_courses_path(:id=>params[:id]), :class => 'btn btn-primary' %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/plugin/personal_selected_course/_profile.html.erb b/app/views/plugin/personal_selected_course/_profile.html.erb
index ac44cb3..bdcc4cf 100644
--- a/app/views/plugin/personal_selected_course/_profile.html.erb
+++ b/app/views/plugin/personal_selected_course/_profile.html.erb
@@ -30,6 +30,7 @@
<% end -%>
<%= t('personal_selected_course.year') %>
<%= t('personal_selected_course.course_title') %>
+ <%= t('personal_selected_course.course_assignment') %>
<%= t('personal_selected_course.selected_course_category') %>
@@ -53,6 +54,7 @@
+ <%= link_to CourseAssignment.where(:course_id=>selected_course.course_id).enabled_for_student.count,show_assignments_admin_selected_courses_path(:id=> selected_course.course_id,:member_profile_name=> params[:name],:member_profile_uid=> params[:uid]) %>
<%= selected_course.course.course_category.title rescue "" %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1b5c6bc..cad5ccb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -4,6 +4,18 @@ en:
selected_courses: Selected Courses
selected_course: Selected Course
personal_selected_course:
+ name: Selected Courses Name
+ view: View
+ status: Status
+ closed: Closed
+ back: Back
+ already_deliver: Already deliver
+ not_yet_deliver: Not yet deliver
+ last_updated_date: Last updated date
+ assignment_delivery_area: Assignment delivery area
+ course_assignment: Assignments
+ assignment_content: Assignment Content
+ student_assignment_file: Assignment file
course_student: Student
students: Students
year: Year
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index e2267c4..7a6cf3d 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -4,6 +4,18 @@ zh_tw:
selected_courses: 修習課程
selected_course: 修習課程
personal_selected_course:
+ name: 修習課程名稱
+ view: 查看
+ status: 狀態
+ closed: 已關閉
+ back: 回上一頁
+ already_deliver: 已繳交
+ not_yet_deliver: 未繳交
+ last_updated_date: 最後更改時間
+ assignment_delivery_area: 作業繳交區
+ course_assignment: 作業
+ assignment_content: 繳交內容
+ student_assignment_file: 繳交檔案
course_student: 修課學生
students: 學生
year: 年度
diff --git a/config/routes.rb b/config/routes.rb
index c74e833..8cd5d57 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,8 +9,21 @@ Rails.application.routes.draw do
get 'analysis'
get 'analysis_report'
get "download_excel"
- end
- end
+ scope ':member_profile_name-:member_profile_uid' do
+ get 'show_assignments'
+ end
+ #delete 'destroy_assignment'
+ post 'create_assignment'
+ scope '(:name-:uid)' do
+ scope ':member_profile_name-:member_profile_uid' do
+ get 'new_assignment'
+ get 'edit_assignment'
+ patch 'update_assignment'
+ put 'update_assignment'
+ end
+ end
+ end
+ end
resources :members do
collection do
diff --git a/personal_selected_course/index.html.erb b/personal_selected_course/index.html.erb
new file mode 100644
index 0000000..366621d
--- /dev/null
+++ b/personal_selected_course/index.html.erb
@@ -0,0 +1,22 @@
+
+ {{widget-title}}
+
+
+ {{th_year}}
+ {{th_course_title}}
+ {{th_course_category}}
+ {{th_course_semester}}
+ {{th_authors}}
+
+
+
+
+ {{year}}
+ {{course_title}}
+ {{category}}
+ {{semester}}
+ {{authors}}
+
+
+
+{{pagination_goes_here}}
\ No newline at end of file
diff --git a/personal_selected_course/info.json b/personal_selected_course/info.json
new file mode 100644
index 0000000..cda3d13
--- /dev/null
+++ b/personal_selected_course/info.json
@@ -0,0 +1,12 @@
+{
+ "frontend": [
+ {
+ "filename" : "index",
+ "name" : {
+ "zh_tw" : "1. 列表",
+ "en" : "1. List"
+ },
+ "thumbnail" : "thumb.png"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/personal_selected_course/show.html.erb b/personal_selected_course/show.html.erb
new file mode 100644
index 0000000..34b30df
--- /dev/null
+++ b/personal_selected_course/show.html.erb
@@ -0,0 +1,5 @@
+
+
+ {{title}} {{value}}
+
+
\ No newline at end of file
diff --git a/personal_selected_course/thumbs/thumb.png b/personal_selected_course/thumbs/thumb.png
new file mode 100644
index 0000000..266af56
Binary files /dev/null and b/personal_selected_course/thumbs/thumb.png differ