Use frontend settings instead of env variable

This commit is contained in:
Michael Shamoon
2022-08-07 15:05:58 -07:00
parent 278e9c12e1
commit 630a4d02e0
11 changed files with 63 additions and 126 deletions

View File

@@ -169,7 +169,7 @@
</div>
</ng-template>
</li>
<li [ngbNavItem]="5" *ngIf="isCommentsEnabled">
<li [ngbNavItem]="5" *ngIf="commentsEnabled">
<a ngbNavLink i18n>Comments</a>
<ng-template ngbNavContent>
<app-document-comment #commentComponent></app-document-comment>

View File

@@ -35,7 +35,6 @@ import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
import { EnvironmentService } from 'src/app/services/rest/environment.service'
@Component({
selector: 'app-document-detail',
@@ -84,8 +83,6 @@ export class DocumentDetailComponent
previewCurrentPage: number = 1
previewNumPages: number = 1
isCommentsEnabled:boolean = false
store: BehaviorSubject<any>
isDirty$: Observable<boolean>
unsubscribeNotifier: Subject<any> = new Subject()
@@ -121,8 +118,7 @@ export class DocumentDetailComponent
private documentTitlePipe: DocumentTitlePipe,
private toastService: ToastService,
private settings: SettingsService,
private storagePathService: StoragePathService,
private environment: EnvironmentService
private storagePathService: StoragePathService
) {}
titleKeyUp(event) {
@@ -278,12 +274,6 @@ export class DocumentDetailComponent
this.suggestions = null
},
})
this.environment.get("PAPERLESS_COMMENTS_ENABLED").subscribe(result => {
this.isCommentsEnabled = (result.value.toString().toLowerCase() === "true"?true:false);
}, error => {
this.isCommentsEnabled = false;
})
this.title = this.documentTitlePipe.transform(doc.title)
this.documentForm.patchValue(doc)
@@ -562,4 +552,8 @@ export class DocumentDetailComponent
this.password = (event.target as HTMLInputElement).value
}
}
get commentsEnabled(): boolean {
return this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED)
}
}

View File

@@ -125,6 +125,14 @@
</div>
</div>
<h4 class="mt-4" i18n>Comments</h4>
<div class="row mb-3">
<div class="offset-md-3 col">
<app-input-check i18n-title title="Enable comments" formControlName="commentsEnabled"></app-input-check>
</div>
</div>
</ng-template>
</li>

View File

@@ -44,6 +44,7 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
notificationsConsumerSuccess: new FormControl(null),
notificationsConsumerFailed: new FormControl(null),
notificationsConsumerSuppressOnDashboard: new FormControl(null),
commentsEnabled: new FormControl(null),
})
savedViews: PaperlessSavedView[]
@@ -116,6 +117,7 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
notificationsConsumerSuppressOnDashboard: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD
),
commentsEnabled: this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED),
}
for (let view of this.savedViews) {
@@ -234,6 +236,10 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD,
this.settingsForm.value.notificationsConsumerSuppressOnDashboard
)
this.settings.set(
SETTINGS_KEYS.COMMENTS_ENABLED,
this.settingsForm.value.commentsEnabled
)
this.settings.setLanguage(this.settingsForm.value.displayLanguage)
this.settings
.storeSettings()

View File

@@ -1,3 +0,0 @@
export interface PaperlessEnvironment {
value?: string;
}

View File

@@ -36,6 +36,7 @@ export const SETTINGS_KEYS = {
'general-settings:notifications:consumer-failed',
NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD:
'general-settings:notifications:consumer-suppress-on-dashboard',
COMMENTS_ENABLED: 'general-settings:comments-enabled',
}
export const SETTINGS: PaperlessUiSetting[] = [
@@ -114,4 +115,9 @@ export const SETTINGS: PaperlessUiSetting[] = [
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.COMMENTS_ENABLED,
type: 'boolean',
default: true,
},
]

View File

@@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { EnvironmentService } from './environment.service';
describe('EnvironmentService', () => {
let service: EnvironmentService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(EnvironmentService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -1,22 +0,0 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PaperlessEnvironment } from 'src/app/data/paperless-environment';
import { environment } from 'src/environments/environment'
@Injectable({
providedIn: 'root'
})
export class EnvironmentService {
protected baseUrl: string = environment.apiBaseUrl
constructor(protected http: HttpClient) { }
get(environment: string): Observable<PaperlessEnvironment> {
let httpParams = new HttpParams();
httpParams = httpParams.set('name', environment);
return this.http.get<PaperlessEnvironment>(`${this.baseUrl}environment/`, {params: httpParams})
}
}