mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	Pass AI enabled to frontend
This commit is contained in:
		
							parent
							
								
									74aaf18630
								
							
						
					
					
						commit
						3186550fd7
					
				@ -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 {
 | 
			
		||||
@ -10,8 +10,9 @@
 | 
			
		||||
      <span class="badge bg-primary ms-2">{{ totalSuggestions }}</span>
 | 
			
		||||
    }
 | 
			
		||||
  </button>
 | 
			
		||||
  <div class="btn-group" ngbDropdown #dropdown="ngbDropdown" [popperOptions]="popperOptions">
 | 
			
		||||
 | 
			
		||||
  @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>
 | 
			
		||||
@ -23,19 +24,19 @@
 | 
			
		||||
              <small class="text-muted small fst-italic" i18n>No novel suggestions</small>
 | 
			
		||||
            </div>
 | 
			
		||||
          }
 | 
			
		||||
        @if (suggestions?.suggested_tags?.length > 0) {
 | 
			
		||||
          @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_document_types?.length > 0) {
 | 
			
		||||
          @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) {
 | 
			
		||||
          @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>
 | 
			
		||||
@ -44,4 +45,5 @@
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  }
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
@ -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: [],
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -115,6 +115,7 @@
 | 
			
		||||
              [disabled]="!userCanEdit || suggestionsLoading"
 | 
			
		||||
              [loading]="suggestionsLoading"
 | 
			
		||||
              [suggestions]="suggestions"
 | 
			
		||||
              [aiEnabled]="aiEnabled"
 | 
			
		||||
              (getSuggestions)="getSuggestions()"
 | 
			
		||||
              (addTag)="createTag($event)"
 | 
			
		||||
              (addDocumentType)="createDocumentType($event)"
 | 
			
		||||
 | 
			
		||||
@ -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')
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
  },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
@ -49,6 +49,7 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase):
 | 
			
		||||
                    "backend_setting": "default",
 | 
			
		||||
                },
 | 
			
		||||
                "email_enabled": False,
 | 
			
		||||
                "ai_enabled": False,
 | 
			
		||||
            },
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user