mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-29 03:01:58 +08:00
Return task inputs/outputs as references [SCI-2822]
This commit is contained in:
parent
20e2cbf0ca
commit
b3a377f949
3 changed files with 15 additions and 17 deletions
|
@ -9,7 +9,7 @@ module Api
|
|||
before_action only: :show do
|
||||
load_task(:id)
|
||||
end
|
||||
before_action :load_task_relative, only: %i(inputs outputs activities)
|
||||
before_action :load_task_relative, only: :activities
|
||||
|
||||
def index
|
||||
tasks = @experiment.my_modules
|
||||
|
@ -23,20 +23,6 @@ module Api
|
|||
render jsonapi: @task, serializer: TaskSerializer
|
||||
end
|
||||
|
||||
def inputs
|
||||
inputs = @task.my_module_antecessors
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: inputs, each_serializer: TaskSerializer
|
||||
end
|
||||
|
||||
def outputs
|
||||
outputs = @task.my_modules
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: outputs, each_serializer: TaskSerializer
|
||||
end
|
||||
|
||||
def activities
|
||||
activities = @task.activities
|
||||
.page(params.dig(:page, :number))
|
||||
|
|
|
@ -5,6 +5,20 @@ module Api
|
|||
class TaskSerializer < ActiveModel::Serializer
|
||||
type :tasks
|
||||
attributes :id, :name, :due_date, :description, :state, :archived
|
||||
has_many :output_tasks, key: :outputs,
|
||||
serializer: TaskSerializer,
|
||||
class_name: 'MyModule'
|
||||
has_many :input_tasks, key: :inputs,
|
||||
serializer: TaskSerializer,
|
||||
class_name: 'MyModule'
|
||||
|
||||
def output_tasks
|
||||
object.my_modules
|
||||
end
|
||||
|
||||
def input_tasks
|
||||
object.my_module_antecessors
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -607,8 +607,6 @@ Rails.application.routes.draw do
|
|||
as: :tags
|
||||
resources :protocols, only: %i(index show)
|
||||
resources :results, only: %i(index create show)
|
||||
get 'inputs', to: 'tasks#inputs'
|
||||
get 'outputs', to: 'tasks#outputs'
|
||||
get 'activities', to: 'tasks#activities'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue