1
| -import {Component, ViewEncapsulation} from "@angular/core"; |
| |
2
| -import {GridOptions} from "ag-grid/main"; |
1
| +import { Component, ViewEncapsulation } from '@angular/core'; |
| |
2
| +import { TdLoadingService } from '@covalent/core'; |
| |
3
| +import { GridOptions } from 'ag-grid/main'; |
3
| |
4
| |
4
| import { BusStopService } from '../../../services/bus-stop.service'; |
5
| import { BusStopService } from '../../../services/bus-stop.service'; |
5
| import { BusStop } from '../../../models/bus-stop'; |
6
| import { BusStop } from '../../../models/bus-stop'; |
| @@ -21,10 +22,12 @@ import { SurfaceTypeSelectList } from '../../../models/surface-type-select-list' |
| @@ -21,10 +22,12 @@ import { SurfaceTypeSelectList } from '../../../models/surface-type-select-list' |
21
| selector: 'bus-grid', |
22
| selector: 'bus-grid', |
22
| templateUrl: 'bus-stop.component.html', |
23
| templateUrl: 'bus-stop.component.html', |
23
| styleUrls: ['bus-stop.scss'], |
24
| styleUrls: ['bus-stop.scss'], |
24
| - encapsulation: ViewEncapsulation.None |
25
| + encapsulation: ViewEncapsulation.None, |
25
| }) |
26
| }) |
26
| export class BusStopComponent { |
27
| export class BusStopComponent { |
27
| |
28
| |
| |
29
| + private columnDefs: any[]; |
| |
30
| + private gridOptions: GridOptions; |
28
| public showGrid: boolean; |
31
| public showGrid: boolean; |
29
| public rowData: any[]; |
32
| public rowData: any[]; |
30
| public rowCount: string; |
33
| public rowCount: string; |
| @@ -37,20 +40,19 @@ export class BusStopComponent { |
| @@ -37,20 +40,19 @@ export class BusStopComponent { |
37
| public isLoading: boolean = false; |
40
| public isLoading: boolean = false; |
38
| public isBootstrapping: boolean = true; |
41
| public isBootstrapping: boolean = true; |
39
| public isSelected: boolean = true; |
42
| public isSelected: boolean = true; |
40
| - private columnDefs: any[]; |
| |
41
| - private gridOptions: GridOptions; |
| |
42
| |
43
| |
43
| constructor( |
44
| constructor( |
44
| protected service: BusStopService, |
45
| protected service: BusStopService, |
45
| private dataService: BusStopCreateService, |
46
| private dataService: BusStopCreateService, |
46
| - private booleanService: BooleanSelectListService |
47
| + private booleanService: BooleanSelectListService, |
| |
48
| + private loadingService: TdLoadingService, |
47
| ) { |
49
| ) { |
48
| this.gridOptions = <GridOptions>{}; |
50
| this.gridOptions = <GridOptions>{}; |
49
| - this.gridOptions.enableSorting = true; |
| |
50
| - this.showGrid = true; |
| |
51
| - this.gridOptions.rowModelType = 'virtual'; |
| |
52
| - this.booleanService.getModels().then((models) => this.boolean = models); |
| |
53
| - this.dataService.getModels().then(models => { |
51
| + this.gridOptions.enableSorting = true; |
| |
52
| + this.showGrid = true; |
| |
53
| + this.gridOptions.rowModelType = 'virtual'; |
| |
54
| + this.booleanService.getModels().then((models) => this.boolean = models); |
| |
55
| + this.dataService.getModels().then(models => { |
54
| this.regions = models.regionSelectListDsM as RegionSelectList[]; |
56
| this.regions = models.regionSelectListDsM as RegionSelectList[]; |
55
| this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; |
57
| this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; |
56
| this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; |
58
| this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; |
| @@ -60,11 +62,11 @@ export class BusStopComponent { |
| @@ -60,11 +62,11 @@ export class BusStopComponent { |
60
| this.createColumnDefs(); |
62
| this.createColumnDefs(); |
61
| this.isBootstrapping = false; |
63
| this.isBootstrapping = false; |
62
| }); |
64
| }); |
63
| - this.service.getData().then((data) => { |
65
| + this.service.getData().then((data) => { |
64
| if (data.length){ |
66
| if (data.length){ |
65
| this.rowData = data; |
67
| this.rowData = data; |
66
| } else { |
68
| } else { |
67
| - this.rowData = [new BusStop]; |
69
| + this.rowData = [new BusStop()]; |
68
| } |
70
| } |
69
| }).then(() => { |
71
| }).then(() => { |
70
| this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
72
| this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
| @@ -90,7 +92,18 @@ export class BusStopComponent { |
| @@ -90,7 +92,18 @@ export class BusStopComponent { |
90
| } |
92
| } |
91
| }; |
93
| }; |
92
| return dataSource; |
94
| return dataSource; |
93
| - |
95
| + } |
| |
96
| + enableLoader(): void { |
| |
97
| + if (!this.isLoading) { |
| |
98
| + this.isLoading = true; |
| |
99
| + this.loadingService.register('loading'); |
| |
100
| + } |
| |
101
| + } |
| |
102
| + disableLoader(): void { |
| |
103
| + if (this.isLoading) { |
| |
104
| + this.isLoading = false; |
| |
105
| + this.loadingService.resolve('loading'); |
| |
106
| + } |
94
| } |
107
| } |
95
| onDeleteConfirm(event): void { |
108
| onDeleteConfirm(event): void { |
96
| if (window.confirm('Вы уверены что хотите удалить??')) { |
109
| if (window.confirm('Вы уверены что хотите удалить??')) { |
| @@ -190,19 +203,19 @@ export class BusStopComponent { |
| @@ -190,19 +203,19 @@ export class BusStopComponent { |
190
| let id = $event.data.busStopId; |
203
| let id = $event.data.busStopId; |
191
| let result = null; |
204
| let result = null; |
192
| if (id) { |
205
| if (id) { |
193
| - this.isLoading = true; |
| |
194
| - result = this.service.update(id, data).then(() => this.isLoading = false); |
206
| + this.enableLoader(); |
| |
207
| + result = this.service.update(id, data).then(() => this.disableLoader()); |
195
| } else { |
208
| } else { |
196
| // Protection of posting new row being already sent. |
209
| // Protection of posting new row being already sent. |
197
| if (this.isLoading) { |
210
| if (this.isLoading) { |
198
| return ; |
211
| return ; |
199
| } |
212
| } |
200
| - this.isLoading = true; |
213
| + this.enableLoader(); |
201
| result = this.service.create(data).then((busStop) => { |
214
| result = this.service.create(data).then((busStop) => { |
202
| this.rowData[$event.node.rowIndex] = busStop; |
215
| this.rowData[$event.node.rowIndex] = busStop; |
203
| this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
216
| this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
204
| this.gridOptions.api.refreshVirtualPageCache(); |
217
| this.gridOptions.api.refreshVirtualPageCache(); |
205
| - this.isLoading = false; |
218
| + this.disableLoader(); |
206
| }); |
219
| }); |
207
| } |
220
| } |
208
| } |
221
| } |
| @@ -216,8 +229,8 @@ export class BusStopComponent { |
| @@ -216,8 +229,8 @@ export class BusStopComponent { |
216
| rows.forEach(element => { |
229
| rows.forEach(element => { |
217
| let id = element.data.busStopId; |
230
| let id = element.data.busStopId; |
218
| if (id) { |
231
| if (id) { |
219
| - this.isLoading = true; |
| |
220
| - this.service.delete(id).then(() => this.isLoading = false); |
232
| + this.enableLoader(); |
| |
233
| + this.service.delete(id).then(() => this.disableLoader()); |
221
| } |
234
| } |
222
| }); |
235
| }); |
223
| // Sort in order to protect array from reindexing (remove rear elements first) |
236
| // Sort in order to protect array from reindexing (remove rear elements first) |