1 import {Pager} from '@eg/share/util/pager';
2 import {Component, OnInit, Input, ViewChild} from '@angular/core';
3 import {GridComponent} from '@eg/share/grid/grid.component';
4 import {GridDataSource} from '@eg/share/grid/grid';
5 import {Router} from '@angular/router';
6 import {IdlObject} from '@eg/core/idl.service';
7 import {PcrudService} from '@eg/core/pcrud.service';
8 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
9 import {StringComponent} from '@eg/share/string/string.component';
10 import {ToastService} from '@eg/share/toast/toast.service';
13 templateUrl: './circ_limit_set.component.html'
16 export class CircLimitSetComponent implements OnInit {
19 gridDataSource: GridDataSource;
21 cspSource: GridDataSource = new GridDataSource();
23 @ViewChild('editDialog', {static: true}) editDialog: FmRecordEditorComponent;
24 @ViewChild('grid', {static: true}) grid: GridComponent;
25 @ViewChild('updateSuccessString', {static: true}) updateSuccessString: StringComponent;
26 @ViewChild('updateFailedString', {static: true}) updateFailedString: StringComponent;
27 @ViewChild('deleteFailedString', {static: true}) deleteFailedString: StringComponent;
28 @ViewChild('deleteSuccessString', {static: true}) deleteSuccessString: StringComponent;
29 @ViewChild('createSuccessString', {static: true}) createSuccessString: StringComponent;
30 @ViewChild('createErrString', {static: true}) createErrString: StringComponent;
32 @Input() dialogSize: 'sm' | 'lg' = 'lg';
35 private pcrud: PcrudService,
36 private toast: ToastService,
37 private router: Router
39 this.gridDataSource = new GridDataSource();
43 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
44 const orderBy: any = {};
50 return this.pcrud.retrieveAll('ccls', searchOps, {fleshSelectors: true});
53 this.grid.onRowActivate.subscribe(
55 const idToEdit = set.id();
56 this.navigateToEditPage(idToEdit);
61 deleteSelected = (idlThings: IdlObject[]) => {
62 idlThings.forEach(idlThing => idlThing.isdeleted(true));
63 this.pcrud.autoApply(idlThings).subscribe(
65 this.deleteSuccessString.current()
66 .then(str => this.toast.success(str));
69 this.deleteFailedString.current()
70 .then(str => this.toast.danger(str));
72 () => this.grid.reload()
76 editSelected(sets: IdlObject[]) {
77 const idToEdit = sets[0].id();
78 this.navigateToEditPage(idToEdit);
81 navigateToEditPage(id: any) {
82 this.router.navigate(['/staff/admin/local/config/circ_limit_set/' + id]);
86 this.editDialog.mode = 'create';
87 this.editDialog.recordId = null;
88 this.editDialog.record = null;
89 this.editDialog.open({size: this.dialogSize}).subscribe(
91 this.createSuccessString.current()
92 .then(str => this.toast.success(str));
96 if (!rejection.dismissed) {
97 this.createErrString.current()
98 .then(str => this.toast.danger(str));
104 showEditDialog(standingPenalty: IdlObject): Promise<any> {
105 this.editDialog.mode = 'update';
106 this.editDialog.recordId = standingPenalty['id']();
107 return new Promise((resolve, reject) => {
108 this.editDialog.open({size: this.dialogSize}).subscribe(
110 this.updateSuccessString.current()
111 .then(str => this.toast.success(str));
116 this.updateFailedString.current()
117 .then(str => this.toast.danger(str));