Class: Dorsale::Flyboy::TasksController

Inherits:
ApplicationController show all
Includes:
TasksSummaryConcern
Defined in:
app/controllers/dorsale/flyboy/tasks_controller.rb

Instance Method Summary collapse

Methods included from TasksSummaryConcern

#setup_tasks_summary

Methods inherited from ApplicationController

#current_user_scope

Instance Method Details

#completeObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 134

def complete
  authorize! :complete, @task

  @task_comment ||= @task.comments.new(
    :progress    => 100,
    :description => t("messages.tasks.complete_ok"),
    :date        => Time.zone.now,
    :author      => current_user
  )

  if @task_comment.save
    flash[:success] = t("messages.tasks.complete_ok")
  else
    flash[:danger] = t("messages.tasks.complete_error")
  end

  redirect_to back_url
end

#createObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 88

def create
  @task ||= current_user_scope.new_task(task_params)

  authorize! :create, @task

  if @task.save
    flash[:success] = t("messages.tasks.create_ok")
    notify_owner(current_user, @task)
    redirect_to back_url
  else
    set_owners
    render :new
  end
end

#destroyObject



122
123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 122

def destroy
  authorize! :delete, @task

  if @task.destroy
    flash[:success] = t("messages.tasks.delete_ok")
  else
    flash[:danger] = t("messages.tasks.delete_error")
  end

  redirect_to url_for(action: :index, id: nil)
end

#editObject



103
104
105
106
107
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 103

def edit
  authorize! :update, @task

  set_owners
end

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
67
68
69
70
71
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 13

def index
  authorize! :list, model

  @tasks ||= current_user_scope.tasks

  @order ||= sortable_column_order do |column, direction|
    case column
    when "name", "status"
      %(LOWER(dorsale_flyboy_tasks.#{column}) #{direction})
    when "progress", "term"
      %(dorsale_flyboy_tasks.#{column} #{direction})
    when "taskable"
      if direction == :asc
        proc { |a, b| a.taskable.name.downcase <=> b.taskable.name.downcase }
      else
        proc { |a, b| b.taskable.name.downcase <=> a.taskable.name.downcase }
      end
    else
      params["sort"] = "term"
      "term ASC"
    end
  end

  @filters ||= ::Dorsale::Flyboy::SmallData::FilterForTasks.new(cookies)

  @tasks = @filters.apply(@tasks)
  @tasks = @tasks.search(params[:q])

  if @order.is_a?(Proc) # when sorting by a polymorphic attribute
    @tasks = @tasks.sort(&@order)
    @tasks_without_pagination = @tasks
    @tasks = Kaminari.paginate_array(@tasks).page(params[:page])
  else
    @tasks = @tasks.order(@order)
    @tasks_without_pagination = @tasks
    @tasks = @tasks.page(params[:page])
  end

  respond_to do |format|
    format.html

    format.csv do
      send_data @tasks_without_pagination.to_csv,
        filename:    "feuille_de_route_#{Time.zone.now.to_date}.csv",
        disposition: "attachment"
    end

    format.xls

    format.pdf do
      pdf = Roadmap.new(@tasks_without_pagination)
      pdf.build
      send_data pdf.render,
        filename:    "feuille_de_route_#{Time.zone.now.to_date}.pdf",
        disposition: "inline"
    end
  end

end

#newObject



79
80
81
82
83
84
85
86
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 79

def new
  @task = current_user_scope.new_task
  @task.taskable_guid = params[:taskable_guid]

  set_owners

  authorize! :create, @task
end

#showObject



73
74
75
76
77
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 73

def show
  @task = model.find(params[:id])

  authorize! :read, @task
end

#snoozeObject



153
154
155
156
157
158
159
160
161
162
163
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 153

def snooze
  @task.snooze

  if @task.save
    flash[:success] = t("messages.tasks.snooze_ok")
  else
    flash[:danger] = t("messages.tasks.snooze_error")
  end

  redirect_to back_url
end

#summaryObject



165
166
167
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 165

def summary
  setup_tasks_summary
end

#updateObject



109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/dorsale/flyboy/tasks_controller.rb', line 109

def update
  authorize! :update, @task


  if @task.update_attributes(task_params)
    flash[:success] = t("messages.tasks.update_ok")
    redirect_to back_url
  else
    set_owners
    render :edit
  end
end