Merge pull request #27 from AlineRinquin/blandine

Blandine
This commit is contained in:
AlineRinquin 2022-02-15 15:38:25 +01:00 committed by GitHub
commit 25830750bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 11763 additions and 42 deletions

11620
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ import { FicheContactComponent } from './components/fiche-contact/fiche-contact.
import { PaginationComponent } from './components/pagination/pagination.component';
import { CreneauComponent } from './components/creneau/creneau.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { PageAjoutContactComponent } from './pages/page-ajout-contact/page-ajout-contact.component';
import { PageModifierContactComponent } from './pages/page-modifier-contact/page-modifier-contact.component';
import { PageCreationTeamComponent } from './pages/page-creation-team/page-creation-team.component';
@ -89,7 +89,9 @@ import { EmoticonComponent } from './emoticon/emoticon.component';
FormsModule,
AutofocusFixModule.forRoot(),
],
providers: [],
providers: [
],
bootstrap: [AppComponent],
})
export class AppModule {}

View File

@ -1 +1,5 @@
<p>card-menu works!</p>
<div class="menu">
<div *ngFor="let menu of listMenus">
<p>{{ menu.dateMenu }} {{ menu.libelle }}</p>
</div>
</div>

View File

@ -0,0 +1,3 @@
.menu {
margin-left: 500px;
}

View File

@ -1,4 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Menu } from 'src/app/models/menu';
import { MenusService } from 'src/app/services/menus.service';
@Component({
selector: 'app-card-menu',
@ -6,10 +11,23 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./card-menu.component.scss']
})
export class CardMenuComponent implements OnInit {
public listMenus:any[];
constructor() { }
constructor(
private menusService: MenusService,
private router: Router,
private route: ActivatedRoute
) {
this.listMenus=[];
}
ngOnInit(): void {
//affichage des menus d'une team
this.menusService.getMenu()?.subscribe((listMenus: any[])=>{
console.log(listMenus);
this.listMenus=listMenus;
});
}
}

View File

@ -6,5 +6,4 @@ export interface Menu {
dateMenu: Date;
membre: Membre;
team: Team;
validationProposition: boolean;
}

View File

@ -2,3 +2,8 @@
<app-side-bar></app-side-bar>
<app-meteo></app-meteo>
<div class="d-flex justify-content-center">
<button button type="button" class="btn btn-primary btn-lg" routerLink="../creation-team"
routerLinkActive="active-custom">Créer ma team</button>
</div>

View File

@ -0,0 +1,5 @@
.meteo {
display: flex;
margin-left: 300px;
margin-top: -60px;
}

View File

@ -1,2 +1,3 @@
<app-header></app-header>
<app-side-bar></app-side-bar>
<app-side-bar></app-side-bar>
<app-card-menu></app-card-menu>

View File

@ -126,10 +126,10 @@
<button
class="w-100 btn btn-lg btn-outline-success"
type="submit"
[disabled]="signupForm.invalid"
>
[disabled]="signupForm.invalid">
CREER MON COMPTE
</button>
</form>
</main>
</div>

View File

@ -41,9 +41,9 @@ export class AuthService {
return this.http.post(`${this.apiUrl}/membres/sign-in`, body).pipe(
map((x: any) => {
console.log('Service : ', x.accessToken);
console.log('Service : ', x.token);
// Modification à faire ici
localStorage.setItem(this.tokenKey, x.accessToken);
localStorage.setItem(this.tokenKey, x.token);
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
})
);

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { MenusService } from './menus.service';
describe('MenusService', () => {
let service: MenusService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MenusService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,51 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map, Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Menu } from '../models/menu';
import { Router } from '@angular/router';
import { TokenService } from './token.service';
@Injectable({
providedIn: 'root'
})
export class MenusService {
apiUrl: string;
constructor(private http: HttpClient, private router: Router, private tokenService: TokenService) {
// On se sert des variables d'environnement de notre application
this.apiUrl = environment.apiUrl;
}
//on affiche les menus d'une team
getMenu(): Observable<any> | void {
const teamId = this.tokenService.getCurrentTeamId();
if (teamId){
return this.http.get(`${this.apiUrl}/menus/team/${teamId}`);
}else {
this.router.navigate(['accueil']);
}
}
getMenuById(id: any): Observable<any> {
return this.http.get(`${this.apiUrl}/menus/` + id);
}
addMenu(menu: Menu): Observable<any> {
console.log(menu);
return this.http.post(`${this.apiUrl}/menus/add`, menu);
}
deleteMenu(id: any): Observable<any> {
return this.http.delete(`${this.apiUrl}/menus/delete/`+ id);
}
updateMenu(menu: Menu): Observable<any> {
return this.http.put(`${this.apiUrl}/contacts/update/`, menu);
}
}

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TokenService } from './token.service';
describe('TokenService', () => {
let service: TokenService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TokenService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import jwt_decode from 'jwt-decode';
@Injectable({
providedIn: 'root'
})
export class TokenService {
tokenKey = environment.tokenKey;
constructor() { }
public getToken(): string | null {
const token = localStorage.getItem(this.tokenKey);
if(token) {
return token;
} else {
return null;
}
}
public getCurrentMembreId(): number | null {
const token = this.getToken();
if(token) {
const decodedToken = jwt_decode<any>(token);
const userId = decodedToken.sub;
return userId;
} else {
return null;
}
}
public getCurrentTeamId(): number | null {
const token = this.getToken();
if(token){
const decodedToken = jwt_decode<any>(token);
const teamId = decodedToken.teamId;
return teamId ;
}else {
return null;
}
}
}