Commit abf7c25f9f21d0c48dc027e3b4ccbc3dd64d77c6
1 parent
d675b823
Dropdown
Showing
16 changed files
with
157 additions
and
25 deletions
Show diff stats
src/app/app.module.ts
... | ... | @@ -5,6 +5,9 @@ import { HttpModule } from '@angular/http'; |
5 | 5 | import { RouterModule } from '@angular/router'; |
6 | 6 | import { removeNgStyles, createNewHosts, createInputTransfer } from '@angularclass/hmr'; |
7 | 7 | |
8 | +// Services | |
9 | +import { RegionSelectListService } from './services/regionselectlist.service'; | |
10 | + | |
8 | 11 | /* |
9 | 12 | * Platform and Environment providers/directives/pipes |
10 | 13 | */ |
... | ... | @@ -50,7 +53,8 @@ export type StoreType = { |
50 | 53 | ], |
51 | 54 | providers: [ // expose our Services and Providers into Angular's dependency injection |
52 | 55 | ENV_PROVIDERS, |
53 | - APP_PROVIDERS | |
56 | + APP_PROVIDERS, | |
57 | + RegionSelectListService | |
54 | 58 | ] |
55 | 59 | }) |
56 | 60 | ... | ... |
1 | +import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core'; | |
2 | + | |
3 | +import { AgEditorComponent } from 'ag-grid-ng2/main'; | |
4 | + | |
5 | +import { RegionSelectList } from '../models/regionselectlist'; | |
6 | + | |
7 | +@Component({ | |
8 | + selector: 'editor-cell', | |
9 | + template: ` | |
10 | + <div #container> | |
11 | + <p *ngFor="let item of data" (click)="onClick(item)" >{{item.name}}</p> | |
12 | + </div> | |
13 | + ` | |
14 | +}) | |
15 | +export class EditorComponent implements AgEditorComponent, AfterViewInit { | |
16 | + @ViewChild('container', {read: ViewContainerRef}) public container; | |
17 | + public item: any; | |
18 | + public data: RegionSelectList[]; | |
19 | + private params: any; | |
20 | + ngAfterViewInit() { | |
21 | + this.container.element.nativeElement.focus(); | |
22 | + } | |
23 | + | |
24 | + agInit(params: any): void { | |
25 | + this.params = params; | |
26 | + this.data = params.data || []; | |
27 | + // this.setHappy(params.value === "Happy"); | |
28 | + } | |
29 | + | |
30 | + getValue(): any { | |
31 | + return this.item; | |
32 | + } | |
33 | + | |
34 | + isPopup(): boolean { | |
35 | + return true; | |
36 | + } | |
37 | + | |
38 | + setValue(item: any): void { | |
39 | + this.item = item; | |
40 | + } | |
41 | + | |
42 | + onClick(item: any) { | |
43 | + this.setValue(item); | |
44 | + this.params.api.stopEditing(); | |
45 | + } | |
46 | + | |
47 | + onKeyDown(event): boolean { | |
48 | + event.stopPropagation(); | |
49 | + return false; | |
50 | + } | |
51 | +} | ... | ... |
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.region">{{this.region.name}}</span>` | |
10 | +}) | |
11 | +export class RendererComponent implements AgRendererComponent { | |
12 | + private params: any; | |
13 | + private region: RegionSelectList; | |
14 | + agInit(params: any): void { | |
15 | + this.params = params; | |
16 | + console.log(params); | |
17 | + this.setValue(params); | |
18 | + } | |
19 | + refresh(params: any): void { | |
20 | + this.params = params; | |
21 | + console.log(params); | |
22 | + this.setValue(params); | |
23 | + } | |
24 | + private setValue(params) { | |
25 | + this.region = params.value; | |
26 | + console.log(params); | |
27 | + } | |
28 | +} | ... | ... |
1 | +export class RoadSelectList { } | ... | ... |
1 | +export class SettlementSelectList { } | ... | ... |
1 | +export class StateCommonSelectList { } | ... | ... |
1 | +export class SurfaceTypeSelectList { } | ... | ... |
src/app/pages/statements/components/busStop2/busStop2.component.ts
... | ... | @@ -4,6 +4,10 @@ import { BusStop2Service } from './busStop2.service'; |
4 | 4 | import { busStop2 } from './busStop2'; |
5 | 5 | import { LocalDataSource } from 'ng2-smart-table'; |
6 | 6 | import { GridOptions } from 'ag-grid/main'; |
7 | +import { RegionSelectListService } from '../../../../services/regionselectlist.service'; | |
8 | +import { RegionSelectList } from '../../../../models/regionselectlist'; | |
9 | +import { EditorComponent } from '../../../../components/editor.component'; | |
10 | +import { RendererComponent } from '../../../../components/renderer.component'; | |
7 | 11 | |
8 | 12 | @Component({ |
9 | 13 | selector: 'statement-table', |
... | ... | @@ -19,24 +23,27 @@ export class BusStop2 { |
19 | 23 | public showGrid: boolean; |
20 | 24 | public rowData: any[]; |
21 | 25 | public rowCount: string; |
26 | + public regions: RegionSelectList[]; | |
22 | 27 | private gridOptions: GridOptions; |
23 | 28 | private columnDefs: any[]; |
24 | 29 | |
25 | 30 | |
26 | - constructor(protected service: BusStop2Service) { | |
31 | + constructor(protected service: BusStop2Service, private regionlistservice: RegionSelectListService) { | |
32 | + this.regionlistservice.getModels().then(models => { | |
33 | + this.regions = models; | |
34 | + this.createColumnDefs(); | |
35 | + }); | |
27 | 36 | this.gridOptions = <GridOptions>{}; |
28 | 37 | // this.gridOptions.rowModelType = 'virtual'; |
29 | 38 | this.service.getData().then((data) => { |
30 | 39 | console.log(data); |
31 | - if(data.length){ | |
40 | + if (data.length){ | |
32 | 41 | // this.source.load(data); |
33 | 42 | this.rowData = data; |
34 | 43 | } else { |
35 | - this.rowData = [new busStop2] | |
44 | + this.rowData = [new busStop2]; | |
36 | 45 | } |
37 | - | |
38 | 46 | }); |
39 | - this.createColumnDefs(); | |
40 | 47 | this.showGrid = true; |
41 | 48 | } |
42 | 49 | |
... | ... | @@ -66,15 +73,20 @@ export class BusStop2 { |
66 | 73 | }, |
67 | 74 | { |
68 | 75 | headerName: 'Назва дороги', |
69 | - field: 'road', | |
76 | + field: 'roadId', | |
70 | 77 | editable: true, |
71 | 78 | width: 150 |
72 | 79 | }, |
73 | 80 | { |
74 | 81 | headerName: 'Область', |
75 | - field: 'region', | |
82 | + field: 'regionId', | |
76 | 83 | editable: true, |
77 | - width: 150 | |
84 | + width: 150, | |
85 | + cellEditorFramework: EditorComponent, | |
86 | + cellRendererFramework: RendererComponent, | |
87 | + cellEditorParams: { | |
88 | + data: this.regions | |
89 | + } | |
78 | 90 | }, |
79 | 91 | { |
80 | 92 | headerName: 'Місцезнаходження, км+ справа', |
... | ... | @@ -90,7 +102,7 @@ export class BusStop2 { |
90 | 102 | }, |
91 | 103 | { |
92 | 104 | headerName: 'Технічний стан', |
93 | - field: 'state', | |
105 | + field: 'stateCommonId', | |
94 | 106 | editable: true, |
95 | 107 | width: 150 |
96 | 108 | } | ... | ... |
src/app/pages/statements/components/busStop2/busStop2.ts
1 | 1 | export class busStop2 { |
2 | - RoadId: number; | |
3 | - RegionId: number; | |
4 | - SettlementId: number; | |
5 | - LocationLeft: string; | |
6 | - LocationRight: string; | |
7 | - SurfaceTypeId: string; | |
8 | - AreaStopAvailability: string; | |
9 | - AreaLandAvailability: string; | |
10 | - PocketAvailability: string; | |
11 | - ToiletAvailability: string; | |
12 | - YearBuild: string; | |
13 | - YearRepair: string; | |
14 | - StateCommonId: number; | |
2 | + roadId: number; | |
3 | + regionId: number; | |
4 | + settlementId: number; | |
5 | + locationLeft: string; | |
6 | + locationRight: string; | |
7 | + surfaceTypeId: string; | |
8 | + areaStopAvailability: string; | |
9 | + areaLandAvailability: string; | |
10 | + pocketAvailability: string; | |
11 | + toiletAvailability: string; | |
12 | + yearBuild: string; | |
13 | + yearRepair: string; | |
14 | + stateCommonId: number; | |
15 | 15 | } | ... | ... |
src/app/pages/statements/statements.module.ts
... | ... | @@ -9,6 +9,8 @@ import { routing } from './statements.routing'; |
9 | 9 | import { Statements } from './statements.component'; |
10 | 10 | import { BusStop } from './components/busStop/busStop.component'; |
11 | 11 | import { BusStop2 } from './components/busStop2/busStop2.component'; |
12 | +import { EditorComponent } from '../../components/editor.component'; | |
13 | +import { RendererComponent } from '../../components/renderer.component'; | |
12 | 14 | import { BusStopService } from './components/busStop/busStop.service'; |
13 | 15 | import { BusStop2Service } from './components/busStop2/busStop2.service'; |
14 | 16 | |
... | ... | @@ -20,13 +22,17 @@ import { BusStop2Service } from './components/busStop2/busStop2.service'; |
20 | 22 | routing, |
21 | 23 | Ng2SmartTableModule, |
22 | 24 | AgGridModule.withComponents([ |
23 | - BusStop2 | |
25 | + BusStop2, | |
26 | + EditorComponent, | |
27 | + RendererComponent, | |
24 | 28 | ]), |
25 | 29 | ], |
26 | 30 | declarations: [ |
27 | 31 | Statements, |
28 | 32 | BusStop, |
29 | - BusStop2 | |
33 | + BusStop2, | |
34 | + EditorComponent, | |
35 | + RendererComponent, | |
30 | 36 | ], |
31 | 37 | providers: [ |
32 | 38 | BusStopService, | ... | ... |
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 | +} | ... | ... |