Merge pull request 'issue index 改造' (#168) from KingChan/forgeplus:pm_project_develop into pm_project_develop
This commit is contained in:
commit
99cab85b54
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the api/v1/pm_issues controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,36 @@
|
|||
class Api::V1::PmIssuesController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
|
||||
def index
|
||||
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
|
||||
object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
||||
@total_issues_count = @object_result[:total_issues_count]
|
||||
@opened_issues_count = @object_result[:opened_issues_count]
|
||||
@closed_issues_count = @object_result[:closed_issues_count]
|
||||
if params[:only_name].present?
|
||||
@issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
||||
else
|
||||
@issues = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
|
||||
@object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user)
|
||||
end
|
||||
|
||||
private
|
||||
def issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id,
|
||||
:branch_name, :start_date, :due_date,
|
||||
:subject, :description, :blockchain_token_num,
|
||||
:pm_project_id, :pm_sprint_id,
|
||||
:issue_tag_ids => [],
|
||||
:assigner_ids => [],
|
||||
:attachment_ids => [],
|
||||
:receivers_login => []
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Api::V1::PmIssuesHelper
|
||||
end
|
|
@ -29,6 +29,8 @@ class Api::V1::Issues::CreateService < ApplicationService
|
|||
@assigner_ids = params[:assigner_ids]
|
||||
@attachment_ids = params[:attachment_ids]
|
||||
@receivers_login = params[:receivers_login]
|
||||
@pm_project_id = params[:pm_project_id]
|
||||
@pm_sprint_id = params[:pm_sprint_id]
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -57,7 +59,8 @@ class Api::V1::Issues::CreateService < ApplicationService
|
|||
@created_issue.assigners = @assigners unless assigner_ids.blank?
|
||||
@created_issue.attachments = @attachments unless attachment_ids.blank?
|
||||
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
|
||||
|
||||
@created_issue.pm_project_id = @pm_project_id
|
||||
@created_issue.pm_sprint_id = @pm_sprint_id
|
||||
@created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank?
|
||||
@created_issue.save!
|
||||
|
||||
|
@ -135,6 +138,7 @@ class Api::V1::Issues::CreateService < ApplicationService
|
|||
end
|
||||
|
||||
def build_issue_project_trends
|
||||
return if @project.id == 0
|
||||
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"})
|
||||
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService
|
|||
attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids
|
||||
attr_reader :begin_date, :end_date
|
||||
attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user
|
||||
attr_reader :pm_project_id, :pm_sprint_id
|
||||
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count
|
||||
|
||||
validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"}
|
||||
|
@ -26,6 +27,8 @@ class Api::V1::Issues::ListService < ApplicationService
|
|||
@begin_date = params[:begin_date]
|
||||
@end_date = params[:end_date]
|
||||
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on'
|
||||
@pm_project_id = params[:pm_project_id]
|
||||
@pm_sprint_id = params[:pm_sprint_id]
|
||||
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase
|
||||
@current_user = current_user
|
||||
end
|
||||
|
@ -65,6 +68,12 @@ class Api::V1::Issues::ListService < ApplicationService
|
|||
# milestone_id
|
||||
issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present?
|
||||
|
||||
# pm_project_id
|
||||
issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present?
|
||||
|
||||
# pm_sprint_id
|
||||
issues = issues.where(pm_sprint_id: pm_sprint_id) if pm_sprint_id.present?
|
||||
|
||||
# assigner_id
|
||||
issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present?
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
json.partial! "api/v1/issues/detail", locals: {issue: @object_result}
|
|
@ -44,6 +44,7 @@ defaults format: :json do
|
|||
collection do
|
||||
patch :batch_update
|
||||
delete :batch_destroy
|
||||
post :pm_create
|
||||
end
|
||||
|
||||
member do
|
||||
|
@ -54,6 +55,9 @@ defaults format: :json do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :pm_issues
|
||||
|
||||
scope module: :issues do
|
||||
resources :issue_tags, except: [:new, :edit] do
|
||||
collection do
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::PmIssuesController, type: :controller do
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Api::V1::PmIssuesHelper. For example:
|
||||
#
|
||||
# describe Api::V1::PmIssuesHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe Api::V1::PmIssuesHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue