parent
							
								
									ba4813ccee
								
							
						
					
					
						commit
						b4ac9b0520
					
				| @ -0,0 +1,111 @@ | ||||
| class IssueTagsController < ApplicationController | ||||
|   before_action :require_login | ||||
|   before_action :set_project | ||||
|   before_action :check_issue_permission, except: :index | ||||
|   before_action :set_issue_tag, only: [:edit, :update, :destroy] | ||||
| 
 | ||||
| 
 | ||||
|   def index | ||||
|     order_name = params[:order_name] || "created_at" | ||||
|     order_type = params[:order_type] || "desc" | ||||
| 
 | ||||
|     issue_tags = @project.issue_tags.order("#{order_name} #{order_type}") | ||||
| 
 | ||||
|     @page  = params[:page]  || 1 | ||||
|     @limit = params[:limit] || 15 | ||||
|     @issue_tags_size = issue_tags.size | ||||
|     @issue_tags = issue_tags.page(@page).per(@limit) | ||||
|   end | ||||
| 
 | ||||
| 
 | ||||
|   def create | ||||
|     title = params[:title].to_s.strip | ||||
|     desc = params[:description] | ||||
|     color = params[:color] || "#ccc" | ||||
| 
 | ||||
|     tag_params = { | ||||
|       title: title, | ||||
|       description: desc, | ||||
|       color: color | ||||
|     } | ||||
| 
 | ||||
|     if title.present? | ||||
|       if IssueTag.exists?(title: title, project_id: @project.id) | ||||
|         normal_status(-1, "标签已存在") | ||||
|       else | ||||
|         issue_tag = IssueTag.new(tag_params.merge(project_id: @project.id, user_id: current_user.id)) | ||||
|         if issue_tag.save | ||||
|           normal_status(0, "标签创建成功") | ||||
|         else | ||||
|           normal_status(-1, "标签创建失败") | ||||
|         end | ||||
|       end | ||||
| 
 | ||||
|     else | ||||
|       normal_status(-1, "标签名称不能为空") | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
|   def edit | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
|   def update | ||||
|     title = params[:title] | ||||
|     desc = params[:description] | ||||
|     color = params[:color] || "#ccc" | ||||
| 
 | ||||
|     tag_params = { | ||||
|       title: title, | ||||
|       description: desc, | ||||
|       color: color | ||||
|     } | ||||
|     if title.present? | ||||
|       if IssueTag.exists?(title: title, project_id: @project.id) && (@issue_tag.title != title) | ||||
|         normal_status(-1, "标签已存在") | ||||
|       else | ||||
|         if @issue_tag.update_attributes(tag_params) | ||||
|           normal_status(0, "标签更新成功") | ||||
|         else | ||||
|           normal_status(-1, "标签更新失败") | ||||
|         end | ||||
|       end | ||||
| 
 | ||||
|     else | ||||
|       normal_status(-1, "标签名称不能为空") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def destroy | ||||
|     if @issue_tag.destroy | ||||
|       normal_status(0, "标签删除成功") | ||||
|     else | ||||
|       normal_status(-1, "标签删除失败") | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
|   private | ||||
| 
 | ||||
|   def set_project | ||||
|     @project = Project.find_by_id(params[:project_id]) | ||||
|     unless @project.present? | ||||
|       normal_status(-1, "项目不存在") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def check_issue_permission | ||||
|     unless @project.member?(current_user) || current_user.admin? | ||||
|       normal_status(-1, "您没有权限") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def set_issue_tag | ||||
|     @issue_tag = IssueTag.find_by_id(params[:id]) | ||||
|     unless @issue_tag.present? | ||||
|       normal_status(-1, "标签不存在") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
| end | ||||
| @ -0,0 +1,7 @@ | ||||
| class IssuesController < ApplicationController | ||||
|   before_action :require_login | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| end | ||||
| @ -0,0 +1,152 @@ | ||||
| class VersionsController < ApplicationController | ||||
|   before_action :require_login | ||||
|   before_action :set_project | ||||
|   before_action :check_issue_permission, except: [:show, :index] | ||||
|   before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status] | ||||
| 
 | ||||
|   def index | ||||
|     order_name = params[:order_name] || "created_on" | ||||
|     order_type = params[:order_type] || "desc" | ||||
|     status = params[:status] | ||||
|     versions = @project.versions.version_includes | ||||
|     if status.present? | ||||
|       versions = versions.where(status: status.to_s.strip) | ||||
|     end | ||||
| 
 | ||||
|     versions = versions.order("#{order_name} #{order_type}") | ||||
| 
 | ||||
|     @page  = params[:page]  || 1 | ||||
|     @limit = params[:limit] || 15 | ||||
|     @versions_size = versions.size | ||||
|     @versions = versions.page(@page).per(@limit) | ||||
|   end | ||||
| 
 | ||||
|   def show | ||||
|     order_name = params[:order_name] || "created_on" | ||||
|     order_type = params[:order_type] || "desc" | ||||
| 
 | ||||
|     version_issues = @version.issues.issue_includes.order("#{order_name} #{order_type}") | ||||
|     @close_issues_size = version_issues.where(status_id: 5).size | ||||
| 
 | ||||
|     @page  = params[:page]  || 1 | ||||
|     @limit = params[:limit] || 15 | ||||
|     @version_issues_size = version_issues.size | ||||
|     @version_issues = version_issues.page(@page).per(@limit) | ||||
|   end | ||||
| 
 | ||||
|   def create | ||||
|     name = params[:name].to_s.strip | ||||
|     desc = params[:description] | ||||
|     effective_date = params[:effective_date] | ||||
|     status = params[:status] || "open" | ||||
|     sharing = params[:sharing] || "" | ||||
|     wiki_page_title = params[:wiki_page_title] || "" | ||||
| 
 | ||||
|     tag_params = { | ||||
|       name: name, | ||||
|       description: desc, | ||||
|       effective_date: effective_date, | ||||
|       status: status, | ||||
|       sharing: sharing, | ||||
|       wiki_page_title: wiki_page_title | ||||
|     } | ||||
| 
 | ||||
|     if name.present? | ||||
|       if Version.exists?(name: name, project_id: @project.id) | ||||
|         normal_status(-1, "里程碑已存在") | ||||
|       else | ||||
|         version = Version.new(tag_params.merge(project_id: @project.id, user_id: current_user.id)) | ||||
|         if version.save | ||||
|           normal_status(0, "里程碑创建成功") | ||||
|         else | ||||
|           normal_status(-1, "里程碑创建失败") | ||||
|         end | ||||
|       end | ||||
| 
 | ||||
|     else | ||||
|       normal_status(-1, "里程碑名称不能为空") | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
|   def edit | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
|   def update | ||||
|     name = params[:name].to_s.strip | ||||
|     desc = params[:description] | ||||
|     effective_date = params[:effective_date] | ||||
|     status = params[:status] || "open" | ||||
|     sharing = params[:sharing] || "" | ||||
|     wiki_page_title = params[:wiki_page_title] || "" | ||||
| 
 | ||||
|     tag_params = { | ||||
|       name: name, | ||||
|       description: desc, | ||||
|       effective_date: effective_date, | ||||
|       status: status, | ||||
|       sharing: sharing, | ||||
|       wiki_page_title: wiki_page_title | ||||
|     } | ||||
| 
 | ||||
|     if name.present? | ||||
|       if Version.exists?(name: name, project_id: @project.id)  && (@version.name != name) | ||||
|         normal_status(-1, "里程碑已存在") | ||||
|       else | ||||
|         if @version.update_attributes(tag_params) | ||||
|           normal_status(0, "里程碑更新成功") | ||||
|         else | ||||
|           normal_status(-1, "里程碑更新失败") | ||||
|         end | ||||
|       end | ||||
|     else | ||||
|       normal_status(-1, "里程碑名称不能为空") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def destroy | ||||
|     if @version.destroy | ||||
|       normal_status(0, "里程碑删除成功") | ||||
|     else | ||||
|       normal_status(-1, "里程碑删除失败") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def update_status | ||||
|     status = params[:status] || "open" | ||||
|     all_status = %w(open closed locked) | ||||
|     if all_status.include?(status) | ||||
|       if @version.update_attribute(:status, status) | ||||
|         normal_status(0, "操作成功") | ||||
|       else | ||||
|         normal_status(-1, "操作失败") | ||||
|       end | ||||
|     else | ||||
|       normal_status(-1, "status状态值错误") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   private | ||||
| 
 | ||||
|   def set_project | ||||
|     @project = Project.find_by_id(params[:project_id]) | ||||
|     unless @project.present? | ||||
|       normal_status(-1, "项目不存在") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def check_issue_permission | ||||
|     unless @project.member?(current_user) || current_user.admin? | ||||
|       normal_status(-1, "您没有权限") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def set_version | ||||
|     @version = Version.find_by_id(params[:id]) | ||||
|     unless @version.present? | ||||
|       normal_status(-1, "里程碑不存在") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
| end | ||||
| @ -0,0 +1,23 @@ | ||||
| module IssuesHelper | ||||
| 
 | ||||
|   def issue_status | ||||
|     { | ||||
|       "新增": "1", | ||||
|       "正在解决": "2", | ||||
|       "已解决": "3", | ||||
|       "反馈": "4", | ||||
|       "关闭": "5", | ||||
|       "拒绝": "6" | ||||
|     } | ||||
|   end | ||||
| 
 | ||||
|   def version_status | ||||
|     { | ||||
|       "开启": "open", | ||||
|       "关闭": "closed", | ||||
|       "锁定": "locked" | ||||
|     } | ||||
| 
 | ||||
|   end | ||||
| 
 | ||||
| end | ||||
| @ -1,3 +1,4 @@ | ||||
| class ComposeProject < ApplicationRecord | ||||
|   #组织的项目记录表 | ||||
|   belongs_to :compose | ||||
| end | ||||
|  | ||||
| @ -1,3 +1,13 @@ | ||||
| class Issue < ApplicationRecord | ||||
|   belongs_to :project | ||||
|   belongs_to :tracker | ||||
|   belongs_to :issue_tag, foreign_key: :priority_id | ||||
|   belongs_to :version, foreign_key: :fixed_version_id | ||||
|   belongs_to :user,optional: true | ||||
| 
 | ||||
|   scope :issue_includes, ->{includes(:user)} | ||||
| 
 | ||||
|   def get_assign_user | ||||
|     User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.assigned_to_id) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,4 @@ | ||||
| class IssueTag < ApplicationRecord | ||||
|   has_many :issues | ||||
|   belongs_to :projects, optional: true | ||||
| end | ||||
| @ -0,0 +1,3 @@ | ||||
| class Tracker < ApplicationRecord | ||||
|   has_many :issues | ||||
| end | ||||
| @ -1,3 +1,20 @@ | ||||
| class Version < ApplicationRecord | ||||
|   belongs_to :project | ||||
|   has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id" | ||||
|   belongs_to :user, optional: true | ||||
| 
 | ||||
|   scope :version_includes, ->{includes(:issues, :user)} | ||||
| 
 | ||||
|   def open_issues_count | ||||
|     issues.select(:id,:status_id).where(status_id: [1,2,3,4,6]).size | ||||
|   end | ||||
| 
 | ||||
|   def close_issues_count | ||||
|     issues.select(:id,:status_id).where(status_id: 5).size | ||||
|   end | ||||
| 
 | ||||
|   def version_user | ||||
|     User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id) | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  | ||||
| @ -0,0 +1 @@ | ||||
| json.extract! @issue_tag, :id, :title, :description, :color,:project_id | ||||
| @ -0,0 +1,7 @@ | ||||
| json.issue_tags_count @issue_tags_size | ||||
| json.issue_tags do | ||||
| 
 | ||||
|   json.array! @issue_tags.each.to_a do |tag| | ||||
|     json.extract! tag, :id, :title, :description, :color, :issues_count, :project_id | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1 @@ | ||||
| json.extract! @version, :id,:name,:project_id,:description, :effective_date, :status, :sharing,:wiki_page_title | ||||
| @ -0,0 +1,13 @@ | ||||
| json.versions_count @versions_size | ||||
| json.versions do | ||||
| 
 | ||||
|   json.array! @versions.each.to_a do |version| | ||||
|     json.extract! version, :id, :name, :description, :effective_date,:status | ||||
|     json.open_issues_count version.open_issues_count | ||||
|     json.close_issues_count version.close_issues_count | ||||
|     json.created_at format_time(version.created_on) | ||||
|     json.updated_at format_time(version.updated_on) | ||||
|     json.user_name version.version_user.try(:show_real_name) | ||||
|     json.user_login version.version_user.try(:login) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,27 @@ | ||||
| json.issues_count @version_issues_size | ||||
| json.close_issues_count @close_issues_size | ||||
| json.user_name @version.version_user.try(:show_real_name) | ||||
| json.user_login @version.version_user.try(:login) | ||||
| json.created_at format_time(@version.created_on) | ||||
| json.updated_at format_time(@version.updated_on) | ||||
| json.extract! @version, :id,:name,:project_id,:description, :effective_date, :status, :sharing,:wiki_page_title | ||||
| 
 | ||||
| json.issues do | ||||
| 
 | ||||
|   json.array! @version_issues.each.to_a do |issue| | ||||
|     user = issue.get_assign_user | ||||
|     json.id issue.id | ||||
|     json.name issue.subject | ||||
|     json.project_id issue.project_id | ||||
|     json.estimated_hours issue.estimated_hours.to_f | ||||
|     json.tracker issue.tracker.try(:name) | ||||
|     json.assign_user_name user.try(:show_real_name) | ||||
|     json.assign_user_login user.try(:login) | ||||
|     json.updated_at format_time(issue.updated_on) | ||||
|     json.status issue_status.key(issue.status_id.to_s) | ||||
|     json.done_ratio "#{issue.done_ratio.to_s}%" | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| @ -0,0 +1,14 @@ | ||||
| class CreateIssueTags < ActiveRecord::Migration[5.2] | ||||
|   def change | ||||
|     create_table :issue_tags do |t| | ||||
|       t.string :title | ||||
|       t.string :description | ||||
|       t.string :color | ||||
|       t.integer :user_id | ||||
|       t.integer :project_id | ||||
|       t.integer :issues_count,default: 0 | ||||
|       t.timestamps | ||||
|     end | ||||
|     add_index :issue_tags, [:user_id, :title,:project_id] | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,5 @@ | ||||
| require 'rails_helper' | ||||
| 
 | ||||
| RSpec.describe IssueTag, type: :model do | ||||
|   pending "add some examples to (or delete) #{__FILE__}" | ||||
| end | ||||
					Loading…
					
					
				
		Reference in new issue