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_project
|
||||||
before_action :load_experiment
|
before_action :load_experiment
|
||||||
before_action :load_task, only: :show
|
before_action :load_task, only: :show
|
||||||
|
before_action :load_task_relative, only: %i(outputs output inputs input)
|
||||||
|
|
||||||
def index
|
def index
|
||||||
tasks = @experiment.my_modules
|
tasks = @experiment.my_modules
|
||||||
|
@ -20,6 +21,32 @@ module Api
|
||||||
render jsonapi: @my_module, serializer: MyModuleSerializer
|
render jsonapi: @my_module, serializer: MyModuleSerializer
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def load_team
|
def load_team
|
||||||
|
@ -45,6 +72,15 @@ module Api
|
||||||
@my_module = @experiment.my_modules.find(params.require(:id))
|
@my_module = @experiment.my_modules.find(params.require(:id))
|
||||||
render jsonapi: {}, status: :not_found if @my_module.nil?
|
render jsonapi: {}, status: :not_found if @my_module.nil?
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -575,12 +575,14 @@ Rails.application.routes.draw do
|
||||||
resources :results, only: %i(index show),
|
resources :results, only: %i(index show),
|
||||||
path: 'results',
|
path: 'results',
|
||||||
as: :results
|
as: :results
|
||||||
resources :my_module_antecessors, only: %i(index show),
|
get 'inputs',
|
||||||
path: 'ancestors',
|
to: 'my_modules#inputs'
|
||||||
as: :ancestors
|
get 'inputs/:id',
|
||||||
resources :my_modules, only: %i(index show),
|
to: 'my_modules#input'
|
||||||
path: 'descendants',
|
get 'outputs',
|
||||||
as: :descendants
|
to: 'my_modules#outputs'
|
||||||
|
get 'outputs/:id',
|
||||||
|
to: 'my_modules#output'
|
||||||
resources :activities, only: %i(index show),
|
resources :activities, only: %i(index show),
|
||||||
path: 'activities',
|
path: 'activities',
|
||||||
as: :activities
|
as: :activities
|
||||||
|
|
Loading…
Reference in a new issue