From b3ca62b548f54f2797b8f901a0690227d6fb518e Mon Sep 17 00:00:00 2001 From: Afiq Date: Thu, 15 May 2025 11:53:59 +0800 Subject: [PATCH] Enhance Process Builder Drag-and-Drop Functionality - Improved drag-and-drop support in the Process Builder by setting drag data to 'text/plain' for better compatibility, especially on Mac. - Added visual feedback during drag operations by applying a 'dragging' class to the event target. - Updated the drop event handler to parse the dragged data correctly and prevent event propagation. - Introduced a computed property for gateway available variables to enhance node configuration options. - Adjusted the layout of the properties panel to accommodate a new VariableManager component for better variable management. --- .../process-flow/ProcessBuilderComponents.vue | 8 +- components/process-flow/ProcessFlowCanvas.vue | 7 +- components/process-flow/VariableManager.vue | 280 ++++++++++++++++++ doc/PROCESS_BUILDER_IMPROVEMENTS.md | 255 ++++++++++++++++ pages/process-builder/index.vue | 165 ++++------- prisma/json/json-schema.json | 38 +-- prisma/schema.prisma | 22 +- stores/processBuilder.js | 78 +++-- stores/variableStore.js | 96 ++++++ 9 files changed, 773 insertions(+), 176 deletions(-) create mode 100644 components/process-flow/VariableManager.vue create mode 100644 doc/PROCESS_BUILDER_IMPROVEMENTS.md create mode 100644 stores/variableStore.js diff --git a/components/process-flow/ProcessBuilderComponents.vue b/components/process-flow/ProcessBuilderComponents.vue index 216f18d..d6c5cf2 100644 --- a/components/process-flow/ProcessBuilderComponents.vue +++ b/components/process-flow/ProcessBuilderComponents.vue @@ -142,9 +142,13 @@ const onDragStart = (event, component) => { data: component.defaultProps.data }; - // Set the drag data + // Set the drag data with text/plain format for better Mac compatibility event.dataTransfer.effectAllowed = 'copy'; - event.dataTransfer.setData('application/json', JSON.stringify(componentData)); + event.dataTransfer.dropEffect = 'copy'; + event.dataTransfer.setData('text/plain', JSON.stringify(componentData)); + + // Add visual feedback + event.target.classList.add('dragging'); }; // Add a component directly via click diff --git a/components/process-flow/ProcessFlowCanvas.vue b/components/process-flow/ProcessFlowCanvas.vue index e52eaba..0b080b3 100644 --- a/components/process-flow/ProcessFlowCanvas.vue +++ b/components/process-flow/ProcessFlowCanvas.vue @@ -269,10 +269,11 @@ const onDeleteKeyPress = () => { // Handle drop event const onDrop = (event) => { event.preventDefault(); + event.stopPropagation(); try { // Get the dragged component data - const componentData = JSON.parse(event.dataTransfer.getData('application/json')); + const componentData = JSON.parse(event.dataTransfer.getData('text/plain')); if (!componentData) return; // Get the Vue Flow wrapper element @@ -296,7 +297,6 @@ const onDrop = (event) => { } }; - // console.log('Adding new node:', newNode); addNodes([newNode]); } catch (error) { console.error('Error handling drop:', error); @@ -306,7 +306,8 @@ const onDrop = (event) => { // Handle drag over const onDragOver = (event) => { event.preventDefault(); - event.dataTransfer.dropEffect = 'move'; + event.stopPropagation(); + event.dataTransfer.dropEffect = 'copy'; }; diff --git a/components/process-flow/VariableManager.vue b/components/process-flow/VariableManager.vue new file mode 100644 index 0000000..91f2880 --- /dev/null +++ b/components/process-flow/VariableManager.vue @@ -0,0 +1,280 @@ + + + + + \ No newline at end of file diff --git a/doc/PROCESS_BUILDER_IMPROVEMENTS.md b/doc/PROCESS_BUILDER_IMPROVEMENTS.md new file mode 100644 index 0000000..81b7223 --- /dev/null +++ b/doc/PROCESS_BUILDER_IMPROVEMENTS.md @@ -0,0 +1,255 @@ +# Process Builder Improvements + +## Overview +This document outlines the planned improvements for the Process Builder core components. The improvements are designed to be manageable and maintainable while adding essential functionality. + +## Variable System + +### 1. Global Variables +```javascript +{ + name: 'string', + type: 'string|number|boolean|object|array', + defaultValue: any, + description: 'string', + scope: 'global', + isRequired: boolean, + isReadOnly: boolean +} +``` + +### 2. Process Variables +```javascript +{ + name: 'string', + type: 'string|number|boolean|object|array', + defaultValue: any, + description: 'string', + scope: 'process', + isRequired: boolean, + isReadOnly: boolean, + direction: 'in|out|inout' // for process arguments +} +``` + +### 3. Task/Form Arguments +```javascript +{ + name: 'string', + type: 'string|number|boolean|object|array', + defaultValue: any, + description: 'string', + direction: 'in|out|inout', + isRequired: boolean, + validation: { + rules: [], + customValidation: 'string' // custom validation script + } +} +``` + +## Core Components Improvements + +### 1. Start Event +```javascript +{ + type: 'start', + data: { + description: 'Process start point', + triggerType: 'manual', // manual, scheduled + schedule: null, // for scheduled triggers + variables: { + input: [], // process input arguments + output: [] // process output arguments + }, + globalVariables: [] // global variables used in this process + } +} +``` + +### 2. End Event +```javascript +{ + type: 'end', + data: { + description: 'Process end point', + resultType: 'success', // success, error + variables: { + input: [], // variables required for end event + output: [] // variables to be returned + }, + returnValues: [] // values to return to calling process + } +} +``` + +### 3. Task +```javascript +{ + type: 'task', + data: { + description: 'A general task', + assignee: '', + taskType: 'manual', // manual, automated + priority: 'medium', // low, medium, high + dueDate: null, + variables: { + input: [], // task input arguments + output: [] // task output arguments + }, + notifications: { + onAssign: true, + onComplete: true + } + } +} +``` + +### 4. Form Task +```javascript +{ + type: 'form', + data: { + description: 'Form submission task', + formId: null, + formName: null, + formSettings: { + allowDraft: true, + autoSave: true + }, + variables: { + input: [], // form input arguments + output: [] // form output arguments + }, + dataMapping: { + input: [], // map process variables to form + output: [] // map form to process variables + } + } +} +``` + +### 5. Gateway +```javascript +{ + type: 'gateway', + data: { + description: 'Decision gateway', + conditions: [], + defaultPath: 'Default', + gatewayType: 'exclusive', // exclusive, parallel + variables: { + input: [], // variables needed for conditions + output: [] // variables to pass to next node + }, + timeout: { + enabled: false, + duration: 0 + } + } +} +``` + +## New Core Components + +### 1. Script Task +```javascript +{ + type: 'script', + data: { + description: 'Execute custom script', + scriptType: 'javascript', + script: '', + variables: { + input: [], // script input arguments + output: [] // script output arguments + }, + timeout: 30 // seconds + } +} +``` + +## Implementation Priority + +### Phase 1 - Essential Improvements +1. Implement basic variable system + - Global variables + - Process variables + - Task/Form arguments +2. Add basic trigger types to Start Event +3. Add result types to End Event +4. Add task priorities and due dates +5. Add form settings for drafts and auto-save + +### Phase 2 - Enhanced Features +1. Add variable validation system +2. Add data mapping for forms +3. Add script task component +4. Add timeout handling +5. Add notifications system + +### Phase 3 - Advanced Features +1. Add subprocess component +2. Add advanced gateway conditions +3. Add process templates +4. Add process versioning +5. Add process analytics + +## Variable System Features + +### 1. Variable Types +- String +- Number +- Boolean +- Object +- Array +- Date +- File +- Custom types + +### 2. Variable Scopes +- Global (accessible across all processes) +- Process (accessible within a process) +- Task/Form (accessible within a task/form) +- Local (accessible within a script) + +### 3. Variable Operations +- Create/Delete +- Read/Write +- Copy/Move +- Transform +- Validate +- Persist + +### 4. Variable Passing +- Process to Process +- Task to Task +- Form to Process +- Script to Process +- Gateway Conditions + +## Notes +- Keep improvements focused on essential functionality +- Maintain backward compatibility +- Ensure easy maintenance +- Document all new features +- Add proper validation +- Include error handling +- Implement proper variable scoping +- Add variable type checking +- Include variable persistence + +## Future Considerations +- Process templates +- Process versioning +- Process analytics +- Advanced notifications +- Custom validations +- Process documentation +- Process testing +- Process deployment +- Variable encryption +- Variable versioning +- Variable dependencies + +Last updated: June 10, 2024 \ No newline at end of file diff --git a/pages/process-builder/index.vue b/pages/process-builder/index.vue index 7ae0014..e96cf25 100644 --- a/pages/process-builder/index.vue +++ b/pages/process-builder/index.vue @@ -1,11 +1,13 @@