Class: Flyboy::TasksController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#completeObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/flyboy/tasks_controller.rb', line 110

def complete
  authorize! :complete, @task

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

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

  redirect_to request.referer
end

#createObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/flyboy/tasks_controller.rb', line 74

def create
  @task ||= Task.new(task_params)

  authorize! :create, @task

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

#destroyObject



98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/flyboy/tasks_controller.rb', line 98

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 tasks_url
end

#editObject



70
71
72
# File 'app/controllers/flyboy/tasks_controller.rb', line 70

def edit
 authorize! :update, @task
end

#indexObject



8
9
10
11
12
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
# File 'app/controllers/flyboy/tasks_controller.rb', line 8

def index
  authorize! :list, Task

  @tasks ||= Task.all

  @order ||= sortable_column_order do |column, direction|
    case column
    when "title", "status"
      %(LOWER(flyboy_tasks.#{column}) #{direction})
    when "progress", "term"
      %(flyboy_tasks.#{column} #{direction})
    when "goal"
      @tasks = @tasks.joins(:goal)
      %(LOWER(flyboy_goals.title) #{direction})
    else
      params["sort"] = "term"
      "term ASC"
    end
  end

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

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

  respond_to do |format|
    format.html

    format.csv do
      send_data @tasks.to_csv,
        filename:    "feuille_de_route_#{Date.today}.csv",
        disposition: "attachment"
    end

    format.xls

    format.pdf do
      pdf = Roadmap.new(@tasks)
      pdf.build
      send_data pdf.render,
        filename:    "feuille_de_route_#{Date.today}.pdf",
        disposition: "inline"
    end
  end

end

#newObject



63
64
65
66
67
68
# File 'app/controllers/flyboy/tasks_controller.rb', line 63

def new
  @goal ||= Goal.find(params[:goal_id])
  @task ||= @goal.tasks.new

  authorize! :create, @task
end

#showObject



57
58
59
60
61
# File 'app/controllers/flyboy/tasks_controller.rb', line 57

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

  authorize! :read, @task
end

#snoozeObject



128
129
130
131
132
133
134
135
136
137
138
# File 'app/controllers/flyboy/tasks_controller.rb', line 128

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 tasks_url
end

#updateObject



87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/flyboy/tasks_controller.rb', line 87

def update
  authorize! :update, @task

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