1 import {Pager} from '@eg/share/util/pager';
2 import {Component, ViewChild, OnInit} from '@angular/core';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {GridDataSource} from '@eg/share/grid/grid';
5 import {GridComponent} from '@eg/share/grid/grid.component';
6 import {ToastService} from '@eg/share/toast/toast.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';
12 templateUrl: './coded-value-maps.component.html'
15 export class CodedValueMapsComponent implements OnInit {
17 gridDataSource: GridDataSource = new GridDataSource();
18 @ViewChild('createString', { static: true }) createString: StringComponent;
19 @ViewChild('createErrString', { static: true }) createErrString: StringComponent;
20 @ViewChild('updateSuccessString', { static: true }) updateSuccessString: StringComponent;
21 @ViewChild('updateFailedString', { static: true }) updateFailedString: StringComponent;
22 @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent;
23 @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
25 @ViewChild('grid', {static: true}) grid: GridComponent;
26 @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
29 private pcrud: PcrudService,
30 private toast: ToastService,
35 this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
36 return this.pcrud.retrieveAll('ccvm', {order_by: {ccvm: 'id'}}, {fleshSelectors: true});
38 this.grid.onRowActivate.subscribe(
39 (idlThing: IdlObject) => this.showEditDialog(idlThing)
43 showEditDialog(standingPenalty: IdlObject): Promise<any> {
44 this.editDialog.mode = 'update';
45 this.editDialog.recordId = standingPenalty['id']();
46 return new Promise((resolve, reject) => {
47 this.editDialog.open({size: 'lg'}).subscribe(
49 this.updateSuccessString.current()
50 .then(str => this.toast.success(str));
55 this.updateFailedString.current()
56 .then(str => this.toast.danger(str));
63 editSelected = (maps: IdlObject[]) => {
64 const editOneThing = (map: IdlObject) => {
65 this.showEditDialog(map).then(
66 () => editOneThing(maps.shift()));
68 editOneThing(maps.shift());
71 deleteSelected = (idlThings: IdlObject[]) => {
72 idlThings.forEach(idlThing => idlThing.isdeleted(true));
73 this.pcrud.autoApply(idlThings).subscribe(
75 console.debug('deleted: ' + val);
76 this.deleteSuccessString.current()
77 .then(str => this.toast.success(str));
80 this.deleteFailedString.current()
81 .then(str => this.toast.danger(str));
83 () => this.grid.reload()
88 this.editDialog.mode = 'create';
89 this.editDialog.recordId = null;
90 this.editDialog.record = null;
91 this.editDialog.open({size: 'lg'}).subscribe(
93 this.createString.current()
94 .then(str => this.toast.success(str));
98 if (!rejection.dismissed) {
99 this.createErrString.current()
100 .then(str => this.toast.danger(str));