-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangfan
committed
Aug 7, 2013
1 parent
68329e3
commit 86cf45d
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<tr><th class="status"><%= l(:field_status) + "-->" %></th><td class="status" colspan=3><% | ||
allowed_statuses = @issue.new_statuses_allowed_to | ||
for status in @issue.tracker.issue_statuses | ||
if @issue.status == status | ||
%><b>[<%= status.name %>]</b> <% | ||
else | ||
%>[<%= link_to_if allowed_statuses.include?(status), | ||
status.name, "javascript:make_status(#{status.id})" %>] <% | ||
end | ||
end | ||
%></td></tr> | ||
<%= javascript_include_tag "status_button.js", :plugin => 'status_button' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% memberFields = CustomField.all.select { |f| f.class.name == 'IssueCustomField' && f.field_format == 'user' } | ||
options = memberFields.map{ |f| [f.name, f.id] } | ||
@settings = {:status_assigned_to => {}} unless @settings[:status_assigned_to] %> | ||
<fieldset> | ||
<legend>Issues Status settings</legend> | ||
<table class="list"> | ||
<thead><tr> | ||
<th><%=l(:field_status)%></th> | ||
<th><%=l(:field_assigned_to)%></th> | ||
</tr></thead> | ||
<tbody> | ||
<% for status in IssueStatus.all() %> | ||
<tr class="<%= cycle("odd", "even") %>" align="center"> | ||
<td><%= h(status.name) %></td> | ||
<td align="center"> | ||
<%= select_tag "settings[status_assigned_to][#{status.id}]", | ||
options_for_select(options, @settings[:status_assigned_to][status.id.to_s]), | ||
:include_blank => true %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function make_status(newStatus) { | ||
if (jQuery) { | ||
// redmine uses jQuery so use it. | ||
var $ = jQuery; | ||
var s = $('#issue_status_id'); | ||
if (s.length === 0) { | ||
return; | ||
} | ||
var f = $('#issue-form'); | ||
if (f.length === 0) { | ||
return; | ||
} | ||
s.val(newStatus); | ||
f.submit(); | ||
} else { | ||
// redmine uses prototype so use it. | ||
var s = $('issue_status_id'); | ||
if (s === null) { | ||
return; | ||
} | ||
var f = $('issue-form'); | ||
s.value = newStatus; | ||
f.submit(); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'redmine' | ||
|
||
require_dependency 'issues_status_hook' | ||
|
||
Redmine::Plugin.register :status_button do | ||
name 'Redmine Status Button plugin' | ||
author 'Zhang Fan' | ||
description 'Change the issues status by just one click.' | ||
version '0.0.1' | ||
url 'http://web.4399.com' | ||
author_url 'mailto:[email protected]' | ||
requires_redmine :version_or_higher => '2.3.0' | ||
settings :default => { | ||
:status_assigned_to => {} | ||
}, :partial => 'settings/status_button_settings' | ||
end | ||
|
||
module StatusButton | ||
class Hooks < Redmine::Hook::ViewListener | ||
render_on :view_issues_show_details_bottom, :partial => 'issues/status_button' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
class IssueStatusHook < Redmine::Hook::ViewListener | ||
def controller_issues_new_before_save(context={}) | ||
update_issues(context[:issue]) | ||
end | ||
|
||
def controller_issues_edit_before_save(context={}) | ||
# TODO: 检测status变更(需要用到issues@attributes_before_change) | ||
update_issues(context[:issue]) | ||
end | ||
|
||
def update_issues(issue) | ||
status_to_user = status_to(issue) | ||
issue.assigned_to_id = status_to_user[issue.status_id] if status_to_user[issue.status_id] | ||
issue.watcher_user_ids = issue.watcher_user_ids | status_to_user.map{|s,u| u} | ||
end | ||
|
||
def status_to(issue) | ||
plugin = Redmine::Plugin.find(:status_button) | ||
setting = Setting["plugin_#{plugin.id}"] || plugin.settings[:default] | ||
status_to_user = {} | ||
setting[:status_assigned_to].each { |s, a| | ||
unless a.blank? | ||
f = issue.custom_field_values.find { |f| f.custom_field_id == Integer(a) } | ||
status_to_user[Integer(s)] = Integer(f.value) if f && !f.value.empty? | ||
end } | ||
status_to_user | ||
end | ||
end |