From 4e815a38b63878d41a033e0f094ed1b955443c3a Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 29 May 2014 15:21:22 +0800 Subject: [PATCH 01/82] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=8C=E8=AF=BE=E7=A8=8B=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=8C=85=E5=90=AB=E5=9C=A8=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{projects => courses}/_course.html.erb | 0 .../_course_form.html.erb | 0 config/routes.rb | 21 ++++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) rename app/views/{projects => courses}/_course.html.erb (100%) rename app/views/{projects => courses}/_course_form.html.erb (100%) diff --git a/app/views/projects/_course.html.erb b/app/views/courses/_course.html.erb similarity index 100% rename from app/views/projects/_course.html.erb rename to app/views/courses/_course.html.erb diff --git a/app/views/projects/_course_form.html.erb b/app/views/courses/_course_form.html.erb similarity index 100% rename from app/views/projects/_course_form.html.erb rename to app/views/courses/_course_form.html.erb diff --git a/config/routes.rb b/config/routes.rb index 05041ac98..c3239154c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -261,8 +261,6 @@ RedmineApp::Application.routes.draw do end resources :projects do member do - post 'finishcourse' - post 'restartcourse' get 'settings(/:tab)', :action => 'settings', :as => 'settings' #by young get 'member', :controller => 'projects', :action => 'member', :as => 'member' @@ -539,6 +537,20 @@ RedmineApp::Application.routes.draw do end end + # add by nwb + # 课程路由设置 + resources :course do + member do + # 之前在项目 + post 'finishcourse' + post 'restartcourse' + end + end + #match 'project/enterprise_course', :to => 'projects#enterprise_course' + #match 'project/course_enterprise', :to => 'projects#course_enterprise' + #match 'project/course', :to => 'projects#course', :as => 'course' + + match 'workflows', :controller => 'workflows', :action => 'index', :via => :get match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post] match 'workflows/permissions', :controller => 'workflows', :action => 'permissions', :via => [:get, :post] @@ -590,8 +602,7 @@ RedmineApp::Application.routes.draw do match 'calls/:id/homework_statistics', :to => 'bids#homework_statistics' match 'calls/:id/fork', :to => 'bids#fork', :as => 'fork' match 'calls/:id/create_fork', :to => 'bids#create_fork' - match 'project/enterprise_course', :to => 'projects#enterprise_course' - match 'project/course_enterprise', :to => 'projects#course_enterprise' + match 'calls/:id/show_course', :to => 'bids#show_course', :as => 'show_course' match 'calls/:id/show_bid_project', :to => 'bids#show_bid_project', :as => 'show_bid_project' match 'calls/:id/show_bid_user', :to => 'bids#show_bid_user', :as => 'show_bid_user' @@ -611,7 +622,7 @@ RedmineApp::Application.routes.draw do match 'new_join_in_contest', :to => 'bids#new_join', :as => 'try_join_in_contest' match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post match 'calls/:id/manage',:to => 'bids#manage',:via => [:get,:post] - match 'project/course', :to => 'projects#course', :as => 'course' + #added by william # match 'calls/:id/set_results',:controller => 'bids', :action => 'set_results',:via => [:get,:post],:as => 'set_results' From f936c30ec93df7c0a85a494e82791392c48bdf04 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 29 May 2014 16:35:34 +0800 Subject: [PATCH 02/82] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8Ecourse.index?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84control=E3=80=81view=E3=80=81help?= =?UTF-8?q?=E7=AD=89=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/contests_controller.rb | 2 +- app/controllers/courses_controller.rb | 178 ++++++++++++++++++++++++- app/helpers/application_helper.rb | 50 ++++++- app/helpers/contests_helper.rb | 5 +- app/helpers/courses_helper.rb | 29 ++++ app/models/course.rb | 71 +++++++++- app/views/courses/index.html.erb | 63 +++++++++ config/routes.rb | 2 +- 8 files changed, 390 insertions(+), 10 deletions(-) create mode 100644 app/views/courses/index.html.erb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index e7490f5b0..cd6d5abbe 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -73,7 +73,7 @@ class ContestsController < ApplicationController end end - def show_contest + def show_contest @user = @contest.author @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 215dd3a58..6cbec8546 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,9 +1,19 @@ class CoursesController < ApplicationController include CoursesHelper - + + menu_item l(:label_sort_by_time), :only => :index + menu_item l(:label_sort_by_active), :only => :index + menu_item l(:label_sort_by_influence), :only => :index + + before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] + before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen,:view_homework_attaches,:course] + before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] + before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] + before_filter :require_login, :only => [:join, :unjoin] before_filter :allow_join, :only => [:join] - + + def join if User.current.logged? course = Project.find(params[:object_id]) @@ -59,4 +69,168 @@ class CoursesController < ApplicationController end end + + def course12 + @project_type = params[:project_type] + @school_id = params[:school_id] + per_page_option = 10 + if @school_id == "0" or @school_id.nil? + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + where("#{Project.table_name}.project_type = ? ", Project::ProjectType_course) + else + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + joins(:course_extra). + where("#{Project.table_name}.project_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) + end + + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] + + #gcm activity count + + @project_activity_count=Hash.new + #count initialize + @projects_all.each do |project| + @project_activity_count[project.id]=0 + end + + #@project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcm end + + + case params[:project_sort_type] + when '0' + @projects = @projects_all.order("created_on desc") + @s_type = 0 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '1' + @projects = @projects_all.order("course_ac_para desc") + @s_type = 1 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '2' + @projects = @projects_all.order("watchers_count desc") + @s_type = 2 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + #gcm + when '3' + + #gcm + @project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcmend + + @projects=handle_project @projects_all,@project_activity_count + @s_type = 3 + @projects = @projects[@project_pages.offset, @project_pages.per_page] + else + @s_type = 0 + @projects = @projects_all.order("created_on desc") + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + end + + respond_to do |format| + format.html { + render :layout => 'base' + } + format.api { + # @offset, @limit = api_offset_and_limit + # @project_count = Project.visible.count + # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + } + format.atom { + projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") + } + end + end + + + def index + + per_page_option = 10 + + @courses_all = Course.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.couse_id") + + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] + +#gcm activity count + + @course_activity_count=Hash.new + + @courses_all.each do |course| + @course_activity_count[course.id]=0 + end + + @course_activity_count=get_course_activity @courses_all,@course_activity_count + +#gcm end + + case params[:course_sort_type] + when '0' + @courses = @courses_all.order("created_on desc") + @s_type = 0 + when '1' + @courses = @courses_all.order("grade desc") + @s_type = 1 + when '2' + @courses = @courses_all.order("watchers_count desc") + @s_type = 2 + + #gcm + when '3' + #@courses=desc_sort_course_by_avtivity(@course_activity_count_array,@course_all_array) + @courses=handle_course @courses_all,@course_activity_count + @s_type = 3 + @courses = @courses[@course_pages.offset, @course_pages.per_page] + + else + @courses = @courses = @courses_all.order("grade desc") + @s_type = 1 + end + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + respond_to do |format| + format.html { + render :layout => 'base' + # scope = Project + # unless params[:closed] + # scope = scope.active + # end + } + format.api { + # @offset, @limit = api_offset_and_limit + # @course_count = Project.visible.count + # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all + } + format.atom { + courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") + } + end + end + + end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7dc4b5556..f89023b7e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -170,6 +170,18 @@ module ApplicationHelper end end + def link_to_course(course, options={}, html_options = nil) + if course.archived? + h(course.name) + elsif options.key?(:action) + ActiveSupport::Deprecation.warn "#link_to_course with :action option is deprecated and will be removed in Redmine 3.0." + url = {:controller => 'courses', :action => 'show', :id => project}.merge(options) + link_to course.name, url, html_options + else + link_to course.name, course_path(course, options), html_options + end + end + # Generates a link to a project settings if active def link_to_project_settings(project, options={}, html_options=nil) if project.active? @@ -297,7 +309,41 @@ module ApplicationHelper @project = original_project end s.html_safe + end + + def render_course_nested_lists(courses) + s = '' + if courses.any? + ancestors = [] + original_course = @course + #modified by nie + courses.each do |course| + # set the project environment to please macros. + @course = course + if (ancestors.empty? || course.is_descendant_of?(ancestors.last)) + s << "\n" + end + end + classes = (ancestors.empty? ? 'root' : 'child') + s << "
  • " + + s << (render :partial => 'courses/course', :locals => {:course => course}).to_s + s << "
    \n" + ancestors << course + end + s << ("
  • \n" * ancestors.size) + @course = original_course + end + s.html_safe end + + #added by young def render_project_nested_lists_new(projects) s = '' @@ -1639,9 +1685,9 @@ module ApplicationHelper main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain} main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain} - course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain} + course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index', :host => Setting.course_domain} course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain} - courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain} + courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index',:host => Setting.course_domain} projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain} users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index 8206a8ff0..184fc7c40 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -55,8 +55,9 @@ module ContestsHelper content_tag('div', content, :class => "tabs_enterprise") end #end - - + + + #huang def sort_contest(state) content = ''.html_safe diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 959d36cb0..bcd45ac08 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -82,6 +82,35 @@ module CoursesHelper members end + def sort_courses(state) + content = ''.html_safe + case state + when 0 + + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'))) + content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'), :class=>"selected"), :class=>"selected") + when 1 + + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'))) + when 2 + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'))) + content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end + + def render_course_hierarchy(courses) + render_course_nested_lists(courses) do |course| + s = link_to_course(course, {}, :class => "#{course.css_classes} #{User.current.member_of?(course) ? 'my-course' : nil}").html_safe + s + end + end + #useless def searchMembersByRole project, role_id members = [] diff --git a/app/models/course.rb b/app/models/course.rb index de383a1f5..0bc93c811 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,8 +1,12 @@ class Course < ActiveRecord::Base include Redmine::SafeAttributes + + STATUS_ACTIVE = 1 + STATUS_CLOSED = 5 + STATUS_ARCHIVED = 9 attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password - belongs_to :project, :class_name => 'Project', :foreign_key => :extra, primary_key: :identifier + 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表 has_many :bid @@ -19,7 +23,24 @@ class Course < ActiveRecord::Base 'term', 'password' - #自定义验证 + scope :active, lambda { where(:status => STATUS_ACTIVE) } + scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } + scope :all_public, lambda { where(:is_public => true) } + scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) } + scope :allowed_to, lambda {|*args| + user = User.current + permission = nil + if args.first.is_a?(Symbol) + permission = args.shift + else + user = args.shift + permission = args.shift + end + where(Course.allowed_to_condition(user, permission, *args)) + } + + + #自定义验证 def validate if !class_period.match([0-9]) errors.add_to_base("class period can only digital") @@ -47,4 +68,50 @@ class Course < ActiveRecord::Base return time end end + + def self.allowed_to_condition(user, permission, options={}) + perm = Redmine::AccessControl.permission(permission) + base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") + if perm && perm.project_module + # If the permission belongs to a project module, make sure the module is enabled + base_statement << " AND #{Course.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')" + end + if options[:project] + project_statement = "#{Course.table_name}.id = #{options[:project].id}" + project_statement << " OR (#{Course.table_name}.lft > #{options[:project].lft} AND #{Course.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects] + base_statement = "(#{project_statement}) AND (#{base_statement})" + end + + if user.admin? + base_statement + else + statement_by_role = {} + unless options[:member] + role = user.logged? ? Role.non_member : Role.anonymous + if role.allowed_to?(permission) + statement_by_role[role] = "#{Course.table_name}.is_public = #{connection.quoted_true}" + end + end + if user.logged? + user.projects_by_role.each do |role, projects| + if role.allowed_to?(permission) && projects.any? + statement_by_role[role] = "#{Course.table_name}.id IN (#{projects.collect(&:id).join(',')})" + end + end + end + if statement_by_role.empty? + "1=0" + else + if block_given? + statement_by_role.each do |role, statement| + if s = yield(role, user) + statement_by_role[role] = "(#{statement} AND (#{s}))" + end + end + end + "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))" + end + end + end + end diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb new file mode 100644 index 000000000..87ef68863 --- /dev/null +++ b/app/views/courses/index.html.erb @@ -0,0 +1,63 @@ +<% content_for :header_tags do %> +<%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %> +<% end %> + +
    + <%= form_tag(projects_search_path, :method => :get) do %> + + + + + + + + + + + +
    <%= l(:label_project_deposit) %><%= l(:label_user_location) %> : + <% if User.current.logged? %> + <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type =>( @project_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %> + <% end %> + + +
    <%= link_to request.host()+"/projects", :controller => 'projects', :action => 'index', :project_type => 0 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_project_deposit), :controller => 'projects', :action => 'index', :project_type => 0 %>
    + <% end %> +
    +<%= sort_courses(@s_type) %> +
    + <%= render_course_hierarchy(@projects)%> +
    + + + +<% if User.current.logged? %> +

    + <%= l(:label_my_projects) %> +

    +<% end %> + +<% other_formats_links do |f| %> +<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> +<% end %> + +<% content_for :sidebar do %> + +<%= form_tag({}, :method => :get) do %> +

    <%= l(:label_project_plural) %>

    + +

    + <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> +

    +<% end %> +<% end %> + +<% html_title(l(:label_project_plural)) -%> diff --git a/config/routes.rb b/config/routes.rb index c3239154c..4ccd4195d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -539,7 +539,7 @@ RedmineApp::Application.routes.draw do # add by nwb # 课程路由设置 - resources :course do + resources :courses do member do # 之前在项目 post 'finishcourse' From ea3b80fdc6cde4cff835e49d9a7c7ceed8cdae6a Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 29 May 2014 16:47:32 +0800 Subject: [PATCH 03/82] =?UTF-8?q?=E6=B7=BB=E5=8A=A0CourseStatus=E8=A1=A8?= =?UTF-8?q?=E5=92=8Cmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_status.rb | 3 +++ db/migrate/20140529084427_create_course_statuses.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 app/models/course_status.rb create mode 100644 db/migrate/20140529084427_create_course_statuses.rb diff --git a/app/models/course_status.rb b/app/models/course_status.rb new file mode 100644 index 000000000..d5a01ac4b --- /dev/null +++ b/app/models/course_status.rb @@ -0,0 +1,3 @@ +class CourseStatus < ActiveRecord::Base + attr_accessible :changesets_count, :course_ac_para, :course_id, :grade, :watchers_count +end diff --git a/db/migrate/20140529084427_create_course_statuses.rb b/db/migrate/20140529084427_create_course_statuses.rb new file mode 100644 index 000000000..1244425db --- /dev/null +++ b/db/migrate/20140529084427_create_course_statuses.rb @@ -0,0 +1,13 @@ +class CreateCourseStatuses < ActiveRecord::Migration + def change + create_table :course_statuses do |t| + t.integer :changesets_count + t.integer :watchers_count + t.integer :course_id + t.float :grade ,default:0 + t.integer :course_ac_para ,default:0 + + t.timestamps + end + end +end From e15bad74622d469ff8761928d11f379243bf86de Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 30 May 2014 10:48:06 +0800 Subject: [PATCH 04/82] =?UTF-8?q?course=E6=96=B0=E5=A2=9E=E5=88=97?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=94=B9=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/views/courses/_course.html.erb | 4 +- app/views/courses/index.html.erb | 28 +- .../20140530102015_stored_course_procedure.rb | 392 ++++++++++++++++++ .../20140530102016_add_status_to_course.rb | 9 + 5 files changed, 418 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20140530102015_stored_course_procedure.rb create mode 100644 db/migrate/20140530102016_add_status_to_course.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6cbec8546..e54d50102 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -171,7 +171,7 @@ class CoursesController < ApplicationController per_page_option = 10 @courses_all = Course.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.couse_id") + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.couse_id") @course_count = @courses_all.count @course_pages = Paginator.new @course_count, per_page_option, params['page'] diff --git a/app/views/courses/_course.html.erb b/app/views/courses/_course.html.erb index 6ea802037..4fd807b63 100644 --- a/app/views/courses/_course.html.erb +++ b/app/views/courses/_course.html.erb @@ -15,8 +15,8 @@

    <%= content_tag('span', "#{l(:label_institution_name)}:", :class => "course-font")%> <% @admin = @project.project_infos%> - <%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%> - + <%if @admin&&@adadminmin.first&&@admin.first.user&&@admin.first.user.user_extensions%> + <%# unless @project.course_extra.school.nil? %> <%= @project.course_extra.teacher.user_extensions.school.try(:name) %> <%# end %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index 87ef68863..9b1cf841a 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -3,45 +3,45 @@ <% end %>

    - <%= form_tag(projects_search_path, :method => :get) do %> + <%= form_tag(courses_search_path, :method => :get) do %> - + - - + +
    <%= l(:label_project_deposit) %><%= l(:label_course_deposit) %> <%= l(:label_user_location) %> : <% if User.current.logged? %> - <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type =>( @project_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %> + <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type =>( @course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> <% end %> -
    <%= link_to request.host()+"/projects", :controller => 'projects', :action => 'index', :project_type => 0 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_project_deposit), :controller => 'projects', :action => 'index', :project_type => 0 %><%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_deposit), :controller => 'courses', :action => 'index', :course_type => 0 %>
    <% end %>
    <%= sort_courses(@s_type) %> -
    - <%= render_course_hierarchy(@projects)%> +
    + <%= render_course_hierarchy(@courses)%>
    <% if User.current.logged? %>

    - <%= l(:label_my_projects) %> + <%= l(:label_my_courses) %>

    <% end %> @@ -52,12 +52,12 @@ <% content_for :sidebar do %> <%= form_tag({}, :method => :get) do %> -

    <%= l(:label_project_plural) %>

    - +

    <%= l(:label_course_plural) %>

    +

    <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %>

    <% end %> <% end %> -<% html_title(l(:label_project_plural)) -%> +<% html_title(l(:label_course_plural)) -%> diff --git a/db/migrate/20140530102015_stored_course_procedure.rb b/db/migrate/20140530102015_stored_course_procedure.rb new file mode 100644 index 000000000..0c4defc06 --- /dev/null +++ b/db/migrate/20140530102015_stored_course_procedure.rb @@ -0,0 +1,392 @@ +class StoredCourseProcedure < ActiveRecord::Migration + def up + # 需要完成的数据导入: + # project中所有的课程导入至course + # Project_status导入至course_status + # + def self.up + Project.find_all.each do |project| + if project.project_type == 1 + course = Course.find_by_extra(project.identifier) + if course + course.name = project.name + + end + Course.new do |comment| + comment.name = 'Welcome.' + comment.body = "Article '#{article.name}' is open for comments." + ments << comment + comment.save + article.save + end + end + end + end + + + execute " +CREATE PROCEDURE `sp_course_data_change` () +BEGIN + DECLARE user_uid bigint(22); + DECLARE user_changesets_count int(10); + DECLARE _done tinyint(1) DEFAULT 0; + DECLARE cur_user CURSOR FOR + SELECT + users.id + FROM users + WHERE users.type = 'User' AND users.status = 1 AND users.admin = 0; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; + OPEN cur_user; +loop_xxx: +LOOP + FETCH cur_user INTO user_uid ; + IF _done = 1 THEN + LEAVE loop_xxx; + END IF; + BEGIN + DECLARE journals_for_messages_count int(10); + DECLARE journals_count int(10); + DECLARE comments_count int(10); + DECLARE messages_count int(10); + DECLARE news_count int(10); + DECLARE wiki_contents_count int(10); + DECLARE activities_count int(10); + DECLARE total_count numeric(8, 2); + + SELECT + COUNT(*) INTO journals_for_messages_count + FROM journals_for_messages + WHERE user_id = user_uid ; + SELECT + COUNT(*) INTO journals_count + FROM journals + WHERE user_id = user_uid; + SELECT + COUNT(*) INTO comments_count + FROM comments + WHERE author_id = user_uid; + SELECT + COUNT(*) INTO messages_count + FROM messages + WHERE author_id = user_uid; + SELECT + COUNT(*) INTO news_count + FROM news + WHERE author_id = user_uid; + SELECT + COUNT(*) INTO wiki_contents_count + FROM wiki_contents + WHERE author_id = user_uid; + SELECT + COUNT(*) INTO activities_count + FROM activities + WHERE user_id = user_uid; + SELECT + COUNT(*) INTO user_changesets_count + FROM changesets + WHERE changesets.user_id = user_uid; + + + + SET total_count = journals_for_messages_count * 0.05 + + journals_count * 0.1 + + comments_count * 0.1 + + messages_count * 0.05 + + news_count * 0.1 + + wiki_contents_count * 0.1 + + activities_count * 0.2 + + user_changesets_count * 0.3; + + UPDATE user_statuses + SET changesets_count = user_changesets_count, + grade = total_count + WHERE user_id = user_uid; + COMMIT; + END; +END LOOP; +END; +" + execute " + CREATE EVENT IF NOT EXISTS e_test +ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00' +ON COMPLETION PRESERVE +DO CALL `sp_user_status_cursor`(); +" + execute " + CREATE PROCEDURE `sp_project_status_cursor` () +BEGIN + DECLARE project_uid bigint(22); + DECLARE project_changesets_count int(10); + DECLARE _done tinyint(1) DEFAULT 0; + + DECLARE cur_project CURSOR FOR + SELECT + projects.id + FROM projects + WHERE projects.status <> 9 + AND projects.is_public = 1 AND projects.project_type = 0 ; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; + OPEN cur_project; +loop_xxx: +LOOP + FETCH cur_project INTO project_uid; + IF _done = 1 THEN + LEAVE loop_xxx; + END IF; + + BEGIN + DECLARE total_count numeric(8, 2); + DECLARE news_id int(10); + DECLARE issues_id int(10); + DECLARE issues_count int(10); + DECLARE news_count int(10); + DECLARE time_entries_count int(10); + DECLARE documents_count int(10); + DECLARE issues_jour_count_total int(10) DEFAULT 0; + DECLARE issues_jour_count int(10); + DECLARE news_jour_count_total int(10) DEFAULT 0; + DECLARE news_jour_count int(10); + DECLARE boards_messages_count int(10); + + DECLARE cur_user_id int(10); + DECLARE cur_user_issues_journals_count int(10); + DECLARE cur_user_news_journals_count int(10); + DECLARE cur_user_issues_count int(10); + DECLARE cur_user_news_count int(10); + DECLARE cur_user_issues_id int(10); + DECLARE cur_user_news_id int(10); + + + + + DECLARE _inner_done_one tinyint(1) DEFAULT 0; + DECLARE cur_issues CURSOR FOR + SELECT + issues.id + FROM issues + WHERE project_id = project_uid; + DECLARE cur_news CURSOR FOR + SELECT + news.id + FROM news + WHERE project_id = project_uid; + DECLARE cur_user CURSOR FOR + SELECT + members.user_id + FROM members + INNER JOIN users + ON members.user_id = users.id + WHERE members.project_id = project_uid + AND (users.type = 'User' AND users.status = 1); + DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_done_one = 1; + + OPEN cur_issues; + loop_issues: + LOOP + FETCH cur_issues INTO issues_id; + IF _inner_done_one = 1 THEN + LEAVE loop_issues; + END IF; + + BEGIN + SELECT + COUNT(*) INTO issues_jour_count + FROM `journals` + WHERE `journals`.`journalized_id` = issues_id AND `journals`.`journalized_type` = 'Issue'; + SET issues_jour_count_total = issues_jour_count_total + issues_jour_count; + END; + END LOOP; + -- CLOSE cur_issues; + + SET _inner_done_one = 0; + + OPEN cur_news; + loop_news: + LOOP + FETCH cur_news INTO news_id; + IF _inner_done_one = 1 THEN + LEAVE loop_news; + END IF; + + BEGIN + SELECT + COUNT(*) INTO news_jour_count + FROM `journals` + WHERE `journals`.`journalized_id` = news_id AND `journals`.`journalized_type` = 'News'; + SET news_jour_count_total = news_jour_count_total + news_jour_count; + END; + END LOOP; + -- CLOSE cur_news; + + SET _inner_done_one = 0; + + OPEN cur_user; + loop_user: + LOOP + FETCH cur_user INTO cur_user_id; + IF _inner_done_one = 1 THEN + LEAVE loop_user; + END IF; + + BEGIN + DECLARE total_cur_user_issues_journals_count int(10) DEFAULT 0; + DECLARE total_cur_user_news_journals_count int(10) DEFAULT 0; + DECLARE cur_user_changesets_count INT(10); + DECLARE user_total_count numeric(8, 2); + DECLARE _inner_inner_done tinyint(1) DEFAULT 0; + DECLARE cur_user_issues CURSOR FOR + SELECT + issues.id + FROM issues + WHERE project_id = project_uid AND author_id = cur_user_id; + DECLARE cur_user_news CURSOR FOR + SELECT + news.id + FROM news + WHERE project_id = project_uid AND author_id = cur_user_id; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_inner_done = 1; + + OPEN cur_user_issues; + loop_user_issues: + LOOP + FETCH cur_issues INTO cur_user_issues_id; + IF _inner_inner_done = 1 THEN + LEAVE loop_user_issues; + END IF; + + BEGIN + SELECT + COUNT(*) INTO cur_user_issues_journals_count + FROM journals + WHERE journalized_id = cur_user_issues_id AND user_id = cur_user_id + AND journalized_type = 'Issues'; + SET total_cur_user_issues_journals_count = total_cur_user_issues_journals_count + + cur_user_issues_journals_count; + END; + END LOOP; + + -- CLOSE cur_user_issues; + + SET _inner_inner_done = 0; + + OPEN cur_user_news; + loop_user_news: + LOOP + FETCH cur_user_news INTO cur_user_news_id; + IF _inner_inner_done = 1 THEN + LEAVE loop_user_news; + END IF; + + BEGIN + SELECT + COUNT(*) INTO cur_user_news_journals_count + FROM journals + WHERE journalized_id = cur_user_news_id AND user_id = cur_user_id AND journalized_type = 'News'; + SET total_cur_user_news_journals_count = total_cur_user_news_journals_count + + cur_user_news_journals_count; + END; + END LOOP; + + SELECT + COUNT(*) INTO cur_user_issues_count + FROM issues + WHERE project_id = project_uid AND author_id = cur_user_id; + SELECT + COUNT(*) INTO cur_user_news_count + FROM news + WHERE project_id = project_uid AND author_id = cur_user_id; + SELECT + COUNT(*) INTO cur_user_changesets_count + FROM changesets + WHERE user_id = cur_user_id AND + repository_id IN (SELECT + id + FROM repositories + WHERE project_id = project_uid); + SET user_total_count = cur_user_issues_count*0.2 + + cur_user_news_count*0.2 + + total_cur_user_issues_journals_count*0.1 + + total_cur_user_news_journals_count*0.1 + + cur_user_changesets_count*0.4; + UPDATE user_grades + SET grade = user_total_count + WHERE user_id = cur_user_id AND project_id = project_uid; + COMMIT; + END; + END LOOP; + + SELECT + COUNT(*) INTO issues_count + FROM issues + WHERE project_id = project_uid; + SELECT + COUNT(*) INTO news_count + FROM news + WHERE project_id = project_uid; + SELECT + COUNT(*) INTO documents_count + FROM documents + WHERE project_id = project_uid; + SELECT + SUM(boards.messages_count) INTO boards_messages_count + FROM boards + WHERE project_id = project_uid; + SELECT + COUNT(*) INTO project_changesets_count + FROM `changesets` + INNER JOIN `repositories` ON `changesets`.`repository_id` = `repositories`.`id` + WHERE `repositories`.`project_id` = project_uid AND (is_default = 1); + + SET total_count = issues_count * 0.2 + + issues_jour_count_total * 0.1 + + news_count * 0.1 + + news_jour_count_total * 0.1 + + documents_count * 0.1 + + project_changesets_count * 0.3 + + boards_messages_count * 0.1; + + + IF total_count IS NOT NULL THEN + + UPDATE project_statuses + SET changesets_count = project_changesets_count, + grade = total_count + WHERE project_id = project_uid; + ELSE + UPDATE project_statuses + SET changesets_count = project_changesets_count, + grade = 0 + WHERE project_id = project_uid; + END IF; + + COMMIT; + END; +END LOOP; +END; +" + execute " + CREATE EVENT IF NOT EXISTS e_project_status_test +ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00' +ON COMPLETION PRESERVE +DO CALL `sp_project_status_cursor`(); +" + execute " + SET GLOBAL event_scheduler = ON; +" + end + + def down + execute " DROP PROCEDURE IF EXISTS `sp_user_status_cursor`; + " + execute " + DROP EVENT IF EXISTS e_test; + " + execute " + DROP PROCEDURE IF EXISTS `sp_project_status_cursor`; + " + execute " + DROP EVENT IF EXISTS e_project_status_test; + " + end +end diff --git a/db/migrate/20140530102016_add_status_to_course.rb b/db/migrate/20140530102016_add_status_to_course.rb new file mode 100644 index 000000000..0cca18c7b --- /dev/null +++ b/db/migrate/20140530102016_add_status_to_course.rb @@ -0,0 +1,9 @@ +class AddStatusToCourse < ActiveRecord::Migration + def change + add_column :courses, :description, :text + add_column :courses, :status, :int ,default: 1 + add_column :courses, :attachmenttype, :int ,default: 2 + add_column :courses, :lft, :int + add_column :courses, :rgt, :int + end +end From 77006198a12a3cde3d438c48ef2c1d32316a77ce Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 30 May 2014 11:01:20 +0800 Subject: [PATCH 05/82] =?UTF-8?q?1.=E5=AF=BC=E5=85=A5=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E5=B7=B2=E6=9C=89=E8=AF=BE=E7=A8=8B=E8=87=B3?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=A1=A8=202.=E5=AF=BC=E5=85=A5=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=8A=B6=E6=80=81=E8=A1=A8=E8=87=B3=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20140530102015_stored_course_procedure.rb | 403 ++---------------- 1 file changed, 24 insertions(+), 379 deletions(-) diff --git a/db/migrate/20140530102015_stored_course_procedure.rb b/db/migrate/20140530102015_stored_course_procedure.rb index 0c4defc06..4489791dc 100644 --- a/db/migrate/20140530102015_stored_course_procedure.rb +++ b/db/migrate/20140530102015_stored_course_procedure.rb @@ -1,392 +1,37 @@ class StoredCourseProcedure < ActiveRecord::Migration - def up + def self.up # 需要完成的数据导入: # project中所有的课程导入至course # Project_status导入至course_status # - def self.up - Project.find_all.each do |project| - if project.project_type == 1 - course = Course.find_by_extra(project.identifier) - if course - course.name = project.name - - end - Course.new do |comment| - comment.name = 'Welcome.' - comment.body = "Article '#{article.name}' is open for comments." - ments << comment - comment.save - article.save + Project.find_all.each do |project| + if project.project_type == 1 + course = Course.find_by_extra(project.identifier) + if course + course.name = project.name + course.description = project.description + course.status = project.status + course.attachmenttype = 2 + course.lft = project.lft + course.rgt = project.rgt + course.save + + # 更新状态表 + projectstatus = ProjectStatus.find_by_project_id(project.id) + if projectstatus + courseStatus = CourseStatus.new + courseStatus.course_id = course.id + courseStatus.changesets_count = projectstatus.changesets_count + courseStatus.watchers_count = projectstatus.watchers_count + courseStatus.grade = projectstatus.grade + courseStatus.course_ac_para = projectstatus.course_ac_para + courseStatus.save end end end end - - - execute " -CREATE PROCEDURE `sp_course_data_change` () -BEGIN - DECLARE user_uid bigint(22); - DECLARE user_changesets_count int(10); - DECLARE _done tinyint(1) DEFAULT 0; - DECLARE cur_user CURSOR FOR - SELECT - users.id - FROM users - WHERE users.type = 'User' AND users.status = 1 AND users.admin = 0; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; - OPEN cur_user; -loop_xxx: -LOOP - FETCH cur_user INTO user_uid ; - IF _done = 1 THEN - LEAVE loop_xxx; - END IF; - BEGIN - DECLARE journals_for_messages_count int(10); - DECLARE journals_count int(10); - DECLARE comments_count int(10); - DECLARE messages_count int(10); - DECLARE news_count int(10); - DECLARE wiki_contents_count int(10); - DECLARE activities_count int(10); - DECLARE total_count numeric(8, 2); - - SELECT - COUNT(*) INTO journals_for_messages_count - FROM journals_for_messages - WHERE user_id = user_uid ; - SELECT - COUNT(*) INTO journals_count - FROM journals - WHERE user_id = user_uid; - SELECT - COUNT(*) INTO comments_count - FROM comments - WHERE author_id = user_uid; - SELECT - COUNT(*) INTO messages_count - FROM messages - WHERE author_id = user_uid; - SELECT - COUNT(*) INTO news_count - FROM news - WHERE author_id = user_uid; - SELECT - COUNT(*) INTO wiki_contents_count - FROM wiki_contents - WHERE author_id = user_uid; - SELECT - COUNT(*) INTO activities_count - FROM activities - WHERE user_id = user_uid; - SELECT - COUNT(*) INTO user_changesets_count - FROM changesets - WHERE changesets.user_id = user_uid; - - - - SET total_count = journals_for_messages_count * 0.05 + - journals_count * 0.1 + - comments_count * 0.1 + - messages_count * 0.05 + - news_count * 0.1 + - wiki_contents_count * 0.1 + - activities_count * 0.2 + - user_changesets_count * 0.3; - - UPDATE user_statuses - SET changesets_count = user_changesets_count, - grade = total_count - WHERE user_id = user_uid; - COMMIT; - END; -END LOOP; -END; -" - execute " - CREATE EVENT IF NOT EXISTS e_test -ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00' -ON COMPLETION PRESERVE -DO CALL `sp_user_status_cursor`(); -" - execute " - CREATE PROCEDURE `sp_project_status_cursor` () -BEGIN - DECLARE project_uid bigint(22); - DECLARE project_changesets_count int(10); - DECLARE _done tinyint(1) DEFAULT 0; - - DECLARE cur_project CURSOR FOR - SELECT - projects.id - FROM projects - WHERE projects.status <> 9 - AND projects.is_public = 1 AND projects.project_type = 0 ; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; - OPEN cur_project; -loop_xxx: -LOOP - FETCH cur_project INTO project_uid; - IF _done = 1 THEN - LEAVE loop_xxx; - END IF; - - BEGIN - DECLARE total_count numeric(8, 2); - DECLARE news_id int(10); - DECLARE issues_id int(10); - DECLARE issues_count int(10); - DECLARE news_count int(10); - DECLARE time_entries_count int(10); - DECLARE documents_count int(10); - DECLARE issues_jour_count_total int(10) DEFAULT 0; - DECLARE issues_jour_count int(10); - DECLARE news_jour_count_total int(10) DEFAULT 0; - DECLARE news_jour_count int(10); - DECLARE boards_messages_count int(10); - - DECLARE cur_user_id int(10); - DECLARE cur_user_issues_journals_count int(10); - DECLARE cur_user_news_journals_count int(10); - DECLARE cur_user_issues_count int(10); - DECLARE cur_user_news_count int(10); - DECLARE cur_user_issues_id int(10); - DECLARE cur_user_news_id int(10); - - - - - DECLARE _inner_done_one tinyint(1) DEFAULT 0; - DECLARE cur_issues CURSOR FOR - SELECT - issues.id - FROM issues - WHERE project_id = project_uid; - DECLARE cur_news CURSOR FOR - SELECT - news.id - FROM news - WHERE project_id = project_uid; - DECLARE cur_user CURSOR FOR - SELECT - members.user_id - FROM members - INNER JOIN users - ON members.user_id = users.id - WHERE members.project_id = project_uid - AND (users.type = 'User' AND users.status = 1); - DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_done_one = 1; - - OPEN cur_issues; - loop_issues: - LOOP - FETCH cur_issues INTO issues_id; - IF _inner_done_one = 1 THEN - LEAVE loop_issues; - END IF; - - BEGIN - SELECT - COUNT(*) INTO issues_jour_count - FROM `journals` - WHERE `journals`.`journalized_id` = issues_id AND `journals`.`journalized_type` = 'Issue'; - SET issues_jour_count_total = issues_jour_count_total + issues_jour_count; - END; - END LOOP; - -- CLOSE cur_issues; - - SET _inner_done_one = 0; - - OPEN cur_news; - loop_news: - LOOP - FETCH cur_news INTO news_id; - IF _inner_done_one = 1 THEN - LEAVE loop_news; - END IF; - - BEGIN - SELECT - COUNT(*) INTO news_jour_count - FROM `journals` - WHERE `journals`.`journalized_id` = news_id AND `journals`.`journalized_type` = 'News'; - SET news_jour_count_total = news_jour_count_total + news_jour_count; - END; - END LOOP; - -- CLOSE cur_news; - - SET _inner_done_one = 0; - - OPEN cur_user; - loop_user: - LOOP - FETCH cur_user INTO cur_user_id; - IF _inner_done_one = 1 THEN - LEAVE loop_user; - END IF; - - BEGIN - DECLARE total_cur_user_issues_journals_count int(10) DEFAULT 0; - DECLARE total_cur_user_news_journals_count int(10) DEFAULT 0; - DECLARE cur_user_changesets_count INT(10); - DECLARE user_total_count numeric(8, 2); - DECLARE _inner_inner_done tinyint(1) DEFAULT 0; - DECLARE cur_user_issues CURSOR FOR - SELECT - issues.id - FROM issues - WHERE project_id = project_uid AND author_id = cur_user_id; - DECLARE cur_user_news CURSOR FOR - SELECT - news.id - FROM news - WHERE project_id = project_uid AND author_id = cur_user_id; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_inner_done = 1; - - OPEN cur_user_issues; - loop_user_issues: - LOOP - FETCH cur_issues INTO cur_user_issues_id; - IF _inner_inner_done = 1 THEN - LEAVE loop_user_issues; - END IF; - - BEGIN - SELECT - COUNT(*) INTO cur_user_issues_journals_count - FROM journals - WHERE journalized_id = cur_user_issues_id AND user_id = cur_user_id - AND journalized_type = 'Issues'; - SET total_cur_user_issues_journals_count = total_cur_user_issues_journals_count + - cur_user_issues_journals_count; - END; - END LOOP; - - -- CLOSE cur_user_issues; - - SET _inner_inner_done = 0; - - OPEN cur_user_news; - loop_user_news: - LOOP - FETCH cur_user_news INTO cur_user_news_id; - IF _inner_inner_done = 1 THEN - LEAVE loop_user_news; - END IF; - - BEGIN - SELECT - COUNT(*) INTO cur_user_news_journals_count - FROM journals - WHERE journalized_id = cur_user_news_id AND user_id = cur_user_id AND journalized_type = 'News'; - SET total_cur_user_news_journals_count = total_cur_user_news_journals_count + - cur_user_news_journals_count; - END; - END LOOP; - - SELECT - COUNT(*) INTO cur_user_issues_count - FROM issues - WHERE project_id = project_uid AND author_id = cur_user_id; - SELECT - COUNT(*) INTO cur_user_news_count - FROM news - WHERE project_id = project_uid AND author_id = cur_user_id; - SELECT - COUNT(*) INTO cur_user_changesets_count - FROM changesets - WHERE user_id = cur_user_id AND - repository_id IN (SELECT - id - FROM repositories - WHERE project_id = project_uid); - SET user_total_count = cur_user_issues_count*0.2 + - cur_user_news_count*0.2 + - total_cur_user_issues_journals_count*0.1 + - total_cur_user_news_journals_count*0.1 + - cur_user_changesets_count*0.4; - UPDATE user_grades - SET grade = user_total_count - WHERE user_id = cur_user_id AND project_id = project_uid; - COMMIT; - END; - END LOOP; - - SELECT - COUNT(*) INTO issues_count - FROM issues - WHERE project_id = project_uid; - SELECT - COUNT(*) INTO news_count - FROM news - WHERE project_id = project_uid; - SELECT - COUNT(*) INTO documents_count - FROM documents - WHERE project_id = project_uid; - SELECT - SUM(boards.messages_count) INTO boards_messages_count - FROM boards - WHERE project_id = project_uid; - SELECT - COUNT(*) INTO project_changesets_count - FROM `changesets` - INNER JOIN `repositories` ON `changesets`.`repository_id` = `repositories`.`id` - WHERE `repositories`.`project_id` = project_uid AND (is_default = 1); - - SET total_count = issues_count * 0.2 + - issues_jour_count_total * 0.1 + - news_count * 0.1 + - news_jour_count_total * 0.1 + - documents_count * 0.1 + - project_changesets_count * 0.3 + - boards_messages_count * 0.1; - - - IF total_count IS NOT NULL THEN - - UPDATE project_statuses - SET changesets_count = project_changesets_count, - grade = total_count - WHERE project_id = project_uid; - ELSE - UPDATE project_statuses - SET changesets_count = project_changesets_count, - grade = 0 - WHERE project_id = project_uid; - END IF; - - COMMIT; - END; -END LOOP; -END; -" - execute " - CREATE EVENT IF NOT EXISTS e_project_status_test -ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00' -ON COMPLETION PRESERVE -DO CALL `sp_project_status_cursor`(); -" - execute " - SET GLOBAL event_scheduler = ON; -" end - def down - execute " DROP PROCEDURE IF EXISTS `sp_user_status_cursor`; - " - execute " - DROP EVENT IF EXISTS e_test; - " - execute " - DROP PROCEDURE IF EXISTS `sp_project_status_cursor`; - " - execute " - DROP EVENT IF EXISTS e_project_status_test; - " + def self.down end end From e490f7979d60713bdf6def7d305c9d7a32bb84e3 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 09:39:33 +0800 Subject: [PATCH 06/82] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8Bindex?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 71 +++++++-------- app/views/courses/index.html.erb | 89 ++++++++++--------- config/routes.rb | 1 + ...=> 20140530102014_add_status_to_course.rb} | 0 .../20140530102015_stored_course_procedure.rb | 2 +- db/schema.rb | 26 ++++-- 6 files changed, 107 insertions(+), 82 deletions(-) rename db/migrate/{20140530102016_add_status_to_course.rb => 20140530102014_add_status_to_course.rb} (100%) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e54d50102..3060d1f07 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -70,81 +70,81 @@ class CoursesController < ApplicationController end - def course12 - @project_type = params[:project_type] + def index + @course_type = params[:course_type] @school_id = params[:school_id] per_page_option = 10 if @school_id == "0" or @school_id.nil? - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). - where("#{Project.table_name}.project_type = ? ", Project::ProjectType_course) + @courses_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). + where("#{Project.table_name}.course_type = ? ", Project::ProjectType_course) else - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + @courses_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). joins(:course_extra). - where("#{Project.table_name}.project_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) + where("#{Project.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) end - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] #gcm activity count - @project_activity_count=Hash.new + @course_activity_count=Hash.new #count initialize - @projects_all.each do |project| - @project_activity_count[project.id]=0 + @courses_all.each do |course| + @course_activity_count[course.id]=0 end - #@project_activity_count=get_project_activity @projects_all,@project_activity_count + #@course_activity_count=get_course_activity @courses_all,@course_activity_count #gcm end - case params[:project_sort_type] + case params[:course_sort_type] when '0' - @projects = @projects_all.order("created_on desc") + @courses = @courses_all.order("created_on desc") @s_type = 0 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend when '1' - @projects = @projects_all.order("course_ac_para desc") + @courses = @courses_all.order("course_ac_para desc") @s_type = 1 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend when '2' - @projects = @projects_all.order("watchers_count desc") + @courses = @courses_all.order("watchers_count desc") @s_type = 2 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend #gcm when '3' #gcm - @project_activity_count=get_project_activity @projects_all,@project_activity_count + @course_activity_count=get_course_activity @courses_all,@course_activity_count #gcmend - @projects=handle_project @projects_all,@project_activity_count + @courses=handle_course @courses_all,@course_activity_count @s_type = 3 - @projects = @projects[@project_pages.offset, @project_pages.per_page] + @courses = @courses[@course_pages.offset, @course_pages.per_page] else @s_type = 0 - @projects = @projects_all.order("created_on desc") - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses_all.order("created_on desc") + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend end @@ -155,21 +155,22 @@ class CoursesController < ApplicationController } format.api { # @offset, @limit = api_offset_and_limit - # @project_count = Project.visible.count - # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + # @course_count = Project.visible.count + # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all } format.atom { - projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") + courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") } end end - def index + def index1 per_page_option = 10 + #当前所有的活动课程 @courses_all = Course.active.visible. joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.couse_id") diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index 9b1cf841a..1492264c8 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -1,63 +1,70 @@ <% content_for :header_tags do %> -<%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %> + <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %> <% end %>
    - <%= form_tag(courses_search_path, :method => :get) do %> - - - - - - - - - - - -
    <%= l(:label_course_deposit) %><%= l(:label_user_location) %> : - <% if User.current.logged? %> - <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type =>( @course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> - <% end %> - - -
    <%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_deposit), :controller => 'courses', :action => 'index', :course_type => 0 %>
    - <% end %> + <%= form_tag(courses_search_path, :method => :get) do %> + + + + + + + + + + + +
    <%= l(:label_course_all) %><%= l(:label_user_location) %> : + <% if User.current.logged? %> + <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type => (@course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> + <% end %> + + +
    + <%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> + <%= link_to l(:field_homepage), home_path %> + > <%= link_to l(:label_course_all), :controller => 'courses', :action => 'index', :course_type => 0 %>
    + <% end %>
    <%= sort_courses(@s_type) %>
    - <%= render_course_hierarchy(@courses)%> + <% if @courses %> + <%= render_course_hierarchy(@courses) %> + <% end %>
    <% if User.current.logged? %> -

    - <%= l(:label_my_courses) %> -

    +

    + <%= l(:label_my_courses) %> +

    <% end %> <% other_formats_links do |f| %> -<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> + <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <% end %> <% content_for :sidebar do %> -<%= form_tag({}, :method => :get) do %> -

    <%= l(:label_course_plural) %>

    - -

    - <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> -

    -<% end %> + <%= form_tag({}, :method => :get) do %> +

    <%= l(:label_course_all) %>

    + +

    + <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> +

    + <% end %> <% end %> -<% html_title(l(:label_course_plural)) -%> +<% html_title(l(:label_course_all)) -%> diff --git a/config/routes.rb b/config/routes.rb index 4ccd4195d..b9b44d767 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -546,6 +546,7 @@ RedmineApp::Application.routes.draw do post 'restartcourse' end end + match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] #match 'project/enterprise_course', :to => 'projects#enterprise_course' #match 'project/course_enterprise', :to => 'projects#course_enterprise' #match 'project/course', :to => 'projects#course', :as => 'course' diff --git a/db/migrate/20140530102016_add_status_to_course.rb b/db/migrate/20140530102014_add_status_to_course.rb similarity index 100% rename from db/migrate/20140530102016_add_status_to_course.rb rename to db/migrate/20140530102014_add_status_to_course.rb diff --git a/db/migrate/20140530102015_stored_course_procedure.rb b/db/migrate/20140530102015_stored_course_procedure.rb index 4489791dc..6c31279e1 100644 --- a/db/migrate/20140530102015_stored_course_procedure.rb +++ b/db/migrate/20140530102015_stored_course_procedure.rb @@ -4,7 +4,7 @@ class StoredCourseProcedure < ActiveRecord::Migration # project中所有的课程导入至course # Project_status导入至course_status # - Project.find_all.each do |project| + Project.all.each do |project| if project.project_type == 1 course = Course.find_by_extra(project.identifier) if course diff --git a/db/schema.rb b/db/schema.rb index 12bcab886..8c3bdca4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522025721) do +ActiveRecord::Schema.define(:version => 20140530102015) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -220,6 +220,16 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.datetime "updated_on", :null => false end + create_table "course_statuses", :force => true do |t| + t.integer "changesets_count" + t.integer "watchers_count" + t.integer "course_id" + t.float "grade", :default => 0.0 + t.integer "course_ac_para", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "courses", :force => true do |t| t.integer "tea_id" t.string "name" @@ -227,8 +237,8 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.string "code" t.integer "time" t.string "extra" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "location" t.string "term" t.string "string" @@ -237,6 +247,11 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.string "endup_time" t.string "class_period" t.integer "school_id" + t.text "description" + t.integer "status", :default => 1 + t.integer "attachmenttype", :default => 2 + t.integer "lft" + t.integer "rgt" end create_table "custom_fields", :force => true do |t| @@ -482,12 +497,13 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.text "notes" t.integer "status" t.integer "reply_id" - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false + t.datetime "created_on", :null => false + t.datetime "updated_on", :null => false t.string "m_parent_id" t.boolean "is_readed" t.integer "m_reply_count" t.integer "m_reply_id" + t.integer "is_comprehensive_evaluation" end create_table "member_roles", :force => true do |t| From 9f948c971fd8c3f952aee3b32a873014a6698c48 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 09:56:54 +0800 Subject: [PATCH 07/82] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 34 +++++++++++++++++++ app/views/courses/_course.html.erb | 4 +-- app/views/courses/index.html.erb | 54 +++++++++++++----------------- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index bcd45ac08..6a348a1ea 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -122,6 +122,40 @@ module CoursesHelper members end + def sort_course(state, school_id) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) + # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) + content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + + when 1 + content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected") + # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) + content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + + when 2 + content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) + # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + + #gcm + when 3 + content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) + # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) + content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected") + end + #gcmend + + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end + def findCourseTime project str = "" begin diff --git a/app/views/courses/_course.html.erb b/app/views/courses/_course.html.erb index 4fd807b63..6ea802037 100644 --- a/app/views/courses/_course.html.erb +++ b/app/views/courses/_course.html.erb @@ -15,8 +15,8 @@

    <%= content_tag('span', "#{l(:label_institution_name)}:", :class => "course-font")%> <% @admin = @project.project_infos%> - <%if @admin&&@adadminmin.first&&@admin.first.user&&@admin.first.user.user_extensions%> - + <%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%> + <%# unless @project.course_extra.school.nil? %> <%= @project.course_extra.teacher.user_extensions.school.try(:name) %> <%# end %> diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index 1492264c8..a74668dc4 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -6,49 +6,44 @@ <%= form_tag(courses_search_path, :method => :get) do %> - + + <% end %> <% end %> - - - + + + - - + +
    <%= l(:label_course_all) %><%= l(:label_course_practice) %> <%= l(:label_user_location) %> : - <% if User.current.logged? %> - <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type => (@course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> + <% if User.current.logged?%> + <% if User.current.user_extensions.identity == 0 %> + <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 1}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> - -
    + +
    - <%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> - <%= link_to l(:field_homepage), home_path %> - > <%= link_to l(:label_course_all), :controller => 'courses', :action => 'index', :course_type => 0 %><%= link_to request.host()+"/course", :controller => 'courses', :action => 'course', :course_type => 1 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_practice), :controller => 'courses', :action => 'course', :course_type => 1 %>
    <% end %>

    -<%= sort_courses(@s_type) %> -
    - <% if @courses %> - <%= render_course_hierarchy(@courses) %> - <% end %> +<%= sort_course(@s_type, @course_type, @school_id)%> + +
    + <%= render_project_hierarchy(@projects)%>
    <% if User.current.logged? %>

    - <%= l(:label_my_courses) %> + <%= l(:label_my_course) %>

    <% end %> @@ -57,14 +52,13 @@ <% end %> <% content_for :sidebar do %> - <%= form_tag({}, :method => :get) do %> -

    <%= l(:label_course_all) %>

    - +

    <%= l(:label_project_plural) %>

    +

    <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %>

    <% end %> <% end %> -<% html_title(l(:label_course_all)) -%> +<% html_title(l(:label_new_course)) -%> From 7d3d406c006e91f9296277550951b19974493838 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 11:16:06 +0800 Subject: [PATCH 08/82] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=89=80=E9=9C=80=E7=9A=84=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 94 ++++++++++++++++++--------- app/helpers/application_helper.rb | 4 +- app/models/course.rb | 8 +++ app/views/courses/index.html.erb | 12 ++-- 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3060d1f07..3ebd3369c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -52,37 +52,19 @@ class CoursesController < ApplicationController end end - private - - def allow_join - if course_endTime_timeout? Project.find(params[:object_id]) - respond_to do |format| - format.js{ - @state = 2 - render :partial => 'set_join', - :locals => {:user => User.current, - :course => Project.find(params[:object_id]), - :object_id => params[:object_id] - } - } - end - end - end - def index @course_type = params[:course_type] @school_id = params[:school_id] per_page_option = 10 if @school_id == "0" or @school_id.nil? - @courses_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). - where("#{Project.table_name}.course_type = ? ", Project::ProjectType_course) + @courses_all = Course.active.visible. + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id") else - @courses_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). + @courses_all = Course.active.visible. + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). joins(:course_extra). - where("#{Project.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) + where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id) end @course_count = @courses_all.count @@ -153,18 +135,72 @@ class CoursesController < ApplicationController format.html { render :layout => 'base' } - format.api { - # @offset, @limit = api_offset_and_limit - # @course_count = Project.visible.count - # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all - } format.atom { - courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") } end end + def get_course_activity courses,activities + @course_ids=activities.keys() + + days = Setting.activity_days_default.to_i + date_to ||= Date.today + 1 + date_from = date_to - days-1.years + + #file_count + Attachment.where(container_id: @course_ids, container_type: Project).where("created_on>?",date_from).each do |attachment| + activities[attachment.container_id]+=1 + end + + #message_count + Board.where(course_id: @course_ids).each do |board| +# activities[board.course_id]+=1 + activities[board.course_id]+=board.messages.where("updated_on>?",date_from).count + end + + #time_entry_count + TimeEntry.where(course_id: @course_ids).where("updated_on>?",date_from).each do |timeentry| + activities[timeentry.course_id]+=1 + end + + #feedbackc_count + JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess| + activities[jourformess.jour_id]+=1 + end + + #activities!=0 + i=0; + courses.each do |course| + id=course.id + if activities[id]==0 + activities[id]=1 + end + end + + return activities + end + + private + + def allow_join + if course_endTime_timeout? Project.find(params[:object_id]) + respond_to do |format| + format.js{ + @state = 2 + render :partial => 'set_join', + :locals => {:user => User.current, + :course => Project.find(params[:object_id]), + :object_id => params[:object_id] + } + } + end + end + end + + + def index1 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f89023b7e..da674bb56 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1685,9 +1685,9 @@ module ApplicationHelper main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain} main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain} - course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index', :host => Setting.course_domain} + course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'} course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain} - courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index',:host => Setting.course_domain} + courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'} projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain} users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} diff --git a/app/models/course.rb b/app/models/course.rb index 0bc93c811..0c5abd5c2 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -39,6 +39,14 @@ class Course < ActiveRecord::Base where(Course.allowed_to_condition(user, permission, *args)) } + def visible?(user=User.current) + user.allowed_to?(:view_course, self) + end + + def self.visible_condition(user, options={}) + allowed_to_condition(user, :view_course, options) + end + #自定义验证 def validate diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index a74668dc4..ea32d3863 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -29,21 +29,23 @@ <% end %>
    -<%= sort_course(@s_type, @course_type, @school_id)%> +<%= sort_course(@s_type, @school_id)%> -
    - <%= render_project_hierarchy(@projects)%> +
    + <%if @courses%> + <%= render_course_hierarchy(@courses)%> + <%end%>
    <% if User.current.logged? %>

    - <%= l(:label_my_course) %> + <%= l(:label_my_course) %>

    <% end %> From 846034404303f51113ca3d6da51832034002e979 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 11:52:44 +0800 Subject: [PATCH 09/82] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=A8=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E9=80=BB=E8=BE=91=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20140603033359_add_boards_type_to_boards.rb | 13 +++++++++++++ db/schema.rb | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140603033359_add_boards_type_to_boards.rb diff --git a/db/migrate/20140603033359_add_boards_type_to_boards.rb b/db/migrate/20140603033359_add_boards_type_to_boards.rb new file mode 100644 index 000000000..598f5b517 --- /dev/null +++ b/db/migrate/20140603033359_add_boards_type_to_boards.rb @@ -0,0 +1,13 @@ +class AddBoardsTypeToBoards < ActiveRecord::Migration + def change + add_column :boards, :course_id, :int + + Board.all.each do |board| + project = Project.find_by_id(board.project_id) + if project && project.project_type == 1 + board.course_id = board.project_id + board.save + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8c3bdca4f..9178151a7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140530102015) do +ActiveRecord::Schema.define(:version => 20140603033360) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -119,6 +119,7 @@ ActiveRecord::Schema.define(:version => 20140530102015) do t.integer "messages_count", :default => 0, :null => false t.integer "last_message_id" t.integer "parent_id" + t.integer "course_id" end add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id" From cd10dd54335e7d540ab5a918c0d877f5ba80b5a1 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 16:21:00 +0800 Subject: [PATCH 10/82] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=8F=98=E6=9B=B4=EF=BC=8C=E4=BB=8E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=9D=83=E9=99=90=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 39 +++++++++++++++---- app/helpers/courses_helper.rb | 28 ++++++------- app/models/course.rb | 19 +++++---- ...3081801_add_courseid_to_enabled_modules.rb | 13 +++++++ lib/redmine.rb | 3 +- 5 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20140603081801_add_courseid_to_enabled_modules.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3ebd3369c..12f730e06 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -52,11 +52,40 @@ class CoursesController < ApplicationController end end + def handle_course courses,activities + course_activity_count_array=activities.values() + + course_array=[] + i=0; + courses.each do |course| + course_array[i]=course + i=i+1 + end + + courses=desc_sort_course_by_avtivity(course_activity_count_array,course_array) + + return courses + end + + def desc_sort_course_by_avtivity(activity_count,courses) + return courses if activity_count.size<2 + (activity_count.size-2).downto(0) do |i| + (0..i).each do |j| + if activity_count[j]?",date_from).count end - #time_entry_count - TimeEntry.where(course_id: @course_ids).where("updated_on>?",date_from).each do |timeentry| - activities[timeentry.course_id]+=1 - end - #feedbackc_count JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess| activities[jourformess.jour_id]+=1 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 6a348a1ea..4c27af480 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -126,29 +126,25 @@ module CoursesHelper content = ''.html_safe case state when 0 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) when 1 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) when 2 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) #gcm when 3 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected") end #gcmend diff --git a/app/models/course.rb b/app/models/course.rb index 0c5abd5c2..0df09dd37 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -78,16 +78,15 @@ class Course < ActiveRecord::Base end def self.allowed_to_condition(user, permission, options={}) - perm = Redmine::AccessControl.permission(permission) + perm = Redmine::AccessControl.permission(permission) base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") - if perm && perm.project_module - # If the permission belongs to a project module, make sure the module is enabled + if perm && perm.course_module base_statement << " AND #{Course.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')" end - if options[:project] - project_statement = "#{Course.table_name}.id = #{options[:project].id}" - project_statement << " OR (#{Course.table_name}.lft > #{options[:project].lft} AND #{Course.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects] - base_statement = "(#{project_statement}) AND (#{base_statement})" + 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? @@ -101,9 +100,9 @@ class Course < ActiveRecord::Base end end if user.logged? - user.projects_by_role.each do |role, projects| - if role.allowed_to?(permission) && projects.any? - statement_by_role[role] = "#{Course.table_name}.id IN (#{projects.collect(&:id).join(',')})" + user.courses_by_role.each do |role, courses| + if role.allowed_to?(permission) && courses.any? + statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})" end end end diff --git a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb new file mode 100644 index 000000000..cefc38258 --- /dev/null +++ b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb @@ -0,0 +1,13 @@ +class AddCourseidToEnabledModules < ActiveRecord::Migration + def change + add_column :enabled_modules, :course_id, :int + + EnabledModule.all.each do |enablemodule| + project = Project.find_by_id(enablemodule.project_id) + if project && project.project_type == 1 + enablemodule.course_id = board.project_id + enablemodule.save + end + end + end +end diff --git a/lib/redmine.rb b/lib/redmine.rb index f53860293..7703b2b2b 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -180,7 +180,8 @@ Redmine::AccessControl.map do |map| #课程权限模块 map.project_module :course do - map.permission :view_courses,{:projects => [:course]},:read => true + map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true + map.permission :view_courses,{:courses => [:course]},:read => true end #作业模块权限 From d87b52bedd524086c8efad93f803c743aad58c43 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 09:19:01 +0800 Subject: [PATCH 11/82] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=88=90=E5=91=98?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 2 +- app/models/user.rb | 20 +++++++++++++++++++ ...0140603033359_add_boards_type_to_boards.rb | 1 + ...3081801_add_courseid_to_enabled_modules.rb | 3 ++- ...140604011630_add_courseid_to_to_members.rb | 15 ++++++++++++++ db/schema.rb | 3 ++- lib/redmine.rb | 12 +++++------ lib/redmine/access_control.rb | 8 +++++++- 8 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20140604011630_add_courseid_to_to_members.rb diff --git a/app/models/course.rb b/app/models/course.rb index 0df09dd37..b611261cc 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -81,7 +81,7 @@ class Course < ActiveRecord::Base perm = Redmine::AccessControl.permission(permission) base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") if perm && perm.course_module - base_statement << " AND #{Course.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_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}" diff --git a/app/models/user.rb b/app/models/user.rb index edf703873..d376cd858 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -276,6 +276,7 @@ class User < Principal def reload(*args) @name = nil @projects_by_role = nil + @courses_by_role = nil @membership_by_project_id = nil base_reload(*args) end @@ -634,6 +635,25 @@ class User < Principal @projects_by_role end + # 课程的角色权限 + def courses_by_role + return @courses_by_role if @courses_by_role + + @courses_by_role = Hash.new([]) + memberships.each do |membership| + if membership.course + membership.roles.each do |role| + @courses_by_role[role] = [] unless @courses_by_role.key?(role) + @courses_by_role[role] << membership.course + end + end + end + @courses_by_role.each do |role, courses| + courses.uniq! + end + + @courses_by_role + end # Returns true if user is arg or belongs to arg def is_or_belongs_to?(arg) if arg.is_a?(User) diff --git a/db/migrate/20140603033359_add_boards_type_to_boards.rb b/db/migrate/20140603033359_add_boards_type_to_boards.rb index 598f5b517..76193b642 100644 --- a/db/migrate/20140603033359_add_boards_type_to_boards.rb +++ b/db/migrate/20140603033359_add_boards_type_to_boards.rb @@ -6,6 +6,7 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration project = Project.find_by_id(board.project_id) if project && project.project_type == 1 board.course_id = board.project_id + board.project_id = nil board.save end end diff --git a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb index cefc38258..baa1ef81d 100644 --- a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb +++ b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb @@ -5,7 +5,8 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration EnabledModule.all.each do |enablemodule| project = Project.find_by_id(enablemodule.project_id) if project && project.project_type == 1 - enablemodule.course_id = board.project_id + enablemodule.course_id = enablemodule.project_id + enablemodule.project_id = nil enablemodule.save end end diff --git a/db/migrate/20140604011630_add_courseid_to_to_members.rb b/db/migrate/20140604011630_add_courseid_to_to_members.rb new file mode 100644 index 000000000..14111c1b9 --- /dev/null +++ b/db/migrate/20140604011630_add_courseid_to_to_members.rb @@ -0,0 +1,15 @@ +class AddCourseidToToMembers < ActiveRecord::Migration + def change + add_column :members, :course_id, :int + + # 课程成员数据迁移 + Member.all.each do |member| + project = Project.find_by_id(member.project_id) + if project && project.project_type == 1 + member.course_id = member.project_id + member.project_id = nil + member.save + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9178151a7..34629bc09 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140603033360) do +ActiveRecord::Schema.define(:version => 20140603081801) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -315,6 +315,7 @@ ActiveRecord::Schema.define(:version => 20140603033360) do create_table "enabled_modules", :force => true do |t| t.integer "project_id" t.string "name", :null => false + t.integer "course_id" end add_index "enabled_modules", ["project_id"], :name => "enabled_modules_project_id" diff --git a/lib/redmine.rb b/lib/redmine.rb index 7703b2b2b..ff2dd2bb3 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -98,6 +98,12 @@ Redmine::AccessControl.map do |map| map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member map.permission :view_journals_for_messages, {:gantts => [:show, :update]}, :read => true + #课程权限模块 + map.course_module :course do + map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true + map.permission :view_courses,{:courses => [:course]},:read => true + end + map.project_module :issue_tracking do |map| # Issue categories map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member @@ -178,12 +184,6 @@ Redmine::AccessControl.map do |map| map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]} end - #课程权限模块 - map.project_module :course do - map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true - map.permission :view_courses,{:courses => [:course]},:read => true - end - #作业模块权限 map.project_module :bids do |map| map.permission :view_homework_attaches, {:bids => [:show, :show_project, :revision]}, :read => true diff --git a/lib/redmine/access_control.rb b/lib/redmine/access_control.rb index 7c4a5a5ec..0158a05ea 100644 --- a/lib/redmine/access_control.rb +++ b/lib/redmine/access_control.rb @@ -76,6 +76,7 @@ module Redmine class Mapper def initialize @project_module = nil + @course_module = nil end def permission(name, hash, options={}) @@ -90,13 +91,18 @@ module Redmine @project_module = nil end + def course_module(name, options={}) + @course_module = name + yield self + @course_module = nil + end def mapped_permissions @permissions end end class Permission - attr_reader :name, :actions, :project_module + attr_reader :name, :actions, :project_module ,:course_module def initialize(name, hash, options) @name = name From c43bf84e424e6642c6256c485daf61518e3c0590 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 11:32:32 +0800 Subject: [PATCH 12/82] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=89=80=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E7=9A=84=E5=AD=90=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= =?UTF-8?q?(enabled=5Fmodules)=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/member.rb | 3 ++- app/models/project.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/member.rb b/app/models/member.rb index de4d67687..8901ec52f 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -22,8 +22,9 @@ class Member < ActiveRecord::Base has_many :roles, :through => :member_roles belongs_to :project + belongs_to :course - validates_presence_of :principal, :project + validates_presence_of :principal validates_uniqueness_of :user_id, :scope => :project_id validate :validate_role diff --git a/app/models/project.rb b/app/models/project.rb index b8e11d99e..45e251f5b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -38,7 +38,7 @@ class Project < ActiveRecord::Base :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" has_many :users, :through => :members has_many :principals, :through => :member_principals, :source => :principal - has_many :enabled_modules, :dependent => :delete_all + has_many :enabled_modules, :dependent => :delete_all has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_many :issues, :dependent => :destroy, :include => [:status, :tracker] has_many :issue_changes, :through => :issues, :source => :journals From d4bc8139a3e6799cfa38896815176d0520e64646 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 11:59:26 +0800 Subject: [PATCH 13/82] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20140401004102_create_relative_memos.rb | 2 +- ...0140603033359_add_boards_type_to_boards.rb | 20 ++++++++++------- ...3081801_add_courseid_to_enabled_modules.rb | 19 +++++++++------- ...140604011630_add_courseid_to_to_members.rb | 22 ++++++++++++------- db/schema.rb | 16 ++++++-------- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/db/migrate/20140401004102_create_relative_memos.rb b/db/migrate/20140401004102_create_relative_memos.rb index 6f0d776db..04b8862a3 100644 --- a/db/migrate/20140401004102_create_relative_memos.rb +++ b/db/migrate/20140401004102_create_relative_memos.rb @@ -4,7 +4,7 @@ class CreateRelativeMemos < ActiveRecord::Migration t.integer :osp_id, :null => true t.integer :parent_id, null: true t.string :subject, null: false - t.mediumtext :content, null: false + t.text :content, null: false t.integer :author_id t.integer :replies_count, default: 0 t.integer :last_reply_id diff --git a/db/migrate/20140603033359_add_boards_type_to_boards.rb b/db/migrate/20140603033359_add_boards_type_to_boards.rb index 76193b642..ea06cc200 100644 --- a/db/migrate/20140603033359_add_boards_type_to_boards.rb +++ b/db/migrate/20140603033359_add_boards_type_to_boards.rb @@ -2,13 +2,17 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration def change add_column :boards, :course_id, :int - Board.all.each do |board| - project = Project.find_by_id(board.project_id) - if project && project.project_type == 1 - board.course_id = board.project_id - board.project_id = nil - board.save - end - end + Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id") + Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1) + + #Board.all.each do |board| + # project = Project.find_by_id(board.project_id) + # if project && project.project_type == 1 + # board.course_id = board.project_id + # board.project_id = -1 + # board.save + # end + # end + end end diff --git a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb index baa1ef81d..e31c3f953 100644 --- a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb +++ b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb @@ -2,13 +2,16 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration def change add_column :enabled_modules, :course_id, :int - EnabledModule.all.each do |enablemodule| - project = Project.find_by_id(enablemodule.project_id) - if project && project.project_type == 1 - enablemodule.course_id = enablemodule.project_id - enablemodule.project_id = nil - enablemodule.save - end - end + EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id") + EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1) + + #EnabledModule.all.each do |enablemodule| + # project = Project.find_by_id(enablemodule.project_id) + # if project && project.project_type == 1 + # enablemodule.course_id = enablemodule.project_id + # enablemodule.project_id = -1 + # enablemodule.save + # end + #end end end diff --git a/db/migrate/20140604011630_add_courseid_to_to_members.rb b/db/migrate/20140604011630_add_courseid_to_to_members.rb index 14111c1b9..b52a26924 100644 --- a/db/migrate/20140604011630_add_courseid_to_to_members.rb +++ b/db/migrate/20140604011630_add_courseid_to_to_members.rb @@ -1,15 +1,21 @@ class AddCourseidToToMembers < ActiveRecord::Migration def change add_column :members, :course_id, :int + change_column_null(:members, :project_id, true) + remove_index :members, name: 'index_members_on_user_id_and_project_id' + add_index "members", ["user_id", "project_id","course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true + + Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id") + Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1) # 课程成员数据迁移 - Member.all.each do |member| - project = Project.find_by_id(member.project_id) - if project && project.project_type == 1 - member.course_id = member.project_id - member.project_id = nil - member.save - end - end + #Member.all.each do |member| + # project = Project.find_by_id(member.project_id) + # if project && project.project_type == 1 + # member.course_id = member.project_id + # member.project_id = -1 + # member.save + # end + #end end end diff --git a/db/schema.rb b/db/schema.rb index 34629bc09..470440fc2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140603081801) do +ActiveRecord::Schema.define(:version => 20140604011630) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -57,14 +57,11 @@ ActiveRecord::Schema.define(:version => 20140603081801) do add_index "attachments", ["container_id", "container_type"], :name => "index_attachments_on_container_id_and_container_type" add_index "attachments", ["created_on"], :name => "index_attachments_on_created_on" - create_table "attachmentstypes", :id => false, :force => true do |t| - t.integer "id", :null => false - t.integer "typeId" + create_table "attachmentstypes", :force => true do |t| + t.integer "typeId", :null => false t.string "typeName", :limit => 50 end - add_index "attachmentstypes", ["id"], :name => "id" - create_table "auth_sources", :force => true do |t| t.string "type", :limit => 30, :default => "", :null => false t.string "name", :limit => 60, :default => "", :null => false @@ -519,13 +516,14 @@ ActiveRecord::Schema.define(:version => 20140603081801) do create_table "members", :force => true do |t| t.integer "user_id", :default => 0, :null => false - t.integer "project_id", :default => 0, :null => false + t.integer "project_id", :default => 0 t.datetime "created_on" t.boolean "mail_notification", :default => false, :null => false + t.integer "course_id" end add_index "members", ["project_id"], :name => "index_members_on_project_id" - add_index "members", ["user_id", "project_id"], :name => "index_members_on_user_id_and_project_id", :unique => true + add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true add_index "members", ["user_id"], :name => "index_members_on_user_id" create_table "memos", :force => true do |t| @@ -710,7 +708,7 @@ ActiveRecord::Schema.define(:version => 20140603081801) do end create_table "relative_memos", :force => true do |t| - t.integer "osp_id", :null => false + t.integer "osp_id" t.integer "parent_id" t.string "subject", :null => false t.text "content", :null => false From 0f5c99627854528f582352a3606356cb4bccccc0 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 14:09:37 +0800 Subject: [PATCH 14/82] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 12 ++++++++++++ app/views/courses/new.html.erb | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 app/views/courses/new.html.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 12f730e06..ddeb42538 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -67,6 +67,18 @@ class CoursesController < ApplicationController return courses end + def new + @course_type = params[:course_type] ||= params[:course] + @issue_custom_fields = IssueCustomField.sorted.all + @trackers = Tracker.sorted.all + + @course = Course.new + @course.safe_attributes = params[:course] + + render :layout => 'base' + end + + def desc_sort_course_by_avtivity(activity_count,courses) return courses if activity_count.size<2 (activity_count.size-2).downto(0) do |i| diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb new file mode 100644 index 000000000..81e6ec37a --- /dev/null +++ b/app/views/courses/new.html.erb @@ -0,0 +1,9 @@ +<%= labelled_form_for @course do |f| %> +

    <%=l(:label_course_new)%>

    +
    + <%= render :partial => 'course_form', :locals => { :f => f } %> + <%= submit_tag l(:button_create), :class => "enterprise"%> + + <%= javascript_tag "$('#course_name').focus();" %> +
    +<% end %> From fb36a0d5ba8a373623d82de9fcba659ddc7efd34 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 15:47:09 +0800 Subject: [PATCH 15/82] =?UTF-8?q?1.=E8=AF=BE=E7=A8=8Bcontrol=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0create=E6=96=B9=E6=B3=95=202.=E8=AF=BE=E7=A8=8Bmodel?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=96=B0=E5=88=97=E5=8F=8A?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 146 ++++++++++++------ app/models/course.rb | 7 + app/views/courses/_course_form.html.erb | 49 +++--- app/views/users/_my_course.html.erb | 2 +- ...20140604071623_add_is_public_to_courses.rb | 6 + db/schema.rb | 32 +++- 6 files changed, 158 insertions(+), 84 deletions(-) create mode 100644 db/migrate/20140604071623_add_is_public_to_courses.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ddeb42538..9f823ab9d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -5,10 +5,9 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_active), :only => :index menu_item l(:label_sort_by_influence), :only => :index - before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] - before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen,:view_homework_attaches,:course] - before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] - before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] + before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] + before_filter :authorize_global, :only => [:view_homework_attaches] #:new,:create] + before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] before_filter :require_login, :only => [:join, :unjoin] before_filter :allow_join, :only => [:join] @@ -22,7 +21,7 @@ class CoursesController < ApplicationController members = [] members << Member.new(:role_ids => [10], :user_id => User.current.id) course.members << members - + StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) @state = 0 else @@ -34,13 +33,13 @@ class CoursesController < ApplicationController format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} } end end - + def unjoin if User.current.logged? - + @member = Member.where('project_id = ? and user_id = ?', params[:object_id], User.current.id) @member.first.destroy - + joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) joined.each do |join| join.delete @@ -52,7 +51,7 @@ class CoursesController < ApplicationController end end - def handle_course courses,activities + def handle_course courses, activities course_activity_count_array=activities.values() course_array=[] @@ -62,30 +61,87 @@ class CoursesController < ApplicationController i=i+1 end - courses=desc_sort_course_by_avtivity(course_activity_count_array,course_array) + courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array) return courses end + def create + if User.current.user_extensions.identity + @course = Course.new + @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s + @course.safe_attributes = params[:course] + @course.tea_id = User.current.id + # added by bai + @course.term = params[:term] + @course.time = params[:time] + #@course.school_id = params[:occupation] + @course.school_id = User.current.user_extensions.school_id + @course.setup_time = params[:setup_time] + @course.endup_time = params[:endup_time] + @course.class_period = params[:class_period] + end + + @issue_custom_fields = IssueCustomField.sorted.all + @trackers = Tracker.sorted.all + + if User.current.user_extensions.identity == 0 + if @course.save + unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + #course = ProjectInfo.new(:user_id => User.current.id, :course_id => @course.id) + user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + if params[:course][:is_public] == '1' + course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) + end + @course.members << m + #@course.course_infos << course + end + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + redirect_to new_course_path(attrs, :course => '0') + elsif params[:course_continue] + redirect_to new_course_path(:course => '1') + else + redirect_to settings_course_path(@course, :course_type => 1) + end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } + end + else + @course.destroy + respond_to do |format| + format.html { render :action => 'new', :layout => 'base' } #Added by young + format.api { render_validation_errors(@course) } + end + end + end + + end + + def new - @course_type = params[:course_type] ||= params[:course] + @course_type = params[:course_type] ||= params[:course] @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.all - @course = Course.new - @course.safe_attributes = params[:course] + @course = Course.new + @course.safe_attributes = params[:course] render :layout => 'base' end - def desc_sort_course_by_avtivity(activity_count,courses) + def desc_sort_course_by_avtivity(activity_count, courses) return courses if activity_count.size<2 (activity_count.size-2).downto(0) do |i| (0..i).each do |j| if activity_count[j]?",date_from).each do |attachment| + Attachment.where(container_id: @course_ids, container_type: Project).where("created_on>?", date_from).each do |attachment| activities[attachment.container_id]+=1 end #message_count Board.where(course_id: @course_ids).each do |board| # activities[board.course_id]+=1 - activities[board.course_id]+=board.messages.where("updated_on>?",date_from).count + activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count end #feedbackc_count @@ -224,21 +280,19 @@ class CoursesController < ApplicationController def allow_join if course_endTime_timeout? Project.find(params[:object_id]) respond_to do |format| - format.js{ + format.js { @state = 2 - render :partial => 'set_join', - :locals => {:user => User.current, - :course => Project.find(params[:object_id]), - :object_id => params[:object_id] - } + render :partial => 'set_join', + :locals => {:user => User.current, + :course => Project.find(params[:object_id]), + :object_id => params[:object_id] + } } end end end - - def index1 per_page_option = 10 @@ -258,13 +312,13 @@ class CoursesController < ApplicationController @course_activity_count[course.id]=0 end - @course_activity_count=get_course_activity @courses_all,@course_activity_count + @course_activity_count=get_course_activity @courses_all, @course_activity_count #gcm end case params[:course_sort_type] when '0' - @courses = @courses_all.order("created_on desc") + @courses = @courses_all.order("created_on desc") @s_type = 0 when '1' @courses = @courses_all.order("grade desc") @@ -276,15 +330,15 @@ class CoursesController < ApplicationController #gcm when '3' #@courses=desc_sort_course_by_avtivity(@course_activity_count_array,@course_all_array) - @courses=handle_course @courses_all,@course_activity_count + @courses=handle_course @courses_all, @course_activity_count @s_type = 3 - @courses = @courses[@course_pages.offset, @course_pages.per_page] + @courses = @courses[@course_pages.offset, @course_pages.per_page] else @courses = @courses = @courses_all.order("grade desc") @s_type = 1 end - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) respond_to do |format| format.html { @@ -294,7 +348,7 @@ class CoursesController < ApplicationController # scope = scope.active # end } - format.api { + format.api { # @offset, @limit = api_offset_and_limit # @course_count = Project.visible.count # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all diff --git a/app/models/course.rb b/app/models/course.rb index b611261cc..d0273fa71 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -23,6 +23,8 @@ class Course < ActiveRecord::Base 'term', 'password' + acts_as_customizable + scope :active, lambda { where(:status => STATUS_ACTIVE) } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } scope :all_public, lambda { where(:is_public => true) } @@ -43,6 +45,11 @@ class Course < ActiveRecord::Base user.allowed_to?(:view_course, self) end + def extra_frozen? + errors[:extra].blank? && !(new_record? || extra.blank?) + end + + def self.visible_condition(user, options={}) allowed_to_condition(user, :view_course, options) end diff --git a/app/views/courses/_course_form.html.erb b/app/views/courses/_course_form.html.erb index 017c4e6ee..66054a93e 100644 --- a/app/views/courses/_course_form.html.erb +++ b/app/views/courses/_course_form.html.erb @@ -17,21 +17,21 @@ <% object = [] %> -<% object << 'project' %> +<% object << 'course' %> <% object << 'course' %> <%= error_messages_for object %> - -<% unless @project.new_record? %> -

    <%= render :partial=>"avatar/avatar_form",:locals=> {source:@project} %>

    + +<% unless @course.new_record? %> +

    <%= render :partial=>"avatar/avatar_form",:locals=> {source:@course} %>

    <% end %> -

    +

    - @@ -294,46 +294,33 @@ -

    +

    <%= l(:text_command) %> <% end %> -

    +

    <%= f.check_box :is_public, :style => "margin-left:10px;" %><%= l(:label_public_info) %>

    -

    <%= f.text_field :project_type, :value => 1 %>

    +

    <%= f.text_field :course_type, :value => 1 %>

    -<%= wikitoolbar_for 'project_description' %> +<%= wikitoolbar_for 'course_description' %> -<% @project.custom_field_values.each do |value| %> -

    <%= custom_field_tag_with_label :project, value %>

    +<% @course.custom_field_values.each do |value| %> +

    <%= custom_field_tag_with_label :course, value %>

    <% end %> -<%= call_hook(:view_projects_form, :project => @project, :form => f) %> +<%= call_hook(:view_courses_form, :course => @course, :form => f) %> - + -<% unless @project.identifier_frozen? %> +<% unless @course.extra_frozen? %> <% content_for :header_tags do %> - <%= javascript_include_tag 'project_identifier' %> + <%= javascript_include_tag 'course_identifier' %> <% end %> <% end %> -<% if !User.current.admin? && @project.inherit_members? && @project.parent && User.current.member_of?(@project.parent) %> - <%= javascript_tag do %> - $(document).ready(function() { - $("#project_inherit_members").change(function(){ - if (!$(this).is(':checked')) { - if (!confirm("<%= escape_javascript(l(:text_own_membership_delete_confirmation)) %>")) { - $("#project_inherit_members").attr("checked", true); - } - } - }); - }); - <% end %> -<% end %> diff --git a/app/views/users/_my_course.html.erb b/app/views/users/_my_course.html.erb index 26cfd48e0..85f455b19 100644 --- a/app/views/users/_my_course.html.erb +++ b/app/views/users/_my_course.html.erb @@ -7,7 +7,7 @@ <% else %>

    - <%= l(:label_project_course_unadd) %><%= link_to "#{l(:label_course_new)}", {:controller => 'projects', :action => 'new', :course => 1, :project_type => 1}, :class => 'icon icon-add' %> + <%= l(:label_project_course_unadd) %><%= link_to "#{l(:label_course_new)}", {:controller => 'courses', :action => 'new'}, :class => 'icon icon-add' %>

    <% end %> <% else %> diff --git a/db/migrate/20140604071623_add_is_public_to_courses.rb b/db/migrate/20140604071623_add_is_public_to_courses.rb new file mode 100644 index 000000000..48aa6b5df --- /dev/null +++ b/db/migrate/20140604071623_add_is_public_to_courses.rb @@ -0,0 +1,6 @@ +class AddIsPublicToCourses < ActiveRecord::Migration + def change + add_column :courses, :is_public, :tinyint,:default => 1 + add_column :courses, :inherit_members, :tinyint,:default => 1 + end +end diff --git a/db/schema.rb b/db/schema.rb index 721945ed4..4f3398eb7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140527060344) do +ActiveRecord::Schema.define(:version => 20140604071624) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -116,6 +116,7 @@ ActiveRecord::Schema.define(:version => 20140527060344) do t.integer "messages_count", :default => 0, :null => false t.integer "last_message_id" t.integer "parent_id" + t.integer "course_id" end add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id" @@ -217,6 +218,16 @@ ActiveRecord::Schema.define(:version => 20140527060344) do t.datetime "updated_on", :null => false end + create_table "course_statuses", :force => true do |t| + t.integer "changesets_count" + t.integer "watchers_count" + t.integer "course_id" + t.float "grade", :default => 0.0 + t.integer "course_ac_para", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "courses", :force => true do |t| t.integer "tea_id" t.string "name" @@ -224,8 +235,8 @@ ActiveRecord::Schema.define(:version => 20140527060344) do t.string "code" t.integer "time" t.string "extra" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "location" t.string "term" t.string "string" @@ -234,6 +245,13 @@ ActiveRecord::Schema.define(:version => 20140527060344) do t.string "endup_time" t.string "class_period" t.integer "school_id" + t.text "description" + t.integer "status", :default => 1 + t.integer "attachmenttype", :default => 2 + t.integer "lft" + t.integer "rgt" + t.boolean "is_public", :default => true + t.integer "inherit_members", :limit => 1, :default => 1 end create_table "custom_fields", :force => true do |t| @@ -296,6 +314,7 @@ ActiveRecord::Schema.define(:version => 20140527060344) do create_table "enabled_modules", :force => true do |t| t.integer "project_id" t.string "name", :null => false + t.integer "course_id" end add_index "enabled_modules", ["project_id"], :name => "enabled_modules_project_id" @@ -499,13 +518,14 @@ ActiveRecord::Schema.define(:version => 20140527060344) do create_table "members", :force => true do |t| t.integer "user_id", :default => 0, :null => false - t.integer "project_id", :default => 0, :null => false + t.integer "project_id", :default => 0 t.datetime "created_on" t.boolean "mail_notification", :default => false, :null => false + t.integer "course_id" end add_index "members", ["project_id"], :name => "index_members_on_project_id" - add_index "members", ["user_id", "project_id"], :name => "index_members_on_user_id_and_project_id", :unique => true + add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true add_index "members", ["user_id"], :name => "index_members_on_user_id" create_table "memos", :force => true do |t| @@ -690,7 +710,7 @@ ActiveRecord::Schema.define(:version => 20140527060344) do end create_table "relative_memos", :force => true do |t| - t.integer "osp_id", :null => false + t.integer "osp_id" t.integer "parent_id" t.string "subject", :null => false t.text "content", :null => false From 0d99644fa7acc72e7af9722a215fef79d2ea9623 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 16:45:20 +0800 Subject: [PATCH 16/82] =?UTF-8?q?1.=E7=94=A8=E6=88=B7=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=A1=A8=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=202.=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0link=5Fto=5Fcourse=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 12 ++++++++++-- app/controllers/users_controller.rb | 8 ++++---- app/helpers/courses_helper.rb | 2 +- app/models/course.rb | 16 ++++++++++++++-- app/models/member_role.rb | 14 ++++++++------ app/models/principal.rb | 1 + app/views/courses/_course_form.html.erb | 2 -- app/views/users/_course_form.html.erb | 22 +++++++++++----------- config/routes.rb | 2 +- 9 files changed, 50 insertions(+), 29 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 9f823ab9d..bff99f35a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -6,7 +6,7 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_influence), :only => :index before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] - before_filter :authorize_global, :only => [:view_homework_attaches] #:new,:create] + #before_filter :authorize_global, :only => [:view_homework_attaches, :new,:create] before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] before_filter :require_login, :only => [:join, :unjoin] @@ -66,6 +66,13 @@ class CoursesController < ApplicationController return courses end + def settings + @issue_custom_fields = IssueCustomField.sorted.all + @issue_category ||= IssueCategory.new + @member ||= @courses.members.new + @trackers = Tracker.sorted.all + end + def create if User.current.user_extensions.identity @course = Course.new @@ -80,6 +87,7 @@ class CoursesController < ApplicationController @course.setup_time = params[:setup_time] @course.endup_time = params[:endup_time] @course.class_period = params[:class_period] + @course.description = params[:description] end @issue_custom_fields = IssueCustomField.sorted.all @@ -91,7 +99,7 @@ class CoursesController < ApplicationController r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) #course = ProjectInfo.new(:user_id => User.current.id, :course_id => @course.id) - user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) if params[:course][:is_public] == '1' course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6452bcc81..c508234ae 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -200,19 +200,19 @@ class UsersController < ApplicationController end end - membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) + membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current)) membership.sort! {|older, newer| newer.created_on <=> older.created_on } @memberships = [] membership.collect { |e| - @memberships.push(e) if(e.project.project_type == 1) + @memberships.push(e) } ## 判断课程是否过期 [需封装] @memberships_doing = [] @memberships_done = [] now_time = Time.now.year @memberships.map { |e| - end_time = e.project.course_extra.get_time.year - isDone = course_endTime_timeout?(e.project) + end_time = e.course.get_time.year + isDone = course_endTime_timeout?(e.course) if isDone @memberships_done.push e else diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 70029a55a..8f3e4eb79 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -182,7 +182,7 @@ module CoursesHelper end # 截至到2014-03-17 这个是最终的判断课程是否过期的方法 def course_endTime_timeout? project - end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time) + end_time_str = Course.find_by_extra(project.try(:extra)).try(:endup_time) begin cTime = Time.parse(end_time_str.to_s) rescue TypeError,ArgumentError diff --git a/app/models/course.rb b/app/models/course.rb index d0273fa71..9b2e0d840 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,6 +10,14 @@ class Course < ActiveRecord::Base 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表 has_many :bid + + has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" + has_many :memberships, :class_name => 'Member' + has_many :member_principals, :class_name => 'Member', + :include => :principal, + :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" + has_many :users, :through => :members + validates_presence_of :password, :term validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/ safe_attributes 'extra', @@ -21,7 +29,8 @@ class Course < ActiveRecord::Base 'tea_id', 'password', 'term', - 'password' + 'password', + 'description' acts_as_customizable @@ -49,8 +58,11 @@ class Course < ActiveRecord::Base errors[:extra].blank? && !(new_record? || extra.blank?) end + def archived? + self.status == STATUS_ARCHIVED + end - def self.visible_condition(user, options={}) + def self.visible_condition(user, options={}) allowed_to_condition(user, :view_course, options) end diff --git a/app/models/member_role.rb b/app/models/member_role.rb index 29ad6563d..67122a636 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -54,14 +54,16 @@ class MemberRole < ActiveRecord::Base end def add_role_to_subprojects - member.project.children.each do |subproject| - if subproject.inherit_members? - child_member = Member.find_or_new(subproject.id, member.user_id) - child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) - child_member.save! + if member.project + member.project.children.each do |subproject| + if subproject.inherit_members? + child_member = Member.find_or_new(subproject.id, member.user_id) + child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) + child_member.save! + end end end - end + end def remove_inherited_roles MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles| diff --git a/app/models/principal.rb b/app/models/principal.rb index 15cebdf53..6681855b5 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -26,6 +26,7 @@ class Principal < ActiveRecord::Base has_many :members, :foreign_key => 'user_id', :dependent => :destroy has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name" + has_many :coursememberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :course, :roles ], :conditions => "#{Course.table_name}.status<>#{Course::STATUS_ARCHIVED}", :order => "#{Course.table_name}.name" has_many :projects, :through => :memberships has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify diff --git a/app/views/courses/_course_form.html.erb b/app/views/courses/_course_form.html.erb index 66054a93e..4f2f5a796 100644 --- a/app/views/courses/_course_form.html.erb +++ b/app/views/courses/_course_form.html.erb @@ -292,14 +292,12 @@ -

    <%= l(:text_command) %> <% end %> -

    diff --git a/app/views/users/_course_form.html.erb b/app/views/users/_course_form.html.erb index 13ab819dc..6de99f7d9 100644 --- a/app/views/users/_course_form.html.erb +++ b/app/views/users/_course_form.html.erb @@ -1,44 +1,44 @@
    -