@nocobase/plugin-workflow-action-trigger 0.20.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/ActionTrigger.d.ts +54 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +1 -0
- package/dist/externalVersion.js +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +9 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +39 -0
- package/dist/locale/ko_KR.json +9 -0
- package/dist/locale/zh-CN.json +10 -0
- package/dist/server/ActionTrigger.d.ts +9 -0
- package/dist/server/ActionTrigger.js +130 -0
- package/dist/server/Plugin.d.ts +4 -0
- package/dist/server/Plugin.js +41 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/migrations/20240227172623-change-name.d.ts +6 -0
- package/dist/server/migrations/20240227172623-change-name.js +42 -0
- package/package.json +28 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/ActionTrigger.tsx +132 -0
- package/src/client/__e2e__/configuration.test.ts +661 -0
- package/src/client/__e2e__/workflowCRUD.test.ts +178 -0
- package/src/client/index.ts +100 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +9 -0
- package/src/locale/index.ts +12 -0
- package/src/locale/ko_KR.json +9 -0
- package/src/locale/zh-CN.json +10 -0
- package/src/server/ActionTrigger.ts +132 -0
- package/src/server/Plugin.ts +11 -0
- package/src/server/__tests__/trigger.test.ts +503 -0
- package/src/server/index.ts +1 -0
- package/src/server/migrations/20240227172623-change-name.ts +22 -0
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SchemaInitializerItemType, useCollectionDataSource } from '@nocobase/client';
|
|
2
|
+
import { Trigger } from '@nocobase/plugin-workflow/client';
|
|
3
|
+
export default class extends Trigger {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
fieldset: {
|
|
7
|
+
collection: {
|
|
8
|
+
type: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
'x-decorator': string;
|
|
11
|
+
'x-component': string;
|
|
12
|
+
'x-component-props': {
|
|
13
|
+
className: string;
|
|
14
|
+
};
|
|
15
|
+
title: string;
|
|
16
|
+
description: string;
|
|
17
|
+
'x-reactions': {
|
|
18
|
+
target: string;
|
|
19
|
+
effects: string[];
|
|
20
|
+
fulfill: {
|
|
21
|
+
state: {
|
|
22
|
+
value: any[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
appends: {
|
|
28
|
+
type: string;
|
|
29
|
+
title: string;
|
|
30
|
+
description: string;
|
|
31
|
+
'x-decorator': string;
|
|
32
|
+
'x-component': string;
|
|
33
|
+
'x-component-props': {
|
|
34
|
+
title: string;
|
|
35
|
+
multiple: boolean;
|
|
36
|
+
useCollection(): any;
|
|
37
|
+
};
|
|
38
|
+
'x-reactions': {
|
|
39
|
+
dependencies: string[];
|
|
40
|
+
fulfill: {
|
|
41
|
+
state: {
|
|
42
|
+
visible: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
scope: {
|
|
49
|
+
useCollectionDataSource: typeof useCollectionDataSource;
|
|
50
|
+
};
|
|
51
|
+
isActionTriggerable: (config: any, context: any) => boolean;
|
|
52
|
+
useVariables(config: any, options: any): import("@nocobase/plugin-workflow/client").VariableOption[];
|
|
53
|
+
useInitializers(config: any): SchemaInitializerItemType | null;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@nocobase/plugin-workflow/client"),require("@formily/react"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/plugin-workflow/client","@formily/react","react-i18next"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@nocobase/plugin-workflow-action-trigger"]={},t["@nocobase/client"],t["@nocobase/plugin-workflow"],t["@formily/react"],t["react-i18next"]))})(this,function(t,e,i,w,m){"use strict";var M=Object.defineProperty,D=Object.defineProperties;var R=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var A=(t,e,i)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,g=(t,e)=>{for(var i in e||(e={}))q.call(e,i)&&A(t,i,e[i]);if(y)for(var i of y(e))L.call(e,i)&&A(t,i,e[i]);return t},f=(t,e)=>D(t,R(e));var a=(t,e,i)=>(A(t,typeof e!="symbol"?e+"":e,i),i);var S=(t,e,i)=>new Promise((w,m)=>{var s=r=>{try{l(i.next(r))}catch(n){m(n)}},c=r=>{try{l(i.throw(r))}catch(n){m(n)}},l=r=>r.done?w(r.value):Promise.resolve(r.value).then(s,c);l((i=i.apply(t,e)).next())});const s="workflow-action-trigger";function c(u,k={}){const{t:o}=l(k);return o(u)}function l(u){return m.useTranslation(s,u)}class r extends i.Trigger{constructor(){super(...arguments);a(this,"title",`{{t("Action event", { ns: "${s}" })}}`);a(this,"description",`{{t("Triggers after specific operations on data are submitted, such as create, update, delete, etc., or directly submitting a record to the workflow.", { ns: "${s}" })}}`);a(this,"fieldset",{collection:{type:"string",required:!0,"x-decorator":"FormItem","x-component":"CollectionSelect","x-component-props":{className:"auto-width"},title:`{{t("Collection", { ns: "${s}" })}}`,description:`{{t("Which collection record belongs to.", { ns: "${s}" })}}`,"x-reactions":[{target:"appends",effects:["onFieldValueChange"],fulfill:{state:{value:[]}}}]},appends:{type:"array",title:`{{t("Associations to use", { ns: "${s}" })}}`,description:'{{t("Please select the associated fields that need to be accessed in subsequent nodes. With more than two levels of to-many associations may cause performance issue, please use with caution.", { ns: "workflow" })}}',"x-decorator":"FormItem","x-component":"AppendsTreeSelect","x-component-props":{title:"Preload associations",multiple:!0,useCollection(){const{values:o}=w.useForm();return o==null?void 0:o.collection}},"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}});a(this,"scope",{useCollectionDataSource:e.useCollectionDataSource});a(this,"isActionTriggerable",(o,p)=>["create","update","customize:update","customize:triggerWorkflows"].includes(p.action))}useVariables(o,p){var W;const I=e.useCompile(),{getCollectionFields:h}=e.useCollectionManager_deprecated(),b=c("Trigger data"),T=c("User submitted action"),x=c("Role of user submitted action"),C=[{collectionName:o.collection,name:"data",type:"hasOne",target:o.collection,uiSchema:{title:b}},{collectionName:"users",name:"user",type:"hasOne",target:"users",uiSchema:{title:T}},{name:"roleName",uiSchema:{title:x}}];return i.getCollectionFieldOptions(f(g({appends:["data","user",...((W=o.appends)==null?void 0:W.map(P=>`data.${P}`))||[]]},p),{fields:C,compile:I,getCollectionFields:h}))}useInitializers(o){return o.collection?{name:"triggerData",type:"item",key:"triggerData",title:`{{t("Trigger data", { ns: "${s}" })}}`,Component:i.CollectionBlockInitializer,collection:o.collection,dataSource:"{{$context.data}}"}:null}}const n={name:"submitToWorkflow",title:'{{t("Submit to workflow", { ns: "workflow" })}}',Component:"CustomizeActionInitializer",schema:{title:'{{t("Submit to workflow", { ns: "workflow" })}}',"x-component":"Action","x-component-props":{useProps:"{{ useTriggerWorkflowsActionProps }}"},"x-designer":"Action.Designer","x-action-settings":{skipValidator:!1,onSuccess:{manualClose:!0,redirecting:!1,successMessage:'{{t("Submitted successfully")}}'},triggerWorkflows:[]},"x-action":"customize:triggerWorkflows"}},d={name:"submitToWorkflow",title:'{{t("Submit to workflow", { ns: "workflow" })}}',Component:"CustomizeActionInitializer",schema:{title:'{{t("Submit to workflow", { ns: "workflow" })}}',"x-component":"Action","x-component-props":{useProps:"{{ useRecordTriggerWorkflowsActionProps }}"},"x-designer":"Action.Designer","x-action-settings":{onSuccess:{manualClose:!0,redirecting:!1,successMessage:'{{t("Submitted successfully")}}'},triggerWorkflows:[]},"x-action":"customize:triggerWorkflows"}},z=f(g({},d),{schema:f(g({},d.schema),{"x-component":"Action.Link"})});class F extends e.Plugin{load(){return S(this,null,function*(){this.app.pm.get("workflow").registerTrigger("action",r),this.app.addScopes({useTriggerWorkflowsActionProps:i.useTriggerWorkflowsActionProps,useRecordTriggerWorkflowsActionProps:i.useRecordTriggerWorkflowsActionProps}),this.app.schemaInitializerManager.get("FormActionInitializers").add("customize.submitToWorkflow",n),this.app.schemaInitializerManager.get("CreateFormActionInitializers").add("customize.submitToWorkflow",n),this.app.schemaInitializerManager.get("UpdateFormActionInitializers").add("customize.submitToWorkflow",n),this.app.schemaInitializerManager.get("DetailsActionInitializers").add("customize.submitToWorkflow",d),this.app.schemaInitializerManager.get("ReadPrettyFormActionInitializers").add("customize.submitToWorkflow",d),this.app.schemaInitializerManager.get("TableActionColumnInitializers").add("customize.submitToWorkflow",z),this.app.schemaInitializerManager.get("GridCardItemActionInitializers").add("customize.submitToWorkflow",z),this.app.schemaInitializerManager.get("ListItemActionInitializers").add("customize.submitToWorkflow",z)})}}t.default=F,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"@formily/react": "2.3.0",
|
|
3
|
+
"@nocobase/client": "0.20.0-alpha.6",
|
|
4
|
+
"@nocobase/plugin-workflow": "0.20.0-alpha.6",
|
|
5
|
+
"react-i18next": "11.18.6",
|
|
6
|
+
"lodash": "4.17.21",
|
|
7
|
+
"sequelize": "6.35.2",
|
|
8
|
+
"@nocobase/database": "0.20.0-alpha.6",
|
|
9
|
+
"@nocobase/server": "0.20.0-alpha.6",
|
|
10
|
+
"@nocobase/plugin-workflow-test": "0.20.0-alpha.6",
|
|
11
|
+
"@nocobase/test": "0.20.0-alpha.6",
|
|
12
|
+
"@nocobase/utils": "0.20.0-alpha.6"
|
|
13
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Form event": "Form event",
|
|
3
|
+
"Event triggers when submitted a workflow bound form action.": "Event triggers when submitted a workflow bound form action.",
|
|
4
|
+
"Form data model": "Form data model",
|
|
5
|
+
"Use a collection to match form data.": "Use a collection to match form data.",
|
|
6
|
+
"Associations to use": "Associations to use",
|
|
7
|
+
"User submitted form": "User submitted form",
|
|
8
|
+
"Role of user submitted form": "Role of user submitted form"
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const NAMESPACE = "workflow-action-trigger";
|
|
2
|
+
export declare function useLang(key: string, options?: {}): string;
|
|
3
|
+
export declare function usePluginTranslation(options: any): import("react-i18next").UseTranslationResponse<"workflow-action-trigger", undefined>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var locale_exports = {};
|
|
19
|
+
__export(locale_exports, {
|
|
20
|
+
NAMESPACE: () => NAMESPACE,
|
|
21
|
+
useLang: () => useLang,
|
|
22
|
+
usePluginTranslation: () => usePluginTranslation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(locale_exports);
|
|
25
|
+
var import_react_i18next = require("react-i18next");
|
|
26
|
+
const NAMESPACE = "workflow-action-trigger";
|
|
27
|
+
function useLang(key, options = {}) {
|
|
28
|
+
const { t } = usePluginTranslation(options);
|
|
29
|
+
return t(key);
|
|
30
|
+
}
|
|
31
|
+
function usePluginTranslation(options) {
|
|
32
|
+
return (0, import_react_i18next.useTranslation)(NAMESPACE, options);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
NAMESPACE,
|
|
37
|
+
useLang,
|
|
38
|
+
usePluginTranslation
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Form event": "폼 이벤트",
|
|
3
|
+
"Event triggers when submitted a workflow bound form action.": "작업 흐름에 바인딩된 폼 작업이 제출될 때 이벤트가 트리거됩니다.",
|
|
4
|
+
"Form data model": "폼 데이터 모델",
|
|
5
|
+
"Use a collection to match form data.": "폼 데이터를 일치시키기 위해 데이터 테이블을 사용합니다.",
|
|
6
|
+
"Associations to use": "사용할 관련 데이터",
|
|
7
|
+
"User submitted form": "사용자가 제출한 폼",
|
|
8
|
+
"Role of user submitted form": "사용자 제출 폼의 역할"
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Action event": "操作事件",
|
|
3
|
+
"Triggers after specific operations on data are submitted, such as create, update, delete, etc., or directly submitting a record to the workflow.": "在对数据的特定操作提交后触发,如创建、更新、删除等,或直接提交一条数据至工作流。",
|
|
4
|
+
"Collection": "数据表",
|
|
5
|
+
"Which collection record belongs to.": "数据所属的数据表。",
|
|
6
|
+
"Associations to use": "待使用的关系数据",
|
|
7
|
+
"Trigger data": "触发器数据",
|
|
8
|
+
"User submitted action": "提交操作的用户",
|
|
9
|
+
"Role of user submitted action": "提交操作用户的角色"
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import WorkflowPlugin, { Trigger, WorkflowModel } from '@nocobase/plugin-workflow';
|
|
2
|
+
export default class extends Trigger {
|
|
3
|
+
constructor(workflow: WorkflowPlugin);
|
|
4
|
+
triggerAction(context: any, next: any): Promise<any>;
|
|
5
|
+
middleware: (context: any, next: any) => Promise<any>;
|
|
6
|
+
private trigger;
|
|
7
|
+
on(workflow: WorkflowModel): void;
|
|
8
|
+
off(workflow: WorkflowModel): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var ActionTrigger_exports = {};
|
|
19
|
+
__export(ActionTrigger_exports, {
|
|
20
|
+
default: () => ActionTrigger_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(ActionTrigger_exports);
|
|
23
|
+
var import_lodash = require("lodash");
|
|
24
|
+
var import_database = require("@nocobase/database");
|
|
25
|
+
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
26
|
+
class ActionTrigger_default extends import_plugin_workflow.Trigger {
|
|
27
|
+
constructor(workflow) {
|
|
28
|
+
super(workflow);
|
|
29
|
+
workflow.app.resourcer.use(this.middleware);
|
|
30
|
+
}
|
|
31
|
+
async triggerAction(context, next) {
|
|
32
|
+
const { triggerWorkflows } = context.action.params;
|
|
33
|
+
if (!triggerWorkflows) {
|
|
34
|
+
return context.throw(400);
|
|
35
|
+
}
|
|
36
|
+
context.status = 202;
|
|
37
|
+
await next();
|
|
38
|
+
this.trigger(context);
|
|
39
|
+
}
|
|
40
|
+
middleware = async (context, next) => {
|
|
41
|
+
const {
|
|
42
|
+
resourceName,
|
|
43
|
+
actionName,
|
|
44
|
+
params: { triggerWorkflows }
|
|
45
|
+
} = context.action;
|
|
46
|
+
if (resourceName === "workflows" && actionName === "trigger") {
|
|
47
|
+
return this.triggerAction(context, next);
|
|
48
|
+
}
|
|
49
|
+
await next();
|
|
50
|
+
if (!triggerWorkflows) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!["create", "update"].includes(actionName)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return this.trigger(context);
|
|
57
|
+
};
|
|
58
|
+
async trigger(context) {
|
|
59
|
+
const { triggerWorkflows = "", values } = context.action.params;
|
|
60
|
+
const { currentUser, currentRole } = context.state;
|
|
61
|
+
const userInfo = {
|
|
62
|
+
user: (0, import_plugin_workflow.toJSON)(currentUser),
|
|
63
|
+
roleName: currentRole
|
|
64
|
+
};
|
|
65
|
+
const triggers = triggerWorkflows.split(",").map((trigger) => trigger.split("!"));
|
|
66
|
+
const workflowRepo = this.workflow.db.getRepository("workflows");
|
|
67
|
+
const workflows = await workflowRepo.find({
|
|
68
|
+
filter: {
|
|
69
|
+
key: triggers.map((trigger) => trigger[0]),
|
|
70
|
+
current: true,
|
|
71
|
+
type: "action",
|
|
72
|
+
enabled: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const syncGroup = [];
|
|
76
|
+
const asyncGroup = [];
|
|
77
|
+
for (const workflow of workflows) {
|
|
78
|
+
const trigger = triggers.find((trigger2) => trigger2[0] == workflow.key);
|
|
79
|
+
const event = [workflow];
|
|
80
|
+
if (context.action.resourceName !== "workflows") {
|
|
81
|
+
if (!context.body) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const { body: data } = context;
|
|
85
|
+
for (const row of Array.isArray(data) ? data : [data]) {
|
|
86
|
+
let payload = row;
|
|
87
|
+
if (trigger[1]) {
|
|
88
|
+
const paths = trigger[1].split(".");
|
|
89
|
+
for (const field of paths) {
|
|
90
|
+
if (payload.get(field)) {
|
|
91
|
+
payload = payload.get(field);
|
|
92
|
+
} else {
|
|
93
|
+
const association = (0, import_database.modelAssociationByKey)(payload, field);
|
|
94
|
+
payload = await payload[association.accessors.get]();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const { collection, appends = [] } = workflow.config;
|
|
99
|
+
const model = payload.constructor;
|
|
100
|
+
if (payload instanceof import_database.Model) {
|
|
101
|
+
if (collection !== model.collection.name) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (appends.length) {
|
|
105
|
+
payload = await model.collection.repository.findOne({
|
|
106
|
+
filterByTk: payload.get(model.primaryKeyAttribute),
|
|
107
|
+
appends
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
event.push({ data: (0, import_plugin_workflow.toJSON)(payload), ...userInfo });
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
const data = trigger[1] ? (0, import_lodash.get)(values, trigger[1]) : values;
|
|
115
|
+
event.push({ data, ...userInfo });
|
|
116
|
+
}
|
|
117
|
+
(workflow.sync ? syncGroup : asyncGroup).push(event);
|
|
118
|
+
}
|
|
119
|
+
for (const event of syncGroup) {
|
|
120
|
+
await this.workflow.trigger(event[0], event[1], { httpContext: context });
|
|
121
|
+
}
|
|
122
|
+
for (const event of asyncGroup) {
|
|
123
|
+
this.workflow.trigger(event[0], event[1]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
on(workflow) {
|
|
127
|
+
}
|
|
128
|
+
off(workflow) {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Plugin_exports = {};
|
|
29
|
+
__export(Plugin_exports, {
|
|
30
|
+
default: () => Plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
|
|
35
|
+
var import_ActionTrigger = __toESM(require("./ActionTrigger"));
|
|
36
|
+
class Plugin_default extends import_server.Plugin {
|
|
37
|
+
async load() {
|
|
38
|
+
const workflowPlugin = this.app.pm.get(import_plugin_workflow.default);
|
|
39
|
+
workflowPlugin.triggers.register("action", new import_ActionTrigger.default(workflowPlugin));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_Plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_Plugin = __toESM(require("./Plugin"));
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var change_name_exports = {};
|
|
19
|
+
__export(change_name_exports, {
|
|
20
|
+
default: () => change_name_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(change_name_exports);
|
|
23
|
+
var import_server = require("@nocobase/server");
|
|
24
|
+
class change_name_default extends import_server.Migration {
|
|
25
|
+
appVersion = "<0.20.0-alpha.6";
|
|
26
|
+
on = "afterSync";
|
|
27
|
+
async up() {
|
|
28
|
+
const { db } = this.context;
|
|
29
|
+
const WorkflowRepo = db.getRepository("workflows");
|
|
30
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
31
|
+
await WorkflowRepo.update({
|
|
32
|
+
filter: {
|
|
33
|
+
type: "form"
|
|
34
|
+
},
|
|
35
|
+
values: {
|
|
36
|
+
type: "action"
|
|
37
|
+
},
|
|
38
|
+
transaction
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-workflow-action-trigger",
|
|
3
|
+
"displayName": "Workflow: Action trigger",
|
|
4
|
+
"displayName.zh-CN": "工作流:数据操作触发器",
|
|
5
|
+
"description": "Bind action buttons to trigger workflow events when clicked.",
|
|
6
|
+
"description.zh-CN": "可对数据操作按钮绑定,在点击后触发对应的工作流事件。",
|
|
7
|
+
"version": "0.20.0-alpha.6",
|
|
8
|
+
"license": "AGPL-3.0",
|
|
9
|
+
"main": "./dist/server/index.js",
|
|
10
|
+
"homepage": "https://docs.nocobase.com/plugins/workflow-action-trigger",
|
|
11
|
+
"homepage.zh-CN": "https://docs-cn.nocobase.com/plugins/workflow-action-trigger",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"antd": "5.x",
|
|
14
|
+
"react": "18.x",
|
|
15
|
+
"react-i18next": "^11.15.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@nocobase/client": "0.x",
|
|
19
|
+
"@nocobase/database": "0.x",
|
|
20
|
+
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
21
|
+
"@nocobase/server": "0.x",
|
|
22
|
+
"@nocobase/test": "0.x"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "281767b02ce11f9172fb72e5e53ff98bc80b6eaf",
|
|
25
|
+
"keywords": [
|
|
26
|
+
"Workflow"
|
|
27
|
+
]
|
|
28
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|