Commit 46c033fc27f792e34561435b8309b94fc42d6a3a
1 parent
f7d6dd22
Exists in
master
and in
29 other branches
ActionItem371: user can now create tasks for its friends
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2407 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
88 additions
and
27 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
... | ... | @@ -26,9 +26,18 @@ class TasksController < MyProfileController |
26 | 26 | @ticket = Ticket.new(params[:ticket]) |
27 | 27 | @ticket.requestor = profile |
28 | 28 | if request.post? |
29 | - @ticket.save! | |
30 | - redirect_to :action => 'index' | |
29 | + if @ticket.save | |
30 | + redirect_to :action => 'index' | |
31 | + end | |
31 | 32 | end |
32 | 33 | end |
33 | 34 | |
35 | + def list_requested | |
36 | + @tasks = Task.find_all_by_requestor_id(profile.id) | |
37 | + end | |
38 | + | |
39 | + def ticket_details | |
40 | + @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) | |
41 | + end | |
42 | + | |
34 | 43 | end | ... | ... |
app/models/task.rb
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | class Task < ActiveRecord::Base |
13 | 13 | |
14 | 14 | module Status |
15 | + include GetText | |
15 | 16 | # the status of tasks just created |
16 | 17 | ACTIVE = 1 |
17 | 18 | |
... | ... | @@ -20,6 +21,10 @@ class Task < ActiveRecord::Base |
20 | 21 | |
21 | 22 | # the status os a task that was successfully finished |
22 | 23 | FINISHED = 3 |
24 | + | |
25 | + def self.names | |
26 | + [nil, N_('Active'), N_('Cancelled'), N_('Finished')] | |
27 | + end | |
23 | 28 | end |
24 | 29 | |
25 | 30 | belongs_to :requestor, :class_name => 'Person', :foreign_key => :requestor_id | ... | ... |
app/models/ticket.rb
1 | 1 | class Ticket < Task |
2 | - | |
3 | - serialize :data, Hash | |
4 | - | |
5 | - def data | |
6 | - self[:data] ||= {} | |
7 | - end | |
8 | - | |
9 | - def title | |
10 | - data[:title] | |
11 | - end | |
12 | - | |
13 | - def title= value | |
14 | - data[:title] = value | |
15 | - end | |
16 | - | |
17 | - def description | |
18 | - data[:description] | |
19 | - end | |
20 | - | |
21 | - def description= value | |
22 | - data[:description] = value | |
23 | - end | |
24 | - | |
2 | + acts_as_having_settings :field => :data | |
3 | + settings_items :title, :description, :closing_statment | |
25 | 4 | end | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +<h2><%= _('Processing ticket: %s') % task.title %></h2> | |
2 | + | |
3 | +<%= task.description %> | |
4 | + | |
5 | +<% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> | |
6 | + | |
7 | + <%= labelled_form_field(_('Closing statment'), f.text_area(:closing_statment) ) %> | |
8 | + | |
9 | + <div> | |
10 | + <%= radio_button_tag(:decision, 'finish', true) %> | |
11 | + <%= _('OK') %> | |
12 | + </div> | |
13 | + <div> | |
14 | + <%= radio_button_tag(:decision, 'cancel', false) %> | |
15 | + <%= _('Cancel') %> | |
16 | + </div> | |
17 | + | |
18 | + <% button_bar do %> | |
19 | + <%= submit_button(:ok, _('OK')) %> | |
20 | + <% end %> | |
21 | + | |
22 | +<% end %> | ... | ... |
app/views/tasks/index.rhtml
... | ... | @@ -14,5 +14,7 @@ |
14 | 14 | |
15 | 15 | <% button_bar do %> |
16 | 16 | <%= button(:edit, _('View processed tasks'), :action => 'processed') %> |
17 | + <%= button(:edit, _('View my requested tasks'), :action => 'list_requested') %> | |
18 | + <%= button(:new, _('Create task'), :action => 'new') %> | |
17 | 19 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> |
18 | 20 | <% end %> | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<%= _('Tasks that I requested') %> | |
2 | + | |
3 | +<ul> | |
4 | + <% @tasks.each do |task| %> | |
5 | + <li> | |
6 | + <strong><%= task.respond_to?(:title) ? link_to( task.title, :action => 'ticket_details', :id => task.id) : task.description %></strong><br/> | |
7 | + <small> | |
8 | + <%= _('Created:') + ' ' + show_date(task.created_at) %> | |
9 | + — | |
10 | + <%= _('Status:') + ' ' + task.status.to_s %> | |
11 | + </small> | |
12 | + </li> | |
13 | + <% end %> | |
14 | +</ul> | |
15 | + | |
16 | +<% button_bar do %> | |
17 | + <%= button :back, _('Back'), :action => 'index' %> | |
18 | +<% end %> | ... | ... |
app/views/tasks/new.rhtml
1 | 1 | <% labelled_form_for :ticket, @ticket do |f| %> |
2 | 2 | <%= f.text_field :title %> |
3 | 3 | <%= display_form_field( _('Owner: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> |
4 | - <%= f.text_area :description %> | |
4 | + <%= f.text_area :description %> | |
5 | 5 | |
6 | 6 | <% button_bar do %> |
7 | - <%= submit_button('save', _('Create')) %> | |
7 | + <%= submit_button('save', _('Create'), :cancel => {:action => 'index'}) %> | |
8 | 8 | <% end %> |
9 | 9 | <% end %> | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +<h2><%= _('Ticket: %s') % @ticket.title %></h2> | |
2 | +<p><small> | |
3 | + <%= _('Created at %s by %s') % [@ticket.created_at.to_date, link_to(@ticket.requestor.name, @ticket.requestor.url)] %><br/> | |
4 | + <%= _('Owner: %s') % link_to(@ticket.target.name, @ticket.target.url) %> | |
5 | +</small></p> | |
6 | + | |
7 | +<p><%= _('Status: %s') % gettext(Task::Status.names[@ticket.status]) %></p> | |
8 | + | |
9 | +<div> | |
10 | + <p><%= _('Description: %s') % @ticket.description %></p> | |
11 | +</div> | |
12 | + | |
13 | +<% if @ticket.closing_statment %> | |
14 | + <p><%= _('Closing statement: %s') % @ticket.closing_statment %></p> | |
15 | +<% end %> | |
16 | + | |
17 | +<% button_bar do %> | |
18 | + <%= button :back, _('Back'), :action => 'index' %> | |
19 | +<% end %> | ... | ... |
test/functional/tasks_controller_test.rb
... | ... | @@ -121,4 +121,10 @@ class TasksControllerTest < Test::Unit::TestCase |
121 | 121 | assert_equal profile, assigns(:ticket).requestor |
122 | 122 | end |
123 | 123 | |
124 | + should 'list tasks that this profile created' do | |
125 | + task = Ticket.create!(:title => 'test', :requestor => profile) | |
126 | + get :list_requested, :profile => profile.identifier | |
127 | + | |
128 | + assert_includes assigns(:tasks), task | |
129 | + end | |
124 | 130 | end | ... | ... |