From e478b07ed109628ce9a304a5927c7b1516e9495e Mon Sep 17 00:00:00 2001 From: balcirakpeter Date: Mon, 18 Dec 2017 19:14:43 +0100 Subject: [PATCH] Input validation for create and update --- .../area-create/area-create.component.html | 11 +++++++-- .../area-create/area-create.component.ts | 5 ++++ .../area-detail/area-detail.component.html | 11 +++++++-- .../area-detail/area-detail.component.ts | 5 ++++ .../monster-create.component.html | 21 ++++++++++++---- .../monster-create.component.ts | 10 ++++++++ .../monster-detail.component.html | 24 +++++++++++++++---- .../monster-detail.component.ts | 9 +++++++ .../user-create/user-create.component.html | 3 ++- .../weapon-create.component.html | 21 ++++++++++++---- .../weapon-create/weapon-create.component.ts | 10 +++++++- .../weapon-detail.component.html | 23 ++++++++++++++---- .../weapon-detail/weapon-detail.component.ts | 9 +++++++ 13 files changed, 140 insertions(+), 22 deletions(-) diff --git a/creatures-hunting-angular/src/app/manager/area-create/area-create.component.html b/creatures-hunting-angular/src/app/manager/area-create/area-create.component.html index 9300bb7..206f09d 100644 --- a/creatures-hunting-angular/src/app/manager/area-create/area-create.component.html +++ b/creatures-hunting-angular/src/app/manager/area-create/area-create.component.html @@ -1,7 +1,13 @@
- + + + This is not valid name! + + + Name is required! +
@@ -17,7 +23,8 @@
- +
diff --git a/creatures-hunting-angular/src/app/manager/area-create/area-create.component.ts b/creatures-hunting-angular/src/app/manager/area-create/area-create.component.ts index 4d4cbae..70e8477 100644 --- a/creatures-hunting-angular/src/app/manager/area-create/area-create.component.ts +++ b/creatures-hunting-angular/src/app/manager/area-create/area-create.component.ts @@ -5,6 +5,7 @@ import {Router} from "@angular/router"; import {Area} from "../../entity.module"; import {CookieService} from "ngx-cookie-service"; import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; +import {FormControl, Validators} from "@angular/forms"; @Component({ selector: 'app-area-create', templateUrl: './area-create.component.html', @@ -14,6 +15,7 @@ export class AreaCreateComponent implements OnInit { cookie: boolean = false; areaType: string; + nameFormControl: FormControl; type: string; @@ -26,6 +28,9 @@ export class AreaCreateComponent implements OnInit { ngOnInit() { this.cookie = this.cookieService.check('creatures-token'); this.checkIfCookieExist(); + this.nameFormControl = new FormControl('', [ + Validators.required, + ]); } checkIfCookieExist() { diff --git a/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.html b/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.html index 45691a1..45485a6 100644 --- a/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.html +++ b/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.html @@ -6,7 +6,13 @@
- + + + This is not valid name! + + + Name is required! +
@@ -21,7 +27,8 @@
- + diff --git a/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.ts b/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.ts index 45c9244..1d313be 100644 --- a/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.ts +++ b/creatures-hunting-angular/src/app/manager/area-detail/area-detail.component.ts @@ -6,6 +6,7 @@ import {MatDialog, MatTableDataSource} from "@angular/material"; import {CookieService} from "ngx-cookie-service"; import {AddMonstersToAreaComponent} from "../../add-monsters-to-area-dialog/add-monsters-to-area-dialog.component"; import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; +import {FormControl, Validators} from "@angular/forms"; @Component({ selector: 'app-area-detail', @@ -21,6 +22,7 @@ export class AreaDetailComponent implements OnInit { areaType: string; monsters: Monster[] = []; dataSource: MatTableDataSource; + nameFormControl: FormControl; isAdmin: boolean = false; @@ -40,6 +42,9 @@ export class AreaDetailComponent implements OnInit { this.cookie = this.cookieService.check('creatures-token'); this.checkIsAdminCookie(); this.loadData(); + this.nameFormControl = new FormControl('', [ + Validators.required, + ]); } checkIfCookieExist(){ diff --git a/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.html b/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.html index 4886549..8403407 100644 --- a/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.html +++ b/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.html @@ -2,17 +2,29 @@
- + + + This is not valid name! + + + Name is required! +
- + + + This is not valid number! +
- + + + This is not valid number! +
@@ -27,6 +39,7 @@
- + diff --git a/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.ts b/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.ts index 92f35f0..4a32edc 100644 --- a/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.ts +++ b/creatures-hunting-angular/src/app/manager/monster-create/monster-create.component.ts @@ -6,6 +6,7 @@ import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; import {AddMonstersComponent} from "../../add-monsters-dialog/add-monsters-dialog.component"; import {MatDialog} from "@angular/material"; import {ErrorDialogComponent} from "../../error-dialog/error-dialog.component"; +import {FormControl, Validators} from "@angular/forms"; @Component({ selector: 'app-monster-create', @@ -15,6 +16,9 @@ import {ErrorDialogComponent} from "../../error-dialog/error-dialog.component"; export class MonsterCreateComponent implements OnInit { cookie: boolean = false; + nameFormControl: FormControl; + heightFormControl: FormControl; + weightFormControl: FormControl; agility: string; @@ -36,6 +40,12 @@ export class MonsterCreateComponent implements OnInit { return; } this.checkIfCookieExist(); + + this.nameFormControl = new FormControl('', [ + Validators.required, + ]); + this.heightFormControl = new FormControl('', []); + this.weightFormControl = new FormControl('', []); } checkIfCookieExist(){ diff --git a/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.html b/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.html index 1f318cf..8a90bbe 100644 --- a/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.html +++ b/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.html @@ -5,17 +5,32 @@
- + + + This is not valid name! + + + Name is required! +
- + + + This is not valid number! +
- + + + This is not valid number! +
@@ -28,5 +43,6 @@
- + diff --git a/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.ts b/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.ts index ab91526..3a0ee0a 100644 --- a/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.ts +++ b/creatures-hunting-angular/src/app/manager/monster-detail/monster-detail.component.ts @@ -6,6 +6,7 @@ import {CookieService} from "ngx-cookie-service"; import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; import {ErrorDialogComponent} from "../../error-dialog/error-dialog.component"; import {MatDialog} from "@angular/material"; +import {FormControl, Validators} from "@angular/forms"; @Component({ @@ -21,6 +22,9 @@ export class MonsterDetailComponent implements OnInit { selectedAgility: string; cookie: boolean = false; isAdmin: boolean = false; + nameFormControl: FormControl; + heightFormControl: FormControl; + weightFormControl: FormControl; constructor(private http: HttpClient, private route: ActivatedRoute, @@ -43,6 +47,11 @@ export class MonsterDetailComponent implements OnInit { } this.checkIsAdminCookie(); this.loadData(); + this.nameFormControl = new FormControl('', [ + Validators.required + ]); + this.heightFormControl = new FormControl(); + this.weightFormControl = new FormControl(); } checkIsAdminCookie(){ diff --git a/creatures-hunting-angular/src/app/manager/user-create/user-create.component.html b/creatures-hunting-angular/src/app/manager/user-create/user-create.component.html index 1be007b..0669bb3 100644 --- a/creatures-hunting-angular/src/app/manager/user-create/user-create.component.html +++ b/creatures-hunting-angular/src/app/manager/user-create/user-create.component.html @@ -68,7 +68,8 @@
- + diff --git a/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.html b/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.html index 2d98485..58200ee 100644 --- a/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.html +++ b/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.html @@ -1,7 +1,13 @@
- + + + This is not valid name! + + + Name is required! +
@@ -18,17 +24,24 @@
- + + + This is not valid number! +
- + + + This is not valid number! +
- + diff --git a/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.ts b/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.ts index e78ca94..515a7b8 100644 --- a/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.ts +++ b/creatures-hunting-angular/src/app/manager/weapon-create/weapon-create.component.ts @@ -7,6 +7,7 @@ import {CookieService} from "ngx-cookie-service"; import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; import {ErrorDialogComponent} from "../../error-dialog/error-dialog.component"; import {MatDialog} from "@angular/material"; +import {FormControl, Validators} from "@angular/forms"; @Component({ selector: 'app-weapon-create', templateUrl: './weapon-create.component.html', @@ -15,7 +16,9 @@ import {MatDialog} from "@angular/material"; export class WeaponCreateComponent implements OnInit { cookie: boolean = false; - + nameFormControl: FormControl; + rangeFormControl: FormControl; + magazineFormControl: FormControl; type: string; constructor(private http: HttpClient, @@ -34,6 +37,11 @@ export class WeaponCreateComponent implements OnInit { }); return; } + this.nameFormControl = new FormControl('', [ + Validators.required, + ]); + this.rangeFormControl = new FormControl('', []); + this.magazineFormControl = new FormControl('', []); } checkIfCookieExist(){ diff --git a/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.html b/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.html index 8b20217..da70187 100644 --- a/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.html +++ b/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.html @@ -6,7 +6,13 @@
- + + + This is not valid name! + + + Name is required! +
@@ -23,16 +29,25 @@
- + + + This is not valid number! +
- + + + This is not valid number! +
- + diff --git a/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.ts b/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.ts index ea2a12a..2fc81ff 100644 --- a/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.ts +++ b/creatures-hunting-angular/src/app/manager/weapon-detail/weapon-detail.component.ts @@ -7,6 +7,7 @@ import {CookieService} from "ngx-cookie-service"; import {AddMonstersComponent} from "../../add-monsters-dialog/add-monsters-dialog.component"; import {ApplicationConfig, CONFIG_TOKEN} from "../../app-config"; import {ErrorDialogComponent} from "../../error-dialog/error-dialog.component"; +import {FormControl, Validators} from "@angular/forms"; @Component({ selector: 'app-weapon-detail', @@ -22,6 +23,9 @@ export class WeaponDetailComponent implements OnInit { weaponType: string; appropriateMonsters: Monster[] = []; dataSource: MatTableDataSource; + nameFormControl: FormControl; + rangeFormControl: FormControl; + magazineFormControl: FormControl; isAdmin: boolean = false; @@ -49,6 +53,11 @@ export class WeaponDetailComponent implements OnInit { } this.checkIsAdminCookie(); this.loadData(); + this.nameFormControl = new FormControl('', [ + Validators.required, + ]); + this.rangeFormControl = new FormControl('', []); + this.magazineFormControl = new FormControl('', []); } checkIfCookieExist(){