Skip to content

Commit

Permalink
publish
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfan committed Aug 7, 2013
1 parent 68329e3 commit 86cf45d
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/views/issues/_status_button.html.erb
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>&emsp;<%
else
%>[<%= link_to_if allowed_statuses.include?(status),
status.name, "javascript:make_status(#{status.id})" %>]&emsp;<%
end
end
%></td></tr>
<%= javascript_include_tag "status_button.js", :plugin => 'status_button' %>
24 changes: 24 additions & 0 deletions app/views/settings/_status_button_settings.html.erb
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>
26 changes: 26 additions & 0 deletions assets/javascripts/status_button.js
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();
}
};

22 changes: 22 additions & 0 deletions init.rb
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
29 changes: 29 additions & 0 deletions lib/issues_status_hook.rb
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

0 comments on commit 86cf45d

Please sign in to comment.