8ae52ec0
Administrator
add animation fil
|
1
2
|
import {Component, ViewEncapsulation} from '@angular/core';
import {GridOptions} from 'ag-grid/main';
|
74a2441c
Administrator
Add ServiceObject
|
3
4
5
6
7
8
9
10
11
12
|
import { ServiceObjectService } from '../../../services/service-object.service';
import { ServiceObject } from '../../../models/service-object';
import { EditorComponent } from '../../../helpers/editor.component';
import { RendererComponent } from '../../../helpers/renderer.component';
import { ServiceObjectCreateService } from '../../../services/service-object-create.service';
import { BooleanSelectListService } from '../../../services/boolean-select-list.service';
import { RegionSelectList } from '../../../models/region-select-list';
import { StateCommonSelectList } from '../../../models/state-common-select-list';
import { RoadSelectList } from '../../../models/road-select-list';
|
c36e5ea5
Administrator
add service-object
|
13
|
import { DepartmentAffiliationList } from '../../../models/department-affiliation-list';
|
74a2441c
Administrator
Add ServiceObject
|
14
15
|
import { BooleanSelectList } from '../../../models/boolean-select-list';
import { SettlementSelectList } from '../../../models/settlement-select-list';
|
74a2441c
Administrator
Add ServiceObject
|
16
|
|
c36e5ea5
Administrator
add service-object
|
17
|
import { routerTransition } from '../../../animations/router.animation';
|
74a2441c
Administrator
Add ServiceObject
|
18
19
20
21
22
23
24
|
// only import this if you are using the ag-Grid-Enterprise
@Component({
selector: 'service-object',
templateUrl: 'service-object.component.html',
styleUrls: ['service-object.scss'],
|
c36e5ea5
Administrator
add service-object
|
25
|
encapsulation: ViewEncapsulation.None,
|
74a2441c
Administrator
Add ServiceObject
|
26
|
})
|
c36e5ea5
Administrator
add service-object
|
27
|
export class ServiceObjectComponent {
|
74a2441c
Administrator
Add ServiceObject
|
28
29
30
31
32
33
|
public showGrid: boolean;
public rowData: any[];
public rowCount: string;
public regions: RegionSelectList[];
public states: StateCommonSelectList[];
|
c36e5ea5
Administrator
add service-object
|
34
|
public departmentAffiliation: DepartmentAffiliationList[];
|
74a2441c
Administrator
Add ServiceObject
|
35
36
37
38
39
40
41
42
43
44
45
46
|
public settlements: SettlementSelectList[];
public roads: RoadSelectList[];
public boolean: BooleanSelectList[];
public isLoading: boolean = false;
public isBootstrapping: boolean = true;
public isSelected: boolean = true;
private columnDefs: any[];
private gridOptions: GridOptions;
constructor(
protected service: ServiceObjectService,
private dataService: ServiceObjectCreateService,
|
8ae52ec0
Administrator
add animation fil
|
47
|
private booleanService: BooleanSelectListService,
|
74a2441c
Administrator
Add ServiceObject
|
48
49
|
) {
this.gridOptions = <GridOptions>{};
|
8ae52ec0
Administrator
add animation fil
|
50
51
52
53
54
|
this.gridOptions.enableSorting = true;
this.showGrid = true;
this.gridOptions.rowModelType = 'virtual';
this.booleanService.getModels().then((models) => this.boolean = models);
this.dataService.getModels().then((models) => {
|
74a2441c
Administrator
Add ServiceObject
|
55
56
|
this.regions = models.regionSelectListDsM as RegionSelectList[];
this.states = models.stateCommonSelectListDsM as StateCommonSelectList[];
|
c36e5ea5
Administrator
add service-object
|
57
|
this.departmentAffiliation = models.departmentAffiliationListDsM as DepartmentAffiliationList[];
|
74a2441c
Administrator
Add ServiceObject
|
58
59
60
61
62
63
|
this.settlements = models.settlementSelectListDsM as SettlementSelectList[];
this.roads = models.roadSelectListDsM as RoadSelectList[];
}).then(() => {
this.createColumnDefs();
this.isBootstrapping = false;
});
|
8ae52ec0
Administrator
add animation fil
|
64
|
this.service.getData().then((data) => {
|
74a2441c
Administrator
Add ServiceObject
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
if (data.length){
this.rowData = data;
} else {
this.rowData = [new ServiceObject];
}
}).then(() => {
this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
this.gridOptions.api.refreshVirtualPageCache();
});
}
setRowData(allOfTheData) {
let dataSource = {
rowCount: null, // behave as infinite scroll
getRows: function (params) {
console.log('asking for ' + params.startRow + ' to ' + params.endRow);
// At this point in your code, you would call the server, using $http if in AngularJS.
// To make the demo look real, wait for 500ms before returning
// take a slice of the total rows
let rowsThisPage = allOfTheData.slice(params.startRow, params.endRow);
// if on or after the last page, work out the last row.
let lastRow = -1;
if (allOfTheData.length <= params.endRow) {
lastRow = allOfTheData.length;
}
// call the success callback
params.successCallback(rowsThisPage, lastRow);
|
8ae52ec0
Administrator
add animation fil
|
91
|
},
|
74a2441c
Administrator
Add ServiceObject
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
};
return dataSource;
}
onDeleteConfirm(event): void {
if (window.confirm('Вы уверены что хотите удалить??')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
public addNewRow() {
this.rowData.unshift(new ServiceObject());
this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
this.gridOptions.api.refreshVirtualPageCache();
}
private createColumnDefs() {
this.columnDefs = [
{
headerName: '#',
width: 30,
checkboxSelection: true,
suppressSorting: true,
suppressMenu: true,
|
8ae52ec0
Administrator
add animation fil
|
117
|
pinned: true,
|
74a2441c
Administrator
Add ServiceObject
|
118
119
120
|
},
{
headerName: 'ID',
|
c36e5ea5
Administrator
add service-object
|
121
|
field: 'serviceObjectId',
|
74a2441c
Administrator
Add ServiceObject
|
122
123
124
125
126
127
128
129
130
131
|
},
{
headerName: 'Назва дороги',
field: 'roadId',
editable: true,
cellEditorFramework: EditorComponent,
cellRendererFramework: RendererComponent,
cellEditorParams: {
data: this.roads,
valueCol: 'roadId',
|
8ae52ec0
Administrator
add animation fil
|
132
133
|
labelCol: 'name',
},
|
74a2441c
Administrator
Add ServiceObject
|
134
135
136
137
138
139
140
141
142
143
|
},
{
headerName: 'Область',
field: 'regionId',
editable: true,
cellEditorFramework: EditorComponent,
cellRendererFramework: RendererComponent,
cellEditorParams: {
data: this.regions,
valueCol: 'regionId',
|
8ae52ec0
Administrator
add animation fil
|
144
145
|
labelCol: 'name',
},
|
74a2441c
Administrator
Add ServiceObject
|
146
147
148
149
150
151
152
153
154
155
|
},
{
headerName: 'Місцезнаходження, км+ справа',
field: 'locationRight',
editable: true,
},
{
headerName: 'Місцезнаходження, км+ зліва',
field: 'locationLeft',
editable: true,
|
8ae52ec0
Administrator
add animation fil
|
156
|
},
|
74a2441c
Administrator
Add ServiceObject
|
157
158
159
160
161
162
163
164
165
166
|
];
}
private onCellClicked($event) {
console.log('onCellClicked: ' + $event.rowIndex + ' ' + $event.colDef.field);
}
private onCellValueChanged($event) {
if ($event.oldValue !== $event.newValue) {
let data = JSON.stringify($event.data);
|
8ae52ec0
Administrator
add animation fil
|
167
|
let id = $event.data.busStopId;
|
74a2441c
Administrator
Add ServiceObject
|
168
169
170
171
172
173
174
175
176
177
|
let result = null;
if (id) {
this.isLoading = true;
result = this.service.update(id, data).then(() => this.isLoading = false);
} else {
// Protection of posting new row being already sent.
if (this.isLoading) {
return ;
}
this.isLoading = true;
|
8ae52ec0
Administrator
add animation fil
|
178
179
|
result = this.service.create(data).then((busStop) => {
this.rowData[$event.node.rowIndex] = busStop;
|
74a2441c
Administrator
Add ServiceObject
|
180
181
182
183
184
185
186
187
188
189
190
191
192
|
this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
this.gridOptions.api.refreshVirtualPageCache();
this.isLoading = false;
});
}
}
}
private deleteRows() {
let rows = this.gridOptions.api.getSelectedNodes();
if (!rows.length) {
return ;
}
|
8ae52ec0
Administrator
add animation fil
|
193
194
|
rows.forEach((element) => {
let id = element.data.busStopId;
|
74a2441c
Administrator
Add ServiceObject
|
195
196
197
198
199
200
201
202
203
204
205
206
207
|
if (id) {
this.isLoading = true;
this.service.delete(id).then(() => this.isLoading = false);
}
});
// Sort in order to protect array from reindexing (remove rear elements first)
let sorted = rows.sort((a, b) => {
if (a > b) {
return -1;
} else {
return 1;
}
});
|
8ae52ec0
Administrator
add animation fil
|
208
|
sorted.forEach((item) => {
|
74a2441c
Administrator
Add ServiceObject
|
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
this.rowData.splice(item.rowIndex, 1);
});
this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
this.gridOptions.api.refreshVirtualPageCache();
}
private onCellDoubleClicked($event) {
console.log('onCellDoubleClicked: ' + $event.rowIndex + ' ' + $event.colDef.field);
}
private onCellContextMenu($event) {
console.log('onCellContextMenu: ' + $event.rowIndex + ' ' + $event.colDef.field);
}
private onCellFocused($event) {
console.log('onCellFocused: (' + $event.rowIndex + ',' + $event.colIndex + ')');
}
private onRowSelected($event) {
// taking out, as when we 'select all', it prints to much to the console!!
// console.log('onRowSelected: ' + $event.node.data.name);
}
private onSelectionChanged() {
console.log('selectionChanged');
}
private onBeforeFilterChanged() {
console.log('beforeFilterChanged');
}
private onAfterFilterChanged() {
console.log('afterFilterChanged');
}
private onFilterModified() {
console.log('onFilterModified');
}
private onBeforeSortChanged() {
console.log('onBeforeSortChanged');
}
private onAfterSortChanged() {
console.log('onAfterSortChanged');
}
private onVirtualRowRemoved($event) {
// because this event gets fired LOTS of times, we don't print it to the
// console. if you want to see it, just uncomment out this line
// console.log('onVirtualRowRemoved: ' + $event.rowIndex);
}
private onRowClicked($event) {
console.log('onRowClicked: ' + $event.node.data.name);
}
public onQuickFilterChanged($event) {
this.gridOptions.api.setQuickFilter($event.target.value);
}
// here we use one generic event to handle all the column type events.
// the method just prints the event name
private onColumnEvent($event) {
console.log('onColumnEvent: ' + $event);
}
}
|