commit
060d1a6792
@ -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,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
|
@ -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
|
||||||
|
@ -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…
Reference in new issue