Merge pull request 'feature/03' (#3) from feature/03 into develop
Reviewed-on: https://git.gitpushf.uk/SchoolTask/angular-js/pulls/3
This commit is contained in:
commit
bf34632583
7 changed files with 132 additions and 73 deletions
|
|
@ -6,45 +6,97 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h4 class="card-title text-center mb-4">Ajouter vos informations</h4>
|
<h4 class="card-title text-center mb-4">Ajouter vos informations</h4>
|
||||||
|
|
||||||
|
<form [formGroup]="infoForm" (ngSubmit)="addInfo()">
|
||||||
|
|
||||||
|
<!-- Sélection du genre -->
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<input class="form-check-input mt-0" type="radio" value="Mr." aria-label="Mr." [(ngModel)]="info.gender" name="gender" (change)="updateGender()">
|
<input class="form-check-input mt-0" type="radio" formControlName="gender" value="Mr.">
|
||||||
</div>
|
</div>
|
||||||
<input type="text" class="form-control" aria-label="Mr." placeholder="Mr." disabled>
|
<input type="text" class="form-control" placeholder="Mr." disabled>
|
||||||
|
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<input class="form-check-input mt-0" type="radio" value="Ms." aria-label="Ms." [(ngModel)]="info.gender" name="gender" (change)="updateGender()">
|
<input class="form-check-input mt-0" type="radio" formControlName="gender" value="Ms.">
|
||||||
</div>
|
</div>
|
||||||
<input type="text" class="form-control" aria-label="Ms." placeholder="Ms." disabled>
|
<input type="text" class="form-control" placeholder="Ms." disabled>
|
||||||
|
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<input class="form-check-input mt-0" type="radio" value="Other." aria-label="Othef=r." [(ngModel)]="info.gender" name="gender" (change)="updateGender()">
|
<input class="form-check-input mt-0" type="radio" formControlName="gender" value="Other.">
|
||||||
</div>
|
</div>
|
||||||
<input type="text" class="form-control" aria-label="Other." placeholder="Other." disabled>
|
<input type="text" class="form-control" placeholder="Other." disabled>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('gender')?.invalid && infoForm.get('gender')?.touched">
|
||||||
|
Veuillez sélectionner un genre.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Nom & Prénom -->
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input type="text" [(ngModel)]="info.nameLast" class="form-control" placeholder="Last name" aria-label="Last name">
|
<input type="text" formControlName="nameLast" class="form-control" placeholder="Nom">
|
||||||
<span class="input-group-text">@</span>
|
<span class="input-group-text"> — </span>
|
||||||
<input type="text" [(ngModel)]="info.nameFirst" class="form-control" placeholder="First name" aria-label="First name">
|
<input type="text" formControlName="nameFirst" class="form-control" placeholder="Prénom">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="input-group mb-3" *ngIf="(infoForm.get('nameLast')?.invalid && infoForm.get('nameLast')?.touched) ||
|
||||||
|
(infoForm.get('nameFirst')?.invalid && infoForm.get('nameFirst')?.touched)">
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('nameLast')?.hasError('required') && infoForm.get('nameLast')?.touched">
|
||||||
|
Le nom est requis.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('nameLast')?.hasError('minlength') && infoForm.get('nameLast')?.touched">
|
||||||
|
Le nom doit comporter au moins 3 caractères.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-dark fs-40" role="alert"> — </div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('nameFirst')?.hasError('required') && infoForm.get('nameFirst')?.touched">
|
||||||
|
Le prénom est requis.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('nameFirst')?.hasError('minlength') && infoForm.get('nameFirst')?.touched">
|
||||||
|
Le prénom doit comporter au moins 3 caractères.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Email -->
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input type="text" [(ngModel)]="info.email" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
|
<input type="text" formControlName="email" class="form-control" placeholder="Nom d'utilisateur">
|
||||||
<span class="input-group-text" id="basic-addon2">@edu.igensia.com</span>
|
<span class="input-group-text">@edu.igensia.com</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('email')?.invalid && infoForm.get('email')?.touched">
|
||||||
|
Veuillez entrer un nom d'utilisateur valide.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Adresse -->
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<span class="input-group-text">Adresse</span>
|
<input type="text" formControlName="address" class="form-control" placeholder="Adresse">
|
||||||
<textarea class="form-control" [(ngModel)]="info.address" aria-label="Adresse"></textarea>
|
<span class="input-group-text"> — </span>
|
||||||
|
<input type="text" formControlName="codePostal" class="form-control fs-20" placeholder="Code Postal">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary w-100" (click)="addInfo()">Ajouter</button>
|
<div class="input-group mb-3" *ngIf="(infoForm.get('address')?.invalid && infoForm.get('address')?.touched) ||
|
||||||
|
(infoForm.get('codePostal')?.invalid && infoForm.get('codePostal')?.touched)">
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('address')?.hasError('required') && infoForm.get('address')?.touched">
|
||||||
|
L'adresse est requise.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('address')?.hasError('minlength') && infoForm.get('address')?.touched">
|
||||||
|
L'adresse doit comporter au moins 10 caractères.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-dark fs-40" role="alert"> — </div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('codePostal')?.hasError('required') && infoForm.get('codePostal')?.touched">
|
||||||
|
Le code postal est requis.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-danger fs-40" role="alert" *ngIf="infoForm.get('codePostal')?.hasError('minlength') && infoForm.get('codePostal')?.touched">
|
||||||
|
Le code postal doit comporter au moins 4 chiffres.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bouton Ajouter -->
|
||||||
|
<button type="submit" class="btn btn-primary w-100" [disabled]="infoForm.invalid">Ajouter</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Liste des commentaires -->
|
<!-- Liste des informations -->
|
||||||
<div *ngIf="infos.length > 0; else noComment" class="d-flex flex-column align-items-center w-50">
|
<div *ngIf="infos.length > 0; else noComment" class="d-flex flex-column align-items-center w-50">
|
||||||
<h3 class="text-center text-primary">Liste des commentaires</h3>
|
<h3 class="text-center text-primary">Liste des informations</h3>
|
||||||
<ul class="list-group shadow-sm">
|
<ul class="list-group shadow-sm">
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-start" *ngFor="let info of infos">
|
<li class="list-group-item d-flex justify-content-between align-items-start" *ngFor="let info of infos">
|
||||||
<div class="ms-2 me-auto">
|
<div class="ms-2 me-auto">
|
||||||
|
|
@ -62,6 +114,6 @@
|
||||||
|
|
||||||
<!-- Message si aucun commentaire -->
|
<!-- Message si aucun commentaire -->
|
||||||
<ng-template #noComment>
|
<ng-template #noComment>
|
||||||
<p class="text-muted text-center mt-3">Aucun commentaire pour le moment</p>
|
<p class="text-muted text-center mt-3">Aucune information pour le moment</p>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-account',
|
selector: 'app-account',
|
||||||
|
|
@ -8,44 +9,40 @@ import { Component } from '@angular/core';
|
||||||
})
|
})
|
||||||
|
|
||||||
export class AccountComponent {
|
export class AccountComponent {
|
||||||
info: Info = new Info();
|
infoForm: FormGroup;
|
||||||
infos: Array<Info> = [];
|
infos: any[] = [];
|
||||||
newInfo: boolean = false;
|
|
||||||
|
|
||||||
constructor() {}
|
constructor(private fb: FormBuilder) {
|
||||||
ngOnInit(): void {}
|
this.infoForm = this.fb.group({
|
||||||
|
gender: ['', Validators.required],
|
||||||
|
nameLast: ['', [Validators.required, Validators.minLength(3)]],
|
||||||
|
nameFirst: ['', [Validators.required, Validators.minLength(3)]],
|
||||||
|
email: ['', [Validators.required, Validators.pattern(/^[a-zA-Z0-9._%+-]+$/)]],
|
||||||
|
address: ['', [Validators.required, Validators.minLength(10)]],
|
||||||
|
codePostal: ['', [Validators.required, Validators.minLength(4), Validators.pattern(/^\d{4,}$/)]],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
addInfo() {
|
addInfo() {
|
||||||
if (this.info.gender && this.info.nameFirst && this.info.nameLast && this.info.email && this.info.address) {
|
if (this.infoForm.valid) {
|
||||||
this.info.date = new Date();
|
const formData = this.infoForm.value;
|
||||||
this.info.nameFirst = this.info.nameFirst.charAt(0).toUpperCase() + this.info.nameFirst.slice(1).toLowerCase()
|
|
||||||
this.infos.push({
|
|
||||||
gender: this.info.gender,
|
|
||||||
nameFirst: this.info.nameFirst,
|
|
||||||
nameLast: this.info.nameLast.toUpperCase(),
|
|
||||||
email: this.info.email.toLowerCase() + '@edu.igensia.com',
|
|
||||||
address: this.info.address,
|
|
||||||
date: this.info.date
|
|
||||||
})
|
|
||||||
this.info.nameFirst = '';
|
|
||||||
this.info.nameLast = '';
|
|
||||||
this.info.email = '';
|
|
||||||
this.info.address = '';
|
|
||||||
this.info.gender = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateGender() {
|
// Ajouter @edu.igensia.com automatiquement
|
||||||
// console.log("Le genre sélectionné est :", this.info.gender);
|
const email = formData.email.toLowerCase();
|
||||||
}
|
const fullEmail = `${email}@edu.igensia.com`;
|
||||||
|
const nameLast = formData.nameLast.toUpperCase();
|
||||||
|
const nameFirst = formData.nameFirst.charAt(0).toUpperCase() + formData.nameFirst.slice(1).toLowerCase();
|
||||||
|
|
||||||
}
|
const newInfo = {
|
||||||
|
...formData,
|
||||||
export class Info {
|
nameLast: nameLast, // Mettre l'email complet
|
||||||
gender: string = '';
|
nameFirst: nameFirst, // Mettre l'email complet
|
||||||
nameFirst: string = '';
|
email: fullEmail, // Mettre l'email complet
|
||||||
nameLast: string = '';
|
date: new Date() // Ajoute la date actuelle
|
||||||
email: string = '';
|
};
|
||||||
address: string= '';
|
|
||||||
date: Date | null = null;
|
this.infos.push(newInfo);
|
||||||
|
this.infoForm.reset(); // Réinitialise le formulaire après l'ajout
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { AboutComponent } from './about/about.component';
|
import { AboutComponent } from './about/about.component';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { ContactsComponent } from './contacts/contacts.component';
|
import { ContactsComponent } from './contacts/contacts.component';
|
||||||
import { HomeComponent } from './home/home.component';
|
import { HomeComponent } from './home/home.component';
|
||||||
import { NavBarComponent } from './nav-bar/nav-bar.component';
|
import { NavBarComponent } from './nav-bar/nav-bar.component';
|
||||||
|
|
@ -22,7 +22,8 @@ import { AccountComponent } from './account/account.component';
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
FormsModule
|
FormsModule,
|
||||||
|
ReactiveFormsModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<!-- Contenu principal -->
|
<!-- Contenu principal -->
|
||||||
<div class="container text-center mt-4">
|
<div class="container text-center mt-4">
|
||||||
<h1 class="text-primary">Bienvenue à la formation AngularJS</h1>
|
<h1 class="text-primary">Bienvenue à la formation Angular</h1>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<a class="btn btn-outline-primary me-2" routerLink="/about">About</a>
|
<a class="btn btn-outline-primary me-2" routerLink="/about">About</a>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<!-- Navbar Bootstrap -->
|
<!-- Navbar Bootstrap -->
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" routerLink="/">AngularJS</a>
|
<a class="navbar-brand" routerLink="/">Angular</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,15 @@
|
||||||
border-bottom: 2px solid #ffc107;
|
border-bottom: 2px solid #ffc107;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fs-40 {
|
||||||
|
padding-top: 2px !important;
|
||||||
|
padding-bottom: 2px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fs-20 {
|
||||||
|
width: 5vw;
|
||||||
|
}
|
||||||
|
|
||||||
.breakWord {
|
.breakWord {
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
|
|
|
||||||
BIN
formation_angular_session2_04032025.pptx
Normal file
BIN
formation_angular_session2_04032025.pptx
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue