This commit is contained in:
j3d1 2025-09-26 20:00:29 +02:00
parent 4627f0aca2
commit 7c91661be2
14 changed files with 1208 additions and 220 deletions

View file

@ -40,7 +40,7 @@
<div class="progress" style="height: 8px;">
<div class="progress-bar"
:style="{ width: workflow.progress_percentage + '%' }"
:class="getProgressBarClass(workflow.status)">
:class="getProgressBarClass(workflow.state)">
</div>
</div>
<small class="text-muted">{{ workflow.progress_percentage }}%</small>
@ -52,21 +52,9 @@
:disabled="loading">
<b-icon-eye></b-icon-eye>
</button>
<button v-if="workflow.status === 'running'"
class="btn btn-sm btn-outline-warning me-1"
@click="pauseWorkflowInstance(workflow)"
:disabled="loading">
<b-icon-pause></b-icon-pause>
</button>
<button v-if="workflow.status === 'paused'"
class="btn btn-sm btn-outline-success me-1"
@click="resumeWorkflowInstance(workflow)"
:disabled="loading">
<b-icon-play></b-icon-play>
</button>
<button class="btn btn-sm btn-outline-danger"
@click="cancelWorkflowInstance(workflow)"
:disabled="workflow.status === 'completed' || workflow.status === 'cancelled' || loading">
@click="abortWorkflowInstance(workflow)"
:disabled="loading">
<b-icon-x-circle></b-icon-x-circle>
</button>
</td>
@ -93,10 +81,16 @@
<div class="card h-100 workflow-card">
<div class="card-body d-flex flex-column">
<div class="d-flex align-items-center mb-3">
<div class="workflow-icon me-3">
<component :is="workflow.icon" class="text-primary" style="font-size: 1.5rem;"></component>
</div>
<div>
<template v-for="(icon, index) in workflow.icons" :key="icon">
<div class="workflow-icon me-3">
<component :is="icon" class="text-primary" style="font-size: 1.5rem;"></component>
</div>
<!-- Add arrow between icons, but not after the last one -->
<div v-if="index < workflow.icons.length - 1" class="workflow-arrow me-3">
<b-icon-arrow-right class="text-muted" style="font-size: 1rem;"></b-icon-arrow-right>
</div>
</template>
<div class="workflow-header">
<h6 class="card-title mb-1">{{ workflow.name }}</h6>
<small class="text-muted">{{ workflow.category }}</small>
</div>
@ -134,6 +128,7 @@
import * as BIcons from "bootstrap-icons-vue";
import BaseLayout from "@/components/BaseLayout.vue";
import { mapState, mapActions } from 'vuex';
import { workflowRegistry } from '@/workflows.js';
export default {
name: 'Workflows',
@ -143,71 +138,6 @@ export default {
},
data() {
return {
availableWorkflows: [
{
id: 'inventory-audit',
name: 'Inventory Audit',
category: 'Inventory Management',
description: 'Perform a complete audit of your inventory items, checking quantities, locations, and conditions.',
icon: 'b-icon-clipboard-check',
estimatedDuration: '2-4 hours',
steps: 8
},
{
id: 'storage-optimization',
name: 'Storage Optimization',
category: 'Storage Management',
description: 'Analyze and reorganize storage locations for maximum efficiency and accessibility.',
icon: 'b-icon-boxes',
estimatedDuration: '1-2 hours',
steps: 5
},
{
id: 'foto-first-import',
name: 'Foto First Import',
category: 'Data Management',
description: 'Capture unlimited photos via mobile camera or upload images, then sequentially enter details for each item.',
icon: 'b-icon-camera',
estimatedDuration: '10-60 minutes',
steps: 4
},
{
id: 'maintenance-schedule',
name: 'Maintenance Schedule',
category: 'Tool Maintenance',
description: 'Create and execute maintenance schedules for tools and equipment.',
icon: 'b-icon-tools',
estimatedDuration: '30 minutes',
steps: 4
},
{
id: 'expiry-check',
name: 'Expiry Date Check',
category: 'Quality Control',
description: 'Identify and handle items approaching or past their expiry dates.',
icon: 'b-icon-calendar-x',
estimatedDuration: '45 minutes',
steps: 6
},
{
id: 'backup-restore',
name: 'Data Backup',
category: 'System Maintenance',
description: 'Create a comprehensive backup of your inventory and settings data.',
icon: 'b-icon-cloud-arrow-up',
estimatedDuration: '15 minutes',
steps: 3
},
{
id: 'import-items',
name: 'Bulk Item Import',
category: 'Data Management',
description: 'Import multiple inventory items from CSV or Excel files with validation.',
icon: 'b-icon-file-earmark-spreadsheet',
estimatedDuration: '20-60 minutes',
steps: 7
}
],
loading: false,
error: null
}
@ -216,6 +146,9 @@ export default {
...mapState(['active_workflows']),
activeWorkflows() {
return this.active_workflows;
},
availableWorkflows() {
return workflowRegistry.getAll();
}
},
async mounted() {
@ -226,9 +159,6 @@ export default {
'fetchActiveWorkflows',
'createWorkflow',
'updateWorkflow',
'pauseWorkflow',
'resumeWorkflow',
'cancelWorkflow',
'deleteWorkflow'
]),
async loadActiveWorkflows() {
@ -264,7 +194,18 @@ export default {
return classes[status] || 'bg-secondary';
},
formatDate(dateString) {
if (!dateString) {
return 'N/A';
}
const date = new Date(dateString);
// Check if the date is valid
if (isNaN(date.getTime())) {
console.warn('Invalid date string received:', dateString);
return 'Invalid Date';
}
return new Intl.DateTimeFormat('en-US', {
month: 'short',
day: 'numeric',
@ -283,26 +224,22 @@ export default {
this.loading = true;
this.error = null;
const workflowData = {
workflow_type: workflow.id,
state: 'running',
current_step: 0,
total_steps: workflow.steps,
payload: {
workflow_config: {
name: workflow.name,
description: workflow.description,
category: workflow.category,
estimated_duration: workflow.estimatedDuration
}
// Use the workflow's toApiFormat method to get properly formatted data
const workflowData = workflow.toApiFormat();
const newWorkflow = await this.createWorkflow(workflowData);
console.log('Workflow started successfully:', newWorkflow);
// Immediately navigate to the workflow detail view
// Get the first step from the workflow definition
const firstStep = workflow.getStepDefinitions()?.[0]?.step || "initial";
this.$router.push({
name: 'workflow-detail',
params: {
id: newWorkflow.id,
step: firstStep
}
};
await this.createWorkflow(workflowData);
console.log('Workflow started successfully:', workflow.name);
// Refresh active workflows to show the new one
await this.loadActiveWorkflows();
});
} catch (error) {
console.error('Error starting workflow:', error);
@ -312,57 +249,33 @@ export default {
}
},
async viewWorkflowDetails(workflow) {
// TODO: Implement workflow details view/modal
console.log('Viewing workflow details:', workflow);
// For now, show an alert with workflow information
const details = `
Workflow: ${workflow.workflow_type}
Status: ${workflow.status_display || workflow.state}
Progress: ${workflow.progress_percentage}%
Step: ${workflow.current_step + 1} of ${workflow.total_steps}
Started: ${this.formatDate(workflow.started_at)}
`.trim();
alert(details);
console.log('Viewing details for workflow:', workflow);
// Navigate to the workflow detail view
// Use the workflow's current step if available, otherwise use the first step
const currentStep = workflow.current_step ||
workflow.payload?.current_step ||
workflow.getStepDefinitions?.()?.[0]?.step ||
"initial";
this.$router.push({
name: 'workflow-detail',
params: {
id: workflow.id,
step: currentStep
}
});
},
async pauseWorkflowInstance(workflow) {
try {
this.loading = true;
this.error = null;
await this.pauseWorkflow(workflow.id);
await this.loadActiveWorkflows();
console.log('Workflow paused successfully:', workflow.workflow_type);
} catch (error) {
console.error('Error pausing workflow:', error);
this.error = `Failed to pause ${workflow.workflow_type}`;
} finally {
this.loading = false;
}
},
async resumeWorkflowInstance(workflow) {
try {
this.loading = true;
this.error = null;
await this.resumeWorkflow(workflow.id);
await this.loadActiveWorkflows();
console.log('Workflow resumed successfully:', workflow.workflow_type);
} catch (error) {
console.error('Error resuming workflow:', error);
this.error = `Failed to resume ${workflow.workflow_type}`;
} finally {
this.loading = false;
}
},
async cancelWorkflowInstance(workflow) {
if (confirm(`Are you sure you want to cancel "${workflow.workflow_type}"?`)) {
async abortWorkflowInstance(workflow) {
if (confirm(`Are you sure you want to abort "${workflow.workflow_type}"?`)) {
try {
this.loading = true;
this.error = null;
await this.cancelWorkflow(workflow.id);
await this.deleteWorkflow(workflow.id);
await this.loadActiveWorkflows();
console.log('Workflow cancelled successfully:', workflow.workflow_type);
console.log('Workflow aborted successfully:', workflow.workflow_type);
} catch (error) {
console.error('Error cancelling workflow:', error);
this.error = `Failed to cancel ${workflow.workflow_type}`;
console.error('Error aborting workflow:', error);
this.error = `Failed to abort ${workflow.workflow_type}`;
} finally {
this.loading = false;
}
@ -378,11 +291,6 @@ Started: ${this.formatDate(workflow.started_at)}
border: 1px solid #e9ecef;
}
.workflow-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.workflow-icon {
display: flex;
align-items: center;
@ -394,6 +302,19 @@ Started: ${this.formatDate(workflow.started_at)}
flex-shrink: 0;
}
.workflow-header {
margin-left: 1rem;
}
.workflow-arrow {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-left: 0.25rem;
margin-right: 0.25rem;
}
.progress {
border-radius: 4px;
background-color: #e9ecef;