From ebb697a49ff7bf6790c7097b7233e5c61e94ed3f Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 30 Jun 2016 10:44:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E5=88=97=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=A4=A7=E7=BA=B2=E7=9A=84=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E3=80=81=E5=9B=9E=E5=A4=8D=E3=80=81=E8=AF=BE=E7=A8=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 2 + app/controllers/syllabuses_controller.rb | 67 ++++++++++++- app/controllers/users_controller.rb | 34 +++++-- app/controllers/words_controller.rb | 22 +++++ app/helpers/syllabuses_helper.rb | 33 +++++++ app/models/syllabus.rb | 13 +++ app/views/layouts/_syllabus_info.html.erb | 9 +- app/views/layouts/base_syllabus.html.erb | 7 +- app/views/layouts/new_base_user.html.erb | 2 +- .../syllabuses/_syllabus_course_list.html.erb | 72 ++++++++++++++ app/views/syllabuses/edit.html.erb | 61 +++--------- app/views/syllabuses/show.html.erb | 93 +++++++++++++----- .../syllabuses/syllabus_courselist.html.erb | 1 + .../syllabuses/syllabus_courselist.js.erb | 1 + app/views/users/_course_news.html.erb | 2 +- app/views/users/_user_syllabus_list.html.erb | 75 ++++++++++++++ app/views/users/user_courselist.html.erb | 2 +- app/views/users/user_courselist.js.erb | 2 +- config/routes.rb | 3 +- .../20160629084146_add_visits_to_syllabus.rb | 5 + ...160629094716_add_des_status_to_syllabus.rb | 5 + db/schema.rb | 8 +- public/images/syllabus/icons_syllabus.png | Bin 0 -> 21845 bytes public/stylesheets/syllabus.css | 8 +- 24 files changed, 426 insertions(+), 101 deletions(-) create mode 100644 app/views/syllabuses/_syllabus_course_list.html.erb create mode 100644 app/views/syllabuses/syllabus_courselist.html.erb create mode 100644 app/views/syllabuses/syllabus_courselist.js.erb create mode 100644 app/views/users/_user_syllabus_list.html.erb create mode 100644 db/migrate/20160629084146_add_visits_to_syllabus.rb create mode 100644 db/migrate/20160629094716_add_des_status_to_syllabus.rb create mode 100644 public/images/syllabus/icons_syllabus.png diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index b6eb54d2f..9f0fe41c8 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -131,6 +131,8 @@ class PraiseTreadController < ApplicationController @obj = Bid.find_by_id(id) when 'Contest' @obj = Contest.find_by_id(id) + when 'Syllabus' + @obj = Syllabus.find_by_id(id) else @obj = nil end diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 7e4e5cea8..54d1c7569 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -1,7 +1,11 @@ class SyllabusesController < ApplicationController + include ApplicationHelper + helper :attachments + include AttachmentsHelper + include CoursesHelper - before_filter :is_logged, :only => [:index, :show, :edit, :new, :update] - before_filter :find_syllabus, :only => [:show, :edit, :update] + before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy] + before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist] def index user = User.current @syllabuses = user.syllabuses @@ -27,6 +31,7 @@ class SyllabusesController < ApplicationController @syllabus.title = params[:title] @syllabus.eng_name = params[:eng_name] @syllabus.user_id = User.current.id + @syllabus.description = Message.where("id = 17848").first.nil? ? '' : Message.where("id = 17848").first.content if @syllabus && @syllabus.save respond_to do |format| flash[:notice] = l(:notice_successful_create) @@ -51,14 +56,72 @@ class SyllabusesController < ApplicationController def update @syllabus.description = params[:syllabus][:description] + @syllabus.des_status = 1 @syllabus.save_attachments(params[:attachments]) if @syllabus.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@syllabus.id,OwnerTypeHelper::SYLLABUS + end redirect_to syllabus_path(@syllabus) else redirect_to syllabus_path(@syllabus) end end + #删除课程大纲的描述 + def destroy + if @syllabus and @syllabus.courses.empty? + @syllabus.destroy + redirect_to user_path(User.current.id) + end + end + + #班级列表 + def syllabus_courselist + @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + sort_name = "updated_on" + sort_type = @c_sort == 1 ? "asc" : "desc" + + @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + + #根据 作业+资源数排序 + if @order.to_i == 2 + @type = 2 + @courses.each do |course| + course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) + if course[:infocount] < 0 + course[:infocount] = 0 + end + end + @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @courses = sortby_time_countcommon_nosticky @courses,sort_name + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @courses.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @courses = paginateHelper @courses,@limit + + 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/controllers/users_controller.rb b/app/controllers/users_controller.rb index 39a2ae5a5..43d12cadf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3184,23 +3184,34 @@ class UsersController < ApplicationController @c_sort = 2 end - sort_name = "updated_on" + sort_name = "updated_at" sort_type = @c_sort == 1 ? "asc" : "desc" # @courses = @user.courses.visible.where("is_delete =?", 0).order("#{sort_name} #{sort_type}") - @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + #@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + + courses = @user.courses.visible.where("is_delete =?", 0) + syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + @syllabus = Syllabus.where("id in #{syllabus_ids} or user_id = #{User.current.id}").order("#{sort_name} #{sort_type}") #根据 作业+资源数排序 if @order.to_i == 2 @type = 2 - @courses.each do |course| - course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) - if course[:infocount] < 0 - course[:infocount] = 0 + # @courses.each do |course| + # course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) + # if course[:infocount] < 0 + # course[:infocount] = 0 + # end + # end + @syllabus.each do |syllabus| + syllabus[:infocount] = 0 + courses = courses.select("syllabus_id = #{syllabus.id}") + courses.each do |c| + syllabus[:infocount] += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) end end - @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]}) - @courses = sortby_time_countcommon_nosticky @courses,sort_name + @c_sort == 1 ? (@syllabus = @syllabus.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabus = @syllabus.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @syllabus = sortby_time_countcommon_nosticky @syllabus,sort_name else @type = 1 end @@ -3208,10 +3219,10 @@ class UsersController < ApplicationController #分页 @limit = 10 @is_remote = true - @atta_count = @courses.count + @atta_count = @syllabus.count @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 @offset ||= @atta_pages.offset - @courses = paginateHelper @courses,@limit + @syllabus = paginateHelper @syllabus,@limit respond_to do |format| format.js @@ -3276,6 +3287,9 @@ class UsersController < ApplicationController when 'News' obj = News.where('id = ?', params[:id].to_i).first @journals = obj.comments.reorder("created_on desc") + when 'Syllabus' + obj = Syllabus.where('id = ?', params[:id].to_i).first + @journals = obj.comments.reorder("created_on desc") when 'JournalsForMessage' obj = JournalsForMessage.where('id = ?', params[:id].to_i).first journals = [] diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 668269a26..188531c37 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -264,6 +264,28 @@ class WordsController < ApplicationController end end + #课程大纲的回复 + def leave_syllabus_message + if User.current.logged? + @user = User.current + @syllabus = Syllabus.find(params[:id]); + if params[:comment].size>0 && User.current.logged? && @user + feedback = Syllabus.add_syllabus_jour(@user, params[:comment], params[:id]) + if (feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end + redirect_to syllabus_path(@syllabus) + else + flash[:error] = feedback.errors.full_messages[0] + end + end + else + render_403 + end + end + #作业的回复 def leave_homework_message if User.current.logged? diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index d5284586e..af5472ee1 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -2,4 +2,37 @@ module SyllabusesHelper def get_syllabuses_by_tag(tag_name) Syllabus.tagged_with(tag_name).order('updated_at desc') end + + def teacher_count syllabus + count = 0 + courses = syllabus.courses + unless courses.empty? + courses.each do |c| + count += TeacherAndAssistantCount c + end + end + count + end + + def student_count syllabus + count = 0 + courses = syllabus.courses + unless courses.empty? + courses.each do |c| + count += studentCount c + end + end + count + end + + def file_count syllabus + count = 0 + courses = syllabus.courses + unless courses.empty? + courses.each do |c| + count += visable_attachemnts_incourse(c).count + end + end + count + end end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index e16577ff3..2f2ec495f 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -7,10 +7,23 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses + has_many :journals_for_messages, :as => :jour, :dependent => :destroy attr_accessible :description, :title, :eng_name, :type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course safe_attributes 'title', 'description', 'eng_name', 'type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS end + + ###添加回复 + def self.add_syllabus_jour(user, notes, id , options = {}) + syllabus = Syllabus.find(id) + if options.count == 0 + jfm = syllabus.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + else + jfm = syllabus.journals_for_messages.build(options) + end + jfm.save + jfm + end end diff --git a/app/views/layouts/_syllabus_info.html.erb b/app/views/layouts/_syllabus_info.html.erb index 4e7bc1f7b..9717f33a7 100644 --- a/app/views/layouts/_syllabus_info.html.erb +++ b/app/views/layouts/_syllabus_info.html.erb @@ -1,3 +1,6 @@ +<% teachers_num = teacher_count @syllabus%> +<% students_num = student_count @syllabus%> +<% files_num = file_count @syllabus%> @@ -19,7 +22,7 @@
- 教师(10| - 学生(10| - 资源(100
+ 教师(<%=teachers_num %>| + 学生(<%=students_num %>| + 资源(<%=files_num %>
\ 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 5f1f9f126..9e7cd3e1b 100644 --- a/app/views/layouts/base_syllabus.html.erb +++ b/app/views/layouts/base_syllabus.html.erb @@ -45,6 +45,7 @@
<%=render :partial => 'layouts/syllabus_info' %>
+ <% update_visiti_count @syllabus %>