diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 274360f..c80593f 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -26,9 +26,18 @@ class TasksController < MyProfileController @ticket = Ticket.new(params[:ticket]) @ticket.requestor = profile if request.post? - @ticket.save! - redirect_to :action => 'index' + if @ticket.save + redirect_to :action => 'index' + end end end + def list_requested + @tasks = Task.find_all_by_requestor_id(profile.id) + end + + def ticket_details + @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) + end + end diff --git a/app/models/task.rb b/app/models/task.rb index d034882..ab4012e 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -12,6 +12,7 @@ class Task < ActiveRecord::Base module Status + include GetText # the status of tasks just created ACTIVE = 1 @@ -20,6 +21,10 @@ class Task < ActiveRecord::Base # the status os a task that was successfully finished FINISHED = 3 + + def self.names + [nil, N_('Active'), N_('Cancelled'), N_('Finished')] + end end belongs_to :requestor, :class_name => 'Person', :foreign_key => :requestor_id diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 9b13217..ffc22a9 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,25 +1,4 @@ class Ticket < Task - - serialize :data, Hash - - def data - self[:data] ||= {} - end - - def title - data[:title] - end - - def title= value - data[:title] = value - end - - def description - data[:description] - end - - def description= value - data[:description] = value - end - + acts_as_having_settings :field => :data + settings_items :title, :description, :closing_statment end diff --git a/app/views/tasks/_ticket.rhtml b/app/views/tasks/_ticket.rhtml new file mode 100644 index 0000000..817dcae --- /dev/null +++ b/app/views/tasks/_ticket.rhtml @@ -0,0 +1,22 @@ +

<%= _('Processing ticket: %s') % task.title %>

+ +<%= task.description %> + +<% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> + + <%= labelled_form_field(_('Closing statment'), f.text_area(:closing_statment) ) %> + +
+ <%= radio_button_tag(:decision, 'finish', true) %> + <%= _('OK') %> +
+
+ <%= radio_button_tag(:decision, 'cancel', false) %> + <%= _('Cancel') %> +
+ + <% button_bar do %> + <%= submit_button(:ok, _('OK')) %> + <% end %> + +<% end %> diff --git a/app/views/tasks/index.rhtml b/app/views/tasks/index.rhtml index 367e487..4350c33 100644 --- a/app/views/tasks/index.rhtml +++ b/app/views/tasks/index.rhtml @@ -14,5 +14,7 @@ <% button_bar do %> <%= button(:edit, _('View processed tasks'), :action => 'processed') %> + <%= button(:edit, _('View my requested tasks'), :action => 'list_requested') %> + <%= button(:new, _('Create task'), :action => 'new') %> <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> <% end %> diff --git a/app/views/tasks/list_requested.rhtml b/app/views/tasks/list_requested.rhtml new file mode 100644 index 0000000..1e31064 --- /dev/null +++ b/app/views/tasks/list_requested.rhtml @@ -0,0 +1,18 @@ +<%= _('Tasks that I requested') %> + + + +<% button_bar do %> + <%= button :back, _('Back'), :action => 'index' %> +<% end %> diff --git a/app/views/tasks/new.rhtml b/app/views/tasks/new.rhtml index 1fe7f4f..d95b68b 100644 --- a/app/views/tasks/new.rhtml +++ b/app/views/tasks/new.rhtml @@ -1,9 +1,9 @@ <% labelled_form_for :ticket, @ticket do |f| %> <%= f.text_field :title %> <%= display_form_field( _('Owner: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> - <%= f.text_area :description %> + <%= f.text_area :description %> <% button_bar do %> - <%= submit_button('save', _('Create')) %> + <%= submit_button('save', _('Create'), :cancel => {:action => 'index'}) %> <% end %> <% end %> diff --git a/app/views/tasks/ticket_details.rhtml b/app/views/tasks/ticket_details.rhtml new file mode 100644 index 0000000..e93f2a0 --- /dev/null +++ b/app/views/tasks/ticket_details.rhtml @@ -0,0 +1,19 @@ +

<%= _('Ticket: %s') % @ticket.title %>

+

+ <%= _('Created at %s by %s') % [@ticket.created_at.to_date, link_to(@ticket.requestor.name, @ticket.requestor.url)] %>
+ <%= _('Owner: %s') % link_to(@ticket.target.name, @ticket.target.url) %> +

+ +

<%= _('Status: %s') % gettext(Task::Status.names[@ticket.status]) %>

+ +
+

<%= _('Description: %s') % @ticket.description %>

+
+ +<% if @ticket.closing_statment %> +

<%= _('Closing statement: %s') % @ticket.closing_statment %>

+<% end %> + +<% button_bar do %> + <%= button :back, _('Back'), :action => 'index' %> +<% end %> diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 5bfc05d..dab7fce 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -121,4 +121,10 @@ class TasksControllerTest < Test::Unit::TestCase assert_equal profile, assigns(:ticket).requestor end + should 'list tasks that this profile created' do + task = Ticket.create!(:title => 'test', :requestor => profile) + get :list_requested, :profile => profile.identifier + + assert_includes assigns(:tasks), task + end end diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb index d0d88f5..d4812a4 100644 --- a/test/unit/ticket_test.rb +++ b/test/unit/ticket_test.rb @@ -8,4 +8,5 @@ class TicketTest < ActiveSupport::TestCase assert_equal({:test => 'test'}, t.data) end + end -- libgit2 0.21.2