Skip to content

Commit 2d85d79

Browse files
author
Leon Li
committed
add function to delete task from user story; integrate issues query function in sprint; disable unstable diagram function
1 parent 151583b commit 2d85d79

File tree

8 files changed

+225
-20
lines changed

8 files changed

+225
-20
lines changed

app/controllers/issue_sprints_controller.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ def status_change
113113
end
114114
end
115115

116+
def status_delete
117+
issue = Issue.find(params[:task_id])
118+
119+
if !issue.user_story_id.nil? && User.current.allowed_to?(:edit_issues, @project)
120+
journal = issue.init_journal(User.current, nil)
121+
122+
if !issue.nil?
123+
issue.user_story_id = nil
124+
end
125+
126+
if issue.save
127+
else
128+
render :update do |page|
129+
page.insert_html :top, "content", content_tag('div', t(:error_changing_status), :class => "error", :id => "errorExplanation")
130+
end
131+
end
132+
end
133+
render :text => nil
134+
end
135+
116136
private
117137

118138
def find_project
@@ -156,4 +176,4 @@ def status_to_done_ratio(status)
156176
end
157177
end
158178

159-
end
179+
end

app/controllers/sprints_controller.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ def index
2727
# GET /sprints/1.xml
2828
def show
2929
unless @sprint.nil?
30-
@unassigned_tasks = Issue.find(:all, :joins => :status,
31-
:conditions => ["issue_statuses.is_closed = ? AND user_story_id IS NULL AND (fixed_version_id = ? OR project_id = ?)", false, @sprint.id, @project.id ])
32-
@issue_statuses = IssueStatus.find(:all)
33-
@project_users = User.find(:all, :joins => :members, :conditions => ["members.project_id = ?", @project.id])
34-
3530
if defined? @sprint
3631
@data = load_sprint_stats(@sprint,[])
3732
end
33+
@issue_statuses = IssueStatus.find(:all)
34+
@project_users = User.find(:all, :joins => :members, :conditions => ["members.project_id = ?", @project.id])
3835

3936
respond_to do |format|
4037
format.html # show.html.erb

app/controllers/tasks_controller.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
class TasksController < ApplicationController
22
unloadable
33
before_filter :find_project, :except => [:destroy]
4+
helper :queries
5+
include QueriesHelper
6+
helper :sort
7+
include SortHelper
8+
include IssuesHelper
49
# GET /tasks
510
# GET /tasks.xml
611
def index
@@ -12,6 +17,33 @@ def index
1217
end
1318
end
1419

20+
def issues
21+
retrieve_query
22+
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
23+
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
24+
@unassigned_tasks = []
25+
if @query.valid?
26+
limit = per_page_option
27+
28+
@issue_count = @query.issue_count
29+
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
30+
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
31+
:order => sort_clause,
32+
:offset => @issue_pages.current.offset,
33+
:limit => limit)
34+
@issue_count_by_group = @query.issue_count_by_group
35+
# @unassigned_tasks = Issue.find(:all, :joins => :status,
36+
# :conditions => ["issue_statuses.is_closed = ? AND user_story_id IS NULL AND project_id = ?", false, @project.id ])
37+
@unassigned_tasks = @issues
38+
@issue_statuses = IssueStatus.find(:all)
39+
@project_users = User.find(:all, :joins => :members, :conditions => ["members.project_id = ?", @project.id])
40+
end
41+
render :layout => false
42+
rescue ActiveRecord::RecordNotFound
43+
render_404
44+
end
45+
46+
1547
# GET /tasks/1
1648
# GET /tasks/1.xml
1749
def show
@@ -141,4 +173,37 @@ def find_project
141173
rescue ActiveRecord::RecordNotFound
142174
render_404
143175
end
176+
177+
def retrieve_query
178+
if !params[:query_id].blank?
179+
cond = "project_id IS NULL"
180+
cond << " OR project_id = #{@project.id}" if @project
181+
@query = Query.find(params[:query_id], :conditions => cond)
182+
@query.project = @project
183+
session[:query] = {:id => @query.id, :project_id => @query.project_id}
184+
sort_clear
185+
else
186+
if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
187+
# Give it a name, required to be valid
188+
@query = Query.new(:name => "_")
189+
@query.project = @project
190+
if params[:fields] and params[:fields].is_a? Array
191+
params[:fields].each do |field|
192+
@query.add_filter(field, params[:operators][field], params[:values][field])
193+
end
194+
else
195+
@query.available_filters.keys.each do |field|
196+
@query.add_short_filter(field, params[field]) if params[field]
197+
end
198+
end
199+
@query.group_by = params[:group_by]
200+
@query.column_names = params[:query] && params[:query][:column_names]
201+
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
202+
else
203+
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
204+
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
205+
@query.project = @project
206+
end
207+
end
208+
end
144209
end

app/views/sprints/show.html.erb

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,70 @@
7575
<table class="unassigned_tasks">
7676
<tr class="unassigned_tasks_hd">
7777
<td>
78-
<%= t("unassigned_issues") %>
78+
<%= t("label_issue_plural") %>
7979
</td>
8080
</tr>
81-
<% @unassigned_tasks.each do |task| %>
82-
<tr>
83-
<td>
84-
<%= render :partial => "shared/task_view", :locals => {:task => task, :issue_statuses => @issue_statuses,
85-
:project_users => @project_users} %>
86-
</td>
87-
</tr>
88-
<% end %>
89-
</table>
81+
<script type="text/javascript">
82+
//<![CDATA[
83+
function add_filter() {
84+
select = $('add_filter_select');
85+
field = select.value
86+
Element.show('tr_' + field);
87+
check_box = $('cb_' + field);
88+
check_box.checked = true;
89+
toggle_filter(field);
90+
select.selectedIndex = 0;
91+
92+
for (i=0; i<select.options.length; i++) {
93+
if (select.options[i].value == field) {
94+
select.options[i].disabled = true;
95+
}
96+
}
97+
}
9098

99+
function toggle_filter(field) {
100+
check_box = $('cb_' + field);
101+
102+
if (check_box.checked) {
103+
Element.show("operators_" + field);
104+
toggle_operator(field);
105+
} else {
106+
Element.hide("operators_" + field);
107+
Element.hide("div_values_" + field);
108+
}
109+
}
91110

111+
function toggle_operator(field) {
112+
operator = $("operators_" + field);
113+
switch (operator.value) {
114+
case "!*":
115+
case "*":
116+
case "t":
117+
case "w":
118+
case "o":
119+
case "c":
120+
Element.hide("div_values_" + field);
121+
break;
122+
default:
123+
Element.show("div_values_" + field);
124+
break;
125+
}
126+
}
127+
128+
function toggle_multi_select(field) {
129+
select = $('values_' + field);
130+
if (select.multiple == true) {
131+
select.multiple = false;
132+
} else {
133+
select.multiple = true;
134+
}
135+
}
136+
//]]>
137+
</script>
138+
<script><%= remote_function(:url => {:controller => :tasks, :action => :issues},:update => 'unassigned_tasks', :layout => false) %></script>
139+
</table>
140+
<div class="unassigned_tasks" id="unassigned_tasks" style="width:900px">
141+
</div>
92142
<%= render(:partial => "shared/stats_form", :locals => {:sprint => @sprint}) %>
93143
<% end %>
94144

@@ -111,3 +161,12 @@
111161
<%= stylesheet_link_tag('calendar') %>
112162
<%= stylesheet_link_tag 'scm' %>
113163
<% end %>
164+
165+
<%= drop_receiving_element("unassigned_tasks",
166+
:accept => "us_task",
167+
:before => visual_effect(:highlight, "unassigned_tasks"),
168+
:success => "element.remove();",
169+
:with => "'task_id=' + (element.id.split('_').last())",
170+
:hoverclass => 'hover',
171+
:url => {:controller => :issue_sprints, :action => :status_delete, :project_id => @project }
172+
)%>

app/views/tasks/issues.html.erb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %>
2+
<%= hidden_field_tag('project_id', @project.to_param) if @project %>
3+
<div id="query_form_content">
4+
<fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
5+
<legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
6+
<div style="<%= @query.new_record? ? "" : "display: none;" %>">
7+
<%= render :partial => 'queries/filters', :locals => {:query => @query} %>
8+
</div>
9+
</fieldset>
10+
<fieldset class="collapsible collapsed">
11+
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
12+
<div style="display: none;">
13+
<table>
14+
<tr>
15+
<td><%= l(:field_column_names) %></td>
16+
<td><%= render :partial => 'queries/columns', :locals => {:query => @query} %></td>
17+
</tr>
18+
<tr>
19+
<td><%= l(:field_group_by) %></td>
20+
<td><%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %></td>
21+
</tr>
22+
</table>
23+
</div>
24+
</fieldset>
25+
</div>
26+
<p class="buttons">
27+
28+
<%= link_to_remote l(:button_apply),
29+
{ :url => { :set_filter => 1 },
30+
:update => "unassigned_tasks",
31+
:with => "Form.serialize('query_form')"
32+
}, :class => 'icon icon-checked' %>
33+
34+
<%= link_to_remote l(:button_clear),
35+
{ :url => { :set_filter => 1, :project_id => @project },
36+
:method => :get,
37+
:update => "unassigned_tasks",
38+
}, :class => 'icon icon-reload' %>
39+
40+
</p>
41+
<% end %>
42+
43+
<%= error_messages_for 'query' %>
44+
<% if @query.valid? %>
45+
<% if @issues.empty? %>
46+
<p class="nodata"><%= l(:label_no_data) %></p>
47+
<% else %>
48+
<table >
49+
<% @issues.each do |task| %>
50+
<tr>
51+
<td>
52+
<%= render :partial => "shared/task_view", :locals => {:task => task, :issue_statuses => @issue_statuses,
53+
:project_users => @project_users} %>
54+
</td>
55+
</tr>
56+
<% end %>
57+
</table>
58+
<p class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></p>
59+
<% end %>
60+
<% end %>

app/views/user_stories/_us_for_show.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<table>
1111
<tr >
1212
<td><div class="tab_sprint_user_story">#<%= user_story.us_number %></div></td>
13-
<td class="tab_us_name"><%=h user_story.name %></td>
14-
<td class="tab_us_links">
13+
<td class="tab_us_name"><%=h user_story.name %>(P<%= user_story.priority %>)</td>
14+
<td class="tab_us_links">
1515
<!--This will be done at some point-->
1616
<%#= link_to_object(user_story, "show", "story") %>
1717
<%= link_to image_tag("/plugin_assets/redmine_sprints/images/story_edit.png"),
@@ -30,6 +30,7 @@
3030
</td>
3131

3232
</tr>
33+
<!--
3334
<tr>
3435
<td colspan="2" class="tab_us_diagrams">
3536
<div>
@@ -54,6 +55,7 @@
5455
<%= link_to_new_object("diagram",user_story,"diagram_add") %>
5556
</td>
5657
</tr>
58+
-->
5759
</table>
5860
<%= image_tag("/plugin_assets/redmine_sprints/images/us-bottom.png") %>
5961
</td>
@@ -102,4 +104,4 @@
102104
:hoverclass => 'hover',
103105
:url => {:controller => :issue_sprints, :action => :status_change, :status_id => 3, :project_id => @project, :user_story_id => user_story.id }
104106
)%>
105-
</tr>
107+
</tr>

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
map.with_options :controller => 'tasks' do |tasks|
1818
tasks.with_options :conditions => {:method => :get} do |tasks|
1919
tasks.connect 'projects/:project_id/tasks', :action => 'index'
20+
tasks.connect 'projects/:project_id/tasks/issues', :action => 'issues'
2021
tasks.connect 'projects/:project_id/tasks/new/:userstory_id', :action => 'new'
2122
tasks.connect 'projects/:project_id/tasks/:id', :action => 'show'
2223
tasks.connect 'projects/:project_id/tasks/:id/edit', :action => 'edit'
@@ -25,6 +26,7 @@
2526
end
2627
tasks.with_options :conditions => {:method => :post} do |tasks|
2728
tasks.connect 'projects/:project_id/tasks', :action => 'new'
29+
tasks.connect 'projects/:project_id/tasks/issues', :action => 'issues'
2830
tasks.connect 'projects/:project_id/tasks/:task_id/status_change/:status_id/:user_story_id', :action => 'status_change'
2931
tasks.connect 'projects/:project_id/tasks/:task_id/status_change/:status_id', :action => 'status_change'
3032
tasks.connect 'projects/:project_id/tasks/:id/:action', :action => /update|destroy/

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
permission :view_sprints, {:sprints => [:index, :show]}
2121
permission :manage_sprints_and_user_stories, {:sprints => [:create, :new, :edit, :update, :assign_us, :assign_to_milestone, :destroy],
2222
:user_stories => [:new, :create, :edit, :update, :destroy]}
23-
permission :manage_tasks, {:issue_sprints => [:new, :create, :status_change, :update_task]}
23+
permission :manage_tasks, {:issue_sprints => [:new, :create, :status_change, :update_task, :status_delete]}
2424
end
2525

2626
Redmine::MenuManager.map :project_menu do |menu|

0 commit comments

Comments
 (0)