]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Messing with a suggest button
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sun, 20 Apr 2025 06:39:47 +0000 (23:39 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Tue, 22 Apr 2025 15:08:26 +0000 (08:08 -0700)
src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.html
src-ui/src/app/components/document-detail/document-detail.component.html
src-ui/src/app/components/document-detail/document-detail.component.spec.ts
src-ui/src/app/components/document-detail/document-detail.component.ts
src-ui/src/main.ts

index f58cfeeb98cbc2be35539c056a450e8aec7e542f..f3023860b4ed55c82a0b9dd88ae2bcc10ae2b99c 100644 (file)
@@ -1,7 +1,7 @@
 <div ngbDropdown #fieldDropdown="ngbDropdown" (openChange)="onOpenClose($event)" [popperOptions]="popperOptions" placement="bottom-end">
-    <button class="btn btn-sm btn-outline-primary" id="customFieldsDropdown" [disabled]="disabled" ngbDropdownToggle>
+    <button type="button" class="btn btn-sm btn-outline-primary" id="customFieldsDropdown" [disabled]="disabled" ngbDropdownToggle>
       <i-bs name="ui-radios"></i-bs>
-      <div class="d-none d-sm-inline">&nbsp;<ng-container i18n>Custom Fields</ng-container></div>
+      <div class="d-none d-lg-inline">&nbsp;<ng-container i18n>Custom Fields</ng-container></div>
     </button>
     <div ngbDropdownMenu aria-labelledby="customFieldsDropdown" class="shadow custom-fields-dropdown">
         <div class="list-group list-group-flush" (keydown)="listKeyDown($event)">
index eb99cd6b6047a80d03df9a85aebfa3bdddafe506..a95341b9d91168220e3969ee590a956b3c7486b3 100644 (file)
     </div>
   </div>
 
-  <pngx-custom-fields-dropdown
-    *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.CustomField }"
-    [documentId]="documentId"
-    [disabled]="!userCanEdit"
-    [existingFields]="document?.custom_fields"
-    (created)="refreshCustomFields()"
-    (added)="addField($event)">
-  </pngx-custom-fields-dropdown>
-
-
   <div class="ms-auto" ngbDropdown>
     <button class="btn btn-sm btn-outline-primary" id="sendDropdown" ngbDropdownToggle>
       <i-bs name="send"></i-bs>
 </pngx-page-header>
 
 <div class="row">
-  <div class="col-md-6 col-xl-4 mb-4">
+  <div class="col-md-6 col-xl-5 mb-4">
 
     <form [formGroup]='documentForm' (ngSubmit)="save()">
 
           </button>
         </div>
 
+        <ng-container *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Document }">
+          <div class="btn-group pb-3 ms-auto">
+            <button type="button" class="btn btn-sm btn-outline-primary" (click)="getSuggestions()" [disabled]="!userCanEdit || suggestions || suggestionsLoading" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Document }">
+              @if (suggestionsLoading) {
+                <div class="spinner-border spinner-border-sm" role="status"></div>
+              } @else {
+                <i-bs width="1.2em" height="1.2em" name="stars"></i-bs>
+              }
+              <span class="d-none d-lg-inline ps-1" i18n>Suggest</span>
+            </button>
+          </div>
+
+          <div class="btn-group pb-3 ms-2">
+            <pngx-custom-fields-dropdown
+              *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.CustomField }"
+              [documentId]="documentId"
+              [disabled]="!userCanEdit"
+              [existingFields]="document?.custom_fields"
+              (created)="refreshCustomFields()"
+              (added)="addField($event)">
+            </pngx-custom-fields-dropdown>
+          </div>
+        </ng-container>
+
         <ng-container *ngTemplateOutlet="saveButtons"></ng-container>
       </div>
 
     </form>
   </div>
 
-  <div class="col-md-6 col-xl-8 mb-3 d-none d-md-block position-relative" #pdfPreview>
+  <div class="col-md-6 col-xl-7 mb-3 d-none d-md-block position-relative" #pdfPreview>
     <ng-container *ngTemplateOutlet="previewContent"></ng-container>
   </div>
 
 </div>
 
 <ng-template #saveButtons>
-  <div class="btn-group pb-3 ms-auto">
+  <div class="btn-group pb-3 ms-4">
     <ng-container *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Document }">
       <button type="submit" class="order-3 btn btn-sm btn-primary" i18n [disabled]="!userCanEdit || networkActive || (isDirty$ | async) !== true">Save</button>
       @if (hasNext()) {
index d7b1f606932fed4d86dc51e9794e58355add163d..6f386ad73c3292113ef3a6680c94f40c0bda04b1 100644 (file)
@@ -993,7 +993,7 @@ describe('DocumentDetailComponent', () => {
     expect(component.document.custom_fields).toHaveLength(initialLength - 1)
     expect(component.customFieldFormFields).toHaveLength(initialLength - 1)
     expect(
-      fixture.debugElement.query(By.css('form')).nativeElement.textContent
+      fixture.debugElement.query(By.css('form ul')).nativeElement.textContent
     ).not.toContain('Field 1')
     const updateSpy = jest.spyOn(documentService, 'update')
     component.save(true)
index 0a3d9ec382b288f020d3c8b2f10a2071823570e0..4f08934744a88baed78ac4b1ab994fc797079d51 100644 (file)
@@ -191,6 +191,7 @@ export class DocumentDetailComponent
   document: Document
   metadata: DocumentMetadata
   suggestions: DocumentSuggestions
+  suggestionsLoading: boolean = false
   users: User[]
 
   title: string
@@ -650,25 +651,7 @@ export class DocumentDetailComponent
       this.tagService.getCachedMany(doc.tags).subscribe((tags) => {
         // only show suggestions if document has inbox tags
         if (tags.some((tag) => tag.is_inbox_tag)) {
-          this.documentsService
-            .getSuggestions(doc.id)
-            .pipe(
-              first(),
-              takeUntil(this.unsubscribeNotifier),
-              takeUntil(this.docChangeNotifier)
-            )
-            .subscribe({
-              next: (result) => {
-                this.suggestions = result
-              },
-              error: (error) => {
-                this.suggestions = null
-                this.toastService.showError(
-                  $localize`Error retrieving suggestions.`,
-                  error
-                )
-              },
-            })
+          this.getSuggestions()
         }
       })
     }
@@ -687,6 +670,31 @@ export class DocumentDetailComponent
     return this.documentForm.get('custom_fields') as FormArray
   }
 
+  getSuggestions() {
+    this.suggestionsLoading = true
+    this.documentsService
+      .getSuggestions(this.documentId)
+      .pipe(
+        first(),
+        takeUntil(this.unsubscribeNotifier),
+        takeUntil(this.docChangeNotifier)
+      )
+      .subscribe({
+        next: (result) => {
+          this.suggestions = result
+          this.suggestionsLoading = false
+        },
+        error: (error) => {
+          this.suggestions = null
+          this.suggestionsLoading = false
+          this.toastService.showError(
+            $localize`Error retrieving suggestions.`,
+            error
+          )
+        },
+      })
+  }
+
   createDocumentType(newName: string) {
     var modal = this.modalService.open(DocumentTypeEditDialogComponent, {
       backdrop: 'static',
index eb34b94b4906fdba1ac480ae3ea4ecf0f8aa473e..c906856bb680e5447aa5e069c21fc7d7d589063b 100644 (file)
@@ -118,6 +118,7 @@ import {
   sliders2Vertical,
   sortAlphaDown,
   sortAlphaUpAlt,
+  stars,
   tag,
   tagFill,
   tags,
@@ -324,6 +325,7 @@ const icons = {
   sliders2Vertical,
   sortAlphaDown,
   sortAlphaUpAlt,
+  stars,
   tagFill,
   tag,
   tags,