mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 12:09:17 +08:00
Added task inputs and outputs functionality
This commit is contained in:
parent
2519a010f6
commit
426bd129cc
4 changed files with 44 additions and 6 deletions
|
@ -7,6 +7,7 @@ module Api
|
|||
before_action :load_project
|
||||
before_action :load_experiment
|
||||
before_action :load_task, only: :show
|
||||
before_action :load_task_relative, only: %i(outputs output inputs input)
|
||||
|
||||
def index
|
||||
tasks = @experiment.my_modules
|
||||
|
@ -20,6 +21,32 @@ module Api
|
|||
render jsonapi: @my_module, serializer: MyModuleSerializer
|
||||
end
|
||||
|
||||
def outputs
|
||||
outputs = @my_module.my_modules
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: outputs, each_serializer: MyModuleSerializer
|
||||
end
|
||||
|
||||
def output
|
||||
output = @my_module.my_modules.find(params.require(:id))
|
||||
render jsonapi: {}, status: :not_found if output.nil?
|
||||
render jsonapi: output, serializer: MyModuleSerializer
|
||||
end
|
||||
|
||||
def inputs
|
||||
inputs = @my_module.my_module_antecessors
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: inputs, each_serializer: MyModuleSerializer
|
||||
end
|
||||
|
||||
def input
|
||||
input = @my_module.my_module_antecessors.find(params.require(:id))
|
||||
render jsonapi: {}, status: :not_found if input.nil?
|
||||
render jsonapi: input, serializer: MyModuleSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_team
|
||||
|
@ -45,6 +72,15 @@ module Api
|
|||
@my_module = @experiment.my_modules.find(params.require(:id))
|
||||
render jsonapi: {}, status: :not_found if @my_module.nil?
|
||||
end
|
||||
|
||||
# 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
|
||||
@my_module = @experiment.my_modules.find(params.require(:task_id))
|
||||
render jsonapi: {}, status: :not_found if @my_module.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -575,12 +575,14 @@ Rails.application.routes.draw do
|
|||
resources :results, only: %i(index show),
|
||||
path: 'results',
|
||||
as: :results
|
||||
resources :my_module_antecessors, only: %i(index show),
|
||||
path: 'ancestors',
|
||||
as: :ancestors
|
||||
resources :my_modules, only: %i(index show),
|
||||
path: 'descendants',
|
||||
as: :descendants
|
||||
get 'inputs',
|
||||
to: 'my_modules#inputs'
|
||||
get 'inputs/:id',
|
||||
to: 'my_modules#input'
|
||||
get 'outputs',
|
||||
to: 'my_modules#outputs'
|
||||
get 'outputs/:id',
|
||||
to: 'my_modules#output'
|
||||
resources :activities, only: %i(index show),
|
||||
path: 'activities',
|
||||
as: :activities
|
||||
|
|
Loading…
Reference in a new issue