stash
This commit is contained in:
parent
2fe8d14c2c
commit
4627f0aca2
14 changed files with 1064 additions and 11 deletions
449
frontend/src/views/Workflows.vue
Normal file
449
frontend/src/views/Workflows.vue
Normal file
|
|
@ -0,0 +1,449 @@
|
|||
<template>
|
||||
<BaseLayout>
|
||||
<main class="content">
|
||||
<div class="container-fluid p-0">
|
||||
<h1 class="h3 mb-3">Workflows</h1>
|
||||
|
||||
<!-- Active/Unfinished Workflows Section - Only show if there are active workflows -->
|
||||
<div v-if="activeWorkflows.length > 0" class="row mb-4">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="card-title mb-0">Workflows in progress</h5>
|
||||
<span class="badge bg-primary">{{ activeWorkflows.length }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Workflow</th>
|
||||
<th>Status</th>
|
||||
<th>Progress</th>
|
||||
<th>Started</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="workflow in activeWorkflows" :key="workflow.id">
|
||||
<td>
|
||||
<strong>{{ workflow.workflow_type }}</strong>
|
||||
<br>
|
||||
<small class="text-muted">{{ workflow.payload?.workflow_config?.category || 'System' }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span :class="getStatusBadgeClass(workflow.state)">
|
||||
{{ workflow.status_display || workflow.state }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress" style="height: 8px;">
|
||||
<div class="progress-bar"
|
||||
:style="{ width: workflow.progress_percentage + '%' }"
|
||||
:class="getProgressBarClass(workflow.status)">
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-muted">{{ workflow.progress_percentage }}%</small>
|
||||
</td>
|
||||
<td>{{ formatDate(workflow.started_at) }}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary me-1"
|
||||
@click="viewWorkflowDetails(workflow)"
|
||||
: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">
|
||||
<b-icon-x-circle></b-icon-x-circle>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Available System Workflows Section -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title mb-0">Available Workflows</h5>
|
||||
<small class="text-muted">Start a new workflow instance</small>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div v-for="workflow in availableWorkflows" :key="workflow.id" class="col-lg-4 col-md-6 mb-3">
|
||||
<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>
|
||||
<h6 class="card-title mb-1">{{ workflow.name }}</h6>
|
||||
<small class="text-muted">{{ workflow.category }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<p class="card-text flex-grow-1">{{ workflow.description }}</p>
|
||||
<div class="mt-auto">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<small class="text-muted">
|
||||
<b-icon-clock class="me-1"></b-icon-clock>
|
||||
~{{ workflow.estimatedDuration }}
|
||||
</small>
|
||||
<span class="badge bg-light text-dark">{{ workflow.steps }} steps</span>
|
||||
</div>
|
||||
<button class="btn btn-primary w-100"
|
||||
@click="startWorkflow(workflow)"
|
||||
:disabled="isWorkflowRunning(workflow.id)">
|
||||
<b-icon-play-fill class="me-1"></b-icon-play-fill>
|
||||
{{ isWorkflowRunning(workflow.id) ? 'Running...' : 'Start Workflow' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</BaseLayout>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as BIcons from "bootstrap-icons-vue";
|
||||
import BaseLayout from "@/components/BaseLayout.vue";
|
||||
import { mapState, mapActions } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'Workflows',
|
||||
components: {
|
||||
...BIcons,
|
||||
BaseLayout
|
||||
},
|
||||
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
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(['active_workflows']),
|
||||
activeWorkflows() {
|
||||
return this.active_workflows;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.loadActiveWorkflows();
|
||||
},
|
||||
methods: {
|
||||
...mapActions([
|
||||
'fetchActiveWorkflows',
|
||||
'createWorkflow',
|
||||
'updateWorkflow',
|
||||
'pauseWorkflow',
|
||||
'resumeWorkflow',
|
||||
'cancelWorkflow',
|
||||
'deleteWorkflow'
|
||||
]),
|
||||
async loadActiveWorkflows() {
|
||||
try {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
await this.fetchActiveWorkflows();
|
||||
} catch (error) {
|
||||
console.error('Error loading active workflows:', error);
|
||||
this.error = 'Failed to load active workflows';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
getStatusBadgeClass(status) {
|
||||
const classes = {
|
||||
'running': 'badge bg-success',
|
||||
'paused': 'badge bg-warning',
|
||||
'failed': 'badge bg-danger',
|
||||
'completed': 'badge bg-primary',
|
||||
'cancelled': 'badge bg-secondary'
|
||||
};
|
||||
return classes[status] || 'badge bg-secondary';
|
||||
},
|
||||
getProgressBarClass(status) {
|
||||
const classes = {
|
||||
'running': 'bg-success',
|
||||
'paused': 'bg-warning',
|
||||
'failed': 'bg-danger',
|
||||
'completed': 'bg-primary',
|
||||
'cancelled': 'bg-secondary'
|
||||
};
|
||||
return classes[status] || 'bg-secondary';
|
||||
},
|
||||
formatDate(dateString) {
|
||||
const date = new Date(dateString);
|
||||
return new Intl.DateTimeFormat('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}).format(date);
|
||||
},
|
||||
isWorkflowRunning(workflowId) {
|
||||
return this.activeWorkflows.some(active =>
|
||||
active.workflow_type === workflowId &&
|
||||
active.state === 'running'
|
||||
);
|
||||
},
|
||||
async startWorkflow(workflow) {
|
||||
try {
|
||||
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
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
this.error = `Failed to start ${workflow.name}`;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
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);
|
||||
},
|
||||
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}"?`)) {
|
||||
try {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
await this.cancelWorkflow(workflow.id);
|
||||
await this.loadActiveWorkflows();
|
||||
console.log('Workflow cancelled successfully:', workflow.workflow_type);
|
||||
} catch (error) {
|
||||
console.error('Error cancelling workflow:', error);
|
||||
this.error = `Failed to cancel ${workflow.workflow_type}`;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.workflow-card {
|
||||
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
||||
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;
|
||||
justify-content: center;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
background-color: rgba(13, 110, 253, 0.1);
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.progress {
|
||||
border-radius: 4px;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
border-radius: 4px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.table th {
|
||||
border-top: none;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
font-size: 0.875rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
background-color: #f8f9fa;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.workflow-card .btn {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.workflow-card .btn:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.workflow-card .btn:disabled {
|
||||
opacity: 0.6;
|
||||
transform: none;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue