diff --git a/app/assets/javascripts/pm/issues.js b/app/assets/javascripts/pm/issues.js deleted file mode 100644 index dee720fac..000000000 --- a/app/assets/javascripts/pm/issues.js +++ /dev/null @@ -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. diff --git a/app/assets/stylesheets/pm/issues.scss b/app/assets/stylesheets/pm/issues.scss deleted file mode 100644 index cdf9fbc43..000000000 --- a/app/assets/stylesheets/pm/issues.scss +++ /dev/null @@ -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/ diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 9df5bf7ea..4b76783d2 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -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 diff --git a/app/controllers/pm/issues_controller.rb b/app/controllers/pm/issues_controller.rb deleted file mode 100644 index ec2370cdf..000000000 --- a/app/controllers/pm/issues_controller.rb +++ /dev/null @@ -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 diff --git a/app/helpers/pm/issues_helper.rb b/app/helpers/pm/issues_helper.rb deleted file mode 100644 index 79cd6dd3e..000000000 --- a/app/helpers/pm/issues_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Pm::IssuesHelper -end diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index a3782abaf..e8ffa4c0a 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -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) diff --git a/db/migrate/20231101090823_add_pm_project_id.rb b/db/migrate/20231101090823_add_pm_project_id.rb new file mode 100644 index 000000000..81ba7130b --- /dev/null +++ b/db/migrate/20231101090823_add_pm_project_id.rb @@ -0,0 +1,5 @@ +class AddPmProjectId < ActiveRecord::Migration[5.2] + def change + add_column :issue_tags, :pm_project_id, :integer + end +end diff --git a/spec/controllers/pm/issues_controller_spec.rb b/spec/controllers/pm/issues_controller_spec.rb deleted file mode 100644 index cb80ebb71..000000000 --- a/spec/controllers/pm/issues_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Pm::IssuesController, type: :controller do - -end diff --git a/spec/helpers/pm/issues_helper_spec.rb b/spec/helpers/pm/issues_helper_spec.rb deleted file mode 100644 index 43b9ba751..000000000 --- a/spec/helpers/pm/issues_helper_spec.rb +++ /dev/null @@ -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