menu service
This commit is contained in:
parent
d89214db19
commit
26032019c5
11620
package-lock.json
generated
11620
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||||
|
@ -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>
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
.menu {
|
||||||
|
margin-left: 500px;
|
||||||
|
}
|
@ -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;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,4 @@ export interface Menu {
|
|||||||
dateMenu: Date;
|
dateMenu: Date;
|
||||||
membre: Membre;
|
membre: Membre;
|
||||||
team: Team;
|
team: Team;
|
||||||
validationProposition: boolean;
|
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
.meteo {
|
||||||
|
display: flex;
|
||||||
|
margin-left: 300px;
|
||||||
|
margin-top: -60px;
|
||||||
|
}
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -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
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
16
src/app/services/menus.service.spec.ts
Normal file
16
src/app/services/menus.service.spec.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
58
src/app/services/menus.service.ts
Normal file
58
src/app/services/menus.service.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user