]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Pass AI enabled to frontend
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 23 Apr 2025 19:40:42 +0000 (12:40 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 2 Jul 2025 18:01:51 +0000 (11:01 -0700)
src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.html
src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.spec.ts
src-ui/src/app/components/common/suggestions-dropdown/suggestions-dropdown.component.ts
src-ui/src/app/components/document-detail/document-detail.component.html
src-ui/src/app/components/document-detail/document-detail.component.ts
src-ui/src/app/data/ui-settings.ts
src/documents/tests/test_api_uisettings.py
src/documents/views.py

index ac9d7c47e8fffd6c02707f9a7fdb35c797316a0e..af207c05c6d186641b3b409852f31baefbcca975 100644 (file)
@@ -1,5 +1,5 @@
 <div class="btn-group">
-  <button type="button" class="btn btn-sm btn-outline-primary" (click)="clickSuggest()" [disabled]="loading">
+  <button type="button" class="btn btn-sm btn-outline-primary" (click)="clickSuggest()" [disabled]="loading || (suggestions && !aiEnabled)">
     @if (loading) {
       <div class="spinner-border spinner-border-sm" role="status"></div>
     } @else {
       <span class="badge bg-primary ms-2">{{ totalSuggestions }}</span>
     }
   </button>
-  <div class="btn-group" ngbDropdown #dropdown="ngbDropdown" [popperOptions]="popperOptions">
 
-    <button type="button" class="btn btn-sm btn-outline-primary" ngbDropdownToggle [disabled]="loading || !suggestions" aria-expanded="false" aria-controls="suggestionsDropdown" aria-label="Suggestions dropdown">
-      <span class="visually-hidden" i18n>Show suggestions</span>
-    </button>
+  @if (aiEnabled) {
+    <div class="btn-group" ngbDropdown #dropdown="ngbDropdown" [popperOptions]="popperOptions">
+      <button type="button" class="btn btn-sm btn-outline-primary" ngbDropdownToggle [disabled]="loading || !suggestions" aria-expanded="false" aria-controls="suggestionsDropdown" aria-label="Suggestions dropdown">
+        <span class="visually-hidden" i18n>Show suggestions</span>
+      </button>
 
-    <div ngbDropdownMenu aria-labelledby="suggestionsDropdown" class="shadow suggestions-dropdown">
-      <div class="list-group list-group-flush small pb-0">
-        @if (!suggestions?.suggested_tags && !suggestions?.suggested_document_types && !suggestions?.suggested_correspondents) {
-          <div class="list-group-item text-muted fst-italic">
-            <small class="text-muted small fst-italic" i18n>No novel suggestions</small>
-          </div>
-        }
-        @if (suggestions?.suggested_tags?.length > 0) {
-          <small class="list-group-item text-uppercase text-muted small">Tags</small>
-          @for (tag of suggestions.suggested_tags; track tag) {
-            <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addTag.emit(tag)" i18n>{{ tag }}</button>
+      <div ngbDropdownMenu aria-labelledby="suggestionsDropdown" class="shadow suggestions-dropdown">
+        <div class="list-group list-group-flush small pb-0">
+          @if (!suggestions?.suggested_tags && !suggestions?.suggested_document_types && !suggestions?.suggested_correspondents) {
+            <div class="list-group-item text-muted fst-italic">
+              <small class="text-muted small fst-italic" i18n>No novel suggestions</small>
+            </div>
           }
-        }
-        @if (suggestions?.suggested_document_types?.length > 0) {
-          <div class="list-group-item text-uppercase text-muted small">Document Types</div>
-          @for (type of suggestions.suggested_document_types; track type) {
-            <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addDocumentType.emit(type)" i18n>{{ type }}</button>
+          @if (suggestions?.suggested_tags.length > 0) {
+            <small class="list-group-item text-uppercase text-muted small">Tags</small>
+            @for (tag of suggestions.suggested_tags; track tag) {
+              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addTag.emit(tag)" i18n>{{ tag }}</button>
+            }
           }
-        }
-        @if (suggestions?.suggested_correspondents?.length > 0) {
-          <div class="list-group-item text-uppercase text-muted small">Correspondents</div>
-          @for (correspondent of suggestions.suggested_correspondents; track correspondent) {
-            <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addCorrespondent.emit(correspondent)" i18n>{{ correspondent }}</button>
+          @if (suggestions?.suggested_document_types.length > 0) {
+            <div class="list-group-item text-uppercase text-muted small">Document Types</div>
+            @for (type of suggestions.suggested_document_types; track type) {
+              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addDocumentType.emit(type)" i18n>{{ type }}</button>
+            }
           }
-        }
+          @if (suggestions?.suggested_correspondents.length > 0) {
+            <div class="list-group-item text-uppercase text-muted small">Correspondents</div>
+            @for (correspondent of suggestions.suggested_correspondents; track correspondent) {
+              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addCorrespondent.emit(correspondent)" i18n>{{ correspondent }}</button>
+            }
+          }
+        </div>
       </div>
     </div>
-  </div>
+  }
 </div>
index 6d202a1b163459dbe9fd5b7d9b24e4c6a2dd2cff..801a56af316d220398eef9a66b22afba9a776c9d 100644 (file)
@@ -38,6 +38,8 @@ describe('SuggestionsDropdownComponent', () => {
   })
 
   it('should toggle dropdown when clickSuggest is called and suggestions are not null', () => {
+    component.aiEnabled = true
+    fixture.detectChanges()
     component.suggestions = {
       suggested_correspondents: [],
       suggested_tags: [],
index 485c68627689d56a17eddef5e5390f26973c3a5d..b165f0a5e8d4dd7c5d118d6da0421f89b3893c2e 100644 (file)
@@ -24,6 +24,9 @@ export class SuggestionsDropdownComponent {
   @Input()
   suggestions: DocumentSuggestions = null
 
+  @Input()
+  aiEnabled: boolean = false
+
   @Input()
   loading: boolean = false
 
@@ -47,7 +50,7 @@ export class SuggestionsDropdownComponent {
     if (!this.suggestions) {
       this.getSuggestions.emit(this)
     } else {
-      this.dropdown.toggle()
+      this.dropdown?.toggle()
     }
   }
 
index 1843a56d9ce83bbec3042ab9f7e4aa3e9b5d30df..e15966b58831f4de0099015baa48c3f20368fd80 100644 (file)
               [disabled]="!userCanEdit || suggestionsLoading"
               [loading]="suggestionsLoading"
               [suggestions]="suggestions"
+              [aiEnabled]="aiEnabled"
               (getSuggestions)="getSuggestions()"
               (addTag)="createTag($event)"
               (addDocumentType)="createDocumentType($event)"
index 32963aa5cd62a12fcaf7a5f25d9ded4062f93e0d..337cba668217049d33bc068418cac03f7b8e37b6 100644 (file)
@@ -294,6 +294,10 @@ export class DocumentDetailComponent
     return this.settings.get(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER)
   }
 
+  get aiEnabled(): boolean {
+    return this.settings.get(SETTINGS_KEYS.AI_ENABLED)
+  }
+
   get archiveContentRenderType(): ContentRenderType {
     return this.document?.archived_file_name
       ? this.getRenderType('application/pdf')
index e3cdeabae967739aa49ff0e375b138f80b6d0103..f8c090effbd415bdd8f31f50f0b9bee3fde571bd 100644 (file)
@@ -74,6 +74,7 @@ export const SETTINGS_KEYS = {
   GMAIL_OAUTH_URL: 'gmail_oauth_url',
   OUTLOOK_OAUTH_URL: 'outlook_oauth_url',
   EMAIL_ENABLED: 'email_enabled',
+  AI_ENABLED: 'ai_enabled',
 }
 
 export const SETTINGS: UiSetting[] = [
@@ -282,4 +283,9 @@ export const SETTINGS: UiSetting[] = [
     type: 'string',
     default: 'page-width', // ZoomSetting from 'document-detail.component'
   },
+  {
+    key: SETTINGS_KEYS.AI_ENABLED,
+    type: 'boolean',
+    default: false,
+  },
 ]
index 26c6f17ae5d957012f9ae753cb2961e8f2b70f78..c733315e6a7c09b08949ca4f50379156c9450f12 100644 (file)
@@ -49,6 +49,7 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase):
                     "backend_setting": "default",
                 },
                 "email_enabled": False,
+                "ai_enabled": False,
             },
         )
 
index d2bf03f0c2513a42833b6cc084c8d57f1c31e29a..ff721512d2bacec990be2d7dd1bcb782c6e95bca 100644 (file)
@@ -2279,6 +2279,7 @@ class UiSettingsView(GenericAPIView):
                 request.session["oauth_state"] = manager.state
 
         ui_settings["email_enabled"] = settings.EMAIL_ENABLED
+        ui_settings["ai_enabled"] = settings.AI_ENABLED
 
         user_resp = {
             "id": user.id,