Commit 6c0454b938d5c7d64f428dee9b69cbab56b53fd7

Authored by Yarik
1 parent c285d303

Table

src/app/app.module.ts
... ... @@ -5,7 +5,15 @@ import { FormsModule } from '@angular/forms';
5 5 import { HttpModule } from '@angular/http';
6 6 import { MaterialModule } from '@angular/material';
7 7 import { AgGridModule } from 'ag-grid-ng2/main';
8   -import { RichGridComponent } from "./components/grid/rich-grid.component";
  8 +
  9 +// Services
  10 +import { BusStopCreateService } from './services/busstopcreate.service';
  11 +import { BooleanSelectListService } from './services/booleanselectlist.service';
  12 +import { BusStopService } from './components/grid/busStop.service';
  13 +
  14 +import { EditorComponent } from './helpers/editor.component';
  15 +import { RendererComponent } from './helpers/renderer.component';
  16 +import { RichGridComponent } from './components/grid/rich-grid.component';
9 17  
10 18 import 'hammerjs';
11 19  
... ... @@ -14,7 +22,9 @@ import { AppComponent } from './components/app/app.component';
14 22 @NgModule({
15 23 declarations: [
16 24 AppComponent,
17   - RichGridComponent
  25 + RichGridComponent,
  26 + EditorComponent,
  27 + RendererComponent
18 28 ],
19 29 imports: [
20 30 RouterModule.forRoot([
... ... @@ -24,11 +34,17 @@ import { AppComponent } from './components/app/app.component';
24 34 FormsModule,
25 35 HttpModule,
26 36 MaterialModule.forRoot(),
27   - AgGridModule.withComponents([
28   - RichGridComponent
29   - ])
  37 + AgGridModule.withComponents([
  38 + RichGridComponent,
  39 + EditorComponent,
  40 + RendererComponent,
  41 + ])
  42 + ],
  43 + providers: [
  44 + BusStopCreateService,
  45 + BooleanSelectListService,
  46 + BusStopService
30 47 ],
31   - providers: [],
32 48 bootstrap: [AppComponent]
33 49 })
34 50 export class AppModule { }
... ...
src/app/components/grid/busStop.service.ts 0 → 100644
  1 +import { Injectable } from '@angular/core';
  2 +import { Headers, Http } from '@angular/http';
  3 +
  4 +import 'rxjs/add/operator/toPromise';
  5 +
  6 +import { busStop } from './busStop';
  7 +
  8 +@Injectable()
  9 +export class BusStopService {
  10 + private url = 'http://localhost:5000/busstop';
  11 + private headers = new Headers({'Content-Type': 'application/json'});
  12 + constructor(private http: Http) { }
  13 + getData(): Promise<busStop[]> {
  14 + // let busStops: busStop2[] = [{
  15 + // roadId: 1,
  16 + // regionId: 1,
  17 + // settlementId: 1,
  18 + // surfaceTypeId: '1',
  19 + // locationLeft: '1',
  20 + // locationRight: '1',
  21 + // stateCommonId: 1,
  22 + // areaStopAvailability: '',
  23 + // areaLandAvailability: '',
  24 + // pocketAvailability: '',
  25 + // toiletAvailability: '',
  26 + // yearBuild: '',
  27 + // yearRepair: '',
  28 + // }];
  29 + // return Promise.resolve(busStops);
  30 + return this.http.get(this.url)
  31 + .toPromise()
  32 + .then(response => response.json().busStopEditDsM as busStop[])
  33 + .catch(this.handleError);
  34 + }
  35 + update(id: number, data: string): Promise<any> {
  36 + return this.http.post(this.url + '/update?id=' + id, data, { headers: this.headers })
  37 + .toPromise()
  38 + .then(response => response.json())
  39 + .catch(this.handleError);
  40 + }
  41 + create(data: string): Promise<busStop> {
  42 + return this.http.post(this.url + '/create', data, { headers: this.headers })
  43 + .toPromise()
  44 + .then(response => response.json() as busStop)
  45 + .catch(this.handleError);
  46 + }
  47 + delete(id: number): Promise<any> {
  48 + return this.http.delete(this.url + '/delete?id=' + id, { headers: this.headers })
  49 + .toPromise()
  50 + .then(response => response.json())
  51 + .catch(this.handleError);
  52 + }
  53 + private handleError(error: any): Promise<any> {
  54 + console.error('An error occured', error);
  55 + return Promise.reject(error.message || error);
  56 + }
  57 +}
... ...
src/app/components/grid/busStop.ts 0 → 100644
  1 +export class busStop {
  2 + busStopID: number;
  3 + roadId: number;
  4 + regionId: number;
  5 + settlementId: number;
  6 + locationLeft: string;
  7 + locationRight: string;
  8 + surfaceTypeId: number;
  9 + areaStopAvailability: string;
  10 + areaLandAvailability: string;
  11 + pocketAvailability: string;
  12 + toiletAvailability: string;
  13 + yearBuild: string;
  14 + yearRepair: string;
  15 + stateCommonId: number;
  16 +}
... ...
src/app/components/grid/rich-grid.component.html
1 1 <div style="width: 800px;">
2 2 <h1>Rich Grid with Pure JavaScript</h1>
3   - <div style="padding: 4px;">
4   - <div style="float: right;">
5   - <input (keyup)="onQuickFilterChanged($event)" type="text" id="quickFilterInput" placeholder="Type text to filter..." />
6   - <button [disabled]="!showGrid" (click)="showGrid=false">Destroy Grid</button>
7   - <button [disabled]="showGrid" (click)="showGrid=true">Create Grid</button>
8   - </div>
9   - <div>
10   - <b>Employees Skills and Contact Details</b> {{rowCount}}
11   - </div>
12   - </div>
13 3 <div style="clear: both;"></div>
14   -
15 4 <div *ngIf="showGrid">
16   -
17   - <!-- Because we are using the Angular ID (ie #ag-grid marker), we have to have all the items that use
18   - that marker inside the same ng-if as the grid -->
19   -
20   - <div style="padding: 4px;" class="toolbar">
21   - <span>
22   - Grid API:
23   - <button (click)="agGrid.api.selectAll()">Select All</button>
24   - <button (click)="agGrid.api.deselectAll()">Clear Selection</button>
25   - </span>
26   - <span style="margin-left: 20px;">
27   - Column API:
28   - <button (click)="agGrid.columnApi.setColumnVisible('country', false)">Hide Country Column</button>
29   - <button (click)="agGrid.columnApi.setColumnVisible('country', true)">Show Country Column</button>
30   - </span>
  5 + <button class="btn btn-warning" (click)="addNewRow()" type="button">Добавить новое поле</button>
  6 + <button class="btn btn-danger" (click)="deleteRows()" type="button">Удалить</button>
  7 + <div *ngIf="isLoading" class="">
  8 + ...Loading
31 9 </div>
32   - <div style="clear: both;"></div>
33   - <div style="padding: 4px;" class="toolbar">
34   - <label>
35   - <input type="checkbox" (change)="showToolPanel=$event.target.checked"/>
36   - Show Tool Panel
37   - </label>
38   - <button (click)="createRowData()">Refresh Data</button>
39   - </div>
40   - <div style="clear: both;"></div>
41   -
42   - <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-fresh" [gridOptions]="gridOptions" [columnDefs]="columnDefs" [showToolPanel]="showToolPanel" [rowData]="rowData" enableColResize enableSorting enableFilter groupHeaders suppressRowClickSelection
43   - toolPanelSuppressGroups toolPanelSuppressValues debug rowHeight="22" rowSelection="multiple" (modelUpdated)="onModelUpdated()" (cellClicked)="onCellClicked($event)" (cellDoubleClicked)="onCellDoubleClicked($event)" (cellContextMenu)="onCellContextMenu($event)"
44   - (cellValueChanged)="onCellValueChanged($event)" (cellFocused)="onCellFocused($event)" (rowSelected)="onRowSelected($event)" (selectionChanged)="onSelectionChanged()" (beforeFilterChanged)="onBeforeFilterChanged()" (afterFilterChanged)="onAfterFilterChanged()"
45   - (filterModified)="onFilterModified()" (beforeSortChanged)="onBeforeSortChanged()" (afterSortChanged)="onAfterSortChanged()" (virtualRowRemoved)="onVirtualRowRemoved($event)" (rowClicked)="onRowClicked($event)" (gridReady)="onReady($event)" (columnEverythingChanged)="onColumnEvent($event)"
46   - (columnRowGroupChanged)="onColumnEvent($event)" (columnValueChanged)="onColumnEvent($event)" (columnMoved)="onColumnEvent($event)" (columnVisible)="onColumnEvent($event)" (columnGroupOpened)="onColumnEvent($event)" (columnResized)="onColumnEvent($event)"
47   - (columnPinnedCountChanged)="onColumnEvent($event)">
  10 + <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-fresh"
  11 + [gridOptions]="gridOptions"
  12 + [columnDefs]="columnDefs"
  13 + [rowData]="rowData"
  14 + enableColResize
  15 + enableSorting
  16 + enableFilter
  17 + groupHeaders
  18 + suppressRowClickSelection
  19 + toolPanelSuppressGroups
  20 + toolPanelSuppressValues
  21 + debug
  22 + rowHeight="22"
  23 + rowSelection="multiple"
  24 +
  25 + (cellClicked)="onCellClicked($event)"
  26 + (cellDoubleClicked)="onCellDoubleClicked($event)"
  27 + (cellContextMenu)="onCellContextMenu($event)"
  28 + (cellValueChanged)="onCellValueChanged($event)"
  29 + (cellFocused)="onCellFocused($event)"
  30 + (rowSelected)="onRowSelected($event)"
  31 + (selectionChanged)="onSelectionChanged()"
  32 + (beforeFilterChanged)="onBeforeFilterChanged()"
  33 + (afterFilterChanged)="onAfterFilterChanged()"
  34 + (filterModified)="onFilterModified()"
  35 + (beforeSortChanged)="onBeforeSortChanged()"
  36 + (afterSortChanged)="onAfterSortChanged()"
  37 + (virtualRowRemoved)="onVirtualRowRemoved($event)"
  38 + (rowClicked)="onRowClicked($event)" >
48 39 </ag-grid-ng2>
49 40 </div>
50 41  
... ...
src/app/components/grid/rich-grid.component.ts
1 1 import {Component, ViewEncapsulation} from "@angular/core";
2 2 import {GridOptions} from "ag-grid/main";
  3 +
3 4 import ProficiencyFilter from "./proficiencyFilter";
4 5 import SkillFilter from "./skillFilter";
5 6 import RefData from "./refData";
  7 +import { BusStopService } from './busStop.service';
  8 +import { busStop } from './busStop';
  9 +import { EditorComponent } from '../../helpers/editor.component';
  10 +import { RendererComponent } from '../../helpers/renderer.component';
  11 +import { BusStopCreateService } from '../../services/busstopcreate.service';
  12 +import { BooleanSelectListService } from '../../services/booleanselectlist.service';
  13 +import { RegionSelectList } from '../../models/regionselectlist';
  14 +import { StateCommonSelectList } from '../../models/statecommonselectlist';
  15 +import { RoadSelectList } from '../../models/roadselectlist';
  16 +import { BooleanSelectList } from '../../models/booleanselectlist';
  17 +import { SettlementSelectList } from '../../models/settlementselectlist';
  18 +import { SurfaceTypeSelectList } from '../../models/surfacetypeselectlist';
  19 +
6 20  
7 21 // only import this if you are using the ag-Grid-Enterprise
8 22  
... ... @@ -14,82 +28,221 @@ import RefData from &quot;./refData&quot;;
14 28 })
15 29 export class RichGridComponent {
16 30  
17   - private gridOptions: GridOptions;
18 31 public showGrid: boolean;
19 32 public rowData: any[];
20   - private columnDefs: any[];
21 33 public rowCount: string;
  34 + public regions: RegionSelectList[];
  35 + public states: StateCommonSelectList[];
  36 + public surfaceTypes: SurfaceTypeSelectList[];
  37 + public settlements: SettlementSelectList[];
  38 + public roads: RoadSelectList[];
  39 + public boolean: BooleanSelectList[];
  40 + public isLoading: boolean = false;
  41 + public isBootstrapping: boolean = true;
  42 + private columnDefs: any[];
  43 + private gridOptions: GridOptions;
22 44  
23   - constructor() {
24   - // we pass an empty gridOptions in, so we can grab the api out
  45 + constructor(
  46 + protected service: BusStopService,
  47 + private dataService: BusStopCreateService,
  48 + private booleanService: BooleanSelectListService
  49 + ) {
25 50 this.gridOptions = <GridOptions>{};
26   - this.createRowData();
27   - this.createColumnDefs();
28   - this.showGrid = true;
29   - }
30   -
31   - private createRowData() {
32   - var rowData: any[] = [];
33   -
34   - for (var i = 0; i < 100; i++) {
35   - var countryData = RefData.countries[i % RefData.countries.length];
36   - rowData.push({
37   - name: RefData.firstNames[i % RefData.firstNames.length] + ' ' + RefData.lastNames[i % RefData.lastNames.length],
38   - skills: {
39   - android: Math.random() < 0.4,
40   - html5: Math.random() < 0.4,
41   - mac: Math.random() < 0.4,
42   - windows: Math.random() < 0.4,
43   - css: Math.random() < 0.4
44   - },
45   - address: RefData.addresses[i % RefData.addresses.length],
46   - years: Math.round(Math.random() * 100),
47   - proficiency: Math.round(Math.random() * 100),
48   - country: countryData.country,
49   - continent: countryData.continent,
50   - language: countryData.language,
51   - mobile: createRandomPhoneNumber(),
52   - landline: createRandomPhoneNumber()
53   - });
54   - }
55   -
56   - this.rowData = rowData;
  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 => {
  56 + this.regions = models.regionSelectListDsM as RegionSelectList[];
  57 + this.states = models.stateCommonSelectListDsM as StateCommonSelectList[];
  58 + this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[];
  59 + this.settlements = models.settlementSelectListDsM as SettlementSelectList[];
  60 + this.roads = models.roadSelectListDsM as RoadSelectList[];
  61 + }).then(() => {
  62 + this.createColumnDefs();
  63 + this.isBootstrapping = false;
  64 + });
  65 + this.service.getData().then((data) => {
  66 + if (data.length){
  67 + this.rowData = data;
  68 + } else {
  69 + this.rowData = [new busStop];
  70 + }
  71 + }).then(() => {
  72 + this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
  73 + this.gridOptions.api.refreshVirtualPageCache();
  74 + });
57 75 }
58 76  
59   - private createColumnDefs() {
60   - this.columnDefs = [
61   - {
62   - headerName: '#', width: 30, checkboxSelection: true, suppressSorting: true,
63   - suppressMenu: true, pinned: true
64   - }
65   - ];
  77 + setRowData(allOfTheData) {
  78 + let dataSource = {
  79 + rowCount: null, // behave as infinite scroll
  80 + getRows: function (params) {
  81 + console.log('asking for ' + params.startRow + ' to ' + params.endRow);
  82 + // At this point in your code, you would call the server, using $http if in AngularJS.
  83 + // To make the demo look real, wait for 500ms before returning
  84 + // take a slice of the total rows
  85 + let rowsThisPage = allOfTheData.slice(params.startRow, params.endRow);
  86 + // if on or after the last page, work out the last row.
  87 + let lastRow = -1;
  88 + if (allOfTheData.length <= params.endRow) {
  89 + lastRow = allOfTheData.length;
  90 + }
  91 + // call the success callback
  92 + params.successCallback(rowsThisPage, lastRow);
  93 + }
  94 + };
  95 + return dataSource;
  96 +
  97 + }
  98 + onDeleteConfirm(event): void {
  99 + if (window.confirm('Вы уверены что хотите удалить??')) {
  100 + event.confirm.resolve();
  101 + } else {
  102 + event.confirm.reject();
66 103 }
67   -
68   - private calculateRowCount() {
69   - if (this.gridOptions.api && this.rowData) {
70   - var model = this.gridOptions.api.getModel();
71   - var totalRows = this.rowData.length;
72   - var processedRows = model.getRowCount();
73   - this.rowCount = processedRows.toLocaleString() + ' / ' + totalRows.toLocaleString();
  104 + }
  105 + public addNewRow() {
  106 + this.rowData.unshift(new busStop());
  107 + this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
  108 + this.gridOptions.api.refreshVirtualPageCache();
  109 + }
  110 +
  111 + private createColumnDefs() {
  112 + this.columnDefs = [
  113 + {
  114 + headerName: '#',
  115 + width: 30,
  116 + checkboxSelection: true,
  117 + suppressSorting: true,
  118 + suppressMenu: true,
  119 + pinned: true
  120 + },
  121 + {
  122 + headerName: 'ID',
  123 + field: 'busStopId',
  124 + width: 150
  125 + },
  126 + {
  127 + headerName: 'Назва дороги',
  128 + field: 'roadId',
  129 + editable: true,
  130 + width: 150,
  131 + cellEditorFramework: EditorComponent,
  132 + cellRendererFramework: RendererComponent,
  133 + cellEditorParams: {
  134 + data: this.roads,
  135 + valueCol: 'roadId',
  136 + labelCol: 'name'
74 137 }
75   - }
76   -
77   - private onModelUpdated() {
78   - console.log('onModelUpdated');
79   - this.calculateRowCount();
80   - }
81   -
82   - private onReady() {
83   - console.log('onReady');
84   - this.calculateRowCount();
85   - }
  138 + },
  139 + {
  140 + headerName: 'Область',
  141 + field: 'regionId',
  142 + editable: true,
  143 + width: 150,
  144 + cellEditorFramework: EditorComponent,
  145 + cellRendererFramework: RendererComponent,
  146 + cellEditorParams: {
  147 + data: this.regions,
  148 + valueCol: 'regionId',
  149 + labelCol: 'name'
  150 + }
  151 + },
  152 + {
  153 + headerName: 'Місцезнаходження, км+ справа',
  154 + field: 'locationRight',
  155 + editable: true,
  156 + width: 150
  157 + },
  158 + {
  159 + headerName: 'Місцезнаходження, км+ зліва',
  160 + field: 'locationLeft',
  161 + editable: true,
  162 + width: 150
  163 + },
  164 + {
  165 + headerName: 'Технічний стан',
  166 + field: 'stateCommonId',
  167 + editable: true,
  168 + width: 150,
  169 + cellEditorFramework: EditorComponent,
  170 + cellRendererFramework: RendererComponent,
  171 + cellEditorParams: {
  172 + data: this.states,
  173 + valueCol: 'stateCommonId',
  174 + labelCol: 'value'
  175 + }
  176 + },
  177 + {
  178 + headerName: 'Наявність туалету',
  179 + field: 'toiletAvailability',
  180 + editable: true,
  181 + width: 150,
  182 + cellEditorFramework: EditorComponent,
  183 + cellRendererFramework: RendererComponent,
  184 + cellEditorParams: {
  185 + data: this.boolean,
  186 + valueCol: 'value',
  187 + labelCol: 'label'
  188 + }
  189 + }
  190 + ];
  191 + }
86 192  
87 193 private onCellClicked($event) {
88 194 console.log('onCellClicked: ' + $event.rowIndex + ' ' + $event.colDef.field);
89 195 }
90 196  
91 197 private onCellValueChanged($event) {
92   - console.log('onCellValueChanged: ' + $event.oldValue + ' to ' + $event.newValue);
  198 + if ($event.oldValue !== $event.newValue) {
  199 + let data = JSON.stringify($event.data);
  200 + let id = $event.data.busStopId;
  201 + let result = null;
  202 + if (id) {
  203 + this.isLoading = true;
  204 + result = this.service.update(id, data).then(() => this.isLoading = false);
  205 + } else {
  206 + // Protection of posting new row being already sent.
  207 + if (this.isLoading) {
  208 + return ;
  209 + }
  210 + this.isLoading = true;
  211 + result = this.service.create(data).then((busStop) => {
  212 + this.rowData[$event.node.rowIndex] = busStop;
  213 + this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
  214 + this.gridOptions.api.refreshVirtualPageCache();
  215 + this.isLoading = false;
  216 + });
  217 + }
  218 + }
  219 + }
  220 +
  221 + private deleteRows() {
  222 + let rows = this.gridOptions.api.getSelectedNodes();
  223 + if (!rows.length) {
  224 + return ;
  225 + }
  226 + rows.forEach(element => {
  227 + let id = element.data.busStopId;
  228 + if (id) {
  229 + this.isLoading = true;
  230 + this.service.delete(id).then(() => this.isLoading = false);
  231 + }
  232 + });
  233 + // Sort in order to protect array from reindexing (remove rear elements first)
  234 + let sorted = rows.sort((a, b) => {
  235 + if (a > b) {
  236 + return -1;
  237 + } else {
  238 + return 1;
  239 + }
  240 + });
  241 + sorted.forEach(item => {
  242 + this.rowData.splice(item.rowIndex, 1);
  243 + });
  244 + this.gridOptions.api.setDatasource(this.setRowData(this.rowData));
  245 + this.gridOptions.api.refreshVirtualPageCache();
93 246 }
94 247  
95 248 private onCellDoubleClicked($event) {
... ... @@ -152,58 +305,4 @@ export class RichGridComponent {
152 305 private onColumnEvent($event) {
153 306 console.log('onColumnEvent: ' + $event);
154 307 }
155   -
156   -}
157   -
158   -function skillsCellRenderer(params) {
159   - var data = params.data;
160   - var skills = [];
161   - RefData.IT_SKILLS.forEach(function (skill) {
162   - if (data && data.skills && data.skills[skill]) {
163   - skills.push('<img src="images/skills/' + skill + '.png" width="16px" title="' + skill + '" />');
164   - }
165   - });
166   - return skills.join(' ');
167   -}
168   -
169   -function countryCellRenderer(params) {
170   - var flag = "<img border='0' width='15' height='10' style='margin-bottom: 2px' src='images/flags/" + RefData.COUNTRY_CODES[params.value] + ".png'>";
171   - return flag + " " + params.value;
172   -}
173   -
174   -function createRandomPhoneNumber() {
175   - var result = '+';
176   - for (var i = 0; i < 12; i++) {
177   - result += Math.round(Math.random() * 10);
178   - if (i === 2 || i === 5 || i === 8) {
179   - result += ' ';
180   - }
181   - }
182   - return result;
183   -}
184   -
185   -function percentCellRenderer(params) {
186   - var value = params.value;
187   -
188   - var eDivPercentBar = document.createElement('div');
189   - eDivPercentBar.className = 'div-percent-bar';
190   - eDivPercentBar.style.width = value + '%';
191   - if (value < 20) {
192   - eDivPercentBar.style.backgroundColor = 'red';
193   - } else if (value < 60) {
194   - eDivPercentBar.style.backgroundColor = '#ff9900';
195   - } else {
196   - eDivPercentBar.style.backgroundColor = '#00A000';
197   - }
198   -
199   - var eValue = document.createElement('div');
200   - eValue.className = 'div-percent-value';
201   - eValue.innerHTML = value + '%';
202   -
203   - var eOuterDiv = document.createElement('div');
204   - eOuterDiv.className = 'div-outer-div';
205   - eOuterDiv.appendChild(eValue);
206   - eOuterDiv.appendChild(eDivPercentBar);
207   -
208   - return eOuterDiv;
209 308 }
... ...
src/app/helpers/editor.component.ts 0 → 100644
  1 +import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core';
  2 +
  3 +import { AgEditorComponent } from 'ag-grid-ng2/main';
  4 +
  5 +@Component({
  6 + selector: 'editor-cell',
  7 + template: `
  8 + <md-select #container>
  9 + <md-option *ngFor="let item of data" (click)="onClick(item[this.params.valueCol])" >
  10 + {{item[this.params.labelCol]}}
  11 + </md-option>
  12 + </md-select>
  13 + `
  14 +})
  15 +export class EditorComponent implements AgEditorComponent, AfterViewInit {
  16 + @ViewChild('container', {read: ViewContainerRef}) public container;
  17 + @ViewChild('container') public child;
  18 + public item: Object = null;
  19 + public data: Object[];
  20 + private params: any;
  21 + ngAfterViewInit() {
  22 + this.container.element.nativeElement.focus();
  23 + }
  24 +
  25 + agInit(params: any): void {
  26 + this.params = params;
  27 + if (!this.params.valueCol) {
  28 + this.params.valueCol = 'id';
  29 + }
  30 + if (!this.params.labelCol) {
  31 + this.params.labelCol = 'name';
  32 + }
  33 + this.data = params.data || [];
  34 + }
  35 +
  36 + getValue(): any {
  37 + return this.item;
  38 + }
  39 +
  40 + isPopup(): boolean {
  41 + return true;
  42 + }
  43 +
  44 + setValue(item: Object): void {
  45 + this.item = item;
  46 + }
  47 +
  48 + onClick(item: Object) {
  49 + this.setValue(item);
  50 + this.params.api.stopEditing();
  51 + }
  52 +
  53 + onKeyDown(event): boolean {
  54 + event.stopPropagation();
  55 + return false;
  56 + }
  57 +}
... ...
src/app/helpers/renderer.component.ts 0 → 100644
  1 +import { Component } from '@angular/core';
  2 +
  3 +import { AgRendererComponent } from 'ag-grid-ng2/main';
  4 +
  5 +import { RegionSelectList } from '../models/regionselectlist';
  6 +
  7 +@Component({
  8 + selector: 'render-cell',
  9 + template: `<span *ngIf="this.model !== undefined">{{this.label}}</span>`
  10 +})
  11 +export class RendererComponent implements AgRendererComponent {
  12 + private params: any;
  13 + private valueCol: string = 'id';
  14 + private labelCol: string = 'name';
  15 + private model: Object = null;
  16 + private label: string = null;
  17 + agInit(params: any): void {
  18 + this.params = params;
  19 + if (params.colDef.cellEditorParams && params.colDef.cellEditorParams.valueCol) {
  20 + this.valueCol = params.colDef.cellEditorParams.valueCol;
  21 + }
  22 + if (params.colDef.cellEditorParams && params.colDef.cellEditorParams.labelCol) {
  23 + this.labelCol = params.colDef.cellEditorParams.labelCol;
  24 + }
  25 + this.setValue(params);
  26 + }
  27 + refresh(params: any): void {
  28 + this.params = params;
  29 + this.setValue(params);
  30 + }
  31 + private setValue(params) {
  32 + this.model = params.value;
  33 + let label = this.params.colDef.cellEditorParams.data.find((element, index, array) => {
  34 + if (element[this.valueCol] === params.value) {
  35 + return true;
  36 + }
  37 + });
  38 + if (label) {
  39 + this.label = label[this.labelCol];
  40 + }
  41 + }
  42 +}
... ...
src/app/models/booleanselectlist.ts 0 → 100644
  1 +export class BooleanSelectList {
  2 + value: number;
  3 + label: string;
  4 + }
... ...
src/app/models/regionselectlist.ts 0 → 100644
  1 +export class RegionSelectList {
  2 + regionId: number;
  3 + name: string;
  4 + }
... ...
src/app/models/roadselectlist.ts 0 → 100644
  1 +export class RoadSelectList {
  2 + roadId: number;
  3 + name: string;
  4 +}
... ...
src/app/models/settlementselectlist.ts 0 → 100644
  1 +export class SettlementSelectList {
  2 + settlementId: number;
  3 + name: string;
  4 + }
... ...
src/app/models/statecommonselectlist.ts 0 → 100644
  1 +export class StateCommonSelectList {
  2 + stateCommonId: number;
  3 + value: string;
  4 + }
... ...
src/app/models/surfacetypeselectlist.ts 0 → 100644
  1 +export class SurfaceTypeSelectList {
  2 + surfaceTypeId: number;
  3 + name: string;
  4 + }
... ...
src/app/services/booleanselectlist.service.ts 0 → 100644
  1 +import { Injectable } from '@angular/core';
  2 +
  3 +import { BooleanSelectList } from '../models/booleanselectlist';
  4 +
  5 +@Injectable()
  6 +export class BooleanSelectListService {
  7 + getModels(): Promise<BooleanSelectList[]> {
  8 + let values = [];
  9 + let trueValue = new BooleanSelectList();
  10 + trueValue.value = 1;
  11 + trueValue.label = 'Да';
  12 + let falseValue = new BooleanSelectList();
  13 + falseValue.value = 0;
  14 + falseValue.label = 'Нет';
  15 + values.push(falseValue);
  16 + values.push(trueValue);
  17 + return Promise.resolve(values);
  18 + }
  19 +}
... ...
src/app/services/busstopcreate.service.ts 0 → 100644
  1 +import { Injectable } from '@angular/core';
  2 +import { Headers, Http } from '@angular/http';
  3 +
  4 +import 'rxjs/add/operator/toPromise';
  5 +
  6 +@Injectable()
  7 +export class BusStopCreateService {
  8 + private apiUrl = 'http://localhost:5000/busstop/directory';
  9 + private headers = new Headers({'Content-Type': 'applicaton/json'});
  10 + constructor(private http: Http) { }
  11 + getModels(): Promise<any> {
  12 + return this.http.get(this.apiUrl)
  13 + .toPromise()
  14 + .then(response => response.json())
  15 + .catch(this.handleError);
  16 + }
  17 + private handleError(error: any): Promise<any> {
  18 + console.error('An error occured', error);
  19 + return Promise.reject(error.message || error);
  20 + }
  21 +}
... ...
src/app/services/regionselectlist.service.ts 0 → 100644
  1 +import { Injectable } from '@angular/core';
  2 +import { Headers, Http } from '@angular/http';
  3 +
  4 +import 'rxjs/add/operator/toPromise';
  5 +
  6 +import { RegionSelectList } from '../models/regionselectlist';
  7 +
  8 +@Injectable()
  9 +export class RegionSelectListService {
  10 + private apiUrl = 'http://localhost:5000/directory/regionds';
  11 + private headers = new Headers({'Content-Type': 'applicaton/json'});
  12 + constructor(private http: Http) { }
  13 + getModels(): Promise<RegionSelectList[]> {
  14 + return this.http.get(this.apiUrl)
  15 + .toPromise()
  16 + .then(response => response.json().regionSelectListDsM as RegionSelectList[])
  17 + .catch(this.handleError);
  18 + }
  19 + private handleError(error: any): Promise<any> {
  20 + console.error('An error occured', error);
  21 + return Promise.reject(error.message || error);
  22 + }
  23 +}
... ...
src/app/services/roadselectlist.service.ts 0 → 100644
src/app/services/settlementselectlist.service.ts 0 → 100644
src/app/services/statecommonselectlist.service.ts 0 → 100644
  1 +import { Injectable } from '@angular/core';
  2 +import { Headers, Http } from '@angular/http';
  3 +
  4 +import 'rxjs/add/operator/toPromise';
  5 +
  6 +import { StateCommonSelectList } from '../models/statecommonselectlist';
  7 +
  8 +@Injectable()
  9 +export class StateCommonSelectListService {
  10 + private apiUrl = 'http://localhost:5000/directory/statecommonds';
  11 + private headers = new Headers({'Content-Type': 'applicaton/json'});
  12 + constructor(private http: Http) { }
  13 + getModels(): Promise<StateCommonSelectList[]> {
  14 + return this.http.get(this.apiUrl)
  15 + .toPromise()
  16 + .then(response => response.json().stateCommonSelectListDsM as StateCommonSelectList[])
  17 + .catch(this.handleError);
  18 + }
  19 + private handleError(error: any): Promise<any> {
  20 + console.error('An error occured', error);
  21 + return Promise.reject(error.message || error);
  22 + }
  23 +}
... ...
src/app/services/surfacetypeselectlist.service.ts 0 → 100644