menu service

This commit is contained in:
Blandine Bajard 2022-02-15 13:57:42 +01:00
parent d89214db19
commit 26032019c5
13 changed files with 11706 additions and 40 deletions

11620
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@
"@angular/platform-browser-dynamic": "~13.0.0", "@angular/platform-browser-dynamic": "~13.0.0",
"@angular/router": "~13.0.0", "@angular/router": "~13.0.0",
"bootstrap": "^5.1.3", "bootstrap": "^5.1.3",
"bootstrap-icons": "^1.8.1",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"ngx-autofocus-fix": "^1.0.4", "ngx-autofocus-fix": "^1.0.4",
"rxjs": "~7.4.0", "rxjs": "~7.4.0",

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 { 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({ @Component({
selector: 'app-card-menu', selector: 'app-card-menu',
@ -6,10 +11,23 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./card-menu.component.scss'] styleUrls: ['./card-menu.component.scss']
}) })
export class CardMenuComponent implements OnInit { export class CardMenuComponent implements OnInit {
public listMenus:any[];
constructor() { } constructor(
private menusService: MenusService,
private router: Router,
private route: ActivatedRoute
) {
this.listMenus=[];
}
ngOnInit(): void { 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; dateMenu: Date;
membre: Membre; membre: Membre;
team: Team; team: Team;
validationProposition: boolean;
} }

View File

@ -2,3 +2,8 @@
<app-side-bar></app-side-bar> <app-side-bar></app-side-bar>
<app-meteo></app-meteo> <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-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 <button
class="w-100 btn btn-lg btn-outline-success" class="w-100 btn btn-lg btn-outline-success"
type="submit" type="submit"
[disabled]="signupForm.invalid" [disabled]="signupForm.invalid">
>
CREER MON COMPTE CREER MON COMPTE
</button> </button>
</form> </form>
</main> </main>
</div> </div>

View File

@ -41,9 +41,9 @@ export class AuthService {
return this.http.post(`${this.apiUrl}/membres/sign-in`, body).pipe( return this.http.post(`${this.apiUrl}/membres/sign-in`, body).pipe(
map((x: any) => { map((x: any) => {
console.log('Service : ', x.accessToken); console.log('Service : ', x.token);
// Modification à faire ici // 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 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,58 @@
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 jwt_decode from 'jwt-decode';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class MenusService {
apiUrl: string;
tokenKey: string;
constructor(private http: HttpClient, private router: Router) {
// On se sert des variables d'environnement de notre application
this.apiUrl = environment.apiUrl;
this.tokenKey = environment.tokenKey;
}
//on affiche les menus d'une team
getMenu(): Observable<any> | void {
//on récupère l'id de la team grâce au token du membre :
const token = localStorage.getItem(this.tokenKey);
if(token){ //s'il y a un token tu le decode
const decodedToken = jwt_decode<any>(token);
const teamId = decodedToken.teamId;//tu vas chercher le teamId
console.log(teamId); //dans le json du token
return this.http.get(`${this.apiUrl}/menus/team/${teamId}`);
//on reconstruit alors l'url pour afficher les menus via le team_id
}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(menu: Menu): Observable<any> {
return this.http.delete(`${this.apiUrl}/menus/delete/1`);
}
updateMenu(menu: Menu): Observable<any> {
return this.http.put(`${this.apiUrl}/contacts/update/1`, menu);
}
}