stash
This commit is contained in:
parent
6fcdd1eefa
commit
c0f70004eb
21 changed files with 1855 additions and 260 deletions
|
|
@ -24,23 +24,20 @@ import StorageOptimizationWorkflow from '@/components/workflow/workflows/Storage
|
|||
import MaintenanceScheduleWorkflow from '@/components/workflow/workflows/MaintenanceScheduleWorkflow.vue';
|
||||
import ExpiryCheckWorkflow from '@/components/workflow/workflows/ExpiryCheckWorkflow.vue';
|
||||
import BackupRestoreWorkflow from '@/components/workflow/workflows/BackupRestoreWorkflow.vue';
|
||||
|
||||
/**
|
||||
* Workflows with a fully co-located component + metadata.
|
||||
*/
|
||||
const implementedWorkflows = [
|
||||
{ ...FotoFirstBulkImportWorkflow.meta, component: FotoFirstBulkImportWorkflow },
|
||||
{ ...BulkItemImportWorkflow.meta, component: BulkItemImportWorkflow },
|
||||
{ ...InventoryAuditWorkflow.meta, component: InventoryAuditWorkflow },
|
||||
{ ...StorageOptimizationWorkflow.meta, component: StorageOptimizationWorkflow },
|
||||
{ ...MaintenanceScheduleWorkflow.meta, component: MaintenanceScheduleWorkflow },
|
||||
{ ...ExpiryCheckWorkflow.meta, component: ExpiryCheckWorkflow },
|
||||
{ ...BackupRestoreWorkflow.meta, component: BackupRestoreWorkflow },
|
||||
const workflows = [
|
||||
{...FotoFirstBulkImportWorkflow.meta, component: FotoFirstBulkImportWorkflow},
|
||||
{...BulkItemImportWorkflow.meta, component: BulkItemImportWorkflow},
|
||||
{...InventoryAuditWorkflow.meta, component: InventoryAuditWorkflow},
|
||||
{...StorageOptimizationWorkflow.meta, component: StorageOptimizationWorkflow},
|
||||
{...MaintenanceScheduleWorkflow.meta, component: MaintenanceScheduleWorkflow},
|
||||
{...ExpiryCheckWorkflow.meta, component: ExpiryCheckWorkflow},
|
||||
{...BackupRestoreWorkflow.meta, component: BackupRestoreWorkflow},
|
||||
];
|
||||
/**
|
||||
* The full workflow catalog: every workflow type known to the frontend,
|
||||
* whether it has a custom UI or not.
|
||||
*/
|
||||
const workflows = implementedWorkflows;
|
||||
|
||||
/**
|
||||
* Get every workflow in the catalog.
|
||||
* @returns {Array<Object>}
|
||||
|
|
@ -48,14 +45,16 @@ const workflows = implementedWorkflows;
|
|||
export function getAllWorkflows() {
|
||||
return workflows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single workflow definition by id.
|
||||
* @param {string} id
|
||||
* @returns {Object|undefined}
|
||||
*/
|
||||
export function getWorkflow(id) {
|
||||
return workflows.find(workflow => workflow.id === id);
|
||||
export function getWorkflow(slug) {
|
||||
return workflows.find(workflow => workflow.slug === slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Vue component implementing a workflow's UI, if any.
|
||||
* @param {string} id
|
||||
|
|
@ -64,6 +63,7 @@ export function getWorkflow(id) {
|
|||
export function getWorkflowComponent(id) {
|
||||
return getWorkflow(id)?.component || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all workflows belonging to a category.
|
||||
* @param {string} category
|
||||
|
|
@ -72,6 +72,7 @@ export function getWorkflowComponent(id) {
|
|||
export function getWorkflowsByCategory(category) {
|
||||
return workflows.filter(workflow => workflow.category === category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unique categories present in the catalog.
|
||||
* @returns {Array<string>}
|
||||
|
|
@ -79,6 +80,7 @@ export function getWorkflowsByCategory(category) {
|
|||
export function getWorkflowCategories() {
|
||||
return [...new Set(workflows.map(workflow => workflow.category))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the payload sent to the backend to start a new instance of a
|
||||
* workflow, merging the common `workflow_config` metadata block with the
|
||||
|
|
@ -89,31 +91,28 @@ export function getWorkflowCategories() {
|
|||
export function buildWorkflowApiPayload(workflow) {
|
||||
const ownPayload = workflow.getInitialPayload ? workflow.getInitialPayload() : {};
|
||||
return {
|
||||
name: workflow.name,
|
||||
workflow_type: workflow.id,
|
||||
title: workflow.title,
|
||||
slug: workflow.slug,
|
||||
state: 'running',
|
||||
current_step: 1,
|
||||
total_steps: workflow.stepDefinitions.length,
|
||||
payload: {
|
||||
workflow_config: {
|
||||
name: workflow.name,
|
||||
description: workflow.description,
|
||||
category: workflow.category,
|
||||
estimated_duration: workflow.estimatedDuration
|
||||
},
|
||||
...ownPayload
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The backend stores WorkflowInstance.payload as an opaque string - it never
|
||||
* parses or understands it as JSON. The frontend is fully responsible for
|
||||
* serializing it before sending and deserializing it after receiving.
|
||||
*/
|
||||
export function serializeWorkflowPayload(workflow) {
|
||||
console.log(workflow);
|
||||
if (!workflow || !('payload' in workflow)) return workflow;
|
||||
return {...workflow, payload: JSON.stringify(workflow.payload ?? {})};
|
||||
}
|
||||
|
||||
export function deserializeWorkflowPayload(workflow) {
|
||||
if (!workflow) return workflow;
|
||||
let payload = {};
|
||||
|
|
@ -124,6 +123,7 @@ export function deserializeWorkflowPayload(workflow) {
|
|||
}
|
||||
return {...workflow, payload};
|
||||
}
|
||||
|
||||
export default {
|
||||
getAllWorkflows,
|
||||
getWorkflow,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue