]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Enhancement: workflow overview toggle enable button (#7818)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 1 Oct 2024 02:44:02 +0000 (19:44 -0700)
committerGitHub <noreply@github.com>
Tue, 1 Oct 2024 02:44:02 +0000 (19:44 -0700)
src-ui/messages.xlf
src-ui/src/app/components/manage/workflows/workflows.component.html
src-ui/src/app/components/manage/workflows/workflows.component.spec.ts
src-ui/src/app/components/manage/workflows/workflows.component.ts

index e0d30bdc2077ffba6be9e16c036ea0899a557a1c..f5d270376170b4c86b5e338adf21cdce30b1067c 100644 (file)
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">41</context>
+          <context context-type="linenumber">48</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">52</context>
+          <context context-type="linenumber">59</context>
         </context-group>
       </trans-unit>
       <trans-unit id="6338800642797811873" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">40</context>
+          <context context-type="linenumber">47</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">49</context>
+          <context context-type="linenumber">56</context>
         </context-group>
       </trans-unit>
       <trans-unit id="9124347207158517893" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">30</context>
+          <context context-type="linenumber">34</context>
         </context-group>
       </trans-unit>
       <trans-unit id="4348351765075925931" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">42</context>
+          <context context-type="linenumber">49</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">57</context>
+          <context context-type="linenumber">64</context>
         </context-group>
       </trans-unit>
       <trans-unit id="595732867213154214" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.html</context>
-          <context context-type="linenumber">30</context>
+          <context context-type="linenumber">34</context>
         </context-group>
       </trans-unit>
       <trans-unit id="6751234988479444294" 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">66</context>
+          <context context-type="linenumber">73</context>
         </context-group>
       </trans-unit>
       <trans-unit id="4200688335642457098" datatype="html">
           <context context-type="linenumber">128</context>
         </context-group>
       </trans-unit>
+      <trans-unit id="5459159218551862653" datatype="html">
+        <source>Enabled workflow</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
+          <context context-type="linenumber">139</context>
+        </context-group>
+      </trans-unit>
+      <trans-unit id="6035681056091592756" datatype="html">
+        <source>Disabled workflow</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
+          <context context-type="linenumber">140</context>
+        </context-group>
+      </trans-unit>
+      <trans-unit id="1376040678213338380" datatype="html">
+        <source>Error toggling workflow.</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">src/app/components/manage/workflows/workflows.component.ts</context>
+          <context context-type="linenumber">146</context>
+        </context-group>
+      </trans-unit>
       <trans-unit id="2649252321173430744" datatype="html">
         <source>Not Found</source>
         <context-group purpose="location">
index 1e83efd36adaabd7493919c0fe45d88f2757cc2f..ddb8a8654660897fd10bfccf6b7992e4dd7d02af 100644 (file)
@@ -15,9 +15,9 @@
   <li class="list-group-item">
     <div class="row">
       <div class="col" i18n>Name</div>
-      <div class="col d-none d-sm-block" i18n>Sort order</div>
+      <div class="col d-none d-sm-flex" i18n>Sort order</div>
       <div class="col" i18n>Status</div>
-      <div class="col d-none d-sm-block" i18n>Triggers</div>
+      <div class="col d-none d-sm-flex" i18n>Triggers</div>
       <div class="col" i18n>Actions</div>
     </div>
   </li>
     <li class="list-group-item">
       <div class="row">
         <div class="col d-flex align-items-center"><button class="btn btn-link p-0 text-start" type="button" (click)="editWorkflow(workflow)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.Workflow)">{{workflow.name}}</button></div>
-        <div class="col d-flex align-items-center d-none d-sm-block"><code>{{workflow.order}}</code></div>
-        <div class="col d-flex align-items-center"><code> @if(workflow.enabled) { <ng-container i18n>Enabled</ng-container> } @else { <span i18n class="text-muted">Disabled</span> }</code></div>
-        <div class="col d-flex align-items-center d-none d-sm-block">{{getTypesList(workflow)}}</div>
+        <div class="col d-flex align-items-center d-none d-sm-flex"><code>{{workflow.order}}</code></div>
+        <div class="col d-flex align-items-center">
+          <div class="form-check form-switch mb-0">
+            <input #inputField type="checkbox" class="form-check-input cursor-pointer" [id]="workflow.id+'_enable'" [(ngModel)]="workflow.enabled" (change)="onWorkflowEnableToggled(workflow)" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Workflow }">
+            <label class="form-check-label cursor-pointer" [for]="workflow.id+'_enable'">
+              <code> @if(workflow.enabled) { <ng-container i18n>Enabled</ng-container> } @else { <span i18n class="text-muted">Disabled</span> }</code>
+            </label>
+          </div>
+        </div>
+        <div class="col d-flex align-items-center d-none d-sm-flex">{{getTypesList(workflow)}}</div>
         <div class="col">
 
           <div class="btn-group d-block d-sm-none">
index 0bccbad2db5d9c2bffb45afe4a0cc8310412ac5f..9d92d9ba76451dd76b3c32bf489be89448e88e77 100644 (file)
@@ -211,4 +211,27 @@ describe('WorkflowsComponent', () => {
     editDialog.confirmClicked.emit()
     expect(reloadSpy).toHaveBeenCalled()
   })
+
+  it('should update workflow when enable is toggled', () => {
+    const patchSpy = jest.spyOn(workflowService, 'patch')
+    const toggleInput = fixture.debugElement.query(
+      By.css('input[type="checkbox"]')
+    )
+    const toastErrorSpy = jest.spyOn(toastService, 'showError')
+    const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
+    // fail first
+    patchSpy.mockReturnValueOnce(
+      throwError(() => new Error('Error getting config'))
+    )
+    toggleInput.nativeElement.click()
+    expect(patchSpy).toHaveBeenCalled()
+    expect(toastErrorSpy).toHaveBeenCalled()
+    // succeed second
+    patchSpy.mockReturnValueOnce(of(workflows[0]))
+    toggleInput.nativeElement.click()
+    patchSpy.mockReturnValueOnce(of({ ...workflows[0], enabled: false }))
+    toggleInput.nativeElement.click()
+    expect(patchSpy).toHaveBeenCalled()
+    expect(toastInfoSpy).toHaveBeenCalled()
+  })
 })
index 92b421e9fb1e216a4451e98c98765a1926ab27f3..592dd3efe32721e875bee3b624a2c99fda766cae 100644 (file)
@@ -130,4 +130,21 @@ export class WorkflowsComponent
       })
     })
   }
+
+  onWorkflowEnableToggled(workflow: Workflow) {
+    this.workflowService.patch(workflow).subscribe({
+      next: () => {
+        this.toastService.showInfo(
+          workflow.enabled
+            ? $localize`Enabled workflow`
+            : $localize`Disabled workflow`
+        )
+        this.workflowService.clearCache()
+        this.reload()
+      },
+      error: (e) => {
+        this.toastService.showError($localize`Error toggling workflow.`, e)
+      },
+    })
+  }
 }