From 12ad7c16125e6ebcb3ad26ce932edb3004f27396 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 14 Oct 2016 14:28:19 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E8=AE=A8=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E5=A2=9E=E5=8A=A0=E4=BA=8C=E7=BA=A7=E5=AD=90=E6=A0=8F?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 87 ++++++++++--- app/controllers/messages_controller.rb | 4 +- app/models/board.rb | 8 +- app/views/boards/_course_show.html.erb | 2 +- app/views/boards/create.js.erb | 5 + app/views/boards/destroy.js.erb | 5 + app/views/boards/update_name.js.erb | 5 + app/views/boards/update_position.js.erb | 5 + app/views/courses/_tool_expand.html.erb | 14 ++- app/views/courses/settings.html.erb | 7 ++ .../courses/settings/_boards_setting.html.erb | 115 ++++++++++++++++++ .../layouts/_board_children_list.html.erb | 11 ++ app/views/layouts/base_courses.html.erb | 8 +- app/views/messages/_course_new.html.erb | 4 +- app/views/users/_course_message.html.erb | 2 +- config/routes.rb | 2 + public/javascripts/course.js | 2 +- public/stylesheets/css/common.css | 1 + 18 files changed, 259 insertions(+), 28 deletions(-) create mode 100644 app/views/boards/create.js.erb create mode 100644 app/views/boards/destroy.js.erb create mode 100644 app/views/boards/update_name.js.erb create mode 100644 app/views/boards/update_position.js.erb create mode 100644 app/views/courses/settings/_boards_setting.html.erb create mode 100644 app/views/layouts/_board_children_list.html.erb diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 099e9404a..79ac5db44 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -19,7 +19,7 @@ class BoardsController < ApplicationController layout 'base_projects'#by young default_search_scope :messages before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields] - before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields] + before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name] accept_rss_auth :index, :show @@ -56,8 +56,12 @@ class BoardsController < ApplicationController @boards = @course.boards.includes(:last_message => :author).all end end - unless @course.boards.empty? - @board = @course.boards.first + if params[:board_id] + @board = Board.find params[:board_id].to_i + else + unless @course.boards.where("parent_id is NULL").empty? + @board = @course.boards.where("parent_id is NULL").first + end end show and return else @@ -191,18 +195,31 @@ class BoardsController < ApplicationController end end - def create - @board = @project.boards.build - @board.safe_attributes = params[:board] - - if @board.save - flash[:notice] = l(:notice_successful_create) - #Modified by young - #redirect_to_settings_in_projects - redirect_to project_board_url(@project, @board) - #Ended by young - else - render :action => 'new' + def create + if @project + @board = @project.boards.build + @board.safe_attributes = params[:board] + + if @board.save + flash[:notice] = l(:notice_successful_create) + #Modified by young + #redirect_to_settings_in_projects + redirect_to project_board_url(@project, @board) + #Ended by young + else + render :action => 'new' + end + elsif @course + parent = Board.find params[:board_id].to_i + board = @course.boards.build + board.name = params[:name] + board.description = board.name + board.project_id = -1 + board.position = parent.children.count + 1 + parent.children << board + respond_to do |format| + format.js + end end end @@ -223,8 +240,46 @@ class BoardsController < ApplicationController end def destroy + after_boards = @board.parent.children.where("position > #{@board.position}") + after_boards.update_all("position = position - 1") @board.destroy - redirect_to_settings_in_projects + if @course + respond_to do |format| + format.js + end + elsif @project + redirect_to_settings_in_projects + end + end + + def update_position + if @course + boards = @board.parent.children + if params[:opr] == 'up' && @board.position > 1 + before_board = boards.where("position = #{@board.position - 1}").first + if before_board && @board.update_attribute('position', @board.position - 1) + before_board.update_attribute('position', before_board.position + 1) + end + elsif params[:opr] == 'down' && @board.position < boards.count + after_board = boards.where("position = #{@board.position + 1}").first + if after_board && @board.update_attribute('position', @board.position + 1) + after_board.update_attribute('position', after_board.position - 1) + end + end + respond_to do |format| + format.js + end + end + end + + def update_name + if @course + @board.update_attribute("name", params[:name]) + @board.update_attribute("description", params[:name]) + respond_to do |format| + format.js + end + end end def join_to_org_subfields diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 226d24afa..7d13a6f85 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -122,7 +122,7 @@ class MessagesController < ApplicationController if @project redirect_to project_boards_path(@project) elsif @course - redirect_to course_boards_path(@course) + redirect_to course_boards_path(@course, :board_id => @board.id) end else redirect_to board_message_url(@board, @message) @@ -132,7 +132,7 @@ class MessagesController < ApplicationController if @project redirect_to project_boards_path(@project, :flag => true) elsif @course - redirect_to course_boards_path(@course, :flag => true) + redirect_to course_boards_path(@course, :board_id => @board.id, :flag => true) end else layout_file = @project ? 'base_projects' : 'base_courses' diff --git a/app/models/board.rb b/app/models/board.rb index b66719edf..d8b29f5cd 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -35,7 +35,7 @@ class Board < ActiveRecord::Base includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) } - safe_attributes 'name', 'description', 'parent_id', 'move_to' + safe_attributes 'name', 'description', 'parent_id', 'move_to', 'position' def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_messages, project) @@ -51,7 +51,11 @@ class Board < ActiveRecord::Base end def valid_parents - @valid_parents ||= project.boards - self_and_descendants + if project + @valid_parents ||= project.boards - self_and_descendants + elsif course + @valid_parents ||= course.boards - self_and_descendants + end end def reset_counters! diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 6759e33ce..55d4cca62 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -22,7 +22,7 @@
- 班级讨论区 + <%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
diff --git a/app/views/boards/create.js.erb b/app/views/boards/create.js.erb new file mode 100644 index 000000000..8fe824e69 --- /dev/null +++ b/app/views/boards/create.js.erb @@ -0,0 +1,5 @@ +<% if @course %> + $("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); + <% course_board = @course.boards.where("parent_id is NULL").first %> + $("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/destroy.js.erb b/app/views/boards/destroy.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/destroy.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/update_name.js.erb b/app/views/boards/update_name.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/update_name.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/update_position.js.erb b/app/views/boards/update_position.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/update_position.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb index e5fcd8314..df04bd958 100644 --- a/app/views/courses/_tool_expand.html.erb +++ b/app/views/courses/_tool_expand.html.erb @@ -1,10 +1,22 @@ <% course_file_num = visable_attachemnts_incourse(@course).count%> <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> +<% course_board = @course.boards.where("parent_id is NULL").first %> +<% if show_nav?(course_board ? course_board.topics.count : 0) %>
  • 讨论区 <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
  • + <% unless course_board.children.empty? %> + + <% end %> <% end %> <% if show_nav?(@course.homework_commons.count) %>
  • diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index 4c54e2289..654e9ac73 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -22,6 +22,9 @@
  • 组织
  • +
  • + 讨论区设置 +
  • @@ -131,6 +134,10 @@
    <%= render :partial => 'courses/settings/join_org' %>
    + +
    + <%= render :partial => 'courses/settings/boards_setting' %> +
    \ No newline at end of file diff --git a/app/views/layouts/_board_children_list.html.erb b/app/views/layouts/_board_children_list.html.erb new file mode 100644 index 000000000..9eb8938c5 --- /dev/null +++ b/app/views/layouts/_board_children_list.html.erb @@ -0,0 +1,11 @@ +<% unless course_board.children.empty? %> + +<% end %> \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index fe400bfbc..8832665e8 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -64,12 +64,16 @@ 动态<%=@course.course_activities.count %> <% end %> - <% unless show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> + <% course_board = @course.boards.where("parent_id is NULL").first %> + <% unless show_nav?(course_board ? course_board.topics.count : 0) %>
  • - <% count = @course.boards.first ? (@course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", @course.boards.first.id, nil).count) : 0 %> + <% count = course_board ? (course_board.topics.count + Message.where("board_id =? and parent_id is not ?", course_board.id, nil).count) : 0 %> 讨论区<%=count %> <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
  • +
    + <%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %> +
    <% end %> <% unless show_nav?(@course.homework_commons.count) %>
  • diff --git a/app/views/messages/_course_new.html.erb b/app/views/messages/_course_new.html.erb index bac064a9c..8c2be1588 100644 --- a/app/views/messages/_course_new.html.erb +++ b/app/views/messages/_course_new.html.erb @@ -4,11 +4,11 @@

    <%= l(:label_message_new) %>

      - <%= form_for @message, :url => {:action => 'new'}, :html => {:multipart => true, :id => 'message-form'} do |f| %> + <%= form_for @message, :url => {:action => 'new', :board_id => @board.id}, :html => {:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'form_course', :locals => {:f => f,:is_new => true} %> <%= l(:button_submit)%> <%#= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board}, 'message-form' ,target='preview',{:class => 'blue_btn grey_btn fl c_white'} )%> - <%= link_to l(:button_cancel), course_boards_path(@course), :class => "grey_btn fl c_white ml10"%> + <%= link_to l(:button_cancel), course_boards_path(@course, :board_id => @board.id), :class => "grey_btn fl c_white ml10"%> <% end %>
    diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index 99e3aca62..391128287 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -10,7 +10,7 @@ TO <%=link_to activity.course.syllabus.title, syllabus_path(activity.course.syllabus_id), :class => 'newsBlue ml15', :target => '_blank' %> - <%= link_to activity.course.name.to_s+" | 班级讨论区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue mr5"%> + <%= link_to activity.course.name.to_s+" | #{activity.board.parent.nil? ? '班级讨论区' : activity.board.name}", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue mr5"%>