diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3a81d36d..7cd46b65 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -546,22 +546,47 @@ class CoursesController < ApplicationController end end + def get_courses + @user = User.current + membership = @user.coursememberships.all + membership.sort! {|older, newer| newer.created_on <=> older.created_on } + @memberships = [] + membership.collect { |e| + @memberships.push(e) + } + @memberships_doing = [] + @memberships_done = [] + now_time = Time.now.year + @memberships.map { |e| + end_time = e.course.get_time.year + isDone = course_endTime_timeout?(e.course) + if isDone + @memberships_done.push e + else + @memberships_doing.push e + end + } + end + def finishcourse yesterday = Date.today.prev_day.to_time @course_prefs.endup_time = yesterday @save_flag = @course_prefs.save + get_courses respond_to do |format| format.js end end + def restartcourse day = Time.parse("3000-01-01") @course_prefs.endup_time = day @save_flag = @course_prefs.save + get_courses respond_to do |format| format.js { diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c35edfa1..2a408788 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -68,6 +68,9 @@ class MessagesController < ApplicationController call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) render_attachment_warning_if_needed(@message) redirect_to board_message_path(@board, @message) + else + layout_file = @project ? 'base_projects' : 'base_courses' + render :action => 'new', :layout => layout_file end end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index f91bc401..8bce84f9 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -116,7 +116,7 @@ class NewsController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_to project_news_index_path(@project) else - layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects' + layout_file = @project ? 'base_projects' : 'base_courses' render :action => 'new', :layout => layout_file end elsif @course diff --git a/app/models/attachment.rb b/app/models/attachment.rb index fe3ff841..94f8f7c9 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -129,7 +129,7 @@ class Attachment < ActiveRecord::Base nil end - def filename=(arg) + def filename=(arg) write_attribute :filename, sanitize_filename(arg.to_s) filename end diff --git a/app/models/course.rb b/app/models/course.rb index 2dfb6ae4..51b11867 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -33,8 +33,9 @@ class Course < ActiveRecord::Base acts_as_attachable :view_permission => :view_files, :delete_permission => :manage_files - validates_presence_of :password, :term + validates_presence_of :password, :term,:name validates_format_of :class_period, :with =>/^[1-9]\d*$/ + validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/ after_save :create_board_sync before_destroy :delete_all_members diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 512a6d8b..58880919 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -33,9 +33,13 @@ class JournalsForMessage < ActiveRecord::Base :description => Proc.new{|o| o.notes }, :type => Proc.new {|o| o.jour_type }, :url => Proc.new {|o| - (o.jour.kind_of? Project) ? {:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} : {} - }#{:controller => 'documents', :action => 'show', :id => o.id}} - acts_as_activity_provider :author_key => :user_id, + if o.jour.kind_of? Project + {:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} + elsif o.jour.kind_of? Course + {:controller => 'courses', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} + end + } + acts_as_activity_provider :author_key => :user_id, :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :project } diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 1635d612..6371fc12 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -53,7 +53,7 @@ class UserScore < ActiveRecord::Base user_score = current_user.user_score_attr user_grade = nil #项目个人得分 project = obj.project - unless project.nil? && project.project_type == 0 + unless project.nil? user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id) if user_grade.nil? user_grade = UserGrade.create(:user_id => current_user.id,:project_id => project.id) @@ -178,7 +178,7 @@ class UserScore < ActiveRecord::Base current_user_grade = nil #项目个人得分 target_user_grade = nil project = obj.project - unless project.nil? && project.project_type == 0 + unless project.nil? current_user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id) target_user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) if current_user_grade.nil? @@ -285,7 +285,7 @@ class UserScore < ActiveRecord::Base user_score = current_user.try(:user_score_attr) user_grade = nil #项目个人得分 project = obj.project - unless project.nil? && project.project_type == 0 + unless project.nil? user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id) if user_grade.nil? user_grade = UserGrade.create(:user_id => current_user.id,:project_id => project.id) diff --git a/app/views/courses/_course_form.html.erb b/app/views/courses/_course_form.html.erb index ddcad7b9..2e7607bb 100644 --- a/app/views/courses/_course_form.html.erb +++ b/app/views/courses/_course_form.html.erb @@ -18,7 +18,6 @@ <% object = [] %> <% object << 'course' %> -<% object << 'course' %> <%= error_messages_for object %> diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index e356c22e..a8a9e808 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -6,7 +6,11 @@ <%= content_tag "p", "#{format_date(member.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %> <% end %> <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :class => 'avatar')) %> - <%= content_tag "div", link_to(member.user.name, user_path(member.user)), :class => "nomargin avatar_name" %> + <% if @canShowCode %> + <%= content_tag "div", link_to(member.user.show_name, user_path(member.user)), :class => "nomargin avatar_name" %> + <% else %> + <%= content_tag "div", link_to(member.user.name, user_path(member.user)), :class => "nomargin avatar_name" %> + <% end %> <% unless member.user.user_extensions.identity ==0 %> diff --git a/app/views/courses/finishcourse.js.erb b/app/views/courses/finishcourse.js.erb index 025edb05..e6742695 100644 --- a/app/views/courses/finishcourse.js.erb +++ b/app/views/courses/finishcourse.js.erb @@ -1,8 +1,12 @@ <% if @save_flag %> - <% if Rails.env.development? %> - console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>'); - <% end %> - $('#finish_course_<%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>") +<% if Rails.env.development? %> +console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>'); +<% end %> +$('#content-title-top-div').html("<%= j(render partial: 'users/my_course_ex', :locals => {:memberships => @memberships,:user=>@user, +:memberships_doing=>@memberships_doing,:memberships_done=>@memberships_done} )%>") +//$('#finish_course_ <%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>") <% else %> - alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。'); +alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。'); <% end %> + + diff --git a/app/views/courses/new_homework.html.erb b/app/views/courses/new_homework.html.erb index 335ce910..ec25cef0 100644 --- a/app/views/courses/new_homework.html.erb +++ b/app/views/courses/new_homework.html.erb @@ -1,5 +1,6 @@
diff --git a/app/views/users/_my_course_ex.html.erb b/app/views/users/_my_course_ex.html.erb new file mode 100644 index 00000000..839b2863 --- /dev/null +++ b/app/views/users/_my_course_ex.html.erb @@ -0,0 +1,33 @@ +<% if memberships.empty? %> + <% if user != User.current %> +
+ <%= l(:label_project_course_un) %> +
+ <% else %> ++ + <%= l(:label_project_course_unadd) %><%= link_to "#{l(:label_course_new)}", {:controller => 'courses', :action => 'new'}, :class => 'icon icon-add' %> +
+ <% end %> +<% else %> + <%= render partial: 'users/course_list_have_entity_ex',:locals => {:user => user,:memberships_doing=>memberships_doing,:memberships_done=>memberships_done} %> +<% end %> + + \ No newline at end of file