diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6c1d9a3..74a998c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,8 @@ import { HomeComponent } from './components/home/home.component'; import { AgenceComponent } from './components/agence/agence.component'; import { AgenceEditComponent } from './components/agence/agence-edit/agence-edit.component'; import { CollaborateurDetailComponent } from './components/collaborateur/collaborateur-detail/collaborateur-detail.component'; +import { BusinessunitComponent } from './components/businessunit/businessunit.component'; +import { BusinessunitEditComponent } from './components/businessunit/businessunit-edit/businessunit-edit.component'; @NgModule({ declarations: [ @@ -21,7 +23,9 @@ import { CollaborateurDetailComponent } from './components/collaborateur/collabo HomeComponent, AgenceComponent, AgenceEditComponent, - CollaborateurDetailComponent + CollaborateurDetailComponent, + BusinessunitComponent, + BusinessunitEditComponent ], imports: [ BrowserModule, diff --git a/src/app/interfaces/businessunit.ts b/src/app/interfaces/businessunit.ts new file mode 100644 index 0000000..0b1b86a --- /dev/null +++ b/src/app/interfaces/businessunit.ts @@ -0,0 +1,5 @@ +export interface Businessunit { + name: string; + id: number; + agenceId : number; +} diff --git a/src/app/services/businessunit.service.ts b/src/app/services/businessunit.service.ts new file mode 100644 index 0000000..bd17c09 --- /dev/null +++ b/src/app/services/businessunit.service.ts @@ -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 { + return this.http.get(this.businessunitsUrl); + } + + getBusinessunit(id : number):Observable{ + return this.http.get(this.businessunitsUrl+"/"+id); + } + + updateBusinessunit(businessunit : Businessunit):Observable{ + let body = JSON.stringify(businessunit); + return this.http.put(this.businessunitsUrl + "/" + businessunit.id, body, this.httpOptions); + } + + deleteBusinessunit(businessunit: Businessunit) { + return this.http.delete(this.businessunitsUrl + "/" + businessunit.id); + } + + addBusinessunit(businessunit: Businessunit): Observable { + let body = JSON.stringify(businessunit); + return this.http.post(this.businessunitsUrl, body, this.httpOptions); + } +} diff --git a/src/ressources/routes/routes.ts b/src/ressources/routes/routes.ts index 1eb9e54..83e2c54 100644 --- a/src/ressources/routes/routes.ts +++ b/src/ressources/routes/routes.ts @@ -1,2 +1,3 @@ export const collaborateursUrl = 'https://localhost:7125/api/collaborateurs'; export const agencesUrl = 'https://localhost:7125/api/agences'; +export const businessunitsUrl = 'https://localhost:7125/api/businessunits'; From b018d20079f00a2421ef0d1b6bba5d51dfdbfc6b Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Wed, 9 Mar 2022 17:04:03 +0100 Subject: [PATCH 2/4] =?UTF-8?q?cr=C3=A9ation=20de=20la=20page=20businessun?= =?UTF-8?q?it=20et=20de=20la=20page=20businessunitedit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../businessunit-edit.component.html | 1 + .../businessunit-edit.component.scss | 0 .../businessunit-edit.component.ts | 15 ++++++++ .../businessunit/businessunit.component.html | 32 ++++++++++++++++ .../businessunit/businessunit.component.scss | 0 .../businessunit/businessunit.component.ts | 37 +++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html create mode 100644 src/app/components/businessunit/businessunit-edit/businessunit-edit.component.scss create mode 100644 src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts create mode 100644 src/app/components/businessunit/businessunit.component.html create mode 100644 src/app/components/businessunit/businessunit.component.scss create mode 100644 src/app/components/businessunit/businessunit.component.ts diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html new file mode 100644 index 0000000..ea9e272 --- /dev/null +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html @@ -0,0 +1 @@ +

businessunit-edit works!

diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.scss b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts new file mode 100644 index 0000000..9665c1a --- /dev/null +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-businessunit-edit', + templateUrl: './businessunit-edit.component.html', + styleUrls: ['./businessunit-edit.component.scss'] +}) +export class BusinessunitEditComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/src/app/components/businessunit/businessunit.component.html b/src/app/components/businessunit/businessunit.component.html new file mode 100644 index 0000000..99075c3 --- /dev/null +++ b/src/app/components/businessunit/businessunit.component.html @@ -0,0 +1,32 @@ +
+

Business Unit

+ + + + + + + + + +
Name
{{businessunit.name}} Modifier
+ +

Ajouter une businessunit :

+ +
+ + + + + + + +
Name
+ +
+
+ + +
diff --git a/src/app/components/businessunit/businessunit.component.scss b/src/app/components/businessunit/businessunit.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/businessunit/businessunit.component.ts b/src/app/components/businessunit/businessunit.component.ts new file mode 100644 index 0000000..5f4816c --- /dev/null +++ b/src/app/components/businessunit/businessunit.component.ts @@ -0,0 +1,37 @@ +import { Component, OnInit } from '@angular/core'; +import {Businessunit} from "../../interfaces/businessunit"; +import {HttpClient} from "@angular/common/http"; +import {BusinessunitService} from "../../services/businessunit.service"; + +@Component({ + selector: 'app-businessunit', + templateUrl: './businessunit.component.html', + styleUrls: ['./businessunit.component.scss'] +}) +export class BusinessunitComponent implements OnInit { + + businessunits : Businessunit[] = []; + businessunit = {} as Businessunit ; + + constructor( + private http : HttpClient, + private businessunitService: BusinessunitService, + ) { } + + ngOnInit(): void { + this.getBusinessunits(); + } + + getBusinessunits():void { + this.businessunitService.getBusinessunits() + .subscribe(businessunits => this.businessunits = businessunits); + } + + add(businessunit: Businessunit): void { + this.businessunitService.addBusinessunit(businessunit) + .subscribe(businessunit => { + this.businessunits.push(businessunit); + }); + } + +} From e4c80ba6181e7e956e5b2c288d1c8f51590b2a88 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Thu, 10 Mar 2022 15:25:52 +0100 Subject: [PATCH 3/4] =?UTF-8?q?cr=C3=A9ation=20de=20la=20page=20businessun?= =?UTF-8?q?it=20et=20de=20la=20page=20businessunitedit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.module.ts | 4 +- .../businessunit-detail.component.html | 17 ++++++++ .../businessunit-detail.component.scss | 0 .../businessunit-detail.component.ts | 42 +++++++++++++++++++ .../businessunit-edit.component.html | 13 +++++- .../businessunit-edit.component.ts | 37 +++++++++++++++- .../businessunit/businessunit.component.html | 5 +++ .../businessunit/businessunit.component.ts | 11 +++++ 8 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/app/components/businessunit/businessunit-detail/businessunit-detail.component.html create mode 100644 src/app/components/businessunit/businessunit-detail/businessunit-detail.component.scss create mode 100644 src/app/components/businessunit/businessunit-detail/businessunit-detail.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 74a998c..6ecf328 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -14,6 +14,7 @@ import { AgenceEditComponent } from './components/agence/agence-edit/agence-edit import { CollaborateurDetailComponent } from './components/collaborateur/collaborateur-detail/collaborateur-detail.component'; import { BusinessunitComponent } from './components/businessunit/businessunit.component'; import { BusinessunitEditComponent } from './components/businessunit/businessunit-edit/businessunit-edit.component'; +import { BusinessunitDetailComponent } from './components/businessunit/businessunit-detail/businessunit-detail.component'; @NgModule({ declarations: [ @@ -25,7 +26,8 @@ import { BusinessunitEditComponent } from './components/businessunit/businessuni AgenceEditComponent, CollaborateurDetailComponent, BusinessunitComponent, - BusinessunitEditComponent + BusinessunitEditComponent, + BusinessunitDetailComponent ], imports: [ BrowserModule, diff --git a/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.html b/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.html new file mode 100644 index 0000000..b1c3297 --- /dev/null +++ b/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.html @@ -0,0 +1,17 @@ +
+ + + + + + + +
Name
+ +
+ + +
diff --git a/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.scss b/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.ts b/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.ts new file mode 100644 index 0000000..3fe3755 --- /dev/null +++ b/src/app/components/businessunit/businessunit-detail/businessunit-detail.component.ts @@ -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); + } + +} diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html index ea9e272..b54af61 100644 --- a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html @@ -1 +1,12 @@ -

businessunit-edit works!

+ +
+ +

{{businessunit.name | uppercase}}

+
id : {{businessunit.id}}
+ + + + + + +
diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts index 9665c1a..00e2320 100644 --- a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts @@ -1,4 +1,8 @@ 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', @@ -7,9 +11,40 @@ import { Component, OnInit } from '@angular/core'; }) export class BusinessunitEditComponent implements OnInit { - constructor() { } + 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()); + } } } diff --git a/src/app/components/businessunit/businessunit.component.html b/src/app/components/businessunit/businessunit.component.html index 99075c3..45bf93d 100644 --- a/src/app/components/businessunit/businessunit.component.html +++ b/src/app/components/businessunit/businessunit.component.html @@ -24,6 +24,11 @@ + +