Commit 026fffbd1e6d662f0744057dfdf8e7c89f0cdd2f
1 parent
1392e7de
Awesome
Showing
10 changed files
with
106 additions
and
105 deletions
Show diff stats
src/app/data/bus-stop/bus-stop.component.ts
... | ... | @@ -42,21 +42,6 @@ export class BusStopComponent extends StatementBase { |
42 | 42 | protected loadingService: TdLoadingService, |
43 | 43 | ) { |
44 | 44 | super(); |
45 | - this.initGrid(); | |
46 | - this.booleanService.getModels().then((models: BooleanSelectList[]) => this.boolean = models); | |
47 | - this.dataService.getModels().then((models: any) => { | |
48 | - this.regions = models.regionSelectListDsM as RegionSelectList[]; | |
49 | - this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | |
50 | - this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; | |
51 | - this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; | |
52 | - this.roads = models.roadSelectListDsM as RoadSelectList[]; | |
53 | - }).then(() => { | |
54 | - this.bootstrapGrid(); | |
55 | - }); | |
56 | - } | |
57 | - | |
58 | - protected createModel(): Object { | |
59 | - return new BusStop(); | |
60 | 45 | } |
61 | 46 | |
62 | 47 | protected createColumnDefs(): any[] { |
... | ... | @@ -192,4 +177,17 @@ export class BusStopComponent extends StatementBase { |
192 | 177 | }, |
193 | 178 | ]; |
194 | 179 | } |
180 | + | |
181 | + protected initFunction(): void { | |
182 | + this.booleanService.getModels().then((models: BooleanSelectList[]) => this.boolean = models); | |
183 | + this.dataService.getModels().then((models: any) => { | |
184 | + this.regions = models.regionSelectListDsM as RegionSelectList[]; | |
185 | + this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | |
186 | + this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; | |
187 | + this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; | |
188 | + this.roads = models.roadSelectListDsM as RoadSelectList[]; | |
189 | + }).then(() => { | |
190 | + this.bootstrapGrid(); | |
191 | + }); | |
192 | + } | |
195 | 193 | } | ... | ... |
src/app/data/service-object/service-object.component.ts
... | ... | @@ -35,25 +35,10 @@ export class ServiceObjectComponent extends StatementBase { |
35 | 35 | |
36 | 36 | constructor( |
37 | 37 | protected service: ServiceObjectService, |
38 | - private dataService: ServiceObjectCreateService, | |
39 | - private booleanService: BooleanSelectListService, | |
38 | + protected dataService: ServiceObjectCreateService, | |
39 | + protected booleanService: BooleanSelectListService, | |
40 | 40 | ) { |
41 | 41 | super(); |
42 | - this.initGrid(); | |
43 | - this.booleanService.getModels().then((models: BooleanSelectList[]) => this.boolean = models); | |
44 | - this.dataService.getModels().then((models: any) => { | |
45 | - this.regions = models.regionSelectListDsM as RegionSelectList[]; | |
46 | - this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | |
47 | - this.departmentAffiliation = models.departmentAffiliationListDsM as DepartmentAffiliationList[]; | |
48 | - this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; | |
49 | - this.roads = models.roadSelectListDsM as RoadSelectList[]; | |
50 | - }).then(() => { | |
51 | - this.bootstrapGrid(); | |
52 | - }); | |
53 | - } | |
54 | - | |
55 | - protected createModel(): Object { | |
56 | - return new ServiceObject(); | |
57 | 42 | } |
58 | 43 | |
59 | 44 | protected createColumnDefs(): any[] { |
... | ... | @@ -106,4 +91,17 @@ export class ServiceObjectComponent extends StatementBase { |
106 | 91 | }, |
107 | 92 | ]; |
108 | 93 | } |
94 | + | |
95 | + protected initFunction(): void { | |
96 | + this.booleanService.getModels().then((models: BooleanSelectList[]) => this.boolean = models); | |
97 | + this.dataService.getModels().then((models: any) => { | |
98 | + this.regions = models.regionSelectListDsM as RegionSelectList[]; | |
99 | + this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | |
100 | + this.departmentAffiliation = models.departmentAffiliationListDsM as DepartmentAffiliationList[]; | |
101 | + this.settlements = models.settlementSelectListDsM as SettlementSelectList[]; | |
102 | + this.roads = models.roadSelectListDsM as RoadSelectList[]; | |
103 | + }).then(() => { | |
104 | + this.bootstrapGrid(); | |
105 | + }); | |
106 | + } | |
109 | 107 | } | ... | ... |
src/models/statement.base.ts
1 | -import { AfterViewInit } from '@angular/core'; | |
1 | +import { AfterViewInit, OnInit } from '@angular/core'; | |
2 | 2 | import { TdLoadingService } from '@covalent/core'; |
3 | 3 | import { GridOptions, IGetRowsParams, IRowModel, RowNode } from 'ag-grid/main'; |
4 | +import { StatementBaseService } from '../services/statement.base.service'; | |
4 | 5 | |
5 | -export abstract class StatementBase implements AfterViewInit { | |
6 | +export abstract class StatementBase implements AfterViewInit, OnInit { | |
6 | 7 | protected columnDefs: any[]; |
7 | 8 | protected gridOptions: GridOptions; |
8 | - protected service: any; | |
9 | + protected service: StatementBaseService; | |
9 | 10 | protected loadingService: TdLoadingService; |
10 | 11 | public showGrid: boolean; |
11 | 12 | public rowCount: string; |
... | ... | @@ -14,6 +15,11 @@ export abstract class StatementBase implements AfterViewInit { |
14 | 15 | public isSelected: boolean = false; |
15 | 16 | public isNew: boolean = false; |
16 | 17 | |
18 | + ngOnInit(): void { | |
19 | + this.initGrid(); | |
20 | + this.initFunction(); | |
21 | + } | |
22 | + | |
17 | 23 | ngAfterViewInit(): void { |
18 | 24 | this.gridOptions.api.setDatasource(this.setRowData()); |
19 | 25 | } |
... | ... | @@ -46,6 +52,7 @@ export abstract class StatementBase implements AfterViewInit { |
46 | 52 | this.gridOptions.enableServerSideSorting = true; |
47 | 53 | this.showGrid = true; |
48 | 54 | this.gridOptions.rowModelType = 'virtual'; |
55 | + this.gridOptions.paginationPageSize = 25; | |
49 | 56 | } |
50 | 57 | |
51 | 58 | protected bootstrapGrid(): void { |
... | ... | @@ -212,6 +219,9 @@ export abstract class StatementBase implements AfterViewInit { |
212 | 219 | console.log('onColumnEvent: ' + $event); |
213 | 220 | } |
214 | 221 | |
215 | - protected abstract createModel(): Object; | |
222 | + protected createModel(): Object { | |
223 | + return this.service.createModel(); | |
224 | + }; | |
216 | 225 | protected abstract createColumnDefs(): any[]; |
226 | + protected abstract initFunction(): void; | |
217 | 227 | } | ... | ... |
src/services/boolean-select-list.service.ts
1 | 1 | import { Injectable } from '@angular/core'; |
2 | +import { Http } from '@angular/http'; | |
3 | + | |
4 | +import { CreateBaseService } from './create.base.service'; | |
2 | 5 | |
3 | 6 | import { BooleanSelectList } from '../models/boolean-select-list'; |
4 | 7 | |
5 | 8 | @Injectable() |
6 | -export class BooleanSelectListService { | |
9 | +export class BooleanSelectListService extends CreateBaseService { | |
10 | + protected apiUrl: string = ''; | |
11 | + constructor(protected http: Http) { | |
12 | + super(http); | |
13 | + } | |
7 | 14 | getModels(): Promise<BooleanSelectList[]> { |
8 | - let values = []; | |
9 | - let trueValue = new BooleanSelectList(); | |
15 | + let values: BooleanSelectList[] = []; | |
16 | + let trueValue: BooleanSelectList = new BooleanSelectList(); | |
10 | 17 | trueValue.value = 1; |
11 | 18 | trueValue.label = 'ะะฐ'; |
12 | - let falseValue = new BooleanSelectList(); | |
19 | + let falseValue: BooleanSelectList = new BooleanSelectList(); | |
13 | 20 | falseValue.value = 0; |
14 | 21 | falseValue.label = 'ะะตั'; |
15 | 22 | values.push(falseValue); | ... | ... |
src/services/bus-stop-create.service.ts
1 | 1 | import { Injectable } from '@angular/core'; |
2 | -import { Headers, Http } from '@angular/http'; | |
2 | +import { Http } from '@angular/http'; | |
3 | 3 | |
4 | -import 'rxjs/add/operator/toPromise'; | |
4 | +import { CreateBaseService } from './create.base.service'; | |
5 | 5 | |
6 | 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); | |
7 | +export class BusStopCreateService extends CreateBaseService { | |
8 | + protected apiUrl: string = 'http://localhost:5000/busstop/directory'; | |
9 | + constructor(protected http: Http) { | |
10 | + super(http); | |
20 | 11 | } |
21 | 12 | } | ... | ... |
src/services/bus-stop.service.ts
1 | -import { BusStop } from '../models/bus-stop'; | |
2 | 1 | import { Injectable } from '@angular/core'; |
3 | -import { StatementBaseService } from '../services/statement.base.service'; | |
4 | 2 | import { Http } from '@angular/http'; |
5 | 3 | |
4 | +import { StatementBaseService } from './statement.base.service'; | |
5 | + | |
6 | +import { BusStop } from '../models/bus-stop'; | |
7 | + | |
6 | 8 | @Injectable() |
7 | 9 | export class BusStopService extends StatementBaseService { |
8 | 10 | protected url: string = 'http://localhost:5000/busstop'; |
9 | 11 | constructor(protected http: Http) { |
10 | 12 | super(http); |
11 | 13 | } |
14 | + public createModel(): Object { | |
15 | + return new BusStop(); | |
16 | + } | |
12 | 17 | protected parseModels(json: any): any[] { |
13 | 18 | return json.busStopEditDsM as BusStop[]; |
14 | 19 | }; | ... | ... |
1 | +import { Headers, Http, Response } from '@angular/http'; | |
2 | + | |
3 | +export abstract class CreateBaseService { | |
4 | + protected abstract apiUrl: string; | |
5 | + protected headers: Headers = new Headers({'Content-Type': 'applicaton/json'}); | |
6 | + constructor(protected http: Http) { } | |
7 | + getModels(): Promise<any> { | |
8 | + return this.http.get(this.apiUrl) | |
9 | + .toPromise() | |
10 | + .then((response: Response) => response.json()) | |
11 | + .catch(this.handleError); | |
12 | + } | |
13 | + protected handleError(error: any): Promise<any> { | |
14 | + console.error('An error occured', error); | |
15 | + return Promise.reject(error.message || error); | |
16 | + } | |
17 | +} | ... | ... |
src/services/service-object-create.service.ts
1 | 1 | import { Injectable } from '@angular/core'; |
2 | -import { Headers, Http } from '@angular/http'; | |
2 | +import { Http } from '@angular/http'; | |
3 | 3 | |
4 | -import 'rxjs/add/operator/toPromise'; | |
4 | +import { CreateBaseService } from './create.base.service'; | |
5 | 5 | |
6 | 6 | @Injectable() |
7 | -export class ServiceObjectCreateService { | |
8 | - private apiUrl = 'http://localhost:5000/serviceobject/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); | |
7 | +export class ServiceObjectCreateService extends CreateBaseService { | |
8 | + protected apiUrl: string = 'http://localhost:5000/serviceobject/directory'; | |
9 | + constructor(protected http: Http) { | |
10 | + super(http); | |
20 | 11 | } |
21 | 12 | } | ... | ... |
src/services/service-object.service.ts
1 | 1 | import { Injectable } from '@angular/core'; |
2 | 2 | import { Headers, Http } from '@angular/http'; |
3 | 3 | |
4 | -import 'rxjs/add/operator/toPromise'; | |
4 | +import { StatementBaseService } from './statement.base.service'; | |
5 | 5 | |
6 | 6 | import { ServiceObject } from '../models/service-object'; |
7 | 7 | |
8 | 8 | @Injectable() |
9 | -export class ServiceObjectService { | |
10 | - private url = 'http://localhost:5000/serviceobject'; | |
11 | - private headers = new Headers({'Content-Type': 'application/json'}); | |
12 | - constructor(private http: Http) { } | |
13 | - getData(): Promise<ServiceObject[]> { | |
14 | - return this.http.get(this.url) | |
15 | - .toPromise() | |
16 | - .then(response => response.json().serviceObjectEditDsM as ServiceObject[]) | |
17 | - .catch(this.handleError); | |
18 | - } | |
19 | - update(id: number, data: string): Promise<any> { | |
20 | - return this.http.post(this.url + '/update?id=' + id, data, { headers: this.headers }) | |
21 | - .toPromise() | |
22 | - .then(response => response.json()) | |
23 | - .catch(this.handleError); | |
24 | - } | |
25 | - create(data: string): Promise<ServiceObject> { | |
26 | - return this.http.post(this.url + '/create', data, { headers: this.headers }) | |
27 | - .toPromise() | |
28 | - .then(response => response.json() as ServiceObject) | |
29 | - .catch(this.handleError); | |
30 | - } | |
31 | - delete(id: number): Promise<any> { | |
32 | - return this.http.delete(this.url + '/delete?id=' + id, { headers: this.headers }) | |
33 | - .toPromise() | |
34 | - .then(response => response.json()) | |
35 | - .catch(this.handleError); | |
36 | - } | |
37 | - private handleError(error: any): Promise<any> { | |
38 | - console.error('An error occured', error); | |
39 | - return Promise.reject(error.message || error); | |
40 | - } | |
9 | +export class ServiceObjectService extends StatementBaseService { | |
10 | + protected url: string = 'http://localhost:5000/serviceobject'; | |
11 | + constructor(protected http: Http) { | |
12 | + super(http); | |
13 | + } | |
14 | + public createModel(): Object { | |
15 | + return new ServiceObject(); | |
16 | + } | |
17 | + protected parseModels(json: any): any { | |
18 | + return json.serviceObjectEditDsM as ServiceObject[]; | |
19 | + } | |
20 | + protected parseModel(json: any): any { | |
21 | + return json as ServiceObject; | |
22 | + } | |
41 | 23 | } | ... | ... |
src/services/statement.base.service.ts
... | ... | @@ -41,6 +41,8 @@ export abstract class StatementBaseService { |
41 | 41 | .catch(this.handleError); |
42 | 42 | } |
43 | 43 | |
44 | + public abstract createModel(): Object; | |
45 | + | |
44 | 46 | protected handleError(error: any): Promise<any> { |
45 | 47 | console.error('An error occured', error); |
46 | 48 | return Promise.reject(error.message || error); | ... | ... |