From c333a0c55d1656740a1a656d2b1c6432fe42c492 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 31 May 2016 10:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E5=AD=A6=E9=9C=B8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/org_subfields_controller.rb | 8 ++-- app/controllers/organizations_controller.rb | 42 ++++++++++++----- app/helpers/organizations_helper.rb | 5 ++- app/models/org_subfield.rb | 2 + app/models/organization.rb | 4 +- app/views/org_subfields/create.js.erb | 2 +- app/views/org_subfields/destroy.js.erb | 2 +- .../organizations/_org_custom_admin.html.erb | 12 +++++ .../organizations/_org_custom_header.html.erb | 2 +- .../organizations/_org_students_list.html.erb | 45 +++++++++++++++++++ .../_setting_excellent_students.html.erb | 12 +++++ .../organizations/_subfield_list.html.erb | 2 +- .../reset_excellent_teacher.js.erb | 2 +- app/views/organizations/setting.html.erb | 14 +++--- app/views/organizations/students.html.erb | 30 +++++++++++++ app/views/organizations/students.js.erb | 3 ++ config/routes.rb | 3 ++ ...531021244_add_excellent_student_to_user.rb | 5 +++ db/schema.rb | 3 +- 19 files changed, 167 insertions(+), 31 deletions(-) create mode 100644 app/views/organizations/_org_custom_admin.html.erb create mode 100644 app/views/organizations/_org_students_list.html.erb create mode 100644 app/views/organizations/_setting_excellent_students.html.erb create mode 100644 app/views/organizations/students.html.erb create mode 100644 app/views/organizations/students.js.erb create mode 100644 db/migrate/20160531021244_add_excellent_student_to_user.rb diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index c628b25fc..01a36d5b9 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -15,11 +15,9 @@ class OrgSubfieldsController < ApplicationController end end @subfield.update_attributes(:field_type => params[:field_type]) - # 如果栏目是教师,不参入类型的配置,定义为右三模式 - # 新增模块命名规则,左边1开头,右边2开头,以前的不变 - # eg:23 右三 - if params[:field_type] == "Comptec" - @subfield.update_attributes(:status => 23) + # 如果栏目是教师或学生,不参入类型的配置,默认定义为右三模式 + if params[:field_type] == "Comptec" || params[:field_type] == "Compstu" + @subfield.update_attribute(:status, 6) end else @res = false diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 3cf36a781..fc0a8b35e 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -28,7 +28,7 @@ class OrganizationsController < ApplicationController helper :project_score helper :issues include UsersHelper - before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers] + before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers, :students] layout 'base_org' def index @@ -159,7 +159,7 @@ class OrganizationsController < ApplicationController end def teachers - unless @organization.allow_set_teachers + unless User.current.admin? render_403 return end @@ -169,12 +169,6 @@ class OrganizationsController < ApplicationController if @type == "courses" || @type.nil? @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") - elsif @type == "students" - @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count - from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") - elsif @type == "resources" - @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from attachments where attachments.author_id = u.id) as course_count - from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") elsif @type == "famous" @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") @@ -192,6 +186,34 @@ class OrganizationsController < ApplicationController end end + def students + unless User.current.admin? + render_403 + return + end + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type == "courses" || @type.nil? + @org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count + from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + elsif @type == "famous" + @org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count + from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and u.excellent_student =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + end + limit = 10 + # @is_remote = true + @students_count = @org_students.count + @atta_pages = Paginator.new @students_count, limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @org_students = paginateHelper @org_students, limit + respond_to do |format| + format.html + format.js + end + end + def searchmember_by_name members, name #searchPeopleByRoles(project, StudentRoles) mems = [] @@ -474,13 +496,13 @@ class OrganizationsController < ApplicationController # 设置为名师 def set_excellent_teacher @ex_teacher = User.find(params[:user]) - @ex_teacher.update_column(:excellent_teacher, 1) + params[:type] == "student" ? @ex_teacher.update_column(:excellent_student, 1) : @ex_teacher.update_column(:excellent_teacher, 1) end # 取消名师 def reset_excellent_teacher @ex_teacher = User.find(params[:user]) - @ex_teacher.update_column(:excellent_teacher, 0) + params[:type] == "student" ? @ex_teacher.update_column(:excellent_student, 0) : @ex_teacher.update_column(:excellent_teacher, 0) end def hide_org_subfield diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index ab3b3715c..7298841b1 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -140,10 +140,13 @@ module OrganizationsHelper org_acts end + def allow_to_create?(org, type) + !org_subfield_had_created?(org, type) && User.current.admin? + end + def org_subfield_had_created?(org, type) sub_field = org.org_subfields.select{|subfield| subfield.field_type == type} result = sub_field.length > 0 ? true : false - result end def org_subfield_type(field) diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 1151426e3..76d472ad9 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -11,6 +11,8 @@ class OrgSubfield < ActiveRecord::Base acts_as_attachable after_create :create_board_sync after_destroy :update_priority + # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 + # 创建资源栏目讨论区 def create_board_sync @board = self.boards.build diff --git a/app/models/organization.rb b/app/models/organization.rb index c35d0591d..7aa259528 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -24,11 +24,11 @@ class Organization < ActiveRecord::Base end def switch_type - self.show_mode.to_i == 1 ? true : false + self.show_mode.to_i == 1 end def allow_set_teachers - self.allow_teacher.to_i == 1 ? true : false + self.allow_teacher.to_i == 1 end def secdomain_name diff --git a/app/views/org_subfields/create.js.erb b/app/views/org_subfields/create.js.erb index 5cc6d5c91..f1661ba87 100644 --- a/app/views/org_subfields/create.js.erb +++ b/app/views/org_subfields/create.js.erb @@ -4,7 +4,7 @@ :locals => {:subfields => @organization.org_subfields.order("priority") }) %>"); $("#sub_field_left_lists").html(""); $("#sub_field_left_lists").html("<%= escape_javascript(render :partial => 'organizations/org_left_subfield_list', :locals => {:organization => @organization}) %>"); - $("#org_excellent_teachers").html("<%= escape_javascript(render :partial => 'organizations/setting_excellent_teachers') %>"); + $("#org_custom_admin").html("<%= escape_javascript(render :partial => 'organizations/org_custom_admin') %>"); <% end %> $("#subfield_name").val(""); $("#sub_dir").val(""); \ No newline at end of file diff --git a/app/views/org_subfields/destroy.js.erb b/app/views/org_subfields/destroy.js.erb index c14eeae8f..60ce47fe6 100644 --- a/app/views/org_subfields/destroy.js.erb +++ b/app/views/org_subfields/destroy.js.erb @@ -3,4 +3,4 @@ $("#org_subfield_list").html("<%= escape_javascript(render :partial => 'organiza :locals => {:subfields => @organization.org_subfields.order("priority") }) %>"); $("#sub_field_left_lists").html(""); $("#sub_field_left_lists").html("<%= escape_javascript(render :partial => 'organizations/org_left_subfield_list', :locals => {:organization => @organization}) %>"); -$("#org_excellent_teachers").html("<%= escape_javascript(render :partial => 'organizations/setting_excellent_teachers') %>"); \ No newline at end of file +$("#org_custom_admin").html("<%= escape_javascript(render :partial => 'organizations/org_custom_admin') %>"); \ No newline at end of file diff --git a/app/views/organizations/_org_custom_admin.html.erb b/app/views/organizations/_org_custom_admin.html.erb new file mode 100644 index 000000000..559b52b63 --- /dev/null +++ b/app/views/organizations/_org_custom_admin.html.erb @@ -0,0 +1,12 @@ +<% if allow_to_create?(@organization, "Comptec") %> +
  • + + +
  • +<% end %> +<% if allow_to_create?(@organization, "Compstu") %> +
  • + + +
  • +<% end %> \ No newline at end of file diff --git a/app/views/organizations/_org_custom_header.html.erb b/app/views/organizations/_org_custom_header.html.erb index 4d00550a8..fc556255a 100644 --- a/app/views/organizations/_org_custom_header.html.erb +++ b/app/views/organizations/_org_custom_header.html.erb @@ -67,7 +67,7 @@ <% end %> <% if User.current.admin_of_org?(@organization) %> - 配置 + 配置 <% end %>
    diff --git a/app/views/organizations/_org_students_list.html.erb b/app/views/organizations/_org_students_list.html.erb new file mode 100644 index 000000000..4f768d29f --- /dev/null +++ b/app/views/organizations/_org_students_list.html.erb @@ -0,0 +1,45 @@ +<% org_students.each do |org_student| %> + <% school = School.where("id =?", org_student.school_id).first %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(org_student), :width => "90", :height => "90"), user_url_in_org(org_student), :alt => "用户头像" %> +
    +
    +
    <%=link_to org_student.try(:realname).nil? ? org_student.try(:login) : org_student.try(:realname), user_url_in_org(org_student) %> + <% unless school.nil? %> + <%= school.name %> + <% end %> +
    +
    +
    <%= org_student.courses.count %>
    +
    课程数
    +
    +
    +
    +
    <%= org_teacher_resource_count(org_student) %>
    +
    资源数
    +
    +
    + <% if User.current.admin_of_org?(@organization) %> + <%= org_student.excellent_student ==0 ? "设为学霸" : "取消设置" %> + <% end %> +
    +
    +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/organizations/_setting_excellent_students.html.erb b/app/views/organizations/_setting_excellent_students.html.erb new file mode 100644 index 000000000..696d85378 --- /dev/null +++ b/app/views/organizations/_setting_excellent_students.html.erb @@ -0,0 +1,12 @@ +<% if @organization.allow_set_teachers && !org_subfield_had_created?(@organization, "Comptec") %> +
  • + + +
  • +<% end %> +<% if User.current.admin? && !org_subfield_had_created?(@organization, "Compstu") %> +
  • + + +
  • +<% end %> \ No newline at end of file diff --git a/app/views/organizations/_subfield_list.html.erb b/app/views/organizations/_subfield_list.html.erb index f16e53b0e..9307f3eb0 100644 --- a/app/views/organizations/_subfield_list.html.erb +++ b/app/views/organizations/_subfield_list.html.erb @@ -92,7 +92,7 @@ <%= link_to "删除", org_subfield_path(field), :method => 'delete', :remote => true, :confirm => "您确定删除吗?", :class => "linkGrey fr ml5 mr5" %> | 编辑 - <% unless field.field_type == "Resource" || field.field_type == "Comptec" %> + <% unless field.field_type == "Resource" || field.field_type == "Comptec" || field.field_type == "Compstu" %> | diff --git a/app/views/organizations/reset_excellent_teacher.js.erb b/app/views/organizations/reset_excellent_teacher.js.erb index fdf160bc4..8b7c6cc71 100644 --- a/app/views/organizations/reset_excellent_teacher.js.erb +++ b/app/views/organizations/reset_excellent_teacher.js.erb @@ -1 +1 @@ -$("#hide_<%= @ex_teacher.id %>").text("设为名师"); \ No newline at end of file +$("#hide_<%= @ex_teacher.id %>").text(<%= params[:type]== "student" ? "设为学霸" : "设为名师"%>); \ No newline at end of file diff --git a/app/views/organizations/setting.html.erb b/app/views/organizations/setting.html.erb index 0c8af8471..1920213cb 100644 --- a/app/views/organizations/setting.html.erb +++ b/app/views/organizations/setting.html.erb @@ -87,11 +87,11 @@  允许游客下载 <%= @organization.is_public? ? "" : "(私有组织不允许游客下载资源)" %> - <% if User.current.admin? %> -
    允许设置名师榜 : - class="ml3" /> -
    - <% end %> + + + + + 保存 <% end %> @@ -162,8 +162,8 @@ -
    - <%= render :partial => 'organizations/setting_excellent_teachers' %> +
    + <%= render :partial => 'organizations/org_custom_admin' %>
  • 新增
  • diff --git a/app/views/organizations/students.html.erb b/app/views/organizations/students.html.erb new file mode 100644 index 000000000..770967210 --- /dev/null +++ b/app/views/organizations/students.html.erb @@ -0,0 +1,30 @@ +
    +
    + <% if @type == "famous" %> + 学霸列表 + <% else %> + <%= @field.name %> + <% end %> +
    +
    +
    + +
    + <%=render 'organizations/org_students_list', :org_students => @org_students %> +
    +
    +
      + <%= pagination_links_full @atta_pages, @students_count, :per_page_links => false, :flag => true %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/students.js.erb b/app/views/organizations/students.js.erb new file mode 100644 index 000000000..c65f8f861 --- /dev/null +++ b/app/views/organizations/students.js.erb @@ -0,0 +1,3 @@ +$("#org_students_list").html('<%= escape_javascript( render :partial => 'organizations/org_students_list', :locals => {:org_students => @org_students})%>'); +$("#pages").html('<%= pagination_links_full @atta_pages, @students_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#org_student_search").attr('href','<%= students_organization_path(@organization, :type => @type) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2863d49a4..71b8f298e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,6 +77,7 @@ RedmineApp::Application.routes.draw do get 'more_org_courses' get 'search_courses' get 'teachers' + get 'students' post 'join_course_menu' post 'join_courses' get 'search_projects' @@ -94,7 +95,9 @@ RedmineApp::Application.routes.draw do post 'hide_org_subfield' post 'show_org_subfield' post 'set_excellent_teacher' + post 'set_excellent_student' post 'reset_excellent_teacher' + post 'reset_excellent_student' post 'agree_apply_subdomain' end end diff --git a/db/migrate/20160531021244_add_excellent_student_to_user.rb b/db/migrate/20160531021244_add_excellent_student_to_user.rb new file mode 100644 index 000000000..08378bca5 --- /dev/null +++ b/db/migrate/20160531021244_add_excellent_student_to_user.rb @@ -0,0 +1,5 @@ +class AddExcellentStudentToUser < ActiveRecord::Migration + def change + add_column :users, :excellent_student, :integer, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 7462c304e..f7d61f57c 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 => 20160523085440) do +ActiveRecord::Schema.define(:version => 20160531021244) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -2426,6 +2426,7 @@ ActiveRecord::Schema.define(:version => 20160523085440) do t.integer "gid" t.integer "visits", :default => 0 t.integer "excellent_teacher", :default => 0 + t.integer "excellent_student", :default => 0 end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id"