import { createElement } from "../../lib/skeleton/index.js"; import { loadCSS } from "../../helpers/loader.js"; import AdminHOC from "./decorator.js"; import ctrlList from "./ctrl_workflow_list.js"; import ctrlDetails from "./ctrl_workflow_details.js"; const workflows = [ { id: "dummy", name: "My First Workflow", published: false, trigger: { name: "user" }, actions: [ { name: "tools/debug", }, { name: "notify/email", } ], }, { id: "uuid0", name: "Detection de fichier d'inbox", published: true, lastEdited: "2 days ago", trigger: { name: "watch" }, actions: [ { name: "run/program", }, { name: "notify/email", }, ], }, { id: "uuid1", name: "Notify team when file is moved", published: true, lastEdited: "2 days ago", history: [], trigger: { name: "operation" }, actions: [ { name: "notify/email", }, ] }, { id: "uuid2", name: "Any change to the contract folder", published: true, history: [], trigger: { name: "operation", values: {} }, actions: [ { name: "notify/email", // values: {} // TODO }, ] }, ]; const triggers = [ { name: "schedule", title: "On a Schedule", icon: ``, specs: { "start": { name: "test", type: "datetime", }, "frequency": { type: "select", options: ["hourly", "weekly", "monthly", "yearly"], }, }, }, { name: "user", title: "When a User Creates a Request", icon: ``, specs: { name: { type: "text" }, form: { type: "text", placeholder: "Optional form user should submit" }, visibility: { type: "text" }, }, }, { name: "operation", title: "When a File Action Happens", icon: ``, specs: { event: { type: "text", datalist: ["ls", "cat", "mkdir", "mv", "rm", "touch"], multi: true, }, path: { type: "text", }, }, }, { name: "watch", title: "When the Filesystem Changes", icon: ``, specs: { token: { type: "text", }, path: { type: "text", }, }, }, { name: "webhook", title: "From a webhook", icon: ``, specs: { url: { type: "text", readonly: true, value: "http://example.com/workflow/webhook?id=generatedID", } }, }, ]; const actions = [ { name: "run/program", title: "Execute Program", subtitle: "name", icon: ``, specs: { name: { type: "select", options: ["ocr", "duplicate", "expiry", "sign"], } }, }, { name: "run/api", title: "Make API Call", icon: ``, specs: { url: { type: "text", }, method: { options: ["POST", "PUT", "GET"], }, headers: { type: "long_text", }, body: { type: "long_text", }, }, }, { name: "notify/email", title: "Notify", subtitle: "email", icon: ``, specs: { email: { type: "text", }, message: { type: "long_text", } }, }, { name: "approval/email", title: "Approval", subtitle: "email", icon: ``, specs: { email: { type: "text", }, message: { type: "long_text", }, }, }, { name: "tools/debug", title: "Debug", icon: ``, specs: {}, }, { name: "tools/map", title: "Map", icon: ``, specs: { transform: { type: "long_text", } }, } // TODO: expand macros ]; const macros = [ { name: "files/mv", specs: [ { name: "from", type: "text" }, { name: "to", type: "text" }, ], run: [ { name: "run/api", values: [ { name: "url", value: "{{ .endpoint }}/api/files/mv?from={{ .from }}&to={{ .to }}" }, { name: "method", value: "POST" }, { name: "headers", value: "Authorization: Bearer {{ .authorization }}" }, ] }, ], }, // { // name: "metadata/add", // } ] export default AdminHOC(async function(render) { await loadCSS(import.meta.url, "./ctrl_workflow.css"); render(createElement("")); const specs = getSpecs(); if (specs) ctrlDetails(render, { workflow: specs, triggers, actions }); else { await new Promise((done) => setTimeout(() => done(), 100)); ctrlList(render, { workflows, triggers, actions }); } }); function getSpecs() { const GET = new URLSearchParams(location.search) try { return JSON.parse(atob(GET.get("specs"))); } catch (err ) { return null; } }