Merge pull request 'entite_business_unit complète' (#6) from entite_business_unit into develop
Reviewed-on: Clement.Ferrere/Collaborateur_Epa_Front#6pull/7/head^2
commit
81dd033197
@ -0,0 +1,17 @@ |
|||||||
|
<div class = mb-3> |
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<th>Name</th> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<input id="businessunit-name" [(ngModel)]="businessunit.name" placeholder="name"> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<select name="agence" id="agence-select" [(ngModel)]="businessunit.agenceId"> |
||||||
|
<option value="">-- Choisissez l'agence de cette business Unit --</option> |
||||||
|
<option *ngFor="let agence of agences" [ngValue]="agence.id">{{agence.name}}</option> |
||||||
|
</select> |
||||||
|
</div> |
@ -0,0 +1,42 @@ |
|||||||
|
import {Component, Input, OnInit} from '@angular/core'; |
||||||
|
import {Businessunit} from "../../../interfaces/businessunit"; |
||||||
|
import {HttpClient} from "@angular/common/http"; |
||||||
|
import {BusinessunitService} from "../../../services/businessunit.service"; |
||||||
|
import {Agence} from "../../../interfaces/agence"; |
||||||
|
import {AgenceService} from "../../../services/agence.service"; |
||||||
|
|
||||||
|
@Component({ |
||||||
|
selector: 'app-businessunit-detail', |
||||||
|
templateUrl: './businessunit-detail.component.html', |
||||||
|
styleUrls: ['./businessunit-detail.component.scss'] |
||||||
|
}) |
||||||
|
export class BusinessunitDetailComponent implements OnInit { |
||||||
|
|
||||||
|
businessunits : Businessunit[] = []; |
||||||
|
@Input() |
||||||
|
businessunit = {} as Businessunit ; |
||||||
|
agences : Agence[] = []; |
||||||
|
agence = {} as Agence ; |
||||||
|
|
||||||
|
constructor( |
||||||
|
private http : HttpClient, |
||||||
|
private businessunitService: BusinessunitService, |
||||||
|
private agenceService: AgenceService, |
||||||
|
) { } |
||||||
|
|
||||||
|
ngOnInit(): void { |
||||||
|
this.getBusinessunits(); |
||||||
|
this.getAgences(); |
||||||
|
} |
||||||
|
|
||||||
|
getBusinessunits():void { |
||||||
|
this.businessunitService.getBusinessunits() |
||||||
|
.subscribe(businessunits => this.businessunits = businessunits); |
||||||
|
} |
||||||
|
|
||||||
|
getAgences():void { |
||||||
|
this.agenceService.getAgences() |
||||||
|
.subscribe(agences => this.agences = agences); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
|
||||||
|
<div *ngIf="businessunit"> |
||||||
|
|
||||||
|
<h2>{{businessunit.name | uppercase}} </h2> |
||||||
|
<div><span>id : </span>{{businessunit.id}}</div> |
||||||
|
|
||||||
|
<app-businessunit-detail [businessunit]="businessunit"></app-businessunit-detail> |
||||||
|
|
||||||
|
<button (click)="goBack()">Retour</button> |
||||||
|
<button (click)="save()">Sauvegarder les changements</button> |
||||||
|
<button (click)="delete()">Supprimer le businessunit</button> |
||||||
|
</div> |
@ -0,0 +1,50 @@ |
|||||||
|
import { Component, OnInit } from '@angular/core'; |
||||||
|
import {Businessunit} from "../../../interfaces/businessunit"; |
||||||
|
import {ActivatedRoute} from "@angular/router"; |
||||||
|
import {BusinessunitService} from "../../../services/businessunit.service"; |
||||||
|
import {Location} from "@angular/common"; |
||||||
|
|
||||||
|
@Component({ |
||||||
|
selector: 'app-businessunit-edit', |
||||||
|
templateUrl: './businessunit-edit.component.html', |
||||||
|
styleUrls: ['./businessunit-edit.component.scss'] |
||||||
|
}) |
||||||
|
export class BusinessunitEditComponent implements OnInit { |
||||||
|
|
||||||
|
businessunit : Businessunit | undefined; |
||||||
|
|
||||||
|
constructor( |
||||||
|
private route: ActivatedRoute, |
||||||
|
private businessunitService: BusinessunitService, |
||||||
|
private location: Location |
||||||
|
) { } |
||||||
|
|
||||||
|
ngOnInit(): void { |
||||||
|
this.getBusinessunit() |
||||||
|
} |
||||||
|
|
||||||
|
getBusinessunit(): void { |
||||||
|
const id = Number(this.route.snapshot.paramMap.get('id')) |
||||||
|
this.businessunitService.getBusinessunit(id) |
||||||
|
.subscribe(businessunit => this.businessunit = businessunit); |
||||||
|
} |
||||||
|
|
||||||
|
goBack(): void { |
||||||
|
this.location.back(); |
||||||
|
} |
||||||
|
|
||||||
|
save():void{ |
||||||
|
if (this.businessunit){ |
||||||
|
this.businessunitService.updateBusinessunit(this.businessunit) |
||||||
|
.subscribe(()=>this.goBack()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
delete():void { |
||||||
|
if (this.businessunit){ |
||||||
|
this.businessunitService.deleteBusinessunit(this.businessunit) |
||||||
|
.subscribe(()=>this.goBack()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
<div xmlns=""> |
||||||
|
<h2 class = mb-4>Business Unit</h2> |
||||||
|
|
||||||
|
<table class = mb-5> |
||||||
|
<tr> |
||||||
|
<th class="spaced">Name</th> |
||||||
|
</tr> |
||||||
|
<tr *ngFor="let businessunit of businessunits"> |
||||||
|
<td class="spaced"> {{businessunit.name}} </td> |
||||||
|
<td class="spaced"> <a routerLink="{{businessunit.id}}"> Modifier </a></td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<h3>Ajouter une businessunit : </h3> |
||||||
|
|
||||||
|
<div class = mb-3> |
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<th>Name</th> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<input id="businessunit-name" [(ngModel)]="businessunit.name" placeholder="name"> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<select name="agence" id="agence-select" [(ngModel)]="businessunit.agenceId"> |
||||||
|
<option value="">-- Choisissez l'agence de cette business Unit --</option> |
||||||
|
<option *ngFor="let agence of agences" [ngValue]="agence.id">{{agence.name}}</option> |
||||||
|
</select> |
||||||
|
</div> |
||||||
|
|
||||||
|
<button class="add-button" (click)="add(businessunit)"> |
||||||
|
Ajouter une businessunit |
||||||
|
</button> |
||||||
|
</div> |
@ -0,0 +1,48 @@ |
|||||||
|
import { Component, OnInit } from '@angular/core'; |
||||||
|
import {Businessunit} from "../../interfaces/businessunit"; |
||||||
|
import {HttpClient} from "@angular/common/http"; |
||||||
|
import {BusinessunitService} from "../../services/businessunit.service"; |
||||||
|
import {Agence} from "../../interfaces/agence"; |
||||||
|
import {AgenceService} from "../../services/agence.service"; |
||||||
|
|
||||||
|
@Component({ |
||||||
|
selector: 'app-businessunit', |
||||||
|
templateUrl: './businessunit.component.html', |
||||||
|
styleUrls: ['./businessunit.component.scss'] |
||||||
|
}) |
||||||
|
export class BusinessunitComponent implements OnInit { |
||||||
|
|
||||||
|
businessunits : Businessunit[] = []; |
||||||
|
businessunit = {} as Businessunit ; |
||||||
|
agences : Agence[] = []; |
||||||
|
agence = {} as Agence ; |
||||||
|
|
||||||
|
constructor( |
||||||
|
private http : HttpClient, |
||||||
|
private businessunitService: BusinessunitService, |
||||||
|
private agenceService: AgenceService, |
||||||
|
) { } |
||||||
|
|
||||||
|
ngOnInit(): void { |
||||||
|
this.getBusinessunits(); |
||||||
|
this.getAgences(); |
||||||
|
} |
||||||
|
|
||||||
|
getBusinessunits():void { |
||||||
|
this.businessunitService.getBusinessunits() |
||||||
|
.subscribe(businessunits => this.businessunits = businessunits); |
||||||
|
} |
||||||
|
|
||||||
|
getAgences():void { |
||||||
|
this.agenceService.getAgences() |
||||||
|
.subscribe(agences => this.agences = agences); |
||||||
|
} |
||||||
|
|
||||||
|
add(businessunit: Businessunit): void { |
||||||
|
this.businessunitService.addBusinessunit(businessunit) |
||||||
|
.subscribe(businessunit => { |
||||||
|
this.businessunits.push(businessunit); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
export interface Businessunit { |
||||||
|
name: string; |
||||||
|
id: number; |
||||||
|
agenceId : number; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
import { Injectable } from '@angular/core'; |
||||||
|
import {HttpClient, HttpHeaders} from "@angular/common/http"; |
||||||
|
import {Observable} from "rxjs"; |
||||||
|
import {Businessunit} from "../interfaces/businessunit"; |
||||||
|
import {businessunitsUrl} from "../../ressources/routes/routes"; |
||||||
|
|
||||||
|
@Injectable({ |
||||||
|
providedIn: 'root' |
||||||
|
}) |
||||||
|
export class BusinessunitService { |
||||||
|
private businessunitsUrl = businessunitsUrl; |
||||||
|
|
||||||
|
httpOptions = { |
||||||
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) |
||||||
|
}; |
||||||
|
|
||||||
|
constructor(private http: HttpClient) { } |
||||||
|
|
||||||
|
getBusinessunits():Observable<Businessunit[]> { |
||||||
|
return this.http.get<Businessunit[]>(this.businessunitsUrl); |
||||||
|
} |
||||||
|
|
||||||
|
getBusinessunit(id : number):Observable<Businessunit>{ |
||||||
|
return this.http.get<Businessunit>(this.businessunitsUrl+"/"+id); |
||||||
|
} |
||||||
|
|
||||||
|
updateBusinessunit(businessunit : Businessunit):Observable<Businessunit>{ |
||||||
|
let body = JSON.stringify(businessunit); |
||||||
|
return this.http.put<Businessunit>(this.businessunitsUrl + "/" + businessunit.id, body, this.httpOptions); |
||||||
|
} |
||||||
|
|
||||||
|
deleteBusinessunit(businessunit: Businessunit) { |
||||||
|
return this.http.delete(this.businessunitsUrl + "/" + businessunit.id); |
||||||
|
} |
||||||
|
|
||||||
|
addBusinessunit(businessunit: Businessunit): Observable<Businessunit> { |
||||||
|
let body = JSON.stringify(businessunit); |
||||||
|
return this.http.post<Businessunit>(this.businessunitsUrl, body, this.httpOptions); |
||||||
|
} |
||||||
|
} |
@ -1,2 +1,3 @@ |
|||||||
export const collaborateursUrl = 'https://localhost:7125/api/collaborateurs'; |
export const collaborateursUrl = 'https://localhost:7125/api/collaborateurs'; |
||||||
export const agencesUrl = 'https://localhost:7125/api/agences'; |
export const agencesUrl = 'https://localhost:7125/api/agences'; |
||||||
|
export const businessunitsUrl = 'https://localhost:7125/api/businessunits'; |
||||||
|
Loading…
Reference in new issue