From caf5602389ece0a5526cff1c990782724727be9c Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 23 Sep 2016 09:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=A4=A7=E7=BA=B2=E6=95=99?= =?UTF-8?q?=E5=B8=88=E5=9B=A2=E9=98=9F=E7=9A=84=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/syllabus_member.js.coffee | 3 + .../stylesheets/syllabus_member.css.scss | 3 + app/controllers/syllabus_member_controller.rb | 64 +++++++++++++++++++ app/controllers/syllabuses_controller.rb | 10 ++- app/helpers/syllabus_member_helper.rb | 17 +++++ app/helpers/syllabuses_helper.rb | 14 ++++ app/models/principal.rb | 10 +++ app/models/syllabus.rb | 1 + app/models/syllabus_member.rb | 5 ++ app/models/user.rb | 1 + .../layouts/_syllabus_teacher_list.html.erb | 10 +-- app/views/layouts/base_syllabus.html.erb | 13 ++-- app/views/syllabus_member/create.js.erb | 4 ++ app/views/syllabus_member/destroy.js.erb | 2 + .../syl_member_autocomplete.js.erb | 19 ++++++ app/views/syllabus_member/update_rank.js.erb | 2 + .../syllabuses/_syllabus_course_list.html.erb | 14 ++-- .../syllabuses/_syllabus_member_list.html.erb | 55 ++++++++++++++++ app/views/syllabuses/members.html.erb | 51 +++++++++++++++ app/views/syllabuses/show.html.erb | 3 + .../syllabuses/syllabus_courselist.html.erb | 3 + config/locales/projects/zh.yml | 2 +- config/routes.rb | 11 ++++ .../20160921062340_create_syllabus_members.rb | 23 +++++++ db/schema.rb | 46 ++++++++----- public/stylesheets/syllabus.css | 17 +++++ .../syllabus_member_controller_spec.rb | 5 ++ spec/factories/syllabus_members.rb | 9 +++ spec/models/syllabus_member_spec.rb | 5 ++ 29 files changed, 384 insertions(+), 38 deletions(-) create mode 100644 app/assets/javascripts/syllabus_member.js.coffee create mode 100644 app/assets/stylesheets/syllabus_member.css.scss create mode 100644 app/controllers/syllabus_member_controller.rb create mode 100644 app/helpers/syllabus_member_helper.rb create mode 100644 app/models/syllabus_member.rb create mode 100644 app/views/syllabus_member/create.js.erb create mode 100644 app/views/syllabus_member/destroy.js.erb create mode 100644 app/views/syllabus_member/syl_member_autocomplete.js.erb create mode 100644 app/views/syllabus_member/update_rank.js.erb create mode 100644 app/views/syllabuses/_syllabus_member_list.html.erb create mode 100644 app/views/syllabuses/members.html.erb create mode 100644 db/migrate/20160921062340_create_syllabus_members.rb create mode 100644 spec/controllers/syllabus_member_controller_spec.rb create mode 100644 spec/factories/syllabus_members.rb create mode 100644 spec/models/syllabus_member_spec.rb diff --git a/app/assets/javascripts/syllabus_member.js.coffee b/app/assets/javascripts/syllabus_member.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/syllabus_member.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/syllabus_member.css.scss b/app/assets/stylesheets/syllabus_member.css.scss new file mode 100644 index 000000000..579bf153b --- /dev/null +++ b/app/assets/stylesheets/syllabus_member.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the SyllabusMember controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/syllabus_member_controller.rb b/app/controllers/syllabus_member_controller.rb new file mode 100644 index 000000000..ac686c0a2 --- /dev/null +++ b/app/controllers/syllabus_member_controller.rb @@ -0,0 +1,64 @@ +class SyllabusMemberController < ApplicationController + + def syl_member_autocomplete + @syllabus = Syllabus.find(params[:syllabus]) + @flag = params[:flag] || false + respond_to do |format| + format.js + end + end + + def create + @syllabus = Syllabus.find(params[:syllabus]) + if params[:membership].nil? + @fail_hint = l(:label_blank_user_lists_for_org) + else + member_ids = params[:membership][:user_ids] + last_rank = @syllabus.syllabus_members.order("rank asc").last.rank + user_ids = @syllabus.syllabus_members.map{|sy| sy.user_id} + member_ids.each_with_index do |user_id, i| + unless user_ids.include?(user_id.to_i) + member = SyllabusMember.create(:user_id => user_id, :rank => last_rank + 1 + i) + @syllabus.syllabus_members << member + end + end + @members = @syllabus.syllabus_members.order("rank asc") + end + respond_to do |format| + format.js + end + end + + def destroy + member = SyllabusMember.find(params[:id]) + @syllabus = member.syllabus + after_syl_members = @syllabus.syllabus_members.where("rank > #{member.rank}") + after_syl_members.update_all("rank = rank - 1") + member.destroy + @members = @syllabus.syllabus_members.order("rank asc") + respond_to do |format| + format.js + end + end + + def update_rank + member = SyllabusMember.find(params[:id]) + @syllabus = member.syllabus + members = @syllabus.syllabus_members + if params[:opr] == 'up' && member.rank > 2 + before_mem = members.where("rank = #{member.rank - 1}").first + if before_mem && member.update_attribute('rank', member.rank - 1) + before_mem.update_attribute('rank', before_mem.rank + 1) + end + elsif params[:opr] == 'down' && member.rank > 1 && member.rank < members.count + after_mem = members.where("rank = #{member.rank + 1}").first + if after_mem && member.update_attribute('rank', member.rank + 1) + after_mem.update_attribute('rank', after_mem.rank - 1) + end + end + @members = @syllabus.syllabus_members.order("rank asc") + respond_to do |format| + format.js + end + end +end diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index e77b19511..94f05409c 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -6,7 +6,7 @@ class SyllabusesController < ApplicationController include CoursesHelper before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus] - before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :edit_syllabus_title, :update_base_info, :delete_syllabus, :delete_des] + before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :edit_syllabus_title, :update_base_info, :delete_syllabus, :delete_des, :members] def index user = User.current @syllabuses = user.syllabuses @@ -170,6 +170,14 @@ class SyllabusesController < ApplicationController end end + def members + @members = @syllabus.syllabus_members.includes(:user => {:user_extensions => [], :courses => []}).order("rank asc") + respond_to do |format| + format.js + format.html{render :layout => 'base_syllabus'} + end + end + private def find_syllabus @syllabus = Syllabus.find params[:id] diff --git a/app/helpers/syllabus_member_helper.rb b/app/helpers/syllabus_member_helper.rb new file mode 100644 index 000000000..491928d74 --- /dev/null +++ b/app/helpers/syllabus_member_helper.rb @@ -0,0 +1,17 @@ +module SyllabusMemberHelper + include ApplicationHelper + + def find_user_not_in_current_syllabus_by_name syllabus + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_syllabus(syllabus).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals', :class => 'sy_new_tchlist') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, host_with_protocol + "/syllabus_member/syl_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:syllabus=> syllabus, :format => 'js').to_query, :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "syllabus_member_pagination_links" ) + end +end diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index 7e815950b..b9e3d09c1 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -4,6 +4,20 @@ module SyllabusesHelper Syllabus.tagged_with(tag_name).order('updated_at desc') end + def find_user_not_in_current_syllabus_by_name syllabus + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_syllabus(syllabus).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals', :class => 'sy_new_tchlist') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, host_with_protocol + "/syllabus_member/syl_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:syllabus=> syllabus, :format => 'js').to_query, :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "syllabus_member_pagination_links" ) + end + def teacher_count syllabus count = 0 courses = syllabus.courses diff --git a/app/models/principal.rb b/app/models/principal.rb index e65816e83..7c2b24587 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -97,6 +97,16 @@ class Principal < ActiveRecord::Base end } + scope :not_member_of_syllabus, lambda {|syllabus| + syllabuses = [syllabus] unless syllabus.is_a?(Array) + if syllabuses.empty? + where("1=0") + else + ids = syllabuses.map(&:id) + where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{SyllabusMember.table_name} WHERE syllabus_id IN (?))", ids) + end + } + scope :sorted, lambda { order(*Principal.fields_for_order_statement)} scope :applied_members, lambda {|project| diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 29b675d25..0c23c1b13 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -9,6 +9,7 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :syllabus_members, :dependent => :destroy attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' diff --git a/app/models/syllabus_member.rb b/app/models/syllabus_member.rb new file mode 100644 index 000000000..40d3dacbe --- /dev/null +++ b/app/models/syllabus_member.rb @@ -0,0 +1,5 @@ +class SyllabusMember < ActiveRecord::Base + belongs_to :syllabus + belongs_to :user + attr_accessible :rank, :user_id, :syllabus_id +end diff --git a/app/models/user.rb b/app/models/user.rb index f2b2b6824..c1a830809 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,7 @@ class User < Principal has_many :homework_attaches, :through => :homework_users has_many :homework_evaluations has_many :syllabuses, :dependent => :destroy + has_many :syllabus_members, :dependent => :destroy #问卷相关关关系 has_many :poll_users, :dependent => :destroy has_many :poll_votes, :dependent => :destroy diff --git a/app/views/layouts/_syllabus_teacher_list.html.erb b/app/views/layouts/_syllabus_teacher_list.html.erb index 344036ccf..c6d6fd59a 100644 --- a/app/views/layouts/_syllabus_teacher_list.html.erb +++ b/app/views/layouts/_syllabus_teacher_list.html.erb @@ -1,10 +1,12 @@

教师团队 - 增加教师 + <% if User.current == @syllabus.user || User.current.admin? %> + 增加教师 + <% end %>

\ No newline at end of file diff --git a/app/views/layouts/base_syllabus.html.erb b/app/views/layouts/base_syllabus.html.erb index 445af2a8b..3153741e0 100644 --- a/app/views/layouts/base_syllabus.html.erb +++ b/app/views/layouts/base_syllabus.html.erb @@ -60,11 +60,12 @@ <%= yield %>
+ <% members = @syllabus.syllabus_members.order("rank asc") %>
<%= render :partial => 'layouts/syllabus_base_info', :locals => {:syllabus => @syllabus} %>
-
- <%= render :partial => 'layouts/syllabus_teacher_list', :locals => {:syllabus => @syllabus} %> +
+ <%= render :partial => 'layouts/syllabus_teacher_list', :locals => {:syllabus => @syllabus, :members => members} %>
@@ -123,16 +124,18 @@ } function g(o){return document.getElementById(o);} function HoverLi(n){ - for(var i=1;i<=2;i++){ + //for(var i=1;i<=2;i++){ //g('sy_tab_nav_'+i).className='sy_tab_nomal'; //g('sy_tab_con_'+i).className='undis'; - } + //} //g('sy_tab_con_'+n).className='dis'; //g('sy_tab_nav_'+n).className='sy_tab_hover'; if(n == 1) { window.location.href = '<%=syllabus_path(@syllabus) %>'; - } else { + } else if(n == 2) { window.location.href = '<%=syllabus_courselist_syllabus_path(@syllabus) %>'; + } else if(n == 3) { + window.location.href = '<%=members_syllabus_path(@syllabus) %>'; } } //侧导航栏配置设置 diff --git a/app/views/syllabus_member/create.js.erb b/app/views/syllabus_member/create.js.erb new file mode 100644 index 000000000..d63db3288 --- /dev/null +++ b/app/views/syllabus_member/create.js.erb @@ -0,0 +1,4 @@ +$("#syllabus_member_list").replaceWith("<%= escape_javascript(render :partial => 'syllabuses/syllabus_member_list') %>"); +$("#syllabus_teacher_list").html("<%= escape_javascript(render :partial => 'layouts/syllabus_teacher_list', :locals => {:syllabus => @syllabus, :members => @members}) %>"); +$("#principal_search").val(""); +$("#principals_for_new_member").html(""); \ No newline at end of file diff --git a/app/views/syllabus_member/destroy.js.erb b/app/views/syllabus_member/destroy.js.erb new file mode 100644 index 000000000..8b1621741 --- /dev/null +++ b/app/views/syllabus_member/destroy.js.erb @@ -0,0 +1,2 @@ +$("#syllabus_member_list").replaceWith("<%= escape_javascript(render :partial => 'syllabuses/syllabus_member_list') %>"); +$("#syllabus_teacher_list").html("<%= escape_javascript(render :partial => 'layouts/syllabus_teacher_list', :locals => {:syllabus => @syllabus, :members => @members}) %>"); \ No newline at end of file diff --git a/app/views/syllabus_member/syl_member_autocomplete.js.erb b/app/views/syllabus_member/syl_member_autocomplete.js.erb new file mode 100644 index 000000000..f6160697d --- /dev/null +++ b/app/views/syllabus_member/syl_member_autocomplete.js.erb @@ -0,0 +1,19 @@ +<% if @syllabus %> +var checked = $("#principals_for_new_member input:checked").size(); +if(checked > 0) +{ + alert('翻页或搜索后将丢失当前选择的用户数据!'); +} +$('#principals_for_new_member').html('<%= escape_javascript(find_user_not_in_current_syllabus_by_name(@syllabus)) %>'); + +<% end %> +var collection = $("#principals_for_new_member").children("#principals").children("label"); +collection.css("text-overflow", "ellipsis"); +collection.css("white-space", "nowrap"); +collection.css("width", "200px"); +collection.css("overflow", "hidden"); +for(i = 0; i < collection.length; i++) { //增加悬浮显示 + var label = collection[i]; + var text = $(label).text(); + $(label).attr("title", text); +} \ No newline at end of file diff --git a/app/views/syllabus_member/update_rank.js.erb b/app/views/syllabus_member/update_rank.js.erb new file mode 100644 index 000000000..8b1621741 --- /dev/null +++ b/app/views/syllabus_member/update_rank.js.erb @@ -0,0 +1,2 @@ +$("#syllabus_member_list").replaceWith("<%= escape_javascript(render :partial => 'syllabuses/syllabus_member_list') %>"); +$("#syllabus_teacher_list").html("<%= escape_javascript(render :partial => 'layouts/syllabus_teacher_list', :locals => {:syllabus => @syllabus, :members => @members}) %>"); \ No newline at end of file diff --git a/app/views/syllabuses/_syllabus_course_list.html.erb b/app/views/syllabuses/_syllabus_course_list.html.erb index e90e274dc..8bbbd3cf9 100644 --- a/app/views/syllabuses/_syllabus_course_list.html.erb +++ b/app/views/syllabuses/_syllabus_course_list.html.erb @@ -9,7 +9,7 @@ <% if @type.to_i == 2 %> <%= link_to "", {:controller => 'syllabuses', :action => 'syllabus_courselist', :id =>@syllabus, :type => @type, :sort => @c_sort, :order => 2 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} mt15 fl", :remote => true %> <% end %> - <% if @syllabus.user == User.current %> + <% if @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) %> <%= link_to "新建班级", new_course_path(:host=> Setting.host_course, :syllabus_id => @syllabus.id), :class => "sy_btn_green fr mt10 mr15", :target => '_blank'%> <% end %>
@@ -21,13 +21,13 @@ <% if course.is_public == 0 && !User.current.member_of_course?(course) && !User.current.admin? %>

<%= link_to @syllabus.title, syllabus_path(@syllabus.id), :style => 'color:#000', :target => '_blank' %> -  ·  + · <%=course.name %>(<%=current_time_and_term_short(course) %>)

<% else %>

<%= link_to @syllabus.title, syllabus_path(@syllabus.id), :style => 'color:#000', :target => '_blank' %> -  ·  + · <%= link_to course.name+"("+current_time_and_term_short(course)+")", course_path(course.id,:host=>Setting.host_course), :style => 'color:#000',:id => "show_course_#{course.id}", :target => '_blank', :title => (course.is_public? ? "公开班级:":"私有班级:")+course.name+"("+current_time_and_term(course)+")"%>

@@ -88,12 +88,6 @@ \ No newline at end of file diff --git a/app/views/syllabuses/_syllabus_member_list.html.erb b/app/views/syllabuses/_syllabus_member_list.html.erb new file mode 100644 index 000000000..4ee3b9c28 --- /dev/null +++ b/app/views/syllabuses/_syllabus_member_list.html.erb @@ -0,0 +1,55 @@ +<% is_admin = User.current == @syllabus.user || User.current.admin? %> + + + + + + + + + <% if is_admin %> + + <% end %> + + + + <% @members.each_with_index do |member, i| %> + <% user = member.user %> + + + + + <% courses = user.courses.not_deleted %> + + + <% if is_admin %> + + <% end %> + + <% end %> + +
序号姓名身份创建班级数参与班级数操作
<%= member.rank %> + <% if member.rank == 1 %> +
<%= user.show_name %>创建者
+ <% else %> + <%= user.show_name %> + <% end %> +
+ <% if user.user_extensions && user.user_extensions.identity %> + <%= get_user_roll user %> + <% end%> + <%= courses.where("tea_id = #{user.id}").count %><%= courses.where("tea_id != #{user.id}").count %> + <% if i == 0 %> +   + <% elsif i == 1 %> + <%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %> + <%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %> + <% elsif i == @members.count - 1 %> + <%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %> + <%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %> + <% else %> + <%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %> + <%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %> + <%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %> + <% end %> +
\ No newline at end of file diff --git a/app/views/syllabuses/members.html.erb b/app/views/syllabuses/members.html.erb new file mode 100644 index 000000000..fd4041b20 --- /dev/null +++ b/app/views/syllabuses/members.html.erb @@ -0,0 +1,51 @@ + + +
+
+ <%= render :partial => 'syllabus_member_list' %> + 添加成员 +
+ +
+ + \ No newline at end of file diff --git a/app/views/syllabuses/show.html.erb b/app/views/syllabuses/show.html.erb index 17d03b8c5..03eb3f90a 100644 --- a/app/views/syllabuses/show.html.erb +++ b/app/views/syllabuses/show.html.erb @@ -14,6 +14,9 @@
  • 班级列表
  • +
  • + 教师团队 +
  • <% if @syllabus.des_status == 0 && User.current == @syllabus.user %> diff --git a/app/views/syllabuses/syllabus_courselist.html.erb b/app/views/syllabuses/syllabus_courselist.html.erb index ecb8ed7b8..123d1e332 100644 --- a/app/views/syllabuses/syllabus_courselist.html.erb +++ b/app/views/syllabuses/syllabus_courselist.html.erb @@ -5,6 +5,9 @@
  • 班级列表
  • +
  • + 教师团队 +
  • diff --git a/config/locales/projects/zh.yml b/config/locales/projects/zh.yml index 792ff35fd..4040edcc8 100644 --- a/config/locales/projects/zh.yml +++ b/config/locales/projects/zh.yml @@ -369,7 +369,7 @@ zh: label_input_email: 请输入邮箱地址 label_invite_trustie_user: "邀请Trustie注册用户" - label_invite_trustie_user_tips: "支持姓名、邮箱、登录名搜索!" + label_invite_trustie_user_tips: "支持姓名、邮箱、登录名搜索" label_user_role_null: 用户和角色不能留空! label_invite_project: 邀请您加入项目 label_mail_invite_success: 您已成功加入项目! diff --git a/config/routes.rb b/config/routes.rb index afe30d4de..d3700bb73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1140,6 +1140,7 @@ RedmineApp::Application.routes.draw do post 'update_base_info' get 'delete_syllabus' get 'delete_des' + get 'members' end collection do @@ -1147,6 +1148,16 @@ RedmineApp::Application.routes.draw do end end + resources :syllabus_member do + member do + post 'update_rank' + end + + collection do + get 'syl_member_autocomplete' + end + end + # add by nwb # 课程路由设置 resources :courses do diff --git a/db/migrate/20160921062340_create_syllabus_members.rb b/db/migrate/20160921062340_create_syllabus_members.rb new file mode 100644 index 000000000..c2e76ee3f --- /dev/null +++ b/db/migrate/20160921062340_create_syllabus_members.rb @@ -0,0 +1,23 @@ +class CreateSyllabusMembers < ActiveRecord::Migration + def change + create_table :syllabus_members do |t| + t.integer :rank + t.references :syllabus + t.references :user + + t.timestamps + end + add_index :syllabus_members, :syllabus_id + add_index :syllabus_members, :user_id + add_index :syllabus_members, :rank + + count = Syllabus.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + Syllabus.page(i).per(30).each do |syllabus| + SyllabusMember.create(:user_id => syllabus.user_id, :syllabus_id => syllabus.id, :rank => 1) + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 443e8c426..d8a60c93f 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 => 20160907080621) do +ActiveRecord::Schema.define(:version => 20160921062340) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -56,10 +56,10 @@ ActiveRecord::Schema.define(:version => 20160907080621) do t.integer "user_id" t.integer "applied_id" t.string "applied_type" - t.integer "viewed" - t.integer "status" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "viewed", :default => 0 + t.integer "status", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "name" t.integer "applied_user_id" t.integer "role" @@ -157,13 +157,13 @@ ActiveRecord::Schema.define(:version => 20160907080621) do create_table "attachments", :force => true do |t| t.integer "container_id" t.string "container_type", :limit => 30 - t.string "filename", :default => "", :null => false - t.string "disk_filename", :default => "", :null => false - t.integer "filesize", :default => 0, :null => false + t.string "filename", :default => "", :null => false + t.string "disk_filename", :default => "", :null => false + t.integer "filesize", :default => 0, :null => false t.string "content_type", :default => "" - t.string "digest", :limit => 40, :default => "", :null => false - t.integer "downloads", :default => 0, :null => false - t.integer "author_id", :default => 0, :null => false + t.string "digest", :limit => 40, :default => "", :null => false + t.integer "downloads", :default => 0, :null => false + t.integer "author_id", :default => 0, :null => false t.datetime "created_on" t.string "description" t.string "disk_directory" @@ -173,7 +173,6 @@ ActiveRecord::Schema.define(:version => 20160907080621) do t.integer "quotes" t.integer "is_publish", :default => 1 t.date "publish_time" - t.boolean "init_file", :default => false end add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id" @@ -311,16 +310,14 @@ ActiveRecord::Schema.define(:version => 20160907080621) do add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids" create_table "changesets", :force => true do |t| - t.integer "repository_id", :null => false - t.string "revision", :null => false + t.integer "repository_id", :null => false + t.string "revision", :null => false t.string "committer" - t.datetime "committed_on", :null => false + t.datetime "committed_on", :null => false t.text "comments" t.date "commit_date" t.string "scmid" t.integer "user_id" - t.integer "project_id" - t.integer "type", :default => 0 end add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on" @@ -1881,6 +1878,9 @@ ActiveRecord::Schema.define(:version => 20160907080621) do t.datetime "updated_at", :null => false end + add_index "student_works_scores", ["student_work_id"], :name => "student_work_id" + add_index "student_works_scores", ["user_id"], :name => "user_id" + create_table "students_for_courses", :force => true do |t| t.integer "student_id" t.integer "course_id" @@ -1923,6 +1923,18 @@ ActiveRecord::Schema.define(:version => 20160907080621) do t.datetime "updated_at", :null => false end + create_table "syllabus_members", :force => true do |t| + t.integer "rank" + t.integer "syllabus_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "syllabus_members", ["rank"], :name => "index_syllabus_members_on_rank" + add_index "syllabus_members", ["syllabus_id"], :name => "index_syllabus_members_on_syllabus_id" + add_index "syllabus_members", ["user_id"], :name => "index_syllabus_members_on_user_id" + create_table "syllabuses", :force => true do |t| t.string "title" t.text "description" diff --git a/public/stylesheets/syllabus.css b/public/stylesheets/syllabus.css index 9aac34eae..1a04c73a5 100644 --- a/public/stylesheets/syllabus.css +++ b/public/stylesheets/syllabus.css @@ -617,3 +617,20 @@ a:hover.sy_class_ltitle{ color:#333;} /* 我的作业 */ .hw_classname{ width:180px; overflow:hidden; display:block;overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} .hw_tab_top{ height: 50px; line-height: 50px; padding-left: 15px; border-bottom:1px solid #ddd; border-left:3px solid #3b94d6; } + +/*20160918教师团队*/ +.sy_new_tablebox{ padding:15px; padding-bottom:none;} +.sy_new_table{ width:100%; background:#fff; border:1px solid #e5e5e5; padding-bottom:30px;} +.sy_new_table thead tr{ height:40px; line-height:40px;} +.sy_new_table thead tr th{ border-bottom:1px solid #e5e5e5;} +.sy_new_table tbody tr:hover{ background:#f5f5f5;} +.sy_new_table tbody tr td{ height:40px; line-height:40px; border-bottom:1px dashed #e5e5e5; font-weight:normal; color:#888; text-align: center} +.sy_new_table tbody tr:last-child{ height:40px;} +.sy_new_tchlist li{ height:30px; line-height:30px;} +.sy_new_search{-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;border-radius:3px; border:1px solid #d3d3d3; background:#fff; padding-left:5px; color:#888; height:32px; width:370px;box-shadow: inset 0px 0px 3px #dcdcdc; } +.sy_new_tchbox{ background:#f5f5f5; padding:15px; margin:15px; margin-top:0px;} +.sy_new_orange{font-size: 12px;padding: 0 5px;border-radius: 3px;line-height: 14px;color: #ff4a1b;border: 1px solid #ff4a1b;} +.sy_new_namebox{ width:180px; overflow:hidden;} +.sy_new_name{ display:block;max-width:120px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} +.sy_new_long_name{ display:block;width:180px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} +.mt12{ margin-top:12px;} diff --git a/spec/controllers/syllabus_member_controller_spec.rb b/spec/controllers/syllabus_member_controller_spec.rb new file mode 100644 index 000000000..b56654f55 --- /dev/null +++ b/spec/controllers/syllabus_member_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SyllabusMemberController, :type => :controller do + +end diff --git a/spec/factories/syllabus_members.rb b/spec/factories/syllabus_members.rb new file mode 100644 index 000000000..ab1bd6701 --- /dev/null +++ b/spec/factories/syllabus_members.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :syllabus_member do + rank 1 + syllabus nil + user nil + end +end diff --git a/spec/models/syllabus_member_spec.rb b/spec/models/syllabus_member_spec.rb new file mode 100644 index 000000000..464c1e965 --- /dev/null +++ b/spec/models/syllabus_member_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SyllabusMember, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end