Skip to content

Commit

Permalink
Fixing forms - part 1. Animal and shelter finished. User in process.
Browse files Browse the repository at this point in the history
  • Loading branch information
IhoFenixMFS committed Apr 10, 2020
1 parent ef74b48 commit cf95345
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ <h1 class="mb-20">Animal data:</h1>
<!-- +8 -->
</select>
</div>
<div *ngIf="alert" class="alert alert-danger">
All fields must be Completed
</div>
<button type="submit" (click)="createAnimal()" class="genric-btn primary circle float-right">Add Animal</button>
</form>
</div>
Expand Down
27 changes: 18 additions & 9 deletions AngularAnimalShelter/src/app/animalform/animalform.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,38 @@ import { Router } from '@angular/router';
export class AnimalformComponent {
data: FormData;
animal: Animal;
alert:boolean;
file:any;

constructor(private router: Router, private animalFormService: AnimalformService) {
this.data = new FormData;
this.animal={
animalName:'',
animalAge:0,
animalAge:null,
animalType:'',
animalSize:'',
animalDescription:''
}
this.alert=false;
}
loadAnimalImage(event){
const file = event.target.files;
this.data.append('animalPhoto', file[0]);
this.file = event.target.files;
this.data.append('animalPhoto', this.file[0]);

}

createAnimal(){
this.data.append('jsondata',JSON.stringify(this.animal));
this.animalFormService.createAnimal(this.data).subscribe(
error => this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['/animalform']);
})
);
if((this.animal.animalName=='') || (this.animal.animalAge == null) || (this.animal.animalType =='') || (this.animal.animalSize =='') || (this.animal.animalDescription =='')){
this.alert=true;
}else {
this.alert=false;
this.data.append('jsondata',JSON.stringify(this.animal));
this.animalFormService.createAnimal(this.data).subscribe();
}




}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ <h1 class="mb-20">Shelter data:</h1>
class="form-control" placeholder="Password" name="shelterPassword"
required>
</div>
<div *ngIf="alert" class="alert alert-danger">
{{alertText}}
</div>
<button (click)="createShelter(); $event.stopPropagation(); $event.preventDefault()" type="submit" class="genric-btn primary circle">Create Shelter</button>
</div>
</div>
Expand Down
36 changes: 29 additions & 7 deletions AngularAnimalShelter/src/app/shelterform/shelterform.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Shelter } from '../models/Shelter/shelter.model';
export class ShelterformComponent {

shelter: Shelter;
alert:boolean;
alertText:string;

constructor(private router: Router, private shelterFormService: ShelterFormService) {
this.shelter = {
Expand All @@ -23,16 +25,19 @@ export class ShelterformComponent {
shelterPassword: '',
role: 'SHELTER'
};
this.alert=false;
}

createShelter(){
if(this.shelter.shelterName.length == 0 || this.shelter.shelterNif.length == 0
|| this.shelter.shelterEmail.length == 0 || this.shelter.shelterDescription.length == 0
|| this.shelter.shelterAdress.length == 0 || this.shelter.shelterPassword.length == 0){

alert('Fill all the blanks');
this.alertText='All fields must be Completed';
this.alert=true;

} else {
this.alert=false;
this.alertText='';
const formData = new FormData();
formData.append('jsondata',JSON.stringify(this.shelter));
formData.append('password',this.shelter.shelterPassword);
Expand All @@ -42,18 +47,35 @@ export class ShelterformComponent {
if(shelter){
this.router.navigate(['/']);
} else {
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
/*this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate(['/shelterform']);
});
alert('User already registered');
});*/
this.shelter.shelterName='';
this.shelter.shelterEmail='';
this.shelter.shelterNif='';
this.shelter.shelterPassword='';
this.shelter.shelterDescription='';
this.shelter.shelterAdress='';
this.shelter.shelterPassword='';
this.alertText='Profile already registered. Please, send a mail to Tecnical Service for recovering your data';
this.alert=true;
}
console.log(shelter)
},
error => {
alert('Something went wrong, try again');
/*
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate(['/shelterform']);
});
});*/
this.shelter.shelterName='';
this.shelter.shelterEmail='';
this.shelter.shelterNif='';
this.shelter.shelterPassword='';
this.shelter.shelterDescription='';
this.shelter.shelterAdress='';
this.shelter.shelterPassword='';
this.alertText='Your profile hasn\'t been created. Please, try again. If the problem persist, contact with the Tecnical Service.';
this.alert=true;
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions AngularAnimalShelter/src/app/userform/userform.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ <h1 class="mb-20">User data:</h1>
class="form-control" placeholder="Password" name="userPassword"
required>
</div>
<div *ngIf="alert" class="alert alert-danger">
All fields must be Completed
</div>
<button (click)="createWebUser()" type="submit" class="genric-btn primary circle">Create
User</button>
</form>
Expand Down
34 changes: 22 additions & 12 deletions AngularAnimalShelter/src/app/userform/userform.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ export class UserformComponent {

data: FormData;
user: WebUser;
alert:boolean;


constructor(private router: Router, private userFormService: UserformService) {
this.data = new FormData;

this.user = {
userName:'',
userDni:'',
userAge:0,
userAge:null,
userAdress:'',
userHouseSize:'',
userGarden:'',
userNumChildren:0,
userNumPeopleInHouse:0,
userNumChildren:null,
userNumPeopleInHouse:null,
userEmail:'',
userPassword:'',
role: 'USER'
}
this.alert=false;
}

loadImage(event){
Expand All @@ -36,15 +40,21 @@ export class UserformComponent {
}

createWebUser(){
this.data.append('jsondata',JSON.stringify(this.user));
this.data.append('password',this.user.userPassword);

this.userFormService.createWebUser(this.data).subscribe(
shelter => this.router.navigate(['/']),
error => this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['/userform']);
})
);
if((this.user.userName=='') || (this.user.userDni == null) || (this.user.userAge == null) || (this.user.userAdress =='') || (this.user.userHouseSize =='')|| (this.user.userGarden =='') || (this.user.userGarden =='') || (this.user.userNumChildren == null) || (this.user.userNumPeopleInHouse ==null) || (this.user.userEmail =='') || (this.user.userPassword =='')){
this.alert=true;
}else{
this.data.append('jsondata',JSON.stringify(this.user));
this.data.append('password',this.user.userPassword);

this.userFormService.createWebUser(this.data).subscribe(
shelter => this.router.navigate(['/']),
error => this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['/userform']);
})
);
}


}

}

0 comments on commit cf95345

Please sign in to comment.