diff --git a/Gemfile.lock b/Gemfile.lock index 66d3dfb4e..355ca422d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,10 +91,6 @@ GEM descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) diff-lcs (1.2.5) - dnsruby (1.57.0) - email_verifier (0.0.7) - dnsruby (>= 1.5) - rails (>= 3.0.0) equalizer (0.0.9) erubis (2.7.0) execjs (2.2.1) @@ -170,7 +166,6 @@ GEM mysql2 (0.3.11-x86-mingw32) nenv (0.2.0) net-ldap (0.3.1) - newrelic_rpm (3.9.9.275) nokogiri (1.6.3) mini_portile (= 0.6.0) nokogiri (1.6.3-x86-mingw32) @@ -320,7 +315,6 @@ DEPENDENCIES capybara (~> 2.4.1) coderay (~> 1.0.6) coffee-rails (~> 3.2.1) - email_verifier factory_girl (~> 4.4.0) faker fastercsv (~> 1.5.0) @@ -336,7 +330,6 @@ DEPENDENCIES mocha (~> 1.1.0) mysql2 (= 0.3.11) net-ldap (~> 0.3.1) - newrelic_rpm nokogiri (~> 1.6.3) paperclip (~> 3.5.4) rack-mini-profiler! diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index bee78a20e..8f7f0342f 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -6,6 +6,7 @@ module Mobile require_relative 'apis/watches' require_relative 'apis/upgrade' require_relative 'apis/homeworks' + require_relative 'apis/comments' class API < Grape::API version 'v1', using: :path format :json @@ -37,6 +38,7 @@ module Mobile mount Apis::Watches mount Apis::Upgrade mount Apis::Homeworks + mount Apis::Comments #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? diff --git a/app/api/mobile/apis/comments.rb b/app/api/mobile/apis/comments.rb new file mode 100644 index 000000000..a7eea735d --- /dev/null +++ b/app/api/mobile/apis/comments.rb @@ -0,0 +1,79 @@ +#coding=utf-8 +module Mobile + module Apis + class Comments < Grape::API + resource :comments do + desc '课程通知评论' + params do + requires :token, type: String + requires :comments, type: String + end + post ':id' do + cs = CommentService.new + cs_params = { + id: params[:id], + comment: params.reject{|k,v| [:id].include?(k)}} + comments = cs.news_comments cs_params,current_user + raise "create comments failed #{comments.errors.full_messages}" if comments.new_record? + present :data, comments, with: Mobile::Entities::Comment + present :status, 0 + end + + desc '作业留言(教师布置的作业)' + params do + requires :token, type: String + requires :message,type: String, desc: '留言' + #optional :reference_content, type: String ,desc: '引用的内容' + #optional :reference_user_id, type: Integer,desc: '被引用的人' + end + post ':id/create_homework_message' do + cs_params = { + id: params[:id], + token: params[:token], + reference_content: params[:reference_content], + bid_message: params.reject{|k,v| [:id,:token,:reference_content].include?(k)}} + cs = CommentService.new + message = cs.homework_message cs_params,current_user + present :data, message, with: Mobile::Entities::Jours + present :status, 0 + end + + desc '课程留言' + params do + requires :token, type: String + requires :course_message,type: String, desc: '留言' + end + post ':id/leave_course_message' do + cs_params = { + id: params[:id], + token: params[:token], + new_form: params.reject{|k,v| [:id,:token].include?(k)}} + cs = CommentService.new + message = cs.leave_course_message cs_params,current_user + present :data, message, with: Mobile::Entities::Jours + present :status, 0 + end + + desc '回复留言' + params do + requires :token, type: String + requires :reference_id, type: Integer,desc: '所属留言树的根留言id(最顶层的非回复的留言,留言对象中的m_parent_id)' + requires :reference_user_id,type: Integer ,desc: '被回复的留言的作者id' + #requires :reference_message_id,type: Integer,desc: '被回复的留言的id' + requires :user_notes,type: String,desc: '留言的内容' + requires :jour_type,type: String,desc: '等于父留言的jour_type' + requires :jour_id,type:Integer, desc: '等于父留言的jour_id' + end + post ':reference_message_id/create_reply'do + cs = CommentService.new + message = cs.create_reply params,current_user + raise "create reply failed #{message.errors.full_messages}" if message.new_record? + present :data, message, with: Mobile::Entities::Jours + present :status, 0 + end + + + end + end + end +end \ No newline at end of file diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 7c1aa5e7e..7dbfaffb0 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -188,17 +188,18 @@ module Mobile desc "课程通知列表" params do + optional :token, type: String end get ":course_id/news" do cs = CoursesService.new - news = cs.course_news_list params + news = cs.course_news_list params,current_user.nil? ? User.find(2):current_user present :data, news, with: Mobile::Entities::News present :status, 0 end desc "显示课程通知" params do - + optional :token, type: String end get "news/:id" do cs = CoursesService.new @@ -208,6 +209,16 @@ module Mobile present :status, 0 end + desc '课程动态' + params do + requires :token, type: String + end + get "course_dynamic/:id" do + cs = CoursesService.new + count = cs.course_dynamic(params,current_user) + present :data, count, with: Mobile::Entities::CourseDynamic + present :status, 0 + end end end diff --git a/app/api/mobile/apis/homeworks.rb b/app/api/mobile/apis/homeworks.rb index cba295064..7a8c87987 100644 --- a/app/api/mobile/apis/homeworks.rb +++ b/app/api/mobile/apis/homeworks.rb @@ -70,6 +70,32 @@ module Mobile present :status, 0 end + desc "作品打分" + params do + requires :token, type: String + requires :is_teacher, type: String,desc: '是否为教师(匿评作品详情返回的结果中可获取此参数的值)' + requires :is_anonymous_comments, type: String, desc: '是否为匿评(匿评作品详情返回的结果中可获取此参数的值)' + optional :stars_value, type: Integer,desc: '用户给出的评分' + optional :cur_page,type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值' + optional :cur_type, type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值' + optional :user_message, type: String, desc: '用户评论' + end + + post ':homework_id/scoring' do + cs_params = { + new_form: params.reject{|k,v| [:token,:is_teacher,:is_anonymous_comments,:stars_value,:cur_page,:cur_type,:homework_id].include?(k)}, + token: params[:token], + is_teacher: params[:is_teacher], + is_anonymous_comments: params[:is_anonymous_comments], + stars_value: params[:stars_value], + cur_page: params[:cur_page], + cur_type: params[:cur_type], + homework_id: params[:homework_id] + } + Homeworks.get_service.add_score_and_jour cs_params,current_user + present :status, 0 + end + end end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 69260716e..9a5307be6 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -22,13 +22,15 @@ module Mobile desc "显示用户" params do - + requires :id, type: Integer end - get ':id' do - us = UsersService.new - ue = us.show_user params - present :data, ue,with: Mobile::Entities::User - present :status, 0 + route_param :id do + get do + us = UsersService.new + ue = us.show_user params + present :data, ue,with: Mobile::Entities::User + present :status, 0 + end end desc "修改用户" @@ -77,11 +79,12 @@ module Mobile present :status, 0 end - desc "用户搜索" + desc "用户搜索" params do requires :name, type: String, desc: '用户名关键字' + requires :search_by, type: String,desc: '搜索依据:0 昵称,1 用户名,2 邮箱' end - get 'search' do + get 'search/search_user' do us = UsersService.new user = us.search_user params present :data, user, with: Mobile::Entities::User diff --git a/app/api/mobile/entities/comment.rb b/app/api/mobile/entities/comment.rb new file mode 100644 index 000000000..803d0c6d0 --- /dev/null +++ b/app/api/mobile/entities/comment.rb @@ -0,0 +1,30 @@ +module Mobile + module Entities + class Comment < Grape::Entity + include Redmine::I18n + def self.comment_expose(field) + expose field do |f,opt| + if f.is_a?(Hash) && f.key?(field) + f[field] + elsif f.is_a?(::Comment) + if f.respond_to?(field) + if field == :created_on + format_time(f.send(field)) + else + f.send(field) + end + end + end + end + end + comment_expose :id + expose :author, using: Mobile::Entities::User do |c, opt| + if c.is_a? ::Comment + c.author + end + end + comment_expose :comments + comment_expose :created_on + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb new file mode 100644 index 000000000..11f8c2682 --- /dev/null +++ b/app/api/mobile/entities/course_dynamic.rb @@ -0,0 +1,17 @@ +module Mobile + module Entities + class CourseDynamic < Grape::Entity + def self.course_dynamic_expose(field) + expose field do |c,opt| + c[field] if (c.is_a?(Hash) && c.key?(field)) + end + end + + course_dynamic_expose :course_name + course_dynamic_expose :need_anonymous_comments_count + course_dynamic_expose :student_commit_number + course_dynamic_expose :news_count + course_dynamic_expose :message_count + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/homework_attach.rb b/app/api/mobile/entities/homework_attach.rb index 256dcdf61..690ec8e94 100644 --- a/app/api/mobile/entities/homework_attach.rb +++ b/app/api/mobile/entities/homework_attach.rb @@ -17,6 +17,8 @@ module Mobile case field when :homework_times f.bid.courses.first.homeworks.index(f.bid) + 1 unless (f.bid.nil? || f.bid.courses.nil? || f.bid.courses.first.nil?) + when :comment_status + f.bid.comment_status end end end @@ -28,6 +30,8 @@ module Mobile homework_attach_expose :homework_times homework_attach_expose :description homework_attach_expose :created_at + #comment_status 0:所属作业尚未开启匿评,1:匿评中 2:匿评结束 + homework_attach_expose :comment_status expose :attachments,using: Mobile::Entities::Attachment do |f, opt| if f.respond_to?(:attachments) f.send(:attachments) diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb index 5a9f48cbc..10fd0f893 100644 --- a/app/api/mobile/entities/jours.rb +++ b/app/api/mobile/entities/jours.rb @@ -18,12 +18,15 @@ module Mobile end end jours_expose :id + jours_expose :jour_type + jours_expose :jour_id expose :user,using: Mobile::Entities::User do |f, opt| f.user end jours_expose :created_on jours_expose :notes jours_expose :m_reply_id + jours_expose :m_parent_id expose :reply_user,using: Mobile::Entities::User do |f, opt| f.at_user end diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 7c77f8c82..406db59e4 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -34,7 +34,11 @@ module Mobile #评论数量 news_expose :comments_count #评论 - news_expose :comments + expose :comments, using: Mobile::Entities::Comment do |f, opt| + if f.is_a?(Hash) && f.key?(:comments) + f[:comments] + end + end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 9b1e045e3..aab9d7b69 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -283,4 +283,43 @@ class AdminController < ApplicationController end end + #企业主页定制 + def enterprise_page_made + @enterprise_page = FirstPage.find_by_page_type('enterprise') + if @enterprise_page.nil? + @enterprise_page = FirstPage.new + @enterprise_page.page_type = 'enterprise' + end + if request.get? + @first_page = FirstPage.find_by_page_type('project') + elsif request.post? + @first_page = FirstPage.find_by_page_type('project') + @first_page.web_title = params[:web_title] + @enterprise_page.web_title = params[:web_title] + @enterprise_page.title = params[:course_title] + @enterprise_page.image_width = params[:image_width] + @enterprise_page.image_height = params[:image_height] + @enterprise_page.description = params[:course_description] + if @first_page.save && @enterprise_page.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to enterprise_page_made_url + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@enterprise_page.errors.full_messages[0]}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'enterprise_page_made' + } + format.api { render_validation_errors(@first_page) } + format.api { render_validation_errors(@enterprise_page) } + end + end + end + end + end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7653be94d..61944ca2c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -254,8 +254,8 @@ class CoursesController < ApplicationController end @is_remote = true @result_count = @results.count - @results = paginateHelper @results - + @results = paginateHelper @results, 10 + @search_name = q end def addgroups @@ -428,17 +428,34 @@ class CoursesController < ApplicationController # @results = paginateHelper @results@score_sort_by = "desc" @is_remote = true @score_sort_by = params[:sort_by] if params[:sort_by] + @search_name = params[:search_name] if params[:search_name] group_id = params[:group_id] - if group_id == '0' - page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = student_homework_score(0,page, 10,@score_sort_by) + if !@search_name.nil? + if group_id == '0' + page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = paginateHelper_for_members @results, 10 + @results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name) + @result_count = @results.count + @results = paginateHelper @results, 10 + else + @group = CourseGroup.find(group_id) + @results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by),@search_name) + @result_count = @results.count + @results = paginateHelper @results, 10 + end else - @group = CourseGroup.find(group_id) - @results = student_homework_score(group_id, 0, 0,@score_sort_by) - @results = paginateHelper @results, 10 + if group_id == '0' + page = params[:page].nil? ? 0 : (params['page'].to_i - 1) + @results = student_homework_score(0,page, 10,@score_sort_by) + + @results = paginateHelper_for_members @results, 10 + else + @group = CourseGroup.find(group_id) + @results = student_homework_score(group_id, 0, 0,@score_sort_by) + @results = paginateHelper @results, 10 + end end + end # 显示每个学生的作业评分详情 def show_member_score diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 000000000..c9cce5752 --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,6 @@ +class OrganizationsController < ApplicationController + layout 'project_base' + def index + @projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)") + end +end diff --git a/app/controllers/originizations_controller.rb b/app/controllers/originizations_controller.rb deleted file mode 100644 index 033f9d8ec..000000000 --- a/app/controllers/originizations_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class OriginizationsController < ApplicationController - layout 'project_base' - def index - @enterprises = Project.find_by_sql("select distinct(enterprise_name) from projects") - end -end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 64706887b..02bfc9e19 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -20,11 +20,12 @@ class ProjectsController < ApplicationController layout :select_project_layout - menu_item :overview + menu_item :overview, :only => :show menu_item :roadmap, :only => :roadmap menu_item :settings, :only => :settings menu_item :homework, :only => [:homework, :new_homework] menu_item :feedback, :only => :feedback + menu_item :share, :only => :share before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index b1138f964..3ae5538e9 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -25,17 +25,30 @@ class WelcomeController < ApplicationController before_filter :entry_select, :only => [:index] def index - unless params[:originization].nil? - @originization = params[:originization] - @originization_projects = Project.find_by_sql(["select * from projects where enterprise_name =? ", @originization]) - @e_count = @originization_projects.count - if @e_count < 10 - part_count = 10 -@e_count - # @part_projects = find_all_hot_project part_count, order - @part_projects = find_miracle_project(part_count, 3,"score desc") - limit = 10 - @e_count + # 企业版定制: params[:project]为传过来的参数 + unless params[:organization].nil? + @cur_projects = Project.find(params[:organization]) + @organization = @cur_projects.enterprise_name + @organization_projects = (current_user.admin? || User.current.member_of?(@cur_projects)) ? Project.where("enterprise_name =? ", @organization) : Project.all_public.where("enterprise_name =? ", @organization) + @e_count = @organization_projects.count + @part_projects = [] + # 取十个 + @organization_projects.each do |obj| + break if(@organization_projects[10] == obj) + @part_projects << Project.visible.find_by_id("#{obj.id}") unless obj.id.nil? end + # 不够十个的用最火项目替代 + @e_count < 9 ? @part_projects = find_miracle_project( 9 - @e_count, 3,"score desc") : @part_projects + # 配置文件首页定制 + @enterprise_page = FirstPage.find_by_page_type('enterprise') + if @enterprise_page.nil? + @enterprise_page = FirstPage.new + @enterprise_page.page_type = 'enterprise' + end + # 主页配置部分结束 + end + # end 企业版定制结束 if @first_page.nil? || @first_page.sort_type.nil? @projects = find_miracle_project(10, 3,"score desc") else diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index b329e4c27..6c5385115 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -7,6 +7,7 @@ class ZipdownController < ApplicationController SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + def assort if params[:obj_class] == "Bid" bid = Bid.find params[:obj_id] diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 8ff6f725c..c865a500b 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -37,4 +37,27 @@ module ApiHelper end result end + + ######################################################### + #sw + #获取课程未匿评数量 + #param: user => "用户", course_id => "查询的课程ID" + #return: 作业的数量 + ######################################################### + def get_course_anonymous_evaluation user,course + count = 0 + if course + is_teacher = is_course_teacher user,course + if is_teacher #如果是老师,显示学生提交的作业数 + course.homeworks.each do |bid| + count += bid.homeworks.count + end + else #如果是学生,显示未匿评的数量 + course.homeworks.each do |bid| + count += get_student_not_batch_homework_list bid,user + end + end + end + [count,is_teacher] + end end \ No newline at end of file diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index c41ba54ee..0b98283ff 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -130,4 +130,22 @@ module HomeworkAttachHelper WHERE homework_attaches.bid_id = #{bid.id} AND homework_evaluations.user_id = #{user.id} ORDER BY m_score DESC") student_batch_homework_list end + + ######################################################### + #sw + #获取学生未进行匿评的数量 + #param: bid => 作业 user => 用户 + #return 指定用户未进行匿评的作业的数量 + #user必须是学生用户 + ####################################################### + def get_student_not_batch_homework_list bid,user + HomeworkAttach.find_by_sql("SELECT * FROM(SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{user.id} AND is_teacher_score = 0) AS m_score + FROM homework_attaches + INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{bid.id} AND homework_evaluations.user_id = #{user.id}) AS table1 + WHERE table1.m_score IS NULL").count + end end \ No newline at end of file diff --git a/app/helpers/originizations_helper.rb b/app/helpers/organizations_helper.rb similarity index 100% rename from app/helpers/originizations_helper.rb rename to app/helpers/organizations_helper.rb diff --git a/app/models/bid.rb b/app/models/bid.rb index f423266b8..eb7e5d83f 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -93,7 +93,9 @@ class Bid < ActiveRecord::Base # 'deadline' def add_jour(user, notes, reference_user_id = 0, options = {}) if options.count == 0 - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + jfm = JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + self.journals_for_messages << jfm + jfm else jfm = self.journals_for_messages.build(options) jfm.save diff --git a/app/models/forum.rb b/app/models/forum.rb index e47d18b02..baa8e6260 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -23,7 +23,7 @@ class Forum < ActiveRecord::Base acts_as_taggable scope :by_join_date, order("created_at DESC") - after_create :send_email + #after_create :send_email def reset_counters! self.class.reset_counters!(id) end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index f42c20acc..2cae982a7 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -50,10 +50,15 @@ class Mailer < ActionMailer::Base @forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id) @issue_author_url = url_for(user_activities_url(@author)) recipients ||= [] - mems = memo.self_and_siblings - mems.each do |mem| - recipients << mem.author.mail unless recipients.include? mem.author.mail - end + # if !memo.parent_id.nil? + # mems = memo.self_and_siblings + # mems.each do |mem| + # recipients << mem.author.mail unless recipients.include? mem.author.mail + # end + # else + # recipients << memo.author.mail + # end + recipients << @author.mail # cc = wiki_content.page.wiki.watcher_recipients - recipients @memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))) @@ -98,10 +103,7 @@ class Mailer < ActionMailer::Base #收件人邮箱 @recipients ||= [] @members.each do |teacher| - @recipients << teacher.user.mail - - end mail :to => @recipients, :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " diff --git a/app/models/memo.rb b/app/models/memo.rb index 165f8e144..7d463c28b 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -47,7 +47,7 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters!, :sendmail#,:be_user_score -- 公共区发帖暂不计入得分 + after_create :add_author_as_watcher, :reset_counters! #, :sendmail#,:be_user_score -- 公共区发帖暂不计入得分 # after_update :update_memos_forum after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification diff --git a/app/services/comment_service.rb b/app/services/comment_service.rb new file mode 100644 index 000000000..42dc8c415 --- /dev/null +++ b/app/services/comment_service.rb @@ -0,0 +1,81 @@ +class CommentService + #评论 + def news_comments params,current_user + @news = News.find(params[:id]) + @course = @news.course + if @course.nil? + raise 'news in unknown course' + end + raise Unauthorized unless @news.commentable?(current_user) + if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) + raise '403' + end + @comment = Comment.new + @comment.send(:safe_attributes=,params[:comment],current_user) + @comment.author = current_user + @news.comments << @comment + @comment + end + + #作业留言 + def homework_message params,current_user + @bid = Bid.find(params[:id], :include => [{:homeworks => :user}]) + if params[:bid_message][:message].size>0 + if params[:reference_content] + message = params[:bid_message][:message] + "\n" + params[:reference_content] + else + message = params[:bid_message][:message] + @m = message + end + refer_user_id = params[:bid_message][:reference_user_id].to_i + jfm = @bid.add_jour(current_user, message, refer_user_id) + end + #@user = @bid.author + #@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + #@jour = paginateHelper @jours,10 + @bid.set_commit(@feedback_count) + jfm + end + #课程留言接口 + def leave_course_message params,current_user + message = params[:new_form][:course_message] + feedback = Course.add_new_jour(current_user, message, params[:id]) + feedback + end + + #回复留言接口 + def create_reply params,current_user + # 这里是创建回复所使用的方法,此方法只针对回复,每一个新的留言并不在此方法管理范围内。 + # 由于多个地方用到了留言,而之前的表设计也有jour_type/jour_id这类信息 + # 所以在方法 add_reply_adapter 中判断所有调用此方法的来源页面, + # 为了保证兼容以往所有的代码,保证以往的方法可以调用,在返回页面中都做了各式各样的判断。 + # 页面保证 render new_respond/journal_reply + # 修改 add_reply_adapter 中可以确保留言创建成功 + # 删除留言功能要调用destroy,也记得在destroy.js中修改 + + # deny api. api useless + parent_id = params[:reference_id] + author_id = current_user.id + reply_user_id = params[:reference_user_id] + reply_id = params[:reference_message_id] # 暂时不实现 + content = params[:user_notes] + jour_type = params[:jour_type] + jour_id = params[:jour_id] + @show_name = params[:show_name] == "true" + options = { + :jour_id => jour_id, + :jour_type => jour_type, + :user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + @jfm = ::JournalsForMessage.new(options) + #@save_succ = true if @jfm.errors.empty? + @jfm.save + @jfm + end + +end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 41b6f2c68..f4201774a 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -2,6 +2,7 @@ class CoursesService include ApplicationHelper include CoursesHelper include HomeworkAttachHelper + include ApiHelper #TODO:尚未整合权限系统 #参数school_id为0或不传时返回所有课程,否则返回对应学校的课程 #参数per_page_count分页功能,每页显示的课程数 @@ -106,11 +107,14 @@ class CoursesService end #课程通知列表 - def course_news_list params + def course_news_list params,current_user if params[:course_id] && @course==nil @course = Course.find(params[:course_id]) end - scope = @course ? @course.news.course_visible : News.course_visible + if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) + raise '403' + end + scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) news = [] scope.each do |n| news << {:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} @@ -128,9 +132,16 @@ class CoursesService #显示课程通知(包括评论) 需验证权限 def show_course_news params,current_user @news = News.find(params[:id]) + @course = @news.course + if @course + if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) + raise '403' + end + end @comments = @news.comments @comments.reverse! if current_user.wants_comments_in_reverse_order? {:news => @news,:comments => @comments} + #comments = [] #@comments.each do |comment| # comments << {:author_id => comment.author_id,:author_name => comment.author.name,:commont_content => comment.comments,:time => format_time(comment.created_on)} @@ -316,6 +327,22 @@ class CoursesService end end + def course_dynamic(params,current_user) + course = Course.find(params[:id]) + if current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course))) + raise '403' + end + count,is_teacher = get_course_anonymous_evaluation current_user,course + if is_teacher + student_commit_number = count + else + need_anonymous_comments_count = count + end + news_count = course.news.count + message_count = course.journals_for_messages.count + {:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count} + end + private def show_homework_info course,bid,current_user,is_course_teacher author = bid.author.lastname + bid.author.firstname @@ -351,4 +378,6 @@ class CoursesService :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation} end + + end \ No newline at end of file diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index a2c063e15..b468e1110 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -141,16 +141,51 @@ class HomeworkService end #作品打分/留言 - def add_score_and_jour params + def add_score_and_jour params,current_user @is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value] @cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5 @homework = HomeworkAttach.find(params[:homework_id]) + comment_status = @homework.bid.comment_status + if @is_anonymous_comments && comment_status == 0 + raise '尚未开启匿评!' + end + if @is_anonymous_comments && ((@m_score.nil? || @m_score.blank?) || !(params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "")) + raise '您尚未打分或评论!' + end #保存评分 - @homework.rate(@m_score.to_i,User.current.id,:quality) if @m_score + homework = @homework + is_teacher = @is_teacher ? 1 : 0 + #保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0)) + if @m_score + rate = @homework.rates(:quality).where(:rater_id => current_user.id, :is_teacher_score => is_teacher).first + if rate + rate.stars = @m_score + rate.save! + else + @homework.rates(:quality).new(:stars => @m_score, :rater_id => current_user.id, :is_teacher_score => is_teacher).save! + end + + if homework.is_teacher_score == 0 + if is_teacher == 1 + homework.score = @m_score + homework.is_teacher_score = 1 + else + sql = "SELECT AVG(stars) as stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id}" + score= HomeworkAttach.find_by_sql(sql).first.stars + homework.score = score + end + else + if is_teacher == 1 + homework.score = @m_score + homework.is_teacher_score = 1 + end + end + homework.save! + end #保存评论 @is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言 if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言 - @homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation + @homework.addjours current_user.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation end end diff --git a/app/views/admin/_tab_partial.html.erb b/app/views/admin/_tab_partial.html.erb index 6b8788a90..917d7dd3f 100644 --- a/app/views/admin/_tab_partial.html.erb +++ b/app/views/admin/_tab_partial.html.erb @@ -4,5 +4,6 @@
  • <%= link_to l(:label_course_first_page), {:action => 'course_page_made'}, class: "#{current_page?(course_page_made_path)? 'selected' : nil }" %>
  • <%= link_to l(:label_contest_first_page), {:action => 'contest_page_made'}, class: "#{current_page?(contest_page_made_path)? 'selected' : nil }" %>
  • <%= link_to l(:label_web_footer_page), {:action => 'web_footer_made'}, class: "#{current_page?(web_footer_made_path)? 'selected' : nil }" %>
  • +
  • <%= link_to l(:label_enterprise_page_made), {:action => 'enterprise_page_made'}, class: "#{current_page?(enterprise_page_made_path)? 'selected' : nil }" %>
  • \ No newline at end of file diff --git a/app/views/admin/enterprise_page_made.html.erb b/app/views/admin/enterprise_page_made.html.erb new file mode 100644 index 000000000..566f09bb8 --- /dev/null +++ b/app/views/admin/enterprise_page_made.html.erb @@ -0,0 +1,39 @@ +

    <%=l(:label_first_page_made)%>

    + +<%= form_tag(:controller => 'admin', :action => 'enterprise_page_made') do %> +

    + + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    + <%= render 'tab_partial' %> +

    <%=l(:label_enterprise_page_made)%>

    +

    + +

    +
    + <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@enterprise_page} %> +
    +

    + + <%= text_field_tag 'image_width', params[:label_image_width],:value => @enterprise_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    +

    + + <%= text_field_tag 'image_height', params[:label_imgae_height], :value => @enterprise_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    +

    + + <%= text_field_tag 'course_title', params[:label_site_title], :value => @enterprise_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    +

    + + <%= text_area_tag 'course_description',@enterprise_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    + + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +
    + + + +
    \ No newline at end of file diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 2954adbcb..989ed776d 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -1,14 +1,21 @@
    +<% is_float ||= false %> <% for attachment in attachments %>

    - - <% if options[:length] %> - <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true,:length => options[:length] -%> - <% else %> - <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> - <% end %> + <%if is_float%> +

    + <% end%> + + <% if options[:length] %> + <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true,:length => options[:length] -%> + <% else %> + <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <% end %> + + <%if is_float%> +
    + <% end%> - <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', @@ -19,8 +26,9 @@ <%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %> - (<%= number_to_human_size attachment.filesize %>) - + ( + <%= number_to_human_size attachment.filesize %>) + <% if options[:deletable] %> <% if attachment.container_type == 'HomeworkAttach' %> <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id}, @@ -39,8 +47,8 @@ <% end %> <% end %> <% if options[:wrap] %> -
    -   +
    +   <% end %> <% if options[:author] %> diff --git a/app/views/contests/show_attendingcontest.html.erb b/app/views/contests/show_attendingcontest.html.erb index f8c231550..3f8ef4264 100644 --- a/app/views/contests/show_attendingcontest.html.erb +++ b/app/views/contests/show_attendingcontest.html.erb @@ -136,34 +136,35 @@ <% else %> <%= l(:label_noawards_current) %> <% end %> - <% else %> - <% case get_prize(c_project) %> - <% when '-1' %> - <%= image_tag("/images/bid/special_reward.png") %> - <% when '0' %> - <%= image_tag("/images/bid/first_reward.png") %> - <% when '1' %> - <%= image_tag("/images/bid/second_reward.png") %> - <% when '2' %> - <%= image_tag("/images/bid/third_reward.png") %> - <% when '3' %> - <%= image_tag("/images/bid/forth_reward.png") %> - <% when '4' %> - <%= image_tag("/images/bid/fifth_reward.png") %> - <% when '5' %> - <%= image_tag("/images/bid/qualified.png") %> - <% end %> - <% end %> + <% else %> + <% case get_prize(c_project) %> + <% when '-1' %> + <%= image_tag("/images/bid/special_reward.png") %> + <% when '0' %> + <%= image_tag("/images/bid/first_reward.png") %> + <% when '1' %> + <%= image_tag("/images/bid/second_reward.png") %> + <% when '2' %> + <%= image_tag("/images/bid/third_reward.png") %> + <% when '3' %> + <%= image_tag("/images/bid/forth_reward.png") %> + <% when '4' %> + <%= image_tag("/images/bid/fifth_reward.png") %> + <% when '5' %> + <%= image_tag("/images/bid/qualified.png") %> + <% end %> + <% end %> - <% if ((User.current.id == @contest.author_id) && (@contest.deadline > Date.today))||User.current.admin %> + <% if ((User.current.id == @contest.author_id) && (@contest.deadline >= Date.today))||User.current.admin %> + <%= toggle_link l(:label_reward), c_project.id.to_s %> -
    @@ -282,7 +284,7 @@ - <% if ((User.current.id == @contest.author_id) && (@contest.deadline > Date.today))||User.current.admin %> + <% if ((User.current.id == @contest.author_id) && (@contest.deadline >= Date.today))||User.current.admin %>
    <%= toggle_link '评奖', c_softapplication.id.to_s %> diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index dd543ec2c..11bfd9f81 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -25,7 +25,7 @@