新增:项目标记关联组织初始化

This commit is contained in:
yystopf 2024-01-10 14:03:08 +08:00
parent 5fafd8195c
commit 05aeecf67a
3 changed files with 16 additions and 4 deletions

View File

@ -2,7 +2,10 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController
def index
@issue_tags = IssueTag.pm_able
@issue_tags = @issue_tags.where(organization_id: params[:organization_id]) if params[:organization_id].present?
if params[:organization_id].present?
IssueTag.pm_org_init_data(params[:organization_id]) unless $redis_cache.hget("pm_org_init_issue_tags", params[:organization_id])
@issue_tags = @issue_tags.where(organization_id: params[:organization_id])
end
@issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present?
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
@issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}")
@ -19,7 +22,7 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController
render_error("创建标记失败!")
end
end
before_action :load_issue_tag, only: [:update, :destroy]
def update
@ -48,7 +51,7 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController
end
def tag_sort_direction
sort_direction = params.fetch(:sort_direction, "desc").downcase
sort_direction = params.fetch(:sort_direction, "desc")&.downcase
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
sort_direction
end

View File

@ -98,7 +98,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
end
def tags
IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id])
# 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

View File

@ -59,6 +59,15 @@ class IssueTag < ApplicationRecord
$redis_cache.hset("pm_project_init_issue_tags", pm_project_id, 1)
end
def self.pm_org_init_data(organization_id)
data = init_issue_tag_data
data.each do |item|
next if IssueTag.exists?(organization_id: organization_id, project_id: 0, name: item[0])
IssueTag.create!(organization_id: organization_id, project_id: 0, name: item[0], description: item[1], color: item[2])
end
$redis_cache.hset("pm_org_init_issue_tags", organization_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)