2018-09-05 18:54:08 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
2018-10-07 15:45:24 +08:00
|
|
|
class TasksController < BaseController
|
2018-09-05 18:54:08 +08:00
|
|
|
before_action :load_team
|
|
|
|
before_action :load_project
|
|
|
|
before_action :load_experiment
|
2018-11-07 22:43:44 +08:00
|
|
|
before_action only: :show do
|
|
|
|
load_task(:id)
|
|
|
|
end
|
2018-11-28 18:33:00 +08:00
|
|
|
before_action :load_task_relative, only: :activities
|
2018-09-05 18:54:08 +08:00
|
|
|
|
|
|
|
def index
|
2018-09-06 21:38:48 +08:00
|
|
|
tasks = @experiment.my_modules
|
2018-09-07 17:58:02 +08:00
|
|
|
.page(params.dig(:page, :number))
|
|
|
|
.per(params.dig(:page, :size))
|
2018-09-05 18:54:08 +08:00
|
|
|
|
2018-10-07 01:53:31 +08:00
|
|
|
render jsonapi: tasks, each_serializer: TaskSerializer
|
2018-09-05 18:54:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2018-10-07 16:07:37 +08:00
|
|
|
render jsonapi: @task, serializer: TaskSerializer
|
2018-09-05 18:54:08 +08:00
|
|
|
end
|
|
|
|
|
2018-10-07 17:49:11 +08:00
|
|
|
def activities
|
2019-04-08 21:07:45 +08:00
|
|
|
activities = ActivitiesService.my_module_activities(@task)
|
|
|
|
.page(params.dig(:page, :number))
|
|
|
|
.per(params.dig(:page, :size))
|
2018-10-07 17:49:11 +08:00
|
|
|
|
|
|
|
render jsonapi: activities,
|
|
|
|
each_serializer: ActivitySerializer
|
|
|
|
end
|
|
|
|
|
2018-09-05 18:54:08 +08:00
|
|
|
private
|
|
|
|
|
2018-09-10 20:22:27 +08:00
|
|
|
# Made the method below because its more elegant than changing parameters
|
|
|
|
# in routes file, and here. It exists because when we call input or output
|
|
|
|
# for a task, the "id" that used to be task id is now an id for the output
|
|
|
|
# or input.
|
|
|
|
def load_task_relative
|
2018-10-07 16:07:37 +08:00
|
|
|
@task = @experiment.my_modules.find(params.require(:task_id))
|
2018-09-10 20:22:27 +08:00
|
|
|
end
|
2018-09-05 18:54:08 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|