Issue uses StateMachine now
This commit is contained in:
parent
0b512af803
commit
1644117a1a
13 changed files with 144 additions and 145 deletions
|
@ -6,7 +6,7 @@ module IssuesHelper
|
|||
|
||||
def issue_css_classes issue
|
||||
classes = "issue"
|
||||
classes << " closed" if issue.closed
|
||||
classes << " closed" if issue.closed?
|
||||
classes << " today" if issue.today?
|
||||
classes
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# project_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# closed :boolean default(FALSE), not null
|
||||
# state :string default(FALSE), not null
|
||||
# position :integer default(0)
|
||||
# branch_name :string(255)
|
||||
# description :text
|
||||
|
@ -19,11 +19,29 @@
|
|||
class Issue < ActiveRecord::Base
|
||||
include Issuable
|
||||
|
||||
attr_accessible :title, :assignee_id, :closed, :position, :description,
|
||||
:milestone_id, :label_list, :author_id_of_changes
|
||||
attr_accessible :title, :assignee_id, :position, :description,
|
||||
:milestone_id, :label_list, :author_id_of_changes,
|
||||
:state_event
|
||||
|
||||
acts_as_taggable_on :labels
|
||||
|
||||
state_machine :state, :initial => :opened do
|
||||
event :close do
|
||||
transition [:reopened, :opened] => :closed
|
||||
end
|
||||
|
||||
event :reopen do
|
||||
transition :closed => :reopened
|
||||
end
|
||||
|
||||
state :opened
|
||||
|
||||
state :reopened
|
||||
|
||||
state :closed
|
||||
end
|
||||
|
||||
|
||||
def self.open_for(user)
|
||||
opened.assigned(user)
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
has_many :events, dependent: :destroy
|
||||
has_many :merge_requests, dependent: :destroy
|
||||
has_many :issues, dependent: :destroy, order: "closed, created_at DESC"
|
||||
has_many :issues, dependent: :destroy, order: "state, created_at DESC"
|
||||
has_many :milestones, dependent: :destroy
|
||||
has_many :users_projects, dependent: :destroy
|
||||
has_many :notes, dependent: :destroy
|
||||
|
|
|
@ -7,22 +7,31 @@ class IssueObserver < ActiveRecord::Observer
|
|||
end
|
||||
end
|
||||
|
||||
def after_update(issue)
|
||||
def after_close(issue, transition)
|
||||
send_reassigned_email(issue) if issue.is_being_reassigned?
|
||||
|
||||
status = nil
|
||||
status = 'closed' if issue.is_being_closed?
|
||||
status = 'reopened' if issue.is_being_reopened?
|
||||
if status
|
||||
Note.create_status_change_note(issue, current_user, status)
|
||||
[issue.author, issue.assignee].compact.each do |recipient|
|
||||
Notify.delay.issue_status_changed_email(recipient.id, issue.id, status, current_user.id)
|
||||
end
|
||||
end
|
||||
create_note(issue)
|
||||
end
|
||||
|
||||
def after_reopen(issue, transition)
|
||||
send_reassigned_email(issue) if issue.is_being_reassigned?
|
||||
|
||||
create_note(issue)
|
||||
end
|
||||
|
||||
def after_update(issue)
|
||||
send_reassigned_email(issue) if issue.is_being_reassigned?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def create_note(issue)
|
||||
Note.create_status_change_note(issue, current_user, issue.state)
|
||||
[issue.author, issue.assignee].compact.each do |recipient|
|
||||
Notify.delay.issue_status_changed_email(recipient.id, issue.id, issue.state, current_user.id)
|
||||
end
|
||||
end
|
||||
|
||||
def send_reassigned_email(issue)
|
||||
recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id }
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
%i.icon-comment
|
||||
= issue.notes.count
|
||||
- if can? current_user, :modify_issue, issue
|
||||
- if issue.closed
|
||||
= link_to 'Reopen', project_issue_path(issue.project, issue, issue: {closed: false }, status_only: true), method: :put, class: "btn btn-small grouped reopen_issue", remote: true
|
||||
- if issue.closed?
|
||||
= link_to 'Reopen', project_issue_path(issue.project, issue, issue: {state: :reopened }, status_only: true), method: :put, class: "btn btn-small grouped reopen_issue", remote: true
|
||||
- else
|
||||
= link_to 'Close', project_issue_path(issue.project, issue, issue: {closed: true }, status_only: true), method: :put, class: "btn btn-small grouped close_issue", remote: true
|
||||
= link_to 'Close', project_issue_path(issue.project, issue, issue: {state: :closed }, status_only: true), method: :put, class: "btn btn-small grouped close_issue", remote: true
|
||||
= link_to edit_project_issue_path(issue.project, issue), class: "btn btn-small edit-issue-link grouped" do
|
||||
%i.icon-edit
|
||||
Edit
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
%span.pull-right
|
||||
- if can?(current_user, :admin_project, @project) || @issue.author == current_user
|
||||
- if @issue.closed
|
||||
= link_to 'Reopen', project_issue_path(@project, @issue, issue: {closed: false }, status_only: true), method: :put, class: "btn grouped reopen_issue"
|
||||
- if @issue.closed?
|
||||
= link_to 'Reopen', project_issue_path(@project, @issue, issue: {state: :reopened }, status_only: true), method: :put, class: "btn grouped reopen_issue"
|
||||
- else
|
||||
= link_to 'Close', project_issue_path(@project, @issue, issue: {closed: true }, status_only: true), method: :put, class: "btn grouped close_issue", title: "Close Issue"
|
||||
= link_to 'Close', project_issue_path(@project, @issue, issue: {state: :closed }, status_only: true), method: :put, class: "btn grouped close_issue", title: "Close Issue"
|
||||
- if can?(current_user, :admin_project, @project) || @issue.author == current_user
|
||||
= link_to edit_project_issue_path(@project, @issue), class: "btn grouped" do
|
||||
%i.icon-edit
|
||||
|
@ -27,7 +27,7 @@
|
|||
.ui-box.ui-box-show
|
||||
.ui-box-head
|
||||
%h4.box-title
|
||||
- if @issue.closed
|
||||
- if @issue.closed?
|
||||
.error.status_info Closed
|
||||
= gfm escape_once(@issue.title)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue