Resourcified issue statuses.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7890 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-22 22:04:07 +00:00
parent 35e8f0d25d
commit 68f3e91bd7
7 changed files with 25 additions and 37 deletions

View File

@ -22,9 +22,6 @@ class IssueStatusesController < ApplicationController
before_filter :require_admin_or_api_request, :only => :index before_filter :require_admin_or_api_request, :only => :index
accept_api_auth :index accept_api_auth :index
verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
:redirect_to => { :action => :index }
def index def index
respond_to do |format| respond_to do |format|
format.html { format.html {
@ -43,7 +40,7 @@ class IssueStatusesController < ApplicationController
def create def create
@issue_status = IssueStatus.new(params[:issue_status]) @issue_status = IssueStatus.new(params[:issue_status])
if @issue_status.save if request.post? && @issue_status.save
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index' redirect_to :action => 'index'
else else
@ -57,7 +54,7 @@ class IssueStatusesController < ApplicationController
def update def update
@issue_status = IssueStatus.find(params[:id]) @issue_status = IssueStatus.find(params[:id])
if @issue_status.update_attributes(params[:issue_status]) if request.put? && @issue_status.update_attributes(params[:issue_status])
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index' redirect_to :action => 'index'
else else
@ -65,6 +62,7 @@ class IssueStatusesController < ApplicationController
end end
end end
verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
def destroy def destroy
IssueStatus.find(params[:id]).destroy IssueStatus.find(params[:id]).destroy
redirect_to :action => 'index' redirect_to :action => 'index'
@ -74,7 +72,7 @@ class IssueStatusesController < ApplicationController
end end
def update_issue_done_ratio def update_issue_done_ratio
if IssueStatus.update_issue_done_ratios if request.post? && IssueStatus.update_issue_done_ratios
flash[:notice] = l(:notice_issue_done_ratios_updated) flash[:notice] = l(:notice_issue_done_ratios_updated)
else else
flash[:error] = l(:error_issue_done_ratios_not_updated) flash[:error] = l(:error_issue_done_ratios_not_updated)

View File

@ -1,22 +1,12 @@
<%= error_messages_for 'issue_status' %> <%= error_messages_for 'issue_status' %>
<div class="box"> <div class="box tabular">
<!--[form:issue_status]--> <p><%= f.text_field :name, :required => true %></p>
<p><label for="issue_status_name"><%=l(:field_name)%><span class="required"> *</span></label>
<%= text_field 'issue_status', 'name' %></p>
<% if Issue.use_status_for_done_ratio? %> <% if Issue.use_status_for_done_ratio? %>
<p><label for="issue_done_ratio"><%=l(:field_done_ratio)%></label> <p><%= f.select :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :include_blank => true, :label => :field_done_ratio %></p>
<%= select 'issue_status', :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :include_blank => true %></p>
<% end %> <% end %>
<p><%= f.check_box :is_closed %></p>
<p><label for="issue_status_is_closed"><%=l(:field_is_closed)%></label> <p><%= f.check_box :is_default %></p>
<%= check_box 'issue_status', 'is_closed' %></p>
<p><label for="issue_status_is_default"><%=l(:field_is_default)%></label>
<%= check_box 'issue_status', 'is_default' %></p>
<%= call_hook(:view_issue_statuses_form, :issue_status => @issue_status) %> <%= call_hook(:view_issue_statuses_form, :issue_status => @issue_status) %>
<!--[eoform:issue_status]-->
</div> </div>

View File

@ -1,6 +1,6 @@
<h2><%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses', :action => 'index' %> &#187; <%=h @issue_status %></h2> <h2><%= link_to l(:label_issue_status_plural), issue_statuses_path %> &#187; <%=h @issue_status %></h2>
<% form_tag({:action => 'update', :id => @issue_status}, :class => "tabular") do %> <% form_for @issue_status, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form' %> <%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_save) %> <%= submit_tag l(:button_save) %>
<% end %> <% end %>

View File

@ -1,6 +1,6 @@
<div class="contextual"> <div class="contextual">
<%= link_to l(:label_issue_status_new), {:action => 'new'}, :class => 'icon icon-add' %> <%= link_to l(:label_issue_status_new), new_issue_status_path, :class => 'icon icon-add' %>
<%= link_to(l(:label_update_issue_done_ratios), {:action => 'update_issue_done_ratio'}, :class => 'icon icon-multiple', :method => 'post', :confirm => l(:text_are_you_sure)) if Issue.use_status_for_done_ratio? %> <%= link_to(l(:label_update_issue_done_ratios), update_issue_done_ratio_issue_statuses_path, :class => 'icon icon-multiple', :method => 'post', :confirm => l(:text_are_you_sure)) if Issue.use_status_for_done_ratio? %>
</div> </div>
<h2><%=l(:label_issue_status_plural)%></h2> <h2><%=l(:label_issue_status_plural)%></h2>
@ -19,16 +19,16 @@
<tbody> <tbody>
<% for status in @issue_statuses %> <% for status in @issue_statuses %>
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td><%= link_to h(status.name), :action => 'edit', :id => status %></td> <td><%= link_to h(status.name), edit_issue_status_path(status) %></td>
<% if Issue.use_status_for_done_ratio? %> <% if Issue.use_status_for_done_ratio? %>
<td align="center"><%= h status.default_done_ratio %></td> <td align="center"><%= h status.default_done_ratio %></td>
<% end %> <% end %>
<td align="center"><%= checked_image status.is_default? %></td> <td align="center"><%= checked_image status.is_default? %></td>
<td align="center"><%= checked_image status.is_closed? %></td> <td align="center"><%= checked_image status.is_closed? %></td>
<td align="center" style="width:15%;"><%= reorder_links('issue_status', {:action => 'update', :id => status}) %></td> <td align="center" style="width:15%;"><%= reorder_links('issue_status', {:action => 'update', :id => status}, :put) %></td>
<td class="buttons"> <td class="buttons">
<%= link_to(l(:button_delete), { :action => 'destroy', :id => status }, <%= link_to(l(:button_delete), issue_status_path(status),
:method => :post, :method => :delete,
:confirm => l(:text_are_you_sure), :confirm => l(:text_are_you_sure),
:class => 'icon icon-del') %> :class => 'icon icon-del') %>
</td> </td>

View File

@ -1,6 +1,6 @@
<h2><%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses', :action => 'index' %> &#187; <%=l(:label_issue_status_new)%></h2> <h2><%= link_to l(:label_issue_status_plural), issue_statuses_path %> &#187; <%=l(:label_issue_status_new)%></h2>
<% form_tag({:action => 'create'}, :class => "tabular") do %> <% form_for @issue_status, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form' %> <%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create) %>
<% end %> <% end %>

View File

@ -223,9 +223,9 @@ ActionController::Routing::Routes.draw do |map|
map.resources :groups map.resources :groups
map.resources :trackers, :except => :show map.resources :trackers, :except => :show
map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post}
#left old routes at the bottom for backwards compat #left old routes at the bottom for backwards compat
map.connect 'issue_statuses.:format', :controller => 'issue_statuses', :action => 'index'
map.connect 'projects/:project_id/issues/:action', :controller => 'issues' map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
map.connect 'projects/:project_id/documents/:action', :controller => 'documents' map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'

View File

@ -56,7 +56,7 @@ class IssueStatusesControllerTest < ActionController::TestCase
end end
def test_update def test_update
post :update, :id => '3', :issue_status => {:name => 'Renamed status'} put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
assert_redirected_to :action => 'index' assert_redirected_to :action => 'index'
status = IssueStatus.find(3) status = IssueStatus.find(3)
assert_equal 'Renamed status', status.name assert_equal 'Renamed status', status.name
@ -66,7 +66,7 @@ class IssueStatusesControllerTest < ActionController::TestCase
Issue.delete_all("status_id = 1") Issue.delete_all("status_id = 1")
assert_difference 'IssueStatus.count', -1 do assert_difference 'IssueStatus.count', -1 do
post :destroy, :id => '1' delete :destroy, :id => '1'
end end
assert_redirected_to :action => 'index' assert_redirected_to :action => 'index'
assert_nil IssueStatus.find_by_id(1) assert_nil IssueStatus.find_by_id(1)
@ -76,7 +76,7 @@ class IssueStatusesControllerTest < ActionController::TestCase
assert_not_nil Issue.find_by_status_id(1) assert_not_nil Issue.find_by_status_id(1)
assert_no_difference 'IssueStatus.count' do assert_no_difference 'IssueStatus.count' do
post :destroy, :id => '1' delete :destroy, :id => '1'
end end
assert_redirected_to :action => 'index' assert_redirected_to :action => 'index'
assert_not_nil IssueStatus.find_by_id(1) assert_not_nil IssueStatus.find_by_id(1)