From 27a9170318938750c20ee927fc4f5fc24d701844 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 1 Jun 2016 17:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=B7=BB=E5=8A=A0=E8=AE=BE?= =?UTF-8?q?=E4=B8=BA=E7=B2=BE=E5=93=81=E9=A1=B9=E7=9B=AE=EF=BC=8C=E7=83=AD?= =?UTF-8?q?=E9=97=A8=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/org_subfields_controller.rb | 24 +++++-- app/controllers/organizations_controller.rb | 68 ++++++++++++++++--- app/helpers/organizations_helper.rb | 5 ++ app/models/org_subfield.rb | 2 +- .../organizations/_org_container.html.erb | 39 +++++++++++ .../organizations/_org_custom_admin.html.erb | 18 +++++ .../_org_left_subfield_list.html.erb | 16 +++++ app/views/organizations/courses.html.erb | 30 ++++++++ app/views/organizations/courses.js.erb | 3 + app/views/organizations/projects.html.erb | 30 ++++++++ app/views/organizations/projects.js.erb | 3 + config/routes.rb | 5 ++ .../20160601073753_add_hot_to_project.rb | 5 ++ db/schema.rb | 3 +- public/javascripts/org.js | 19 ++++++ 15 files changed, 254 insertions(+), 16 deletions(-) create mode 100644 app/views/organizations/_org_container.html.erb create mode 100644 app/views/organizations/courses.html.erb create mode 100644 app/views/organizations/courses.js.erb create mode 100644 app/views/organizations/projects.html.erb create mode 100644 app/views/organizations/projects.js.erb create mode 100644 db/migrate/20160601073753_add_hot_to_project.rb diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 01a36d5b9..496c3aa92 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -6,7 +6,7 @@ class OrgSubfieldsController < ApplicationController if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0 @res = true @organization = Organization.find(params[:organization_id]) - @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1) + @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id], :priority => @organization.org_subfields.order("priority").last.priority + 1) if !params[:sub_dir].blank? sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" @@ -15,15 +15,29 @@ class OrgSubfieldsController < ApplicationController end end @subfield.update_attributes(:field_type => params[:field_type]) - # 如果栏目是教师或学生,不参入类型的配置,默认定义为右三模式 - if params[:field_type] == "Comptec" || params[:field_type] == "Compstu" - @subfield.update_attribute(:status, 6) - end + # admin配置的类型 + update_status_by_type(@subfield, params[:field_type]) else @res = false end end + # status类型说明,详见SubField + def update_status_by_type subfield, type + case type + when "Comptec" + subfield.update_attribute(:status, 6) + when "Compstu" + subfield.update_attribute(:status, 7) + when "Comppro" + subfield.update_attribute(:status, 8) + when "Compcou" + subfield.update_attribute(:status, 9) + when "Compact" + subfield.update_attribute(:status, 10) + end + end + def show @flag = params[:flag] || false sort = "" diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index fc0a8b35e..1b328ad7e 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -28,7 +28,8 @@ class OrganizationsController < ApplicationController helper :project_score helper :issues include UsersHelper - before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers, :students] + before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers, :students, :projects, :courses] + before_filter :allow_as_admin, :only => [:students, :teachers, :projects, :courses, :acts] layout 'base_org' def index @@ -159,10 +160,6 @@ class OrganizationsController < ApplicationController end def teachers - 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, "Comptec").first : OrgSubfield.find(params[:org_subfield_id]) @type = params[:type] @@ -187,10 +184,6 @@ class OrganizationsController < ApplicationController 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] @@ -214,6 +207,56 @@ class OrganizationsController < ApplicationController end end + def atta_page_public container + limit = 10 + @containers_count = container.count + @atta_pages = Paginator.new @containers_count, limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @containers = paginateHelper container, limit + respond_to do |format| + format.html + format.js + end + end + + def projects + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comppro").first : OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type.nil? + @containers = Project.find_by_sql("SELECT * FROM `projects` where status = 1 and is_public = 1 and name like '%#{q}%' order by updated_on desc;") + elsif @type == "famous" + @containers = Project.find_by_sql("SELECT * FROM `projects` where status =1 and is_public = 1 and hot = 1 and name like '%#{q}%' order by updated_on desc;") + end + atta_page_public @containers + end + + def courses + 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.nil? + @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and name like '%#{q}%' order by updated_at desc;") + elsif @type == "famous" + @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and hot = 1 and name like '%#{q}%' order by updated_at desc;") + end + atta_page_public @containers + end + + def acts + 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 + atta_page_public container @containers + end + def searchmember_by_name members, name #searchPeopleByRoles(project, StudentRoles) mems = [] @@ -344,6 +387,13 @@ class OrganizationsController < ApplicationController @organization = Organization.find(params[:id]) end + def allow_as_admin + unless User.current.admin? + render_403 + return + end + end + def setting @organization = Organization.find(params[:id]) diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 437014528..8e75ec5d1 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -175,6 +175,11 @@ module OrganizationsHelper end end + # 获取最新动态 + def get_latest_acts + acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'news', 'message', 'Issue') and (container_type = 'Course' or container_type = 'Project') order by created_at limit 10;") + end + def org_teacher_resource_count user results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count end diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 76d472ad9..32212a0e8 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -11,7 +11,7 @@ class OrgSubfield < ActiveRecord::Base acts_as_attachable after_create :create_board_sync after_destroy :update_priority - # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 + # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 默认的 7 学霸 8 热门项目 9 精品课程 10 最新动态 # 创建资源栏目讨论区 def create_board_sync diff --git a/app/views/organizations/_org_container.html.erb b/app/views/organizations/_org_container.html.erb new file mode 100644 index 000000000..42c216879 --- /dev/null +++ b/app/views/organizations/_org_container.html.erb @@ -0,0 +1,39 @@ +<% containers.each do |container| %> +
+
+
+ <%= link_to image_tag(url_to_avatar(container), :width => "90", :height => "90"), container.class == Course ? course_path(container) : project_path(container) %> +
+
+
<%=link_to container.name, container.class == Course ? course_path(container) : project_path(container) %>
+
+
<%= container.members.count %>
+
成员
+
+
+
+
<%= container.attachments.count %>
+
资源
+
+
+ + <%= (container.class == Course ? container.is_excellent == 0 : container.hot ==0) ? "设为热门" : "取消设置" %> +
+
+
+<% end %> + + \ 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 index 559b52b63..2f454819c 100644 --- a/app/views/organizations/_org_custom_admin.html.erb +++ b/app/views/organizations/_org_custom_admin.html.erb @@ -9,4 +9,22 @@ +<% end %> +<% if allow_to_create?(@organization, "Comppro") %> +
  • + + +
  • +<% end %> +<% if allow_to_create?(@organization, "Compcou") %> +
  • + + +
  • +<% end %> +<% if allow_to_create?(@organization, "Compact") %> +
  • + + +
  • <% end %> \ No newline at end of file diff --git a/app/views/organizations/_org_left_subfield_list.html.erb b/app/views/organizations/_org_left_subfield_list.html.erb index e621df8bd..30234c300 100644 --- a/app/views/organizations/_org_left_subfield_list.html.erb +++ b/app/views/organizations/_org_left_subfield_list.html.erb @@ -125,6 +125,22 @@
    <%= link_to "#{field.name}", students_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %>
    + <% elsif field.field_type == "Compstu" && User.current.admin? %> +
    + <%= link_to "#{field.name}", students_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> +
    + <% elsif field.field_type == "Comppro" && User.current.admin? %> +
    + <%= link_to "#{field.name}", projects_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> +
    + <% elsif field.field_type == "Compcou" && User.current.admin? %> +
    + <%= link_to "#{field.name}", courses_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> +
    + <% elsif field.field_type == "Compact" && User.current.admin? %> +
    + <%= link_to "#{field.name}", acts_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> +
    <% elsif field.field_type == "Resource" %>
    <% if !field.subfield_subdomain_dir.nil? %> diff --git a/app/views/organizations/courses.html.erb b/app/views/organizations/courses.html.erb new file mode 100644 index 000000000..875fc3340 --- /dev/null +++ b/app/views/organizations/courses.html.erb @@ -0,0 +1,30 @@ +
    +
    + <% if @type == "famous" %> + 精品课程 + <% else %> + <%= @field.name %> + <% end %> +
    +
    +
    + +
    + <%=render 'organizations/org_container', :containers => @containers %> +
    +
    +
      + <%= pagination_links_full @atta_pages, @containers_count, :per_page_links => false, :flag => true %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/courses.js.erb b/app/views/organizations/courses.js.erb new file mode 100644 index 000000000..dc42c115c --- /dev/null +++ b/app/views/organizations/courses.js.erb @@ -0,0 +1,3 @@ +$("#org_container_list").html('<%= escape_javascript( render :partial => 'organizations/org_container', :locals => {:containers => @containers})%>'); +$("#pages").html('<%= pagination_links_full @atta_pages, @container_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#org_student_search").attr('href','<%= courses_organization_path(@organization, :type => @type) %>'); \ No newline at end of file diff --git a/app/views/organizations/projects.html.erb b/app/views/organizations/projects.html.erb new file mode 100644 index 000000000..1c6cfa1d1 --- /dev/null +++ b/app/views/organizations/projects.html.erb @@ -0,0 +1,30 @@ +
    +
    + <% if @type == "famous" %> + 热门项目 + <% else %> + <%= @field.name %> + <% end %> +
    +
    +
    + +
    + <%=render 'organizations/org_container', :containers => @containers %> +
    +
    +
      + <%= pagination_links_full @atta_pages, @containers_count, :per_page_links => false, :flag => true %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/projects.js.erb b/app/views/organizations/projects.js.erb new file mode 100644 index 000000000..e8d4f244a --- /dev/null +++ b/app/views/organizations/projects.js.erb @@ -0,0 +1,3 @@ +$("#org_container_list").html('<%= escape_javascript( render :partial => 'organizations/org_container', :locals => {:containers => @containers})%>'); +$("#pages").html('<%= pagination_links_full @atta_pages, @container_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#org_student_search").attr('href','<%= projects_organization_path(@organization, :type => @type) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 71b8f298e..0349fc122 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,9 @@ RedmineApp::Application.routes.draw do get 'search_courses' get 'teachers' get 'students' + get 'projects' + get 'courses' + get 'acts' post 'join_course_menu' post 'join_courses' get 'search_projects' @@ -99,6 +102,8 @@ RedmineApp::Application.routes.draw do post 'reset_excellent_teacher' post 'reset_excellent_student' post 'agree_apply_subdomain' + post 'update_field_by_admin' + post 'reset_update_field_by_admin' end end diff --git a/db/migrate/20160601073753_add_hot_to_project.rb b/db/migrate/20160601073753_add_hot_to_project.rb new file mode 100644 index 000000000..f35afa97f --- /dev/null +++ b/db/migrate/20160601073753_add_hot_to_project.rb @@ -0,0 +1,5 @@ +class AddHotToProject < ActiveRecord::Migration + def change + add_column :projects, :hot, :integer, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index f7d61f57c..05a6f4e22 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 => 20160531021244) do +ActiveRecord::Schema.define(:version => 20160601073753) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1810,6 +1810,7 @@ ActiveRecord::Schema.define(:version => 20160531021244) do t.integer "journals_count", :default => 0 t.integer "boards_reply_count", :default => 0 t.integer "visits", :default => 0 + t.integer "hot", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft" diff --git a/public/javascripts/org.js b/public/javascripts/org.js index 5b18372ed..05ae5e717 100644 --- a/public/javascripts/org.js +++ b/public/javascripts/org.js @@ -108,4 +108,23 @@ function chooseTeacherType(org_id){ } } lastSendType = sendType; +} + +//修改状态 +function admin_hide_org(content, id){ + if (content.text() == '设为热门') + $.ajax({ + url: "/organizations/update_field_by_admin?user=" + id + "&type=project", + type: "post" + }); + else if (content.text() == '设为精品') + $.ajax({ + url: "/organizations/update_field_by_admin?user=" + id + "&type=course", + type: "post" + }); + else if (content.text() == '取消设置') + $.ajax({ + url: "/organizations/reset_update_field_by_admin?user=" + id + "&type=student", + type: "post" + }); } \ No newline at end of file