diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9d54772f8..b9667f080 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -277,9 +277,13 @@ class ApplicationController < ActionController::Base # Find project of id params[:project_id] def find_project_by_project_id - @project = Project.find(params[:project_id]) + if params[:project_id] + @project = Project.find(params[:project_id]) + elsif params[:course_id] + @course = Course.find(params[:course_id]) + end rescue ActiveRecord::RecordNotFound - render_404 + render_404 end # Find a project based on params[:project_id] diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index cdf6e7d5a..ab392789b 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -181,7 +181,7 @@ class BidsController < ApplicationController @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) # @bid. if @homework.save - HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id) + HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id) unless @bid.watched_by?(User.current) if @bid.add_watcher(User.current) flash[:notice] = l(:label_bid_succeed) @@ -191,11 +191,9 @@ class BidsController < ApplicationController else @bid.safe_attributes = params[:bid] @courses = [] - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current)) @membership.each do |membership| - if membership.project.project_type == 1 - @courses << membership.project - end + @courses << membership.course end render :action => 'fork' end @@ -699,7 +697,7 @@ class BidsController < ApplicationController @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) # @bid. if @bid.save - HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id) + HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id) unless @bid.watched_by?(User.current) if @bid.add_watcher(User.current) flash[:notice] = l(:label_bid_succeed) @@ -709,9 +707,9 @@ class BidsController < ApplicationController else @bid.safe_attributes = params[:bid] @homework = @bid - @project = Project.find_by_id(params[:course_id]) - @project_id = @project.id - render file: 'projects/new_homework', layout: 'base_courses' + @course = Course.find_by_id(params[:course_id]) + @course_id = @course.id + render file: 'courses/new_homework', layout: 'base_courses' end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1273a6e59..8ab6d5b62 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,6 +1,7 @@ class CoursesController < ApplicationController include CoursesHelper helper :activities + helper :members menu_item l(:label_sort_by_time), :only => :index menu_item l(:label_sort_by_active), :only => :index @@ -53,6 +54,35 @@ class CoursesController < ApplicationController end end + def update + @course.safe_attributes = params[:course] + @course.class_period = params[:class_period] + if @course.save + if params[:course][:is_public] == '0' + course_status = CourseStatus.find_by_course_id(@course.id) + course_status.destroy if course_status + elsif params[:course][:is_public] == '1' + course_status = CourseStatus.create(:course_id => @course.id, :grade => 0) + end + + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to settings_course_path(@course) + } + format.api { render_api_ok } + end + else + respond_to do |format| + format.html { + settings + render :action => 'settings' + } + format.api { render_validation_errors(@course) } + end + end + end + def handle_course courses, activities course_activity_count_array=activities.values() @@ -71,9 +101,9 @@ class CoursesController < ApplicationController def settings @issue_custom_fields = IssueCustomField.sorted.all @issue_category ||= IssueCategory.new - @member ||= @courses.members.new + @member ||= @course.members.new @trackers = Tracker.sorted.all - end + end def create if User.current.user_extensions.identity @@ -265,7 +295,29 @@ class CoursesController < ApplicationController @bids = @bids.offset(@offset).limit(limit).all.reverse end render :layout => 'base_courses' - end + end + + # 新建作业 + def new_homework + if (User.current.logged? && + (User.current.admin? || + ( + !Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? && + ( + Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles && + ( Role.where(id: [3, 4, 7, 9]).size > 0 ) + ) + ) + ) + ) + @homework = Bid.new + @homework.safe_attributes = params[:bid] + render :layout => 'base_courses' + else + render_404 + end + + end def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index ed6f9937d..048a234f1 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -32,14 +32,16 @@ class FilesController < ApplicationController 'filename' => "#{Attachment.table_name}.filename", 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun - @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort - - if @project.project_type == 1 + + if params[:project_id] + @isproject = true + @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort + @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] + render :layout => !request.xhr? + elsif params[:course_id] + @isproject = false + @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)] render :layout => 'base_courses' - else - render :layout => !request.xhr? end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c508234ae..bf1777508 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -200,7 +200,7 @@ class UsersController < ApplicationController end end - membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current)) + membership = @user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) membership.sort! {|older, newer| newer.created_on <=> older.created_on } @memberships = [] membership.collect { |e| diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index bdc5afbfe..3eed35699 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -31,6 +31,15 @@ module CoursesHelper # searchStudent(project).count end + # 返回课程设置界面 + def course_settings_tabs + tabs = [{:name => 'info', :action => :edit_course, :partial => 'courses/edit', :label => :label_information_plural}, + {:name => 'members', :action => :manage_members, :partial => 'courses/settings/members', :label => :label_member_plural} + ] + tabs.select { |tab| User.current.allowed_to?(tab[:action], @course) } + + end + # garble count 混淆数量 # alias projectCountOrigin projectCount # def projectCount project @@ -38,6 +47,19 @@ module CoursesHelper # garble count # end + def homework_type_option + type = [] + option1 = [] + option2 = [] + option1 << l(:label_task_submit_form_accessory) + option1 << 1 + option2 << l(:label_task_submit_form_project) + option2 << 2 + type << option1 + type << option2 + end + + alias teacherCountOrigin teacherCount def teacherCount project count = teacherCountOrigin project diff --git a/app/models/course.rb b/app/models/course.rb index 36b86b6a9..f282300bc 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -5,7 +5,7 @@ class Course < ActiveRecord::Base STATUS_CLOSED = 5 STATUS_ARCHIVED = 9 - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 @@ -46,8 +46,9 @@ class Course < ActiveRecord::Base 'tea_id', 'password', 'term', - 'password', - 'description' + 'is_public', + 'description', + 'class_period' acts_as_customizable @@ -83,6 +84,20 @@ class Course < ActiveRecord::Base allowed_to_condition(user, :view_course, options) end + + # 获取课程的资源类型列表 + def attachmenttypes + @attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) + end + + # 获取资源后缀名列表 + def contenttypes + attachmenttypes + if @attachmenttypes.length >0 + @attachmenttypes.last().suffixArr + end + end + def active? self.status == STATUS_ACTIVE end @@ -181,11 +196,12 @@ class Course < ActiveRecord::Base if perm && perm.course_module base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')" end - if options[:course] - course_statement = "#{Course.table_name}.id = #{options[:course].id}" - course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses] - base_statement = "(#{course_statement}) AND (#{base_statement})" - end + + if options[:course] + course_statement = "#{Course.table_name}.id = #{options[:course].id}" + course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses] + base_statement = "(#{course_statement}) AND (#{base_statement})" + end if user.admin? base_statement diff --git a/app/views/courses/_edit.html.erb b/app/views/courses/_edit.html.erb new file mode 100644 index 000000000..92f59f85e --- /dev/null +++ b/app/views/courses/_edit.html.erb @@ -0,0 +1,6 @@ +
+<%= labelled_form_for @course do |f| %> + <%= render :partial => 'course_form', :locals => { :f => f } %> + <%= submit_tag l(:button_save) %> +<% end %> +
diff --git a/app/views/projects/_homework_form.html.erb b/app/views/courses/_homework_form.html.erb similarity index 95% rename from app/views/projects/_homework_form.html.erb rename to app/views/courses/_homework_form.html.erb index 13255120f..dc1550a33 100644 --- a/app/views/projects/_homework_form.html.erb +++ b/app/views/courses/_homework_form.html.erb @@ -21,7 +21,7 @@ <%= error_messages_for 'bid' %> - +

<%= l(:label_homeworks_form_new_description) %>

<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %>

@@ -36,7 +36,7 @@

<%= f.select :homework_type, homework_type_option %>

--> -

<%= hidden_field_tag 'course_id', @project.id %> +

<%= hidden_field_tag 'course_id', @course.id %>

<%= l(:label_attachment_plural) %>

<%= render :partial => 'attachments/form', :locals => {:container => @homework} %>

diff --git a/app/views/courses/file.html.erb b/app/views/courses/file.html.erb new file mode 100644 index 000000000..3ea345168 --- /dev/null +++ b/app/views/courses/file.html.erb @@ -0,0 +1 @@ +

文件列表

\ No newline at end of file diff --git a/app/views/projects/homework.html.erb b/app/views/courses/homework.html.erb similarity index 79% rename from app/views/projects/homework.html.erb rename to app/views/courses/homework.html.erb index 0f3d22130..acbbaeb4b 100644 --- a/app/views/projects/homework.html.erb +++ b/app/views/courses/homework.html.erb @@ -7,8 +7,8 @@
- <% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.roles&Role.where(id: [3, 4, 7, 9] )).size >0))%> - <%= link_to(l(:label_course_homework_new), {:controller => 'projects', :action => 'new_homework'}, :class => 'icon icon-add') %> + <% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles&Role.where(id: [3, 4, 7, 9] )).size >0))%> + <%= link_to(l(:label_course_homework_new), {:controller => 'courses', :action => 'new_homework'}, :class => 'icon icon-add') %> <% end %>
@@ -18,7 +18,7 @@
-

课程: <%= @project.name%>

+

课程: <%= @course.name%>

上传作业

diff --git a/app/views/projects/new_homework.html.erb b/app/views/courses/new_homework.html.erb similarity index 100% rename from app/views/projects/new_homework.html.erb rename to app/views/courses/new_homework.html.erb diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb new file mode 100644 index 000000000..c2030ffec --- /dev/null +++ b/app/views/courses/settings.html.erb @@ -0,0 +1,3 @@ +

<%=l(:label_settings)%>

+<%= render_tabs course_settings_tabs %> +<% html_title(l(:label_settings)) -%> diff --git a/app/views/courses/settings/_members.html.erb b/app/views/courses/settings/_members.html.erb new file mode 100644 index 000000000..30a3fbceb --- /dev/null +++ b/app/views/courses/settings/_members.html.erb @@ -0,0 +1,92 @@ +<%= error_messages_for 'member' %> +<% + roles = Role.givable.all + roles = roles[3..5] + members = @course.member_principals.includes(:roles, :principal).all.sort +%> + +
+ <% if members.any? %> + + + + + + + <%= call_hook(:view_projects_settings_members_table_header, :course => @course) %> + + + + <% members.each do |member| %> + <% next if member.new_record? %> + + + + + <% if member.roles.first.to_s == "Manager" %> + + <% else %> + + <% end %> + + <%= call_hook(:view_projects_settings_members_table_header, {:course => @course, :member => member}) %> + + <% end; reset_cycle %> + +
<%= l(:label_user) %><%= l(:label_role_plural) %>
<%= link_to_user member.principal %> + + <%= h member.roles.sort.collect(&:to_s).join(', ') %> + + <%= form_for(member, {:as => :membership, :remote => true, :url => membership_path(member), + :method => :put, + :html => {:id => "member-#{member.id}-roles-form", :class => 'hol'}} + ) do |f| %> + +

+ <% roles.each do |role| %> +
+ <% end %>

+ <%= hidden_field_tag 'membership[role_ids][]', '' %> +

<%= submit_tag l(:button_change), :class => "small" %> + <%= link_to_function l(:button_cancel), + "$('#member-#{member.id}-roles').show(); $('#member-#{member.id}-roles-form').hide(); return false;" + %>

+ <% end %> +
+ <%= link_to_function l(:button_edit), + "$('#member-#{member.id}-roles').hide(); $('#member-#{member.id}-roles-form').show(); return false;", + :class => 'icon icon-edit' %> + <%= delete_link membership_path(member), + :remote => true, + :data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {}) if member.deletable? %> +
+ <% else %> +

<%= l(:label_no_data) %>

+ <% end %> +
+ +
+ <% if roles.any? %> + <%= form_for(@member, {:as => :membership, :url => course_memberships_path(@course), :remote => true, :method => :post}) do |f| %> +
+ <%= l(:label_member_new) %> + +

<%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %>

+ <%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript autocomplete_course_memberships_path(@course, :format => 'js') }')" %> + +
+ <%= render_principals_for_new_members(@course) %> +
+ +

<%= l(:label_role_plural) %>: + <% roles.each do |role| %> + + + <% end %>

+ +

<%= submit_tag l(:button_add), :id => 'member-add-submit' %>

+
+ <% end %> + <% end %> +
diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb new file mode 100644 index 000000000..44970e041 --- /dev/null +++ b/app/views/files/_course_file.html.erb @@ -0,0 +1,71 @@ + +<% attachmenttypes = @course.attachmenttypes %> +<% sufixtypes = @course.contenttypes %> + +<%= t(:label_user_course) %>资源共享区 + +
+ + <%#= link_to(l(:label_attachment_new), 'javascript:void(0);', :onclick=>"$('#file_buttons').slideToggle();", :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @course) %> +
+
+ <%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @course) %> + <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @course) %> + + <% if attachmenttypes.any? %> +       + + <%= select_tag "attachment_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_from_collection_for_select(attachmenttypes, "id", "typeName"), + :onchange => "attachmenttypes_searchex(this.value)" %> + <% end %> + <% if sufixtypes.any? %> +   + + <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), + :onchange => "attachment_contenttypes_searchex(this.value)" %> + <% end %> + + + + +
+ +
+<%= javascript_tag "observeSearchfield('attach_search', null, '#{ escape_javascript attachments_autocomplete_path(:course_id => @course.id, :format => 'js') }')" %> + + +<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> + +
+ <%= render :partial => 'show_all_attachment' %> +
+ +<% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb new file mode 100644 index 000000000..1212db052 --- /dev/null +++ b/app/views/files/_project_file.html.erb @@ -0,0 +1,71 @@ + +<% attachmenttypes = @project.attachmenttypes %> +<% sufixtypes = @project.contenttypes %> + +<%= (@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>资源共享区 + +
+ + <%#= link_to(l(:label_attachment_new), 'javascript:void(0);', :onclick=>"$('#file_buttons').slideToggle();", :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %> +
+
+ <%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @project) %> + <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %> + + <% if attachmenttypes.any? %> +       + + <%= select_tag "attachment_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_from_collection_for_select(attachmenttypes, "id", "typeName"), + :onchange => "attachmenttypes_searchex(this.value)" %> + <% end %> + <% if sufixtypes.any? %> +   + + <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), + :onchange => "attachment_contenttypes_searchex(this.value)" %> + <% end %> + + + + +
+ +
+<%= javascript_tag "observeSearchfield('attach_search', null, '#{ escape_javascript attachments_autocomplete_path(:project_id => @project.id, :format => 'js') }')" %> + + +<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> + +
+ <%= render :partial => 'show_all_attachment' %> +
+ +<% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 9c1eee9d8..3bbc960a4 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,75 +1,10 @@ -<% attachmenttypes = @project.attachmenttypes %> -<% sufixtypes = @project.contenttypes %> +<% if @isproject %> + <%= render :partial => 'project_file', locals: {project: @project} %> +<% else %> + <%= render :partial => 'course_file', locals: {course: @course} %> +<% end %> -<%= (@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>资源共享区 - -
- - <%#= link_to(l(:label_attachment_new), 'javascript:void(0);', :onclick=>"$('#file_buttons').slideToggle();", :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %> -
-
- <%#= link_to('上传文件', new_project_file_path(@project), :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %> - <%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @project) %> - <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %> - - <% if attachmenttypes.any? %> -       - - <%= select_tag "attachment_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_from_collection_for_select(attachmenttypes, "id", "typeName"), - :onchange => "attachmenttypes_searchex(this.value)" %> - <% end %> - <% if sufixtypes.any? %> -   - - <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), - :onchange => "attachment_contenttypes_searchex(this.value)" %> - <% end %> - - - - -
- -
-<%= javascript_tag "observeSearchfield('attach_search', null, '#{ escape_javascript attachments_autocomplete_path(:project_id => @project.id, :format => 'js') }')" %> - - -<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> - -
- <%= render :partial => 'show_all_attachment' %> -
- -<% html_title(l(:label_attachment_plural)) -%>