Feature: clone workflows

This commit is contained in:
shamoon 2024-09-16 10:48:18 -07:00
parent 045b62ca66
commit 38aa288133
4 changed files with 57 additions and 15 deletions

View File

@ -1549,7 +1549,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
<context context-type="linenumber">38</context>
<context context-type="linenumber">41</context>
</context-group>
</trans-unit>
<trans-unit id="6338800642797811873" datatype="html">
@ -2215,7 +2215,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">97</context>
<context context-type="linenumber">115</context>
</context-group>
</trans-unit>
<trans-unit id="1980187861066369604" datatype="html">
@ -2554,7 +2554,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">99</context>
<context context-type="linenumber">117</context>
</context-group>
</trans-unit>
<trans-unit id="857903183180440990" datatype="html">
@ -7817,53 +7817,60 @@
<context context-type="linenumber">30</context>
</context-group>
</trans-unit>
<trans-unit id="5834780181397311898" datatype="html">
<source>Clone</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
<context context-type="linenumber">38</context>
</context-group>
</trans-unit>
<trans-unit id="1624023882313260402" datatype="html">
<source>No workflows defined.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
<context context-type="linenumber">46</context>
<context context-type="linenumber">49</context>
</context-group>
</trans-unit>
<trans-unit id="4200688335642457098" datatype="html">
<source>Saved workflow &quot;<x id="PH" equiv-text="newWorkflow.name"/>&quot;.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">79</context>
<context context-type="linenumber">78</context>
</context-group>
</trans-unit>
<trans-unit id="7593065565369163325" datatype="html">
<source>Error saving workflow.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">87</context>
<context context-type="linenumber">86</context>
</context-group>
</trans-unit>
<trans-unit id="563460864902055482" datatype="html">
<source>Confirm delete workflow</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">95</context>
<context context-type="linenumber">113</context>
</context-group>
</trans-unit>
<trans-unit id="6874008462443189248" datatype="html">
<source>This operation will permanently delete this workflow.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">96</context>
<context context-type="linenumber">114</context>
</context-group>
</trans-unit>
<trans-unit id="1848226135059921165" datatype="html">
<source>Deleted workflow</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">105</context>
<context context-type="linenumber">123</context>
</context-group>
</trans-unit>
<trans-unit id="3177411222429626224" datatype="html">
<source>Error deleting workflow.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
<context context-type="linenumber">110</context>
<context context-type="linenumber">128</context>
</context-group>
</trans-unit>
<trans-unit id="2649252321173430744" datatype="html">

View File

@ -34,6 +34,9 @@
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editWorkflow(workflow)">
<i-bs width="1em" height="1em" name="pencil"></i-bs>&nbsp;<ng-container i18n>Edit</ng-container>
</button>
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-secondary" type="button" (click)="cloneWorkflow(workflow)">
<i-bs width="1em" height="1em" name="files"></i-bs>&nbsp;<ng-container i18n>Clone</ng-container>
</button>
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteWorkflow(workflow)">
<i-bs width="1em" height="1em" name="trash"></i-bs>&nbsp;<ng-container i18n>Delete</ng-container>
</button>

View File

@ -26,6 +26,7 @@ import {
import { WorkflowActionType } from 'src/app/data/workflow-action'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
const workflows: Workflow[] = [
{
@ -173,6 +174,19 @@ describe('WorkflowsComponent', () => {
expect(reloadSpy).toHaveBeenCalled()
})
it('should support clone', () => {
let modal: NgbModalRef
modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1]))
const cloneButton = fixture.debugElement.queryAll(By.css('button'))[4]
cloneButton.triggerEventHandler('click')
expect(modal).not.toBeUndefined()
const editDialog = modal.componentInstance as WorkflowEditDialogComponent
expect(editDialog.object.name).toEqual(workflows[0].name + ' (copy)')
expect(editDialog.dialogMode).toEqual(EditDialogMode.CREATE)
})
it('should support delete, show notification on error / success', () => {
let modal: NgbModalRef
modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1]))
@ -180,7 +194,7 @@ describe('WorkflowsComponent', () => {
const deleteSpy = jest.spyOn(workflowService, 'delete')
const reloadSpy = jest.spyOn(component, 'reload')
const deleteButton = fixture.debugElement.queryAll(By.css('button'))[4]
const deleteButton = fixture.debugElement.queryAll(By.css('button'))[5]
deleteButton.triggerEventHandler('click')
expect(modal).not.toBeUndefined()

View File

@ -57,14 +57,13 @@ export class WorkflowsComponent
.join(', ')
}
editWorkflow(workflow: Workflow) {
editWorkflow(workflow: Workflow, clone: boolean = false) {
const modal = this.modalService.open(WorkflowEditDialogComponent, {
backdrop: 'static',
size: 'xl',
})
modal.componentInstance.dialogMode = workflow
? EditDialogMode.EDIT
: EditDialogMode.CREATE
modal.componentInstance.dialogMode =
workflow && !clone ? EditDialogMode.EDIT : EditDialogMode.CREATE
if (workflow) {
// quick "deep" clone so original doesn't get modified
const clone = Object.assign({}, workflow)
@ -88,6 +87,25 @@ export class WorkflowsComponent
})
}
cloneWorkflow(workflow: Workflow) {
const clone = Object.assign({}, workflow)
clone.id = null
clone.name = `${workflow.name} (copy)`
clone.actions = [
...workflow.actions.map((a) => {
a.id = null
return a
}),
]
clone.triggers = [
...workflow.triggers.map((t) => {
t.id = null
return t
}),
]
this.editWorkflow(clone, true)
}
deleteWorkflow(workflow: Workflow) {
const modal = this.modalService.open(ConfirmDialogComponent, {
backdrop: 'static',