Prettier code cleanup for .ts files

See #182
This commit is contained in:
Michael Shamoon
2022-03-11 10:53:32 -08:00
parent d56c9dc94b
commit bd4a705769
159 changed files with 3882 additions and 2716 deletions

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog.component';
import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog.component'
describe('CorrespondentEditDialogComponent', () => {
let component: CorrespondentEditDialogComponent;
let fixture: ComponentFixture<CorrespondentEditDialogComponent>;
let component: CorrespondentEditDialogComponent
let fixture: ComponentFixture<CorrespondentEditDialogComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CorrespondentEditDialogComponent ]
})
.compileComponents();
});
declarations: [CorrespondentEditDialogComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(CorrespondentEditDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(CorrespondentEditDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,19 +1,22 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component';
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
import { CorrespondentService } from 'src/app/services/rest/correspondent.service';
import { ToastService } from 'src/app/services/toast.service';
import { Component } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { ToastService } from 'src/app/services/toast.service'
@Component({
selector: 'app-correspondent-edit-dialog',
templateUrl: './correspondent-edit-dialog.component.html',
styleUrls: ['./correspondent-edit-dialog.component.scss']
styleUrls: ['./correspondent-edit-dialog.component.scss'],
})
export class CorrespondentEditDialogComponent extends EditDialogComponent<PaperlessCorrespondent> {
constructor(service: CorrespondentService, activeModal: NgbActiveModal, toastService: ToastService) {
constructor(
service: CorrespondentService,
activeModal: NgbActiveModal,
toastService: ToastService
) {
super(service, activeModal, toastService)
}
@@ -29,9 +32,8 @@ export class CorrespondentEditDialogComponent extends EditDialogComponent<Paperl
return new FormGroup({
name: new FormControl(''),
matching_algorithm: new FormControl(1),
match: new FormControl(""),
is_insensitive: new FormControl(true)
match: new FormControl(''),
is_insensitive: new FormControl(true),
})
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { CorrespondentListComponent } from './correspondent-list.component';
import { CorrespondentListComponent } from './correspondent-list.component'
describe('CorrespondentListComponent', () => {
let component: CorrespondentListComponent;
let fixture: ComponentFixture<CorrespondentListComponent>;
let component: CorrespondentListComponent
let fixture: ComponentFixture<CorrespondentListComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CorrespondentListComponent ]
})
.compileComponents();
});
declarations: [CorrespondentListComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(CorrespondentListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(CorrespondentListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,25 +1,31 @@
import { Component } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type';
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { CorrespondentService } from 'src/app/services/rest/correspondent.service';
import { ToastService } from 'src/app/services/toast.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog/correspondent-edit-dialog.component';
import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type'
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { ToastService } from 'src/app/services/toast.service'
import { GenericListComponent } from '../generic-list/generic-list.component'
import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog/correspondent-edit-dialog.component'
@Component({
selector: 'app-correspondent-list',
templateUrl: './correspondent-list.component.html',
styleUrls: ['./correspondent-list.component.scss']
styleUrls: ['./correspondent-list.component.scss'],
})
export class CorrespondentListComponent extends GenericListComponent<PaperlessCorrespondent> {
constructor(correspondentsService: CorrespondentService, modalService: NgbModal,
constructor(
correspondentsService: CorrespondentService,
modalService: NgbModal,
private list: DocumentListViewService,
toastService: ToastService
) {
super(correspondentsService,modalService,CorrespondentEditDialogComponent, toastService)
super(
correspondentsService,
modalService,
CorrespondentEditDialogComponent,
toastService
)
}
getDeleteMessage(object: PaperlessCorrespondent) {
@@ -27,6 +33,8 @@ export class CorrespondentListComponent extends GenericListComponent<PaperlessCo
}
filterDocuments(object: PaperlessCorrespondent) {
this.list.quickFilter([{rule_type: FILTER_CORRESPONDENT, value: object.id.toString()}])
this.list.quickFilter([
{ rule_type: FILTER_CORRESPONDENT, value: object.id.toString() },
])
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog.component';
import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog.component'
describe('DocumentTypeEditDialogComponent', () => {
let component: DocumentTypeEditDialogComponent;
let fixture: ComponentFixture<DocumentTypeEditDialogComponent>;
let component: DocumentTypeEditDialogComponent
let fixture: ComponentFixture<DocumentTypeEditDialogComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DocumentTypeEditDialogComponent ]
})
.compileComponents();
});
declarations: [DocumentTypeEditDialogComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(DocumentTypeEditDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(DocumentTypeEditDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,19 +1,22 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component';
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
import { DocumentTypeService } from 'src/app/services/rest/document-type.service';
import { ToastService } from 'src/app/services/toast.service';
import { Component } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
import { ToastService } from 'src/app/services/toast.service'
@Component({
selector: 'app-document-type-edit-dialog',
templateUrl: './document-type-edit-dialog.component.html',
styleUrls: ['./document-type-edit-dialog.component.scss']
styleUrls: ['./document-type-edit-dialog.component.scss'],
})
export class DocumentTypeEditDialogComponent extends EditDialogComponent<PaperlessDocumentType> {
constructor(service: DocumentTypeService, activeModal: NgbActiveModal, toastService: ToastService) {
constructor(
service: DocumentTypeService,
activeModal: NgbActiveModal,
toastService: ToastService
) {
super(service, activeModal, toastService)
}
@@ -29,9 +32,8 @@ export class DocumentTypeEditDialogComponent extends EditDialogComponent<Paperle
return new FormGroup({
name: new FormControl(''),
matching_algorithm: new FormControl(1),
match: new FormControl(""),
is_insensitive: new FormControl(true)
match: new FormControl(''),
is_insensitive: new FormControl(true),
})
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { DocumentTypeListComponent } from './document-type-list.component';
import { DocumentTypeListComponent } from './document-type-list.component'
describe('DocumentTypeListComponent', () => {
let component: DocumentTypeListComponent;
let fixture: ComponentFixture<DocumentTypeListComponent>;
let component: DocumentTypeListComponent
let fixture: ComponentFixture<DocumentTypeListComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DocumentTypeListComponent ]
})
.compileComponents();
});
declarations: [DocumentTypeListComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(DocumentTypeListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(DocumentTypeListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,21 +1,22 @@
import { Component } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { FILTER_DOCUMENT_TYPE } from 'src/app/data/filter-rule-type';
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { DocumentTypeService } from 'src/app/services/rest/document-type.service';
import { ToastService } from 'src/app/services/toast.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog/document-type-edit-dialog.component';
import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_DOCUMENT_TYPE } from 'src/app/data/filter-rule-type'
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
import { ToastService } from 'src/app/services/toast.service'
import { GenericListComponent } from '../generic-list/generic-list.component'
import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog/document-type-edit-dialog.component'
@Component({
selector: 'app-document-type-list',
templateUrl: './document-type-list.component.html',
styleUrls: ['./document-type-list.component.scss']
styleUrls: ['./document-type-list.component.scss'],
})
export class DocumentTypeListComponent extends GenericListComponent<PaperlessDocumentType> {
constructor(service: DocumentTypeService, modalService: NgbModal,
constructor(
service: DocumentTypeService,
modalService: NgbModal,
private list: DocumentListViewService,
toastService: ToastService
) {
@@ -26,8 +27,9 @@ export class DocumentTypeListComponent extends GenericListComponent<PaperlessDoc
return $localize`Do you really want to delete the document type "${object.name}"?`
}
filterDocuments(object: PaperlessDocumentType) {
this.list.quickFilter([{rule_type: FILTER_DOCUMENT_TYPE, value: object.id.toString()}])
this.list.quickFilter([
{ rule_type: FILTER_DOCUMENT_TYPE, value: object.id.toString() },
])
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { GenericListComponent } from './generic-list.component';
import { GenericListComponent } from './generic-list.component'
describe('GenericListComponent', () => {
let component: GenericListComponent;
let fixture: ComponentFixture<GenericListComponent>;
let component: GenericListComponent
let fixture: ComponentFixture<GenericListComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ GenericListComponent ]
})
.compileComponents();
});
declarations: [GenericListComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(GenericListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(GenericListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,25 +1,39 @@
import { Directive, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
import { MatchingModel, MATCHING_ALGORITHMS, MATCH_AUTO } from 'src/app/data/matching-model';
import { ObjectWithId } from 'src/app/data/object-with-id';
import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive';
import { AbstractNameFilterService } from 'src/app/services/rest/abstract-name-filter-service';
import { ToastService } from 'src/app/services/toast.service';
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component';
import {
Directive,
OnDestroy,
OnInit,
QueryList,
ViewChildren,
} from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { Subject, Subscription } from 'rxjs'
import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
import {
MatchingModel,
MATCHING_ALGORITHMS,
MATCH_AUTO,
} from 'src/app/data/matching-model'
import { ObjectWithId } from 'src/app/data/object-with-id'
import {
SortableDirective,
SortEvent,
} from 'src/app/directives/sortable.directive'
import { AbstractNameFilterService } from 'src/app/services/rest/abstract-name-filter-service'
import { ToastService } from 'src/app/services/toast.service'
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
@Directive()
export abstract class GenericListComponent<T extends ObjectWithId> implements OnInit, OnDestroy {
export abstract class GenericListComponent<T extends ObjectWithId>
implements OnInit, OnDestroy
{
constructor(
private service: AbstractNameFilterService<T>,
private modalService: NgbModal,
private editDialogComponent: any,
private toastService: ToastService) {
}
private toastService: ToastService
) {}
@ViewChildren(SortableDirective) headers: QueryList<SortableDirective>;
@ViewChildren(SortableDirective) headers: QueryList<SortableDirective>
public data: T[] = []
@@ -38,9 +52,11 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
if (o.matching_algorithm == MATCH_AUTO) {
return $localize`Automatic`
} else if (o.match && o.match.length > 0) {
return `${MATCHING_ALGORITHMS.find(a => a.id == o.matching_algorithm).shortName}: ${o.match}`
return `${
MATCHING_ALGORITHMS.find((a) => a.id == o.matching_algorithm).shortName
}: ${o.match}`
} else {
return "-"
return '-'
}
}
@@ -50,20 +66,18 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
this.reloadData()
}
ngOnInit(): void {
this.reloadData()
this.nameFilterDebounce = new Subject<string>()
this.subscription = this.nameFilterDebounce.pipe(
debounceTime(400),
distinctUntilChanged()
).subscribe(title => {
this._nameFilter = title
this.page = 1
this.reloadData()
})
this.subscription = this.nameFilterDebounce
.pipe(debounceTime(400), distinctUntilChanged())
.subscribe((title) => {
this._nameFilter = title
this.page = 1
this.reloadData()
})
}
ngOnDestroy() {
@@ -71,25 +85,37 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
}
reloadData() {
this.service.listFiltered(this.page, null, this.sortField, this.sortReverse, this._nameFilter).subscribe(c => {
this.data = c.results
this.collectionSize = c.count
});
this.service
.listFiltered(
this.page,
null,
this.sortField,
this.sortReverse,
this._nameFilter
)
.subscribe((c) => {
this.data = c.results
this.collectionSize = c.count
})
}
openCreateDialog() {
var activeModal = this.modalService.open(this.editDialogComponent, {backdrop: 'static'})
var activeModal = this.modalService.open(this.editDialogComponent, {
backdrop: 'static',
})
activeModal.componentInstance.dialogMode = 'create'
activeModal.componentInstance.success.subscribe(o => {
activeModal.componentInstance.success.subscribe((o) => {
this.reloadData()
})
}
openEditDialog(object: T) {
var activeModal = this.modalService.open(this.editDialogComponent, {backdrop: 'static'})
var activeModal = this.modalService.open(this.editDialogComponent, {
backdrop: 'static',
})
activeModal.componentInstance.object = object
activeModal.componentInstance.dialogMode = 'edit'
activeModal.componentInstance.success.subscribe(o => {
activeModal.componentInstance.success.subscribe((o) => {
this.reloadData()
})
}
@@ -99,23 +125,31 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
}
openDeleteDialog(object: T) {
var activeModal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
var activeModal = this.modalService.open(ConfirmDialogComponent, {
backdrop: 'static',
})
activeModal.componentInstance.title = $localize`Confirm delete`
activeModal.componentInstance.messageBold = this.getDeleteMessage(object)
activeModal.componentInstance.message = $localize`Associated documents will not be deleted.`
activeModal.componentInstance.btnClass = "btn-danger"
activeModal.componentInstance.btnClass = 'btn-danger'
activeModal.componentInstance.btnCaption = $localize`Delete`
activeModal.componentInstance.confirmClicked.subscribe(() => {
activeModal.componentInstance.buttonsEnabled = false
this.service.delete(object).subscribe(_ => {
activeModal.close()
this.reloadData()
}, error => {
activeModal.componentInstance.buttonsEnabled = true
this.toastService.showError($localize`Error while deleting element: ${JSON.stringify(error.error)}`)
})
}
)
this.service.delete(object).subscribe(
(_) => {
activeModal.close()
this.reloadData()
},
(error) => {
activeModal.componentInstance.buttonsEnabled = true
this.toastService.showError(
$localize`Error while deleting element: ${JSON.stringify(
error.error
)}`
)
}
)
})
}
get nameFilter() {
@@ -125,7 +159,7 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
set nameFilter(nameFilter: string) {
this.nameFilterDebounce.next(nameFilter)
}
onNameFilterKeyUp(event: KeyboardEvent) {
if (event.code == 'Escape') this.nameFilterDebounce.next(null)
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { LogsComponent } from './logs.component';
import { LogsComponent } from './logs.component'
describe('LogsComponent', () => {
let component: LogsComponent;
let fixture: ComponentFixture<LogsComponent>;
let component: LogsComponent
let fixture: ComponentFixture<LogsComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ LogsComponent ]
})
.compileComponents();
});
declarations: [LogsComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(LogsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(LogsComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,14 +1,19 @@
import { Component, ElementRef, OnInit, AfterViewChecked, ViewChild } from '@angular/core';
import { LogService } from 'src/app/services/rest/log.service';
import {
Component,
ElementRef,
OnInit,
AfterViewChecked,
ViewChild,
} from '@angular/core'
import { LogService } from 'src/app/services/rest/log.service'
@Component({
selector: 'app-logs',
templateUrl: './logs.component.html',
styleUrls: ['./logs.component.scss']
styleUrls: ['./logs.component.scss'],
})
export class LogsComponent implements OnInit, AfterViewChecked {
constructor(private logService: LogService) { }
constructor(private logService: LogService) {}
logs: string[] = []
@@ -19,7 +24,7 @@ export class LogsComponent implements OnInit, AfterViewChecked {
@ViewChild('logContainer') logContainer: ElementRef
ngOnInit(): void {
this.logService.list().subscribe(result => {
this.logService.list().subscribe((result) => {
this.logFiles = result
if (this.logFiles.length > 0) {
this.activeLog = this.logFiles[0]
@@ -29,25 +34,28 @@ export class LogsComponent implements OnInit, AfterViewChecked {
}
ngAfterViewChecked() {
this.scrollToBottom();
this.scrollToBottom()
}
reloadLogs() {
this.logService.get(this.activeLog).subscribe(result => {
this.logs = result
}, error => {
this.logs = []
})
this.logService.get(this.activeLog).subscribe(
(result) => {
this.logs = result
},
(error) => {
this.logs = []
}
)
}
getLogLevel(log: string) {
if (log.indexOf("[DEBUG]") != -1) {
if (log.indexOf('[DEBUG]') != -1) {
return 10
} else if (log.indexOf("[WARNING]") != -1) {
} else if (log.indexOf('[WARNING]') != -1) {
return 30
} else if (log.indexOf("[ERROR]") != -1) {
} else if (log.indexOf('[ERROR]') != -1) {
return 40
} else if (log.indexOf("[CRITICAL]") != -1) {
} else if (log.indexOf('[CRITICAL]') != -1) {
return 50
} else {
return 20
@@ -58,8 +66,7 @@ export class LogsComponent implements OnInit, AfterViewChecked {
this.logContainer?.nativeElement.scroll({
top: this.logContainer.nativeElement.scrollHeight,
left: 0,
behavior: 'auto'
});
behavior: 'auto',
})
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { SettingsComponent } from './settings.component';
import { SettingsComponent } from './settings.component'
describe('SettingsComponent', () => {
let component: SettingsComponent;
let fixture: ComponentFixture<SettingsComponent>;
let component: SettingsComponent
let fixture: ComponentFixture<SettingsComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SettingsComponent ]
})
.compileComponents();
});
declarations: [SettingsComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(SettingsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(SettingsComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,39 +1,49 @@
import { Component, Inject, LOCALE_ID, OnInit, OnDestroy, Renderer2 } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
import { LanguageOption, SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
import { ToastService } from 'src/app/services/toast.service';
import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms';
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
import {
Component,
Inject,
LOCALE_ID,
OnInit,
OnDestroy,
Renderer2,
} from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import {
LanguageOption,
SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service'
import { ToastService } from 'src/app/services/toast.service'
import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms'
import { Observable, Subscription, BehaviorSubject } from 'rxjs'
@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.scss']
styleUrls: ['./settings.component.scss'],
})
export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
savedViewGroup = new FormGroup({})
settingsForm = new FormGroup({
'bulkEditConfirmationDialogs': new FormControl(null),
'bulkEditApplyOnClose': new FormControl(null),
'documentListItemPerPage': new FormControl(null),
'darkModeUseSystem': new FormControl(null),
'darkModeEnabled': new FormControl(null),
'darkModeInvertThumbs': new FormControl(null),
'themeColor': new FormControl(null),
'useNativePdfViewer': new FormControl(null),
'savedViews': this.savedViewGroup,
'displayLanguage': new FormControl(null),
'dateLocale': new FormControl(null),
'dateFormat': new FormControl(null),
'notificationsConsumerNewDocument': new FormControl(null),
'notificationsConsumerSuccess': new FormControl(null),
'notificationsConsumerFailed': new FormControl(null),
'notificationsConsumerSuppressOnDashboard': new FormControl(null),
bulkEditConfirmationDialogs: new FormControl(null),
bulkEditApplyOnClose: new FormControl(null),
documentListItemPerPage: new FormControl(null),
darkModeUseSystem: new FormControl(null),
darkModeEnabled: new FormControl(null),
darkModeInvertThumbs: new FormControl(null),
themeColor: new FormControl(null),
useNativePdfViewer: new FormControl(null),
savedViews: this.savedViewGroup,
displayLanguage: new FormControl(null),
dateLocale: new FormControl(null),
dateFormat: new FormControl(null),
notificationsConsumerNewDocument: new FormControl(null),
notificationsConsumerSuccess: new FormControl(null),
notificationsConsumerFailed: new FormControl(null),
notificationsConsumerSuppressOnDashboard: new FormControl(null),
})
savedViews: PaperlessSavedView[]
@@ -44,7 +54,11 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
isDirty: Boolean = false
get computedDateLocale(): string {
return this.settingsForm.value.dateLocale || this.settingsForm.value.displayLanguage || this.currentLocale
return (
this.settingsForm.value.dateLocale ||
this.settingsForm.value.displayLanguage ||
this.currentLocale
)
}
constructor(
@@ -53,48 +67,71 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
private toastService: ToastService,
private settings: SettingsService,
@Inject(LOCALE_ID) public currentLocale: string
) { }
) {}
ngOnInit() {
this.savedViewService.listAll().subscribe(r => {
this.savedViewService.listAll().subscribe((r) => {
this.savedViews = r.results
let storeData = {
'bulkEditConfirmationDialogs': this.settings.get(SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS),
'bulkEditApplyOnClose': this.settings.get(SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE),
'documentListItemPerPage': this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE),
'darkModeUseSystem': this.settings.get(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM),
'darkModeEnabled': this.settings.get(SETTINGS_KEYS.DARK_MODE_ENABLED),
'darkModeInvertThumbs': this.settings.get(SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED),
'themeColor': this.settings.get(SETTINGS_KEYS.THEME_COLOR),
'useNativePdfViewer': this.settings.get(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER),
'savedViews': {},
'displayLanguage': this.settings.getLanguage(),
'dateLocale': this.settings.get(SETTINGS_KEYS.DATE_LOCALE),
'dateFormat': this.settings.get(SETTINGS_KEYS.DATE_FORMAT),
'notificationsConsumerNewDocument': this.settings.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT),
'notificationsConsumerSuccess': this.settings.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS),
'notificationsConsumerFailed': this.settings.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED),
'notificationsConsumerSuppressOnDashboard': this.settings.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD),
bulkEditConfirmationDialogs: this.settings.get(
SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS
),
bulkEditApplyOnClose: this.settings.get(
SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE
),
documentListItemPerPage: this.settings.get(
SETTINGS_KEYS.DOCUMENT_LIST_SIZE
),
darkModeUseSystem: this.settings.get(
SETTINGS_KEYS.DARK_MODE_USE_SYSTEM
),
darkModeEnabled: this.settings.get(SETTINGS_KEYS.DARK_MODE_ENABLED),
darkModeInvertThumbs: this.settings.get(
SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED
),
themeColor: this.settings.get(SETTINGS_KEYS.THEME_COLOR),
useNativePdfViewer: this.settings.get(
SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER
),
savedViews: {},
displayLanguage: this.settings.getLanguage(),
dateLocale: this.settings.get(SETTINGS_KEYS.DATE_LOCALE),
dateFormat: this.settings.get(SETTINGS_KEYS.DATE_FORMAT),
notificationsConsumerNewDocument: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT
),
notificationsConsumerSuccess: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS
),
notificationsConsumerFailed: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED
),
notificationsConsumerSuppressOnDashboard: this.settings.get(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD
),
}
for (let view of this.savedViews) {
storeData.savedViews[view.id.toString()] = {
"id": view.id,
"name": view.name,
"show_on_dashboard": view.show_on_dashboard,
"show_in_sidebar": view.show_in_sidebar
id: view.id,
name: view.name,
show_on_dashboard: view.show_on_dashboard,
show_in_sidebar: view.show_in_sidebar,
}
this.savedViewGroup.addControl(view.id.toString(), new FormGroup({
"id": new FormControl(null),
"name": new FormControl(null),
"show_on_dashboard": new FormControl(null),
"show_in_sidebar": new FormControl(null)
}))
this.savedViewGroup.addControl(
view.id.toString(),
new FormGroup({
id: new FormControl(null),
name: new FormControl(null),
show_on_dashboard: new FormControl(null),
show_in_sidebar: new FormControl(null),
})
)
}
this.store = new BehaviorSubject(storeData)
this.storeSub = this.store.asObservable().subscribe(state => {
this.storeSub = this.store.asObservable().subscribe((state) => {
this.settingsForm.patchValue(state, { emitEvent: false })
})
@@ -102,45 +139,93 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
this.isDirty$ = dirtyCheck(this.settingsForm, this.store.asObservable())
// Record dirty in case we need to 'undo' appearance settings if not saved on close
this.isDirty$.subscribe(dirty => {
this.isDirty$.subscribe((dirty) => {
this.isDirty = dirty
})
// "Live" visual changes prior to save
this.settingsForm.valueChanges.subscribe(() => {
this.settings.updateAppearanceSettings(this.settingsForm.get('darkModeUseSystem').value, this.settingsForm.get('darkModeEnabled').value, this.settingsForm.get('themeColor').value)
this.settings.updateAppearanceSettings(
this.settingsForm.get('darkModeUseSystem').value,
this.settingsForm.get('darkModeEnabled').value,
this.settingsForm.get('themeColor').value
)
})
})
}
ngOnDestroy() {
if (this.isDirty) this.settings.updateAppearanceSettings() // in case user changed appearance but didnt save
this.storeSub && this.storeSub.unsubscribe();
this.storeSub && this.storeSub.unsubscribe()
}
deleteSavedView(savedView: PaperlessSavedView) {
this.savedViewService.delete(savedView).subscribe(() => {
this.savedViewGroup.removeControl(savedView.id.toString())
this.savedViews.splice(this.savedViews.indexOf(savedView), 1)
this.toastService.showInfo($localize`Saved view "${savedView.name}" deleted.`)
this.toastService.showInfo(
$localize`Saved view "${savedView.name}" deleted.`
)
})
}
private saveLocalSettings() {
this.settings.set(SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE, this.settingsForm.value.bulkEditApplyOnClose)
this.settings.set(SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS, this.settingsForm.value.bulkEditConfirmationDialogs)
this.settings.set(SETTINGS_KEYS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
this.settings.set(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM, this.settingsForm.value.darkModeUseSystem)
this.settings.set(SETTINGS_KEYS.DARK_MODE_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString())
this.settings.set(SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED, (this.settingsForm.value.darkModeInvertThumbs == true).toString())
this.settings.set(SETTINGS_KEYS.THEME_COLOR, (this.settingsForm.value.themeColor).toString())
this.settings.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, this.settingsForm.value.useNativePdfViewer)
this.settings.set(SETTINGS_KEYS.DATE_LOCALE, this.settingsForm.value.dateLocale)
this.settings.set(SETTINGS_KEYS.DATE_FORMAT, this.settingsForm.value.dateFormat)
this.settings.set(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT, this.settingsForm.value.notificationsConsumerNewDocument)
this.settings.set(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS, this.settingsForm.value.notificationsConsumerSuccess)
this.settings.set(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED, this.settingsForm.value.notificationsConsumerFailed)
this.settings.set(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD, this.settingsForm.value.notificationsConsumerSuppressOnDashboard)
this.settings.set(
SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE,
this.settingsForm.value.bulkEditApplyOnClose
)
this.settings.set(
SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS,
this.settingsForm.value.bulkEditConfirmationDialogs
)
this.settings.set(
SETTINGS_KEYS.DOCUMENT_LIST_SIZE,
this.settingsForm.value.documentListItemPerPage
)
this.settings.set(
SETTINGS_KEYS.DARK_MODE_USE_SYSTEM,
this.settingsForm.value.darkModeUseSystem
)
this.settings.set(
SETTINGS_KEYS.DARK_MODE_ENABLED,
(this.settingsForm.value.darkModeEnabled == true).toString()
)
this.settings.set(
SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED,
(this.settingsForm.value.darkModeInvertThumbs == true).toString()
)
this.settings.set(
SETTINGS_KEYS.THEME_COLOR,
this.settingsForm.value.themeColor.toString()
)
this.settings.set(
SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER,
this.settingsForm.value.useNativePdfViewer
)
this.settings.set(
SETTINGS_KEYS.DATE_LOCALE,
this.settingsForm.value.dateLocale
)
this.settings.set(
SETTINGS_KEYS.DATE_FORMAT,
this.settingsForm.value.dateFormat
)
this.settings.set(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT,
this.settingsForm.value.notificationsConsumerNewDocument
)
this.settings.set(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS,
this.settingsForm.value.notificationsConsumerSuccess
)
this.settings.set(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED,
this.settingsForm.value.notificationsConsumerFailed
)
this.settings.set(
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD,
this.settingsForm.value.notificationsConsumerSuppressOnDashboard
)
this.settings.setLanguage(this.settingsForm.value.displayLanguage)
this.store.next(this.settingsForm.value)
this.documentListViewService.updatePageSize()
@@ -149,14 +234,14 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
}
get displayLanguageOptions(): LanguageOption[] {
return [
{code: "", name: $localize`Use system language`}
].concat(this.settings.getLanguageOptions())
return [{ code: '', name: $localize`Use system language` }].concat(
this.settings.getLanguageOptions()
)
}
get dateLocaleOptions(): LanguageOption[] {
return [
{code: "", name: $localize`Use date format of display language`}
{ code: '', name: $localize`Use date format of display language` },
].concat(this.settings.getDateLocaleOptions())
}
@@ -170,18 +255,24 @@ export class SettingsComponent implements OnInit, OnDestroy, DirtyComponent {
x.push(this.savedViewGroup.value[id])
}
if (x.length > 0) {
this.savedViewService.patchMany(x).subscribe(s => {
this.saveLocalSettings()
}, error => {
this.toastService.showError($localize`Error while storing settings on server: ${JSON.stringify(error.error)}`)
})
this.savedViewService.patchMany(x).subscribe(
(s) => {
this.saveLocalSettings()
},
(error) => {
this.toastService.showError(
$localize`Error while storing settings on server: ${JSON.stringify(
error.error
)}`
)
}
)
} else {
this.saveLocalSettings()
}
}
clearThemeColor() {
this.settingsForm.get('themeColor').patchValue('');
this.settingsForm.get('themeColor').patchValue('')
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TagEditDialogComponent } from './tag-edit-dialog.component';
import { TagEditDialogComponent } from './tag-edit-dialog.component'
describe('TagEditDialogComponent', () => {
let component: TagEditDialogComponent;
let fixture: ComponentFixture<TagEditDialogComponent>;
let component: TagEditDialogComponent
let fixture: ComponentFixture<TagEditDialogComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TagEditDialogComponent ]
})
.compileComponents();
});
declarations: [TagEditDialogComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(TagEditDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(TagEditDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,20 +1,23 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component';
import { PaperlessTag } from 'src/app/data/paperless-tag';
import { TagService } from 'src/app/services/rest/tag.service';
import { ToastService } from 'src/app/services/toast.service';
import { randomColor } from 'src/app/utils/color';
import { Component } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
import { PaperlessTag } from 'src/app/data/paperless-tag'
import { TagService } from 'src/app/services/rest/tag.service'
import { ToastService } from 'src/app/services/toast.service'
import { randomColor } from 'src/app/utils/color'
@Component({
selector: 'app-tag-edit-dialog',
templateUrl: './tag-edit-dialog.component.html',
styleUrls: ['./tag-edit-dialog.component.scss']
styleUrls: ['./tag-edit-dialog.component.scss'],
})
export class TagEditDialogComponent extends EditDialogComponent<PaperlessTag> {
constructor(service: TagService, activeModal: NgbActiveModal, toastService: ToastService) {
constructor(
service: TagService,
activeModal: NgbActiveModal,
toastService: ToastService
) {
super(service, activeModal, toastService)
}
@@ -32,9 +35,8 @@ export class TagEditDialogComponent extends EditDialogComponent<PaperlessTag> {
color: new FormControl(randomColor()),
is_inbox_tag: new FormControl(false),
matching_algorithm: new FormControl(1),
match: new FormControl(""),
is_insensitive: new FormControl(true)
match: new FormControl(''),
is_insensitive: new FormControl(true),
})
}
}

View File

@@ -1,25 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TagListComponent } from './tag-list.component';
import { TagListComponent } from './tag-list.component'
describe('TagListComponent', () => {
let component: TagListComponent;
let fixture: ComponentFixture<TagListComponent>;
let component: TagListComponent
let fixture: ComponentFixture<TagListComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TagListComponent ]
})
.compileComponents();
});
declarations: [TagListComponent],
}).compileComponents()
})
beforeEach(() => {
fixture = TestBed.createComponent(TagListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(TagListComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,21 +1,22 @@
import { Component } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type';
import { PaperlessTag } from 'src/app/data/paperless-tag';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { TagService } from 'src/app/services/rest/tag.service';
import { ToastService } from 'src/app/services/toast.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { TagEditDialogComponent } from './tag-edit-dialog/tag-edit-dialog.component';
import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type'
import { PaperlessTag } from 'src/app/data/paperless-tag'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { TagService } from 'src/app/services/rest/tag.service'
import { ToastService } from 'src/app/services/toast.service'
import { GenericListComponent } from '../generic-list/generic-list.component'
import { TagEditDialogComponent } from './tag-edit-dialog/tag-edit-dialog.component'
@Component({
selector: 'app-tag-list',
templateUrl: './tag-list.component.html',
styleUrls: ['./tag-list.component.scss']
styleUrls: ['./tag-list.component.scss'],
})
export class TagListComponent extends GenericListComponent<PaperlessTag> {
constructor(tagService: TagService, modalService: NgbModal,
constructor(
tagService: TagService,
modalService: NgbModal,
private list: DocumentListViewService,
toastService: ToastService
) {
@@ -27,7 +28,8 @@ export class TagListComponent extends GenericListComponent<PaperlessTag> {
}
filterDocuments(object: PaperlessTag) {
this.list.quickFilter([{rule_type: FILTER_HAS_TAGS_ALL, value: object.id.toString()}])
this.list.quickFilter([
{ rule_type: FILTER_HAS_TAGS_ALL, value: object.id.toString() },
])
}
}