Skip to content

Commit 9576759

Browse files
committed
date parsing
1 parent d307c5e commit 9576759

File tree

9 files changed

+69
-31
lines changed

9 files changed

+69
-31
lines changed

src/angular/angular.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"newProjectRoot": "projects",
55
"projects": {
66
"ngrxdata": {
7-
"root": "",
7+
"root": "src",
88
"sourceRoot": "src",
99
"projectType": "application",
1010
"architect": {
@@ -96,8 +96,8 @@
9696
}
9797
},
9898
"ngrxdata-e2e": {
99-
"root": "",
100-
"sourceRoot": "",
99+
"root": "e2e",
100+
"sourceRoot": "e2e",
101101
"projectType": "application",
102102
"architect": {
103103
"e2e": {
@@ -131,4 +131,4 @@
131131
"prefix": "app"
132132
}
133133
}
134-
}
134+
}

src/angular/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
"@ngrx/store": "^8.6.0",
3535
"@ngrx/store-devtools": "^8.6.0",
3636
"bootstrap": "^4.4.1",
37-
"core-js": "^2.5.6",
37+
"core-js": "^2.6.11",
3838
"ngx-spinner": "^8.1.0",
3939
"ngx-toastr": "^11.3.3",
4040
"rxjs": "^6.5.4",
41-
"rxjs-compat": "^6.1.0",
41+
"rxjs-compat": "^6.5.4",
4242
"zone.js": "~0.9.1"
4343
},
4444
"devDependencies": {

src/angular/src/app/app-routing/app-routing.module.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
33

44
import { TodoComponent } from '../todo/todo.component';
5-
import { AdminModule } from '../admin/admin.module';
65
import { TodoEditComponent } from '../todo/todo-edit/todo-edit.component';
76

87
const routes: Routes = [
@@ -13,7 +12,7 @@ const routes: Routes = [
1312
},
1413
{
1514
path: 'adminpage',
16-
loadChildren: () => AdminModule
15+
loadChildren: () => import('../admin/admin.module').then(m => m.AdminModule),
1716
},
1817
{
1918
path: 'todopage',
@@ -27,4 +26,4 @@ const routes: Routes = [
2726
imports: [RouterModule.forRoot(routes, { useHash: true })],
2827
exports: [RouterModule]
2928
})
30-
export class AppRoutingModule {}
29+
export class AppRoutingModule { }

src/angular/src/app/app.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HttpClientModule } from '@angular/common/http';
66
import { AppComponent } from './app.component';
77
import { AppStoreModule } from './store/app-store.module';
88
import { ServicesModule } from './services/services.module';
9-
import { NgbModule, NgbDateAdapter } from '@ng-bootstrap/ng-bootstrap';
9+
import { NgbModule, NgbDateAdapter, NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
1010
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
1111
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1212
import { CompModule } from './comp/comp.module';
@@ -15,6 +15,7 @@ import { TodoModule } from './todo/todo.module';
1515
import { AppRoutingModule } from './app-routing/app-routing.module';
1616
import { AdminModule } from './admin/admin.module';
1717
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
18+
import { CustomDateParser } from './shared/custom-date-parser';
1819

1920
@NgModule({
2021
declarations: [AppComponent],
@@ -37,8 +38,11 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
3738
providers: [
3839
{
3940
provide: NgbDateAdapter, useClass: CustomAdapter
41+
},
42+
{
43+
provide: NgbDateParserFormatter, useClass: CustomDateParser
4044
}
4145
],
4246
bootstrap: [AppComponent]
4347
})
44-
export class AppModule {}
48+
export class AppModule { }

src/angular/src/app/comp/navbar/navbar.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<a class="navbar-brand py-0 px-3" href="#" style="">
33
<img height="50px" src="assets/img/logo-ngrx.png" />
44
</a>
5-
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault"
6-
aria-expanded="false" aria-label="Toggle navigation">
5+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"
6+
aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
77
<span class="navbar-toggler-icon"></span>
88
</button>
99

@@ -13,10 +13,10 @@
1313
<a class="nav-link" href="#">NgRx Data / SpringBoot</a>
1414
</li>
1515
<li class="nav-item">
16-
<a class="nav-link" [routerLinkActive]="['active']" [routerLink]="'todopage'">Todo</a>
16+
<a class="nav-link" [routerLinkActive]="['active']" routerLink="todopage">Todo</a>
1717
</li>
1818
<li class="nav-item">
19-
<a class="nav-link" [routerLinkActive]="['active']" [routerLink]="'adminpage'">Admin</a>
19+
<a class="nav-link" [routerLinkActive]="['active']" routerLink="adminpage">Admin</a>
2020
</li>
2121
</ul>
2222
<div class="float-right pr-3">

src/angular/src/app/services/utils.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { Injectable } from '@angular/core';
22
import { FaIconLibrary } from '@fortawesome/angular-fontawesome';
3-
import { faCheck, faBurn, faCommentAlt, faEdit, faTrash, faCheckSquare, faSquare, faUpload } from '@fortawesome/free-solid-svg-icons';
3+
import {
4+
faCheck, faBurn, faCommentAlt, faEdit, faTrash,
5+
faCheckSquare, faSquare, faUpload, faCalendar
6+
} from '@fortawesome/free-solid-svg-icons';
47

58
@Injectable({
69
providedIn: 'root'
710
})
811
export class UtilsService {
9-
constructor(private library: FaIconLibrary) {}
12+
constructor(private library: FaIconLibrary) { }
1013

1114
initIcons(): void {
1215
this.library.addIcons(
13-
faCheck, faBurn, faCommentAlt, faEdit, faTrash, faCheckSquare, faSquare, faUpload
16+
faCheck, faBurn, faCommentAlt, faEdit, faTrash, faCheckSquare, faSquare, faUpload, faCalendar
1417
);
1518
}
1619
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
2+
3+
export class CustomDateParser extends NgbDateParserFormatter {
4+
5+
readonly DELIMITER = '-';
6+
7+
parse(value: string): NgbDateStruct {
8+
let result: NgbDateStruct = null;
9+
if (value) {
10+
const date = value.split(this.DELIMITER);
11+
result = {
12+
day: parseInt(date[0], 10),
13+
month: parseInt(date[1], 10),
14+
year: parseInt(date[2], 10)
15+
};
16+
}
17+
return result;
18+
}
19+
20+
format(date: NgbDateStruct): string {
21+
let result: string = null;
22+
if (date) {
23+
result = date.day + this.DELIMITER + date.month + this.DELIMITER + date.year;
24+
}
25+
return result;
26+
}
27+
28+
}

src/angular/src/app/todo/todo-edit/todo-edit.component.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
<form (ngSubmit)="saveTodo()" novalidate [formGroup]="todoForm">
33
<div class="form-group">
44
<label for="todoTitle">Todo title</label>
5-
<input type="text" class="form-control" id="todoTitle" formControlName="title" aria-describedby="titleHelp" placeholder="Enter title">
5+
<input type="text" class="form-control" id="todoTitle" formControlName="title" aria-describedby="titleHelp"
6+
placeholder="Enter title">
67
<small id="titleHelp" class="form-text text-muted">This is the sound of C.</small>
78
<input type="hidden" formControlName="id">
89
</div>
910
<div class="form-group">
1011
<label for="todoDescription">Todo description</label>
11-
<input type="text" class="form-control" id="todoDescription" formControlName="description" placeholder="Enter description">
12+
<input type="text" class="form-control" id="todoDescription" formControlName="description"
13+
placeholder="Enter description">
1214
</div>
1315
<div class="form-group">
1416
<label for="">Date due</label>
1517
<div class="input-group">
16-
17-
<input class="form-control" placeholder="yyyy-mm-dd"
18-
name="dp" formControlName="dateTodo" ngbDatepicker #d="ngbDatepicker">
18+
<input class="form-control" placeholder="yyyy-mm-dd" name="dp" formControlName="dateTodo" ngbDatepicker
19+
#d="ngbDatepicker">
1920
<div class="input-group-append">
20-
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
21+
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button">
22+
<fa-icon icon="calendar"></fa-icon>
23+
</button>
2124
</div>
2225
</div>
2326
</div>
@@ -34,6 +37,7 @@
3437
</div>
3538

3639
<button type="submit" class="btn btn-primary" [disabled]="todoForm.invalid || todoForm.pristine">
37-
<fa-icon icon="check"></fa-icon> Submit</button>
40+
<fa-icon icon="check"></fa-icon> Submit
41+
</button>
3842
</form>
3943
</div>

0 commit comments

Comments
 (0)