mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-09 16:25:33 +01:00
parent
f8c8161a3e
commit
f34202a82a
159 changed files with 3882 additions and 2716 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue