parent
05cb2181f1
commit
01fb509e75
@ -0,0 +1,49 @@
|
||||
class ProjectTrendsController < ApplicationController
|
||||
before_action :set_project
|
||||
before_action :check_project_public
|
||||
|
||||
def index
|
||||
@project_issues_count = @project.get_issues_count(nil)
|
||||
@project_open_issues_count = @project.get_issues_count([1,2,3,4,6])
|
||||
@project_close_issues_count = @project.get_issues_count(5)
|
||||
|
||||
project_trends = @project.project_trends.includes(:user, trend: :user)
|
||||
check_time = params[:time] #时间的筛选
|
||||
check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version
|
||||
check_status = params[:status] #类型的选择 "create", "close", "journal",
|
||||
|
||||
if check_time.present?
|
||||
check_time = check_time.to_i
|
||||
project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day)
|
||||
end
|
||||
|
||||
if check_type.present?
|
||||
project_trends = project_trends.where(trend_type: check_type.to_s.titleize)
|
||||
end
|
||||
|
||||
if check_status.present?
|
||||
project_trends = project_trends.where(action_type: check_status.to_s)
|
||||
end
|
||||
project_trends = project_trends.order("created_at desc")
|
||||
|
||||
@page = params[:page]
|
||||
@limit = params[:limit] || 15
|
||||
@project_trends_size = project_trends.size
|
||||
@project_trends = project_trends.page(@page).per(@limit)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_project
|
||||
@project = Project.find_by_id(params[:project_id])
|
||||
unless @project.present?
|
||||
normal_status(-1, "项目不存在")
|
||||
end
|
||||
end
|
||||
|
||||
def check_project_public
|
||||
unless @project.is_public || @project.member?(current_user) || current_user.admin?
|
||||
normal_status(-1, "您没有权限")
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class ProjectTrend < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :trend, polymorphic: true, optional: true
|
||||
belongs_to :user
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
json.name issue.subject
|
||||
json.created_at format_time(issue.created_on)
|
||||
json.updated_at format_time(issue.updated_on)
|
||||
json.assign_user_name issue.get_assign_user.try(:show_real_name)
|
||||
json.assign_user_login issue.get_assign_user.try(:login)
|
||||
json.issue_journal_size issue.get_journals_size
|
||||
journals = issue.only_reply_journals
|
||||
|
||||
json.issue_journals do
|
||||
json.array! journals.to_a.each do |j|
|
||||
json.user_name j.user.try(:show_real_name)
|
||||
json.user_login j.user.try(:login)
|
||||
json.user_picture url_to_avatar(j.user)
|
||||
json.content j.try(:notes)
|
||||
json.created_at time_from_now(j.created_on)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,24 @@
|
||||
json.partial! "commons/success"
|
||||
json.issues_count @project_issues_count
|
||||
json.open_issues_count @project_open_issues_count
|
||||
json.close_issues_count @project_close_issues_count
|
||||
json.limit @limit
|
||||
json.project_trends_size @project_trends_size
|
||||
json.project_trends do
|
||||
json.array! @project_trends.to_a.each do |trend|
|
||||
json.id trend.id
|
||||
json.trend_type trend.trend_type
|
||||
json.action_type l("trend.#{trend.action_type}") + l("trend.#{trend.trend_type}")
|
||||
json.trend_id trend.trend_id
|
||||
json.user_login trend.user.login
|
||||
json.user_avatar url_to_avatar(trend.user)
|
||||
|
||||
if trend.trend_type == "Issue"
|
||||
json.partial! "issues/simple_issue_item", locals: {issue: trend.trend}
|
||||
end
|
||||
|
||||
#后续需要天际pullrequest 和 版本的内容
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,12 @@
|
||||
class CreateProjectTrends < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :project_trends do |t|
|
||||
t.integer :user_id
|
||||
t.integer :project_id
|
||||
t.references :trend, polymorphic: true, index: true
|
||||
t.string :action_type
|
||||
t.timestamps
|
||||
end
|
||||
add_index :project_trends, [:user_id, :project_id]
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProjectTrend, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue