update issue tags for pm

This commit is contained in:
呱呱呱 2023-11-02 09:17:32 +08:00
parent 5c72feb705
commit f00c3931a8
9 changed files with 40 additions and 67 deletions

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,3 +0,0 @@
// Place all the styles related to the pm/issues controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -60,8 +60,12 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
end
def tags
@issue_tags = IssueTag.init_mp_issues_tags
render_ok(@issue_tags)
IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id])
@issue_tags = IssueTag.where(pm_project_id: params[:pm_project_id]).reorder("#{tag_sort_by} #{tag_sort_direction}")
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
params[:only_name] = true #强制渲染 不走project
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
render "api/v1/issues/issue_tags/index"
end
def statues
@ -136,4 +140,18 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
receivers_login: []
)
end
private
def tag_sort_by
sort_by = params.fetch(:sort_by, "created_at")
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
sort_by
end
def tag_sort_direction
sort_direction = params.fetch(:sort_direction, "desc").downcase
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
sort_direction
end
end

View File

@ -1,37 +0,0 @@
class Pm::IssuesController < ApplicationController
before_action :require_login, except: [:index]
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, :pm_issue_type,
issue_tag_ids: [],
assigner_ids: [],
attachment_ids: [],
receivers_login: []
)
end
end

View File

@ -1,2 +0,0 @@
module Pm::IssuesHelper
end

View File

@ -14,6 +14,7 @@
# gid :integer
# gitea_url :string(255)
# pull_requests_count :integer default("0")
# pm_project_id :integer
#
# Indexes
#
@ -29,7 +30,11 @@ class IssueTag < ApplicationRecord
belongs_to :project, optional: true, counter_cache: true
belongs_to :user, optional: true
validates :name, uniqueness: {scope: :project_id, message: "已存在" }
validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project?
def pm_project?
!project_id.zero?
end
def self.init_data(project_id)
data = init_issue_tag_data
@ -40,6 +45,15 @@ class IssueTag < ApplicationRecord
$redis_cache.hset("project_init_issue_tags", project_id, 1)
end
def self.pm_init_data(pm_project_id)
data = init_issue_tag_data
data.each do |item|
next if IssueTag.exists?(pm_project_id: pm_project_id, project_id: 0, name: item[0])
IssueTag.create!(pm_project_id: pm_project_id, project_id: 0, name: item[0], description: item[1], color: item[2])
end
$redis_cache.hset("pm_project_init_issue_tags", pm_project_id, 1)
end
def reset_counter_field
self.update_column(:issues_count, issue_issues.size)
self.update_column(:pull_requests_count, pull_request_issues.size)

View File

@ -0,0 +1,5 @@
class AddPmProjectId < ActiveRecord::Migration[5.2]
def change
add_column :issue_tags, :pm_project_id, :integer
end
end

View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Pm::IssuesController, type: :controller do
end

View File

@ -1,15 +0,0 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Pm::IssuesHelper. For example:
#
# describe Pm::IssuesHelper 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 Pm::IssuesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end