Commit 7085f966d544747f29c75c1290f7739599552a92
1 parent
d78dcf2b
Validation try
Showing
8 changed files
with
132 additions
and
51 deletions
Show diff stats
src/app/app.module.ts
1 | import { NgModule, Type } from '@angular/core'; | 1 | import { NgModule, Type } from '@angular/core'; |
2 | import { BrowserModule, Title } from '@angular/platform-browser'; | 2 | import { BrowserModule, Title } from '@angular/platform-browser'; |
3 | 3 | ||
4 | -import { CovalentCoreModule } from '@covalent/core'; | 4 | +import { CovalentCoreModule, CovalentLoadingModule } from '@covalent/core'; |
5 | import { CovalentHttpModule, IHttpInterceptor } from '@covalent/http'; | 5 | import { CovalentHttpModule, IHttpInterceptor } from '@covalent/http'; |
6 | import { CovalentHighlightModule } from '@covalent/highlight'; | 6 | import { CovalentHighlightModule } from '@covalent/highlight'; |
7 | import { CovalentMarkdownModule } from '@covalent/markdown'; | 7 | import { CovalentMarkdownModule } from '@covalent/markdown'; |
@@ -61,6 +61,7 @@ const httpInterceptorProviders: Type<any>[] = [ | @@ -61,6 +61,7 @@ const httpInterceptorProviders: Type<any>[] = [ | ||
61 | }), | 61 | }), |
62 | CovalentHighlightModule.forRoot(), | 62 | CovalentHighlightModule.forRoot(), |
63 | CovalentMarkdownModule.forRoot(), | 63 | CovalentMarkdownModule.forRoot(), |
64 | + CovalentLoadingModule.forRoot(), | ||
64 | appRoutes, | 65 | appRoutes, |
65 | NgxChartsModule, | 66 | NgxChartsModule, |
66 | ], // modules needed to run this module | 67 | ], // modules needed to run this module |
@@ -70,7 +71,7 @@ const httpInterceptorProviders: Type<any>[] = [ | @@ -70,7 +71,7 @@ const httpInterceptorProviders: Type<any>[] = [ | ||
70 | Title, | 71 | Title, |
71 | BusStopCreateService, | 72 | BusStopCreateService, |
72 | BooleanSelectListService, | 73 | BooleanSelectListService, |
73 | - BusStopService | 74 | + BusStopService, |
74 | ], // additional providers needed for this module | 75 | ], // additional providers needed for this module |
75 | entryComponents: [ ], | 76 | entryComponents: [ ], |
76 | bootstrap: [ AppComponent ], | 77 | bootstrap: [ AppComponent ], |
src/app/app.routes.ts
@@ -9,10 +9,10 @@ import { BusStopComponent } from './data/bus-stop/bus-stop.component'; | @@ -9,10 +9,10 @@ import { BusStopComponent } from './data/bus-stop/bus-stop.component'; | ||
9 | const routes: Routes = [ | 9 | const routes: Routes = [ |
10 | {path: 'login', component: LoginComponent}, | 10 | {path: 'login', component: LoginComponent}, |
11 | {path: '', component: MainComponent, children: [ | 11 | {path: '', component: MainComponent, children: [ |
12 | - {path: '',component: TemplatesComponent}, | 12 | + {path: '', component: TemplatesComponent}, |
13 | {path: 'data', component: DataComponent, children: [ | 13 | {path: 'data', component: DataComponent, children: [ |
14 | {path: 'bus-stop', component: BusStopComponent}, | 14 | {path: 'bus-stop', component: BusStopComponent}, |
15 | - ]} | 15 | + ]}, |
16 | ]}, | 16 | ]}, |
17 | ]; | 17 | ]; |
18 | 18 |
src/app/data/bus-stop/bus-stop.component.html
1 | <md-card tdMediaToggle="gt-xs" [mediaClasses]="['push']"> | 1 | <md-card tdMediaToggle="gt-xs" [mediaClasses]="['push']"> |
2 | -<<<<<<< HEAD | ||
3 | - <div> | ||
4 | - <h1>Rich Grid with Pure JavaScript</h1> | ||
5 | - <div style="clear: both;"></div> | ||
6 | - <div *ngIf="showGrid"> | ||
7 | - <button md-raised-button color="accent" (click)="addNewRow()" type="button">Добавить новое поле</button> | ||
8 | - <button md-raised-button color="warn" (click)="deleteRows()" type="button">Удалить</button> | ||
9 | - <div *tdLoading="'overlayStarSyntax'; mode:'indeterminate'; type:'circle'; strategy:'overlay'; color:'accent'"> | ||
10 | - Loading | ||
11 | - </div> | ||
12 | - <div *ngIf="isLoading" class=""> | ||
13 | - ...Loading | ||
14 | - </div> | ||
15 | - <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-dark" [gridOptions]="gridOptions" [columnDefs]="columnDefs" [rowData]="rowData" enableColResize enableSorting enableFilter groupHeaders suppressRowClickSelection toolPanelSuppressGroups | ||
16 | - toolPanelSuppressValues debug rowHeight="22" rowSelection="multiple" (cellClicked)="onCellClicked($event)" (cellDoubleClicked)="onCellDoubleClicked($event)" (cellContextMenu)="onCellContextMenu($event)" (cellValueChanged)="onCellValueChanged($event)" | ||
17 | - (cellFocused)="onCellFocused($event)" (rowSelected)="onRowSelected($event)" (selectionChanged)="onSelectionChanged()" (beforeFilterChanged)="onBeforeFilterChanged()" (afterFilterChanged)="onAfterFilterChanged()" (filterModified)="onFilterModified()" | ||
18 | - (beforeSortChanged)="onBeforeSortChanged()" (afterSortChanged)="onAfterSortChanged()" (virtualRowRemoved)="onVirtualRowRemoved($event)" (rowClicked)="onRowClicked($event)"> | ||
19 | - </ag-grid-ng2> | ||
20 | -======= | ||
21 | <div *ngIf="showGrid"> | 2 | <div *ngIf="showGrid"> |
22 | - <div class="control_button"> | ||
23 | - <button md-fab color="accent" (click)="addNewRow()" type="button"><md-icon>add</md-icon></button> | ||
24 | - <button md-fab color="warn" (click)="deleteRows()" type="button"><md-icon>delete</md-icon></button> | ||
25 | ->>>>>>> f4c3aacea95ba58d99581795e79264058b7dd372 | ||
26 | - </div> | ||
27 | - <div *ngIf="isLoading" class=""> | ||
28 | - ...Loading | ||
29 | - </div> | ||
30 | <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-dark" [gridOptions]="gridOptions" [columnDefs]="columnDefs" [rowData]="rowData" enableColResize enableSorting enableFilter groupHeaders suppressRowClickSelection toolPanelSuppressGroups | 3 | <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-dark" [gridOptions]="gridOptions" [columnDefs]="columnDefs" [rowData]="rowData" enableColResize enableSorting enableFilter groupHeaders suppressRowClickSelection toolPanelSuppressGroups |
31 | toolPanelSuppressValues debug rowHeight="22" rowSelection="multiple" (cellClicked)="onCellClicked($event)" (cellDoubleClicked)="onCellDoubleClicked($event)" (cellContextMenu)="onCellContextMenu($event)" (cellValueChanged)="onCellValueChanged($event)" | 4 | toolPanelSuppressValues debug rowHeight="22" rowSelection="multiple" (cellClicked)="onCellClicked($event)" (cellDoubleClicked)="onCellDoubleClicked($event)" (cellContextMenu)="onCellContextMenu($event)" (cellValueChanged)="onCellValueChanged($event)" |
32 | (cellFocused)="onCellFocused($event)" (rowSelected)="onRowSelected($event)" (selectionChanged)="onSelectionChanged()" (beforeFilterChanged)="onBeforeFilterChanged()" (afterFilterChanged)="onAfterFilterChanged()" (filterModified)="onFilterModified()" | 5 | (cellFocused)="onCellFocused($event)" (rowSelected)="onRowSelected($event)" (selectionChanged)="onSelectionChanged()" (beforeFilterChanged)="onBeforeFilterChanged()" (afterFilterChanged)="onAfterFilterChanged()" (filterModified)="onFilterModified()" |
33 | (beforeSortChanged)="onBeforeSortChanged()" (afterSortChanged)="onAfterSortChanged()" (virtualRowRemoved)="onVirtualRowRemoved($event)" (rowClicked)="onRowClicked($event)"> | 6 | (beforeSortChanged)="onBeforeSortChanged()" (afterSortChanged)="onAfterSortChanged()" (virtualRowRemoved)="onVirtualRowRemoved($event)" (rowClicked)="onRowClicked($event)"> |
34 | </ag-grid-ng2> | 7 | </ag-grid-ng2> |
8 | + <div class="control_button"> | ||
9 | + <div *tdLoading="'loading'; mode:'indeterminate'; type:'circle'; strategy:'replace'; color:'accent'"></div> | ||
10 | + <button md-fab color="accent" (click)="addNewRow()" type="button"><md-icon>add</md-icon></button> | ||
11 | + <button md-fab color="warn" (click)="deleteRows()" type="button"><md-icon>delete</md-icon></button> | ||
12 | + </div> | ||
35 | </div> | 13 | </div> |
36 | </md-card> | 14 | </md-card> |
37 | \ No newline at end of file | 15 | \ No newline at end of file |
src/app/data/bus-stop/bus-stop.component.ts
1 | -import {Component, ViewEncapsulation} from "@angular/core"; | ||
2 | -import {GridOptions} from "ag-grid/main"; | 1 | +import { Component, ViewEncapsulation } from '@angular/core'; |
2 | +import { TdLoadingService } from '@covalent/core'; | ||
3 | +import { GridOptions } from 'ag-grid/main'; | ||
3 | 4 | ||
4 | import { BusStopService } from '../../../services/bus-stop.service'; | 5 | import { BusStopService } from '../../../services/bus-stop.service'; |
5 | import { BusStop } from '../../../models/bus-stop'; | 6 | import { BusStop } from '../../../models/bus-stop'; |
@@ -21,10 +22,12 @@ import { SurfaceTypeSelectList } from '../../../models/surface-type-select-list' | @@ -21,10 +22,12 @@ import { SurfaceTypeSelectList } from '../../../models/surface-type-select-list' | ||
21 | selector: 'rich-grid', | 22 | selector: 'rich-grid', |
22 | templateUrl: 'bus-stop.component.html', | 23 | templateUrl: 'bus-stop.component.html', |
23 | styleUrls: ['bus-stop.scss'], | 24 | styleUrls: ['bus-stop.scss'], |
24 | - encapsulation: ViewEncapsulation.None | 25 | + encapsulation: ViewEncapsulation.None, |
25 | }) | 26 | }) |
26 | export class BusStopComponent { | 27 | export class BusStopComponent { |
27 | 28 | ||
29 | + private columnDefs: any[]; | ||
30 | + private gridOptions: GridOptions; | ||
28 | public showGrid: boolean; | 31 | public showGrid: boolean; |
29 | public rowData: any[]; | 32 | public rowData: any[]; |
30 | public rowCount: string; | 33 | public rowCount: string; |
@@ -37,20 +40,19 @@ export class BusStopComponent { | @@ -37,20 +40,19 @@ export class BusStopComponent { | ||
37 | public isLoading: boolean = false; | 40 | public isLoading: boolean = false; |
38 | public isBootstrapping: boolean = true; | 41 | public isBootstrapping: boolean = true; |
39 | public isSelected: boolean = true; | 42 | public isSelected: boolean = true; |
40 | - private columnDefs: any[]; | ||
41 | - private gridOptions: GridOptions; | ||
42 | 43 | ||
43 | constructor( | 44 | constructor( |
44 | protected service: BusStopService, | 45 | protected service: BusStopService, |
45 | private dataService: BusStopCreateService, | 46 | private dataService: BusStopCreateService, |
46 | - private booleanService: BooleanSelectListService | 47 | + private booleanService: BooleanSelectListService, |
48 | + private loadingService: TdLoadingService, | ||
47 | ) { | 49 | ) { |
48 | this.gridOptions = <GridOptions>{}; | 50 | this.gridOptions = <GridOptions>{}; |
49 | - this.gridOptions.enableSorting = true; | ||
50 | - this.showGrid = true; | ||
51 | - this.gridOptions.rowModelType = 'virtual'; | ||
52 | - this.booleanService.getModels().then((models) => this.boolean = models); | ||
53 | - this.dataService.getModels().then(models => { | 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 => { | ||
54 | this.regions = models.regionSelectListDsM as RegionSelectList[]; | 56 | this.regions = models.regionSelectListDsM as RegionSelectList[]; |
55 | this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; | 57 | this.states = models.stateCommonSelectListDsM as StateCommonSelectList[]; |
56 | this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; | 58 | this.surfaceTypes = models.surfaceTypeSelectListDsM as SurfaceTypeSelectList[]; |
@@ -60,11 +62,11 @@ export class BusStopComponent { | @@ -60,11 +62,11 @@ export class BusStopComponent { | ||
60 | this.createColumnDefs(); | 62 | this.createColumnDefs(); |
61 | this.isBootstrapping = false; | 63 | this.isBootstrapping = false; |
62 | }); | 64 | }); |
63 | - this.service.getData().then((data) => { | 65 | + this.service.getData().then((data) => { |
64 | if (data.length){ | 66 | if (data.length){ |
65 | this.rowData = data; | 67 | this.rowData = data; |
66 | } else { | 68 | } else { |
67 | - this.rowData = [new BusStop]; | 69 | + this.rowData = [new BusStop()]; |
68 | } | 70 | } |
69 | }).then(() => { | 71 | }).then(() => { |
70 | this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); | 72 | this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
@@ -90,7 +92,18 @@ export class BusStopComponent { | @@ -90,7 +92,18 @@ export class BusStopComponent { | ||
90 | } | 92 | } |
91 | }; | 93 | }; |
92 | return dataSource; | 94 | return dataSource; |
93 | - | 95 | + } |
96 | + enableLoader(): void { | ||
97 | + if (!this.isLoading) { | ||
98 | + this.isLoading = true; | ||
99 | + this.loadingService.register('loading'); | ||
100 | + } | ||
101 | + } | ||
102 | + disableLoader(): void { | ||
103 | + if (this.isLoading) { | ||
104 | + this.isLoading = false; | ||
105 | + this.loadingService.resolve('loading'); | ||
106 | + } | ||
94 | } | 107 | } |
95 | onDeleteConfirm(event): void { | 108 | onDeleteConfirm(event): void { |
96 | if (window.confirm('Вы уверены что хотите удалить??')) { | 109 | if (window.confirm('Вы уверены что хотите удалить??')) { |
@@ -190,19 +203,19 @@ export class BusStopComponent { | @@ -190,19 +203,19 @@ export class BusStopComponent { | ||
190 | let id = $event.data.busStopId; | 203 | let id = $event.data.busStopId; |
191 | let result = null; | 204 | let result = null; |
192 | if (id) { | 205 | if (id) { |
193 | - this.isLoading = true; | ||
194 | - result = this.service.update(id, data).then(() => this.isLoading = false); | 206 | + this.enableLoader(); |
207 | + result = this.service.update(id, data).then(() => this.disableLoader()); | ||
195 | } else { | 208 | } else { |
196 | // Protection of posting new row being already sent. | 209 | // Protection of posting new row being already sent. |
197 | if (this.isLoading) { | 210 | if (this.isLoading) { |
198 | return ; | 211 | return ; |
199 | } | 212 | } |
200 | - this.isLoading = true; | 213 | + this.enableLoader(); |
201 | result = this.service.create(data).then((busStop) => { | 214 | result = this.service.create(data).then((busStop) => { |
202 | this.rowData[$event.node.rowIndex] = busStop; | 215 | this.rowData[$event.node.rowIndex] = busStop; |
203 | this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); | 216 | this.gridOptions.api.setDatasource(this.setRowData(this.rowData)); |
204 | this.gridOptions.api.refreshVirtualPageCache(); | 217 | this.gridOptions.api.refreshVirtualPageCache(); |
205 | - this.isLoading = false; | 218 | + this.disableLoader(); |
206 | }); | 219 | }); |
207 | } | 220 | } |
208 | } | 221 | } |
@@ -216,8 +229,8 @@ export class BusStopComponent { | @@ -216,8 +229,8 @@ export class BusStopComponent { | ||
216 | rows.forEach(element => { | 229 | rows.forEach(element => { |
217 | let id = element.data.busStopId; | 230 | let id = element.data.busStopId; |
218 | if (id) { | 231 | if (id) { |
219 | - this.isLoading = true; | ||
220 | - this.service.delete(id).then(() => this.isLoading = false); | 232 | + this.enableLoader(); |
233 | + this.service.delete(id).then(() => this.disableLoader()); | ||
221 | } | 234 | } |
222 | }); | 235 | }); |
223 | // Sort in order to protect array from reindexing (remove rear elements first) | 236 | // Sort in order to protect array from reindexing (remove rear elements first) |
src/app/data/bus-stop/bus-stop.scss
@@ -7,4 +7,13 @@ | @@ -7,4 +7,13 @@ | ||
7 | position: fixed; | 7 | position: fixed; |
8 | bottom: 10px; | 8 | bottom: 10px; |
9 | right: 10px; | 9 | right: 10px; |
10 | + td-loading { | ||
11 | + width: 56px; | ||
12 | + height: 56px; | ||
13 | + float: left; | ||
14 | + margin-right: 20px; | ||
15 | + .td-loading-wrapper { | ||
16 | + margin-top: -10px; | ||
17 | + } | ||
18 | + } | ||
10 | } | 19 | } |
11 | \ No newline at end of file | 20 | \ No newline at end of file |
1 | +import { Component } from '@angular/core'; | ||
2 | + | ||
3 | +import { AgRendererComponent } from 'ag-grid-ng2/main'; | ||
4 | + | ||
5 | +@Component({ | ||
6 | + selector: 'render-cell', | ||
7 | + template: `<span *ngIf="this.value !== undefined">{{this.value}}</span>`, | ||
8 | +}) | ||
9 | +export class RendererValidComponent implements AgRendererComponent { | ||
10 | + private params: any; | ||
11 | + private value: string = null; | ||
12 | + agInit(params: any): void { | ||
13 | + this.params = params; | ||
14 | + this.setValue(params); | ||
15 | + } | ||
16 | + refresh(params: any): void { | ||
17 | + this.params = params; | ||
18 | + console.log(params); | ||
19 | + this.setValue(params); | ||
20 | + } | ||
21 | + private setValue(params) { | ||
22 | + this.value = params.value; | ||
23 | + } | ||
24 | +} |
1 | +<div #container class="form-group" [ngClass]="{'has-error':!form.controls[field].valid && form.controls[field].touched}"> | ||
2 | + <input class="form-control" type="text" placeholder="Doe" [formControl]="form.controls[field]" [(ngModel)]="value"> | ||
3 | + <div *ngIf="form.controls[field].hasError('required') && form.controls[field].touched" class="alert alert-danger">You must include a last name.</div> | ||
4 | + <div *ngIf="form.controls[field].hasError('minlength') && form.controls[field].touched" class="alert alert-danger">Your last name must be at least 5 characters long.</div> | ||
5 | + <div *ngIf="form.controls[field].hasError('maxlength') && form.controls[field].touched" class="alert alert-danger">Your last name cannot exceed 10 characters.</div> | ||
6 | +</div> | ||
0 | \ No newline at end of file | 7 | \ No newline at end of file |
1 | +import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core'; | ||
2 | +import { FormGroup } from '@angular/forms'; | ||
3 | + | ||
4 | +import { AgEditorComponent } from 'ag-grid-ng2/main'; | ||
5 | + | ||
6 | +@Component({ | ||
7 | + selector: 'editor-cell', | ||
8 | + templateUrl: './validate.component.html', | ||
9 | +}) | ||
10 | +export class ValidateComponent implements AgEditorComponent, AfterViewInit { | ||
11 | + private params: any; | ||
12 | + private value: string = null; | ||
13 | + | ||
14 | + @ViewChild('container', {read: ViewContainerRef}) public container: any; | ||
15 | + public form: FormGroup; | ||
16 | + public field: string; | ||
17 | + | ||
18 | + ngAfterViewInit(): void { | ||
19 | + this.container.element.nativeElement.focus(); | ||
20 | + } | ||
21 | + | ||
22 | + agInit(params: any): void { | ||
23 | + this.params = params; | ||
24 | + this.form = params.form; | ||
25 | + this.field = params.field; | ||
26 | + } | ||
27 | + | ||
28 | + getValue(): any { | ||
29 | + console.log('From getter', this.value); | ||
30 | + return this.value; | ||
31 | + } | ||
32 | + | ||
33 | + setValue(value: string): void { | ||
34 | + this.value = value; | ||
35 | + console.log('From setter', this.value); | ||
36 | + } | ||
37 | + | ||
38 | + isPopup(): boolean { | ||
39 | + return true; | ||
40 | + } | ||
41 | + | ||
42 | + editorChange(event): boolean { | ||
43 | + event.preventDefault(); | ||
44 | + event.stopPropagation(); | ||
45 | + this.setValue(this.form.value[this.field]); | ||
46 | + this.params.api.stopEditing(); | ||
47 | + event.stopPropagation(); | ||
48 | + return false; | ||
49 | + } | ||
50 | +} |