Merge branch 'develop' into dev_aliyun

dev_forum
daiao 5 years ago
commit 060d1a6792

@ -229,7 +229,7 @@ class ApplicationController < ActionController::Base
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
if !User.current.logged? && Rails.env.development? if !User.current.logged? && Rails.env.development?
User.current = User.find 12 User.current = User.find 57703
end end
if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除

@ -3,7 +3,7 @@ module ControllerRescueHandler
included do included do
rescue_from Exception do |e| rescue_from Exception do |e|
logger.error e Util.logger_error e
render json: {status: -1, message: e.message} render json: {status: -1, message: e.message}
end end
# rescue_from ActionView::MissingTemplate, with: :object_not_found # rescue_from ActionView::MissingTemplate, with: :object_not_found

@ -1,7 +1,7 @@
module PaginateHelper module PaginateHelper
def paginate(objs, **opts) def paginate(objs, **opts)
page = params[:page].to_i <= 0 ? 1 : params[:page].to_i page = params[:page].to_i <= 0 ? 1 : params[:page].to_i
per_page = params[:per_page].to_i > 0 ? params[:per_page].to_i : 20 per_page = params[:per_page].to_i > 0 ? params[:per_page].to_i : opts[:per_page] || 20
Kaminari.paginate_array(objs).page(page).per(per_page) Kaminari.paginate_array(objs).page(page).per(per_page)
end end

@ -1,6 +1,6 @@
class DepartmentsController < ApplicationController class DepartmentsController < ApplicationController
def for_option def for_option
render_ok(departments: current_school.departments.select(:id, :name).as_json) render_ok(departments: current_school.departments.without_deleted.select(:id, :name).as_json)
end end
private private

@ -1,19 +1,32 @@
class TidingsController < ApplicationController class TidingsController < ApplicationController
include PaginateHelper
after_action :update_onclick_time!, only: [:index]
def index def index
tidings = current_user.tidings.order(created_at: :desc) tidings = current_user.tidings
tiding_types = tiding_types =
case params[:type] case params[:type]
when 'notice' then 'System' when 'notice' then 'System'
when 'apply' then 'Apply' when 'apply' then 'Apply'
when 'course' then %w(HomeworkCommon Exercise Poll) when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic)
when 'project' then 'Project' when 'project' then 'Project'
when 'interaction' then %w(Comment Mentioned Praise Fan) when 'interaction' then %w(Comment Mentioned Praise Fan)
when 'project_package' then %w(Created Destroyed Bidding BiddingEnd BiddingWon BiddingLost)
end end
tidings = tidings.where(tiding_type: tiding_types) if tiding_types.present? tidings = tidings.where(tiding_type: tiding_types) if tiding_types.present?
tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package'
@count = tidings.count @count = tidings.count
@tidings = paginate tidings @tidings = paginate(tidings.order(created_at: :desc), per_page: 10)
@onclick_time = current_user.click_time
end
private
def update_onclick_time!
current_user.onclick_time.touch(:onclick_time)
end end
end end

@ -8,6 +8,10 @@ module TidingDecorator
time_from_now(created_at) time_from_now(created_at)
end end
def unread?(time)
created_at > time
end
# 组装国际化路径locale_format('Apply', 1) ==> tiding.ApplyUserAuthentication.Apply.1_end # 组装国际化路径locale_format('Apply', 1) ==> tiding.ApplyUserAuthentication.Apply.1_end
def locale_format(*arr) def locale_format(*arr)
arr.unshift("tiding.#{container_type}").join('.') << '_end' arr.unshift("tiding.#{container_type}").join('.') << '_end'
@ -340,4 +344,20 @@ module TidingDecorator
def department_content def department_content
I18n.t(locale_format) % [container.try(:name), container.try(:school)&.name] I18n.t(locale_format) % [container.try(:name), container.try(:school)&.name]
end end
def library_content
if tiding_type == 'System'
I18n.t(locale_format(tiding_type, status), reason: extra) % container.try(:title)
else
I18n.t(locale_format) % container.try(:title)
end
end
def project_package_content
if tiding_type == 'System'
I18n.t(locale_format(tiding_type, status), reason: extra) % container.try(:title)
else
I18n.t(locale_format(tiding_type)) % [container.try(:title) || extra]
end
end
end end

@ -2,4 +2,6 @@ class Department < ApplicationRecord
belongs_to :school belongs_to :school
has_many :department_members, dependent: :destroy has_many :department_members, dependent: :destroy
scope :without_deleted, -> { where(is_delete: false) }
end end

@ -1,9 +1,11 @@
json.extract! tiding, :id, :status, :viewed, :user_id, :tiding_type, :container_type, :parent_container_type json.extract! tiding, :id, :status, :viewed, :user_id, :tiding_type, :container_id, :container_type, :parent_container_id, :parent_container_type
json.content tiding.content json.content tiding.content
json.identifier tiding.try(:container).try(:identifier) rescue nil
json.time tiding.how_long_time json.time tiding.how_long_time
json.new_tiding tiding.unread?(@onclick_time)
json.trigger_user do json.trigger_user do
json.partial! 'users/user_simple', user: tiding.trigger_user json.partial! 'users/user_simple', user: tiding.trigger_user_id.zero? ? User.find(1) : tiding.trigger_user
end end
json.attachments tiding.attachments, partial: 'attachments/attachment_small', as: :attachment json.attachments tiding.attachments, partial: 'attachments/attachment_small', as: :attachment

@ -199,3 +199,19 @@
Apply_end: "发起了匿评申诉申请:%s" Apply_end: "发起了匿评申诉申请:%s"
HomeworkCommon_end: "有人对你的匿评发起了申诉:%s" HomeworkCommon_end: "有人对你的匿评发起了申诉:%s"
Department_end: "你选填的二级单位:%s%s因不符合规范,已被系统删除.请重新选择" Department_end: "你选填的二级单位:%s%s因不符合规范,已被系统删除.请重新选择"
Library:
Apply_end: "申请发布教学案例:%s"
System:
1_end: "你提交的发布教学案例申请:%s审核已通过"
2_end: "你提交的发布教学案例申请:%s审核未通过原因%{reason}"
ProjectPackage:
Apply_end: "申请发布众包需求:%s"
System:
1_end: "你提交的众包需求申请:%s审核已通过"
2_end: "你提交的众包需求申请:%s审核未通过原因%{reason}"
Created_end: "你创建了众包需求:%s"
Destroyed_end: "你删除了众包需求:%s"
Bidding_end: "应征了你发布的众包任务:%s"
BiddingEnd_end: "你发布的众包任务:%s已进入选标阶段请尽快进行选择确认"
BiddingWon_end: "恭喜,你应征的众包任务:%s在评选环节中标了"
BiddingLost_end: "很遗憾,你应征投稿的众包任务:%s未中标"

@ -0,0 +1,7 @@
class ModifyAttachmentUrlForChallengeAnswer < ActiveRecord::Migration[5.2]
def change
ChallengeChoose.find_each do |cc|
cc.update_column(:subject, cc.subject.gsub("(/attachments/download", "(/api/attachments")) if cc.subject.present?
end
end
end
Loading…
Cancel
Save