mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-27 01:05:21 +08:00
Add api endpoints for workflows
This commit is contained in:
parent
bd05214514
commit
68f31ce7ec
8 changed files with 93 additions and 2 deletions
|
@ -201,6 +201,10 @@ module Api
|
|||
@checklist_item = @checklist.checklist_items.find(params.require(key))
|
||||
raise PermissionError.new(Protocol, :read) unless can_read_protocol_in_module?(@step.protocol)
|
||||
end
|
||||
|
||||
def load_workflow(key = :workflow_id)
|
||||
@workflow = MyModuleStatusFlow.find(params.require(key))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ module Api
|
|||
def task_params
|
||||
raise TypeError unless params.require(:data).require(:type) == 'tasks'
|
||||
|
||||
params.require(:data).require(:attributes).permit(%i(name x y description state))
|
||||
params.require(:data).require(:attributes).permit(%i(name x y description state my_module_status_id))
|
||||
end
|
||||
|
||||
def load_task_for_managing
|
||||
|
|
16
app/controllers/api/v1/workflow_statuses_controller.rb
Normal file
16
app/controllers/api/v1/workflow_statuses_controller.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WorkflowStatusesController < BaseController
|
||||
before_action only: :index do
|
||||
load_workflow(:workflow_id)
|
||||
end
|
||||
|
||||
def index
|
||||
statuses = @workflow.my_module_statuses
|
||||
render jsonapi: statuses, each_serializer: WorkflowStatusSerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
app/controllers/api/v1/workflows_controller.rb
Normal file
20
app/controllers/api/v1/workflows_controller.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WorkflowsController < BaseController
|
||||
before_action only: :show do
|
||||
load_workflow(:id)
|
||||
end
|
||||
|
||||
def index
|
||||
workflows = MyModuleStatusFlow.all
|
||||
render jsonapi: workflows, each_serializer: WorkflowSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @workflow, serializer: WorkflowSerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,7 +8,8 @@ module Api
|
|||
include InputSanitizeHelper
|
||||
|
||||
type :tasks
|
||||
attributes :id, :name, :started_on, :due_date, :description, :state, :archived
|
||||
attributes :id, :name, :started_on, :due_date, :description, :state, :archived, :status_id, :status_name,
|
||||
:prev_status_id, :prev_status_name, :next_status_id, :next_status_name
|
||||
has_many :output_tasks, key: :outputs,
|
||||
serializer: TaskSerializer,
|
||||
class_name: 'MyModule'
|
||||
|
@ -16,6 +17,30 @@ module Api
|
|||
serializer: TaskSerializer,
|
||||
class_name: 'MyModule'
|
||||
|
||||
def status_id
|
||||
object.my_module_status_id
|
||||
end
|
||||
|
||||
def status_name
|
||||
object.my_module_status.name
|
||||
end
|
||||
|
||||
def prev_status_id
|
||||
object.my_module_status.previous_status&.id
|
||||
end
|
||||
|
||||
def prev_status_name
|
||||
object.my_module_status.previous_status&.name
|
||||
end
|
||||
|
||||
def next_status_id
|
||||
object.my_module_status.next_status&.id
|
||||
end
|
||||
|
||||
def next_status_name
|
||||
object.my_module_status.next_status&.name
|
||||
end
|
||||
|
||||
def output_tasks
|
||||
object.my_modules
|
||||
end
|
||||
|
|
11
app/serializers/api/v1/workflow_serializer.rb
Normal file
11
app/serializers/api/v1/workflow_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WorkflowSerializer < ActiveModel::Serializer
|
||||
type :workflows
|
||||
|
||||
attributes :id, :name, :description, :visibility, :team_id
|
||||
end
|
||||
end
|
||||
end
|
11
app/serializers/api/v1/workflow_status_serializer.rb
Normal file
11
app/serializers/api/v1/workflow_status_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WorkflowStatusSerializer < ActiveModel::Serializer
|
||||
type :workflow_statuses
|
||||
|
||||
attributes :id, :name, :description, :color, :previous_status_id
|
||||
end
|
||||
end
|
||||
end
|
|
@ -707,6 +707,10 @@ Rails.application.routes.draw do
|
|||
path: 'identities',
|
||||
as: :identities
|
||||
end
|
||||
|
||||
resources :workflows, only: %i(index show) do
|
||||
resources :workflow_statuses, path: :statuses, only: %i(index)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue