Commit abf7c25f9f21d0c48dc027e3b4ccbc3dd64d77c6

Authored by Yarik
1 parent d675b823

Dropdown

src/app/app.module.ts
@@ -5,6 +5,9 @@ import { HttpModule } from '@angular/http'; @@ -5,6 +5,9 @@ import { HttpModule } from '@angular/http';
5 import { RouterModule } from '@angular/router'; 5 import { RouterModule } from '@angular/router';
6 import { removeNgStyles, createNewHosts, createInputTransfer } from '@angularclass/hmr'; 6 import { removeNgStyles, createNewHosts, createInputTransfer } from '@angularclass/hmr';
7 7
  8 +// Services
  9 +import { RegionSelectListService } from './services/regionselectlist.service';
  10 +
8 /* 11 /*
9 * Platform and Environment providers/directives/pipes 12 * Platform and Environment providers/directives/pipes
10 */ 13 */
@@ -50,7 +53,8 @@ export type StoreType = { @@ -50,7 +53,8 @@ export type StoreType = {
50 ], 53 ],
51 providers: [ // expose our Services and Providers into Angular's dependency injection 54 providers: [ // expose our Services and Providers into Angular's dependency injection
52 ENV_PROVIDERS, 55 ENV_PROVIDERS,
53 - APP_PROVIDERS 56 + APP_PROVIDERS,
  57 + RegionSelectListService
54 ] 58 ]
55 }) 59 })
56 60
src/app/components/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 +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 +}
src/app/components/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.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 +}
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 { }
src/app/models/settlementselectlist.ts 0 → 100644
  1 +export class SettlementSelectList { }
src/app/models/statecommonselectlist.ts 0 → 100644
  1 +export class StateCommonSelectList { }
src/app/models/surfacetypeselectlist.ts 0 → 100644
  1 +export class SurfaceTypeSelectList { }
src/app/pages/statements/components/busStop2/busStop2.component.ts
@@ -4,6 +4,10 @@ import { BusStop2Service } from &#39;./busStop2.service&#39;; @@ -4,6 +4,10 @@ import { BusStop2Service } from &#39;./busStop2.service&#39;;
4 import { busStop2 } from './busStop2'; 4 import { busStop2 } from './busStop2';
5 import { LocalDataSource } from 'ng2-smart-table'; 5 import { LocalDataSource } from 'ng2-smart-table';
6 import { GridOptions } from 'ag-grid/main'; 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 @Component({ 12 @Component({
9 selector: 'statement-table', 13 selector: 'statement-table',
@@ -19,24 +23,27 @@ export class BusStop2 { @@ -19,24 +23,27 @@ export class BusStop2 {
19 public showGrid: boolean; 23 public showGrid: boolean;
20 public rowData: any[]; 24 public rowData: any[];
21 public rowCount: string; 25 public rowCount: string;
  26 + public regions: RegionSelectList[];
22 private gridOptions: GridOptions; 27 private gridOptions: GridOptions;
23 private columnDefs: any[]; 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 this.gridOptions = <GridOptions>{}; 36 this.gridOptions = <GridOptions>{};
28 // this.gridOptions.rowModelType = 'virtual'; 37 // this.gridOptions.rowModelType = 'virtual';
29 this.service.getData().then((data) => { 38 this.service.getData().then((data) => {
30 console.log(data); 39 console.log(data);
31 - if(data.length){ 40 + if (data.length){
32 // this.source.load(data); 41 // this.source.load(data);
33 this.rowData = data; 42 this.rowData = data;
34 } else { 43 } else {
35 - this.rowData = [new busStop2] 44 + this.rowData = [new busStop2];
36 } 45 }
37 -  
38 }); 46 });
39 - this.createColumnDefs();  
40 this.showGrid = true; 47 this.showGrid = true;
41 } 48 }
42 49
@@ -66,15 +73,20 @@ export class BusStop2 { @@ -66,15 +73,20 @@ export class BusStop2 {
66 }, 73 },
67 { 74 {
68 headerName: 'Назва дороги', 75 headerName: 'Назва дороги',
69 - field: 'road', 76 + field: 'roadId',
70 editable: true, 77 editable: true,
71 width: 150 78 width: 150
72 }, 79 },
73 { 80 {
74 headerName: 'Область', 81 headerName: 'Область',
75 - field: 'region', 82 + field: 'regionId',
76 editable: true, 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 headerName: 'Місцезнаходження, км+ справа', 92 headerName: 'Місцезнаходження, км+ справа',
@@ -90,7 +102,7 @@ export class BusStop2 { @@ -90,7 +102,7 @@ export class BusStop2 {
90 }, 102 },
91 { 103 {
92 headerName: 'Технічний стан', 104 headerName: 'Технічний стан',
93 - field: 'state', 105 + field: 'stateCommonId',
94 editable: true, 106 editable: true,
95 width: 150 107 width: 150
96 } 108 }
src/app/pages/statements/components/busStop2/busStop2.ts
1 export class busStop2 { 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 &#39;./statements.routing&#39;; @@ -9,6 +9,8 @@ import { routing } from &#39;./statements.routing&#39;;
9 import { Statements } from './statements.component'; 9 import { Statements } from './statements.component';
10 import { BusStop } from './components/busStop/busStop.component'; 10 import { BusStop } from './components/busStop/busStop.component';
11 import { BusStop2 } from './components/busStop2/busStop2.component'; 11 import { BusStop2 } from './components/busStop2/busStop2.component';
  12 +import { EditorComponent } from '../../components/editor.component';
  13 +import { RendererComponent } from '../../components/renderer.component';
12 import { BusStopService } from './components/busStop/busStop.service'; 14 import { BusStopService } from './components/busStop/busStop.service';
13 import { BusStop2Service } from './components/busStop2/busStop2.service'; 15 import { BusStop2Service } from './components/busStop2/busStop2.service';
14 16
@@ -20,13 +22,17 @@ import { BusStop2Service } from &#39;./components/busStop2/busStop2.service&#39;; @@ -20,13 +22,17 @@ import { BusStop2Service } from &#39;./components/busStop2/busStop2.service&#39;;
20 routing, 22 routing,
21 Ng2SmartTableModule, 23 Ng2SmartTableModule,
22 AgGridModule.withComponents([ 24 AgGridModule.withComponents([
23 - BusStop2 25 + BusStop2,
  26 + EditorComponent,
  27 + RendererComponent,
24 ]), 28 ]),
25 ], 29 ],
26 declarations: [ 30 declarations: [
27 Statements, 31 Statements,
28 BusStop, 32 BusStop,
29 - BusStop2 33 + BusStop2,
  34 + EditorComponent,
  35 + RendererComponent,
30 ], 36 ],
31 providers: [ 37 providers: [
32 BusStopService, 38 BusStopService,
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
src/app/services/surfacetypeselectlist.service.ts 0 → 100644