Class: ErpWorkEffort::ErpApp::Organizer::Tasks::WorkEffortsController

Inherits:
ErpApp::Organizer::BaseController
  • Object
show all
Defined in:
app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 68

def create
  result = {}

  begin
    ActiveRecord::Base.transaction do
      estimated_completion_time = params[:estimated_completion_time].to_i
      description = params[:description].strip
      work_effort_type_id = params[:work_effort_type]

      work_effort_type = WorkEffortType.find(work_effort_type_id)

      work_effort = WorkEffort.new
      work_effort.work_effort_type = work_effort_type
      work_effort.description = description
      work_effort.projected_completion_time = estimated_completion_time
      work_effort.save

      work_effort.current_status = 'pending'

      unless params[:assignment_type_role].blank?
        role_type = RoleType.find(params[:role_type])

        work_effort.role_types << role_type

      end

      unless params[:assignment_type_party].blank?
        party = Party.find(params[:assigned_party_id])

        work_effort_party_assignment = WorkEffortPartyAssignment.new
        work_effort_party_assignment.party = party
        work_effort_party_assignment.role_type = RoleType.iid('worker')

        work_effort.work_effort_party_assignments << work_effort_party_assignment
      end

      work_effort.save

      result = {:success => true, :message => "Task Added"}

    end
  rescue => ex
    Rails.logger.error ex.message
    Rails.logger.error ex.backtrace.join("\n")
    result = {:success => false, :message => "Error adding task"}
  end

  render :json => result
end

#destroyObject



118
119
120
121
122
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 118

def destroy
  work_effort = WorkEffort.find(params[:id])

  render :json => {:success => work_effort.destroy}
end

#indexObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 33

def index
  offset = params[:offset] || 0
  limit = params[:limit] || 25
  party = params[:party_id].blank? ? nil : Party.find(params[:party_id])
  all_tasks = params[:all_tasks].blank? ? false : true

  if all_tasks
    work_efforts_statement = WorkEffort
  elsif party
    work_efforts_statement = WorkEffort.work_efforts_for_party(party)
  else
    work_efforts_statement = WorkEffort.work_efforts_for_party(current_user.party)
  end

  total = work_efforts_statement.count
  work_efforts = work_efforts_statement.limit(limit).offset(offset)

  work_efforts.sort!

  data = work_efforts.sort.collect { |item| item.to_hash(
      :only => [
          :id,
          :description,
          :created_at,
          :current_status,
          ],
      :current_status_description => (TrackedStatusType.find_by_internal_identifier(item.current_status).description),
      :assigned_parties => item.assigned_parties,
      :assigned_roles => item.assigned_roles
    )
  }

  render :json => {:success => true, :total => total, :work_efforts => data}
end

#role_typesObject



7
8
9
10
11
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 7

def role_types
  data = RoleType.iid('task_master').self_and_descendants.collect{|item| item.to_hash(:only => [:id, :description])}

  render :json => {success: true, role_types: data}
end

#task_countObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 19

def task_count
  party = params[:party_id].blank? ? nil : Party.find(params[:party_id])

  if party
    work_efforts_statement = WorkEffort.work_efforts_for_party(party, 'pending')
  else
    work_efforts_statement = WorkEffort.work_efforts_for_party(current_user.party, 'pending')
  end

  count = work_efforts_statement.count

  render :json => {success: true, count: count}
end

#work_effort_typesObject



13
14
15
16
17
# File 'app/controllers/erp_work_effort/erp_app/organizer/tasks/work_efforts_controller.rb', line 13

def work_effort_types
  data = WorkEffortType.all.collect{|item| item.to_hash(:only => [:id, :description])}

  render :json => {success: true, work_effort_types: data}
end