parent
9603c15061
commit
70456c291f
@ -0,0 +1,18 @@ |
||||
import {NgModule} from '@angular/core'; |
||||
import {RouterModule,Routes} from "@angular/router"; |
||||
import {CollaborateurComponent} from "./collaborateur/collaborateur.component"; |
||||
import {CollaborateurDetailComponent} from "./collaborateur-detail/collaborateur-detail.component"; |
||||
|
||||
const routes : Routes = [ |
||||
{ path: '', redirectTo: '/collaborateurs', pathMatch: 'full' }, |
||||
|
||||
{ path:'collaborateurs',component:CollaborateurComponent }, |
||||
{ path: 'detail/:id', component: CollaborateurDetailComponent }, |
||||
]; |
||||
|
||||
@NgModule({ |
||||
imports: [RouterModule.forRoot(routes)], |
||||
exports: [RouterModule] |
||||
}) |
||||
|
||||
export class AppRoutingModule { } |
@ -0,0 +1,28 @@ |
||||
/* HeroDetailComponent's private CSS styles */ |
||||
label { |
||||
color: #435960; |
||||
font-weight: bold; |
||||
} |
||||
input { |
||||
font-size: 1em; |
||||
padding: .3rem; |
||||
margin: .5rem; |
||||
} |
||||
|
||||
button { |
||||
padding: 5px; |
||||
text-decoration: none; |
||||
margin: 2px; |
||||
display: inline-block; |
||||
background-color: #E77620; |
||||
color: white; |
||||
border-radius: 4px; |
||||
} |
||||
button:hover { |
||||
background-color: #42545C; |
||||
} |
||||
button:disabled { |
||||
background-color: #eee; |
||||
color: #ccc; |
||||
cursor: auto; |
||||
} |
@ -0,0 +1,50 @@ |
||||
|
||||
<div *ngIf="collaborateur"> |
||||
|
||||
<h2>{{collaborateur.name | uppercase}} Details</h2> |
||||
<div><span>id : </span>{{collaborateur.id}}</div> |
||||
<div> |
||||
<label class="col-3" for="collaborateur-name">Collaborateur name </label> |
||||
<input id="collaborateur-name" [(ngModel)]="collaborateur.name" placeholder="name"> |
||||
|
||||
<label class="col-3" for="collaborateur-firstName">Collaborateur firstname </label> |
||||
<input id="collaborateur-firstName" [(ngModel)]="collaborateur.firstName" placeholder="firstname"> |
||||
|
||||
<label class="col-3" for="collaborateur-birthDate">Collaborateur birthDate </label> |
||||
<input id="collaborateur-birthDate" [(ngModel)]="collaborateur.birthDate" placeholder="birthDate"> |
||||
|
||||
<label class="col-3" for="collaborateur-gender">Collaborateur gender </label> |
||||
<input id="collaborateur-gender" [(ngModel)]="collaborateur.gender" placeholder="gender"> |
||||
|
||||
<label class="col-3" for="collaborateur-status">Collaborateur status </label> |
||||
<input id="collaborateur-status" [(ngModel)]="collaborateur.status" placeholder="status"> |
||||
|
||||
<label class="col-3" for="collaborateur-childrenNumber">Collaborateur childrenNumber </label> |
||||
<input id="collaborateur-childrenNumber" [(ngModel)]="collaborateur.childrenNumber" placeholder="childrenNumber"> |
||||
|
||||
<label class="col-3" for="collaborateur-address">Collaborateur address </label> |
||||
<input id="collaborateur-address" [(ngModel)]="collaborateur.address" placeholder="address"> |
||||
|
||||
<label class="col-3" for="collaborateur-telephone">Collaborateur telephone </label> |
||||
<input id="collaborateur-telephone" [(ngModel)]="collaborateur.telephone" placeholder="telephone"> |
||||
|
||||
<label class="col-3" for="collaborateur-personalMail">Collaborateur personalMail </label> |
||||
<input id="collaborateur-personalMail" [(ngModel)]="collaborateur.personalMail" placeholder="personalMail"> |
||||
|
||||
<label class="col-3" for="collaborateur-apsideMail">Collaborateur apsideMail </label> |
||||
<input id="collaborateur-apsideMail" [(ngModel)]="collaborateur.apsideMail" placeholder="apsideMail"> |
||||
|
||||
<label class="col-3" for="collaborateur-resignationDate">Collaborateur resignationDate </label> |
||||
<input id="collaborateur-resignationDate" [(ngModel)]="collaborateur.resignationDate" placeholder="resignationDate"> |
||||
|
||||
<label class="col-3" for="collaborateur-referrerId">Collaborateur referrerId </label> |
||||
<input id="collaborateur-referrerId" [(ngModel)]="collaborateur.referrerId" placeholder="referrerId"> |
||||
|
||||
<label class="col-3" for="collaborateur-businessUnitId">Collaborateur businessUnitId </label> |
||||
<input id="collaborateur-businessUnitId" [(ngModel)]="collaborateur.businessUnitId" placeholder="businessUnitId"> |
||||
</div> |
||||
|
||||
<button (click)="goBack()">Retour</button> |
||||
<button (click)="save()">sauvegarder les changements</button> |
||||
<button (click)="delete()">Supprimer le collaborateur</button> |
||||
</div> |
@ -0,0 +1,25 @@ |
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { CollaborateurDetailComponent } from './collaborateur-detail.component'; |
||||
|
||||
describe('CollaborateurDetailComponent', () => { |
||||
let component: CollaborateurDetailComponent; |
||||
let fixture: ComponentFixture<CollaborateurDetailComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ CollaborateurDetailComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(CollaborateurDetailComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,48 @@ |
||||
import {Component, OnInit} from '@angular/core'; |
||||
import {Collaborateur} from "../collaborateur"; |
||||
import { ActivatedRoute } from '@angular/router'; |
||||
import { Location } from '@angular/common'; |
||||
import { CollaborateurService} from "../collaborateur.service"; |
||||
|
||||
@Component({ |
||||
selector: 'app-collaborateur-detail', |
||||
templateUrl: './collaborateur-detail.component.html', |
||||
styleUrls: ['./collaborateur-detail.component.css'] |
||||
}) |
||||
export class CollaborateurDetailComponent implements OnInit { |
||||
collaborateur : Collaborateur | undefined; |
||||
|
||||
constructor( |
||||
private route: ActivatedRoute, |
||||
private collaborateurService: CollaborateurService, |
||||
private location: Location |
||||
) { } |
||||
|
||||
ngOnInit(): void { |
||||
this.getCollaborateur() |
||||
} |
||||
|
||||
getCollaborateur(): void { |
||||
const id = Number(this.route.snapshot.paramMap.get('id')) |
||||
this.collaborateurService.getCollaborateur(id) |
||||
.subscribe(collaborateur => this.collaborateur = collaborateur); |
||||
} |
||||
|
||||
goBack(): void { |
||||
this.location.back(); |
||||
} |
||||
|
||||
save():void{ |
||||
if (this.collaborateur){ |
||||
this.collaborateurService.updateCollaborateur(this.collaborateur) |
||||
.subscribe(()=>this.goBack()); |
||||
} |
||||
} |
||||
|
||||
delete():void { |
||||
if (this.collaborateur){ |
||||
this.collaborateurService.deleteCollaborateur(this.collaborateur) |
||||
.subscribe(()=>this.goBack()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
import { TestBed } from '@angular/core/testing'; |
||||
|
||||
import { CollaborateurService } from './collaborateur.service'; |
||||
|
||||
describe('CollaborateurService', () => { |
||||
let service: CollaborateurService; |
||||
|
||||
beforeEach(() => { |
||||
TestBed.configureTestingModule({}); |
||||
service = TestBed.inject(CollaborateurService); |
||||
}); |
||||
|
||||
it('should be created', () => { |
||||
expect(service).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,52 @@ |
||||
import {Collaborateur} from "./collaborateur"; |
||||
import {Injectable} from '@angular/core'; |
||||
import {Observable} from "rxjs"; |
||||
import {MessageService} from "./message.service"; |
||||
import {HttpClient, HttpHeaders} from "@angular/common/http"; |
||||
|
||||
|
||||
@Injectable({providedIn: 'root'}) |
||||
|
||||
export class CollaborateurService { |
||||
|
||||
private collaborateursUrl = 'https://localhost:7125/api/collaborateurs'; |
||||
|
||||
httpOptions = { |
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) |
||||
}; |
||||
|
||||
constructor(private http: HttpClient, |
||||
private messageService : MessageService) { } |
||||
|
||||
private log(message : string){ |
||||
this.messageService.add(`CollaborateurService : ${message}`) |
||||
} |
||||
|
||||
getCollaborateurs():Observable<Collaborateur[]> { |
||||
this.log('get all collaborateurs'); |
||||
return this.http.get<Collaborateur[]>(this.collaborateursUrl); |
||||
} |
||||
|
||||
getCollaborateur(id : number):Observable<Collaborateur>{ |
||||
this.log(`get collaborateur by id : ${id}`); |
||||
return this.http.get<Collaborateur>(this.collaborateursUrl+"/"+id); |
||||
} |
||||
|
||||
updateCollaborateur(collaborateur : Collaborateur):Observable<any>{ |
||||
let body = JSON.stringify(collaborateur); |
||||
this.log(`update collaborateur ${collaborateur.id}`) |
||||
return this.http.put(this.collaborateursUrl + "/" + collaborateur.id, body, this.httpOptions); |
||||
} |
||||
|
||||
deleteCollaborateur(collaborateur: Collaborateur) { |
||||
this.log(`delete collaborateur ${collaborateur.id}`) |
||||
return this.http.delete(this.collaborateursUrl + "/" + collaborateur.id); |
||||
} |
||||
|
||||
/** POST: add a new hero to the server */ |
||||
addCollaborateur(collaborateur: Collaborateur): Observable<Collaborateur> { |
||||
let body = JSON.stringify(collaborateur); |
||||
this.log(`add collaborateur ${body}`); |
||||
return this.http.post<Collaborateur>(this.collaborateursUrl, body, this.httpOptions); |
||||
} |
||||
} |
@ -0,0 +1,81 @@ |
||||
/* HeroesComponent's private CSS styles */ |
||||
|
||||
label { |
||||
color: #435960; |
||||
font-weight: bold; |
||||
} |
||||
input { |
||||
font-size: 1em; |
||||
padding: .3rem; |
||||
margin: .5rem; |
||||
} |
||||
|
||||
.collaborateurs { |
||||
margin: 0 0 2em 0; |
||||
list-style-type: none; |
||||
padding: 0; |
||||
width: 15em; |
||||
} |
||||
.collaborateurs li { |
||||
position: relative; |
||||
cursor: pointer; |
||||
} |
||||
|
||||
.collaborateurs li:hover { |
||||
left: .1em; |
||||
} |
||||
|
||||
.collaborateurs a { |
||||
padding: 5px; |
||||
text-decoration: none; |
||||
margin: 2px; |
||||
display: inline-block; |
||||
background-color: #E77620; |
||||
color: white; |
||||
border-radius: 4px; |
||||
|
||||
} |
||||
|
||||
.collaborateurs a:hover { |
||||
background-color: #42545C; |
||||
} |
||||
|
||||
.collaborateurs a:active { |
||||
background-color: #525252; |
||||
color: #fafafa; |
||||
} |
||||
|
||||
.collaborateurs .badge { |
||||
display: inline-block; |
||||
font-size: small; |
||||
color: white; |
||||
padding: 0.8em 0.7em 0 0.7em; |
||||
background-color:#405061; |
||||
line-height: 1em; |
||||
position: relative; |
||||
left: -1px; |
||||
top: -4px; |
||||
height: 1.8em; |
||||
min-width: 16px; |
||||
text-align: right; |
||||
margin-right: .8em; |
||||
border-radius: 4px 0 0 4px; |
||||
} |
||||
|
||||
button { |
||||
padding: 5px; |
||||
text-decoration: none; |
||||
margin: 2px; |
||||
display: inline-block; |
||||
background-color: #E77620; |
||||
color: white; |
||||
border-radius: 4px; |
||||
} |
||||
button:hover { |
||||
background-color: #42545C; |
||||
} |
||||
button:disabled { |
||||
background-color: #eee; |
||||
color: #ccc; |
||||
cursor: auto; |
||||
} |
@ -0,0 +1,62 @@ |
||||
<div> |
||||
<h2>Mes Collaborateurs</h2> |
||||
<ul class="collaborateurs"> |
||||
<li *ngFor="let collaborateur of collaborateurs"> |
||||
<a routerLink="/detail/{{collaborateur.id}}"> |
||||
<span>{{collaborateur.name}} {{collaborateur.firstName}}</span> |
||||
</a> |
||||
</li> |
||||
</ul> |
||||
</div> |
||||
|
||||
|
||||
|
||||
<div> |
||||
|
||||
<h3>Ajouter un collaborateur : </h3> |
||||
|
||||
<div> |
||||
<label class="col-3" for="collaborateur-name">Collaborateur name </label> |
||||
<input id="collaborateur-name" [(ngModel)]="collaborateur.name" placeholder="name"> |
||||
|
||||
<label class="col-3" for="collaborateur-firstName">Collaborateur firstname </label> |
||||
<input id="collaborateur-firstName" [(ngModel)]="collaborateur.firstName" placeholder="firstname"> |
||||
|
||||
<label class="col-3" for="collaborateur-birthDate">Collaborateur birthDate </label> |
||||
<input id="collaborateur-birthDate" [(ngModel)]="collaborateur.birthDate" placeholder="birthDate"> |
||||
|
||||
<label class="col-3" for="collaborateur-gender">Collaborateur name </label> |
||||
<input id="collaborateur-gender" [(ngModel)]="collaborateur.gender" placeholder="gender"> |
||||
|
||||
<label class="col-3" for="collaborateur-status">Collaborateur status </label> |
||||
<input id="collaborateur-status" [(ngModel)]="collaborateur.status" placeholder="status"> |
||||
|
||||
<label class="col-3" for="collaborateur-childrenNumber">Collaborateur childrenNumber </label> |
||||
<input id="collaborateur-childrenNumber" [(ngModel)]="collaborateur.childrenNumber" placeholder="childrenNumber"> |
||||
|
||||
<label class="col-3" for="collaborateur-address">Collaborateur address </label> |
||||
<input id="collaborateur-address" [(ngModel)]="collaborateur.address" placeholder="address"> |
||||
|
||||
<label class="col-3" for="collaborateur-telephone">Collaborateur telephone </label> |
||||
<input id="collaborateur-telephone" [(ngModel)]="collaborateur.telephone" placeholder="telephone"> |
||||
|
||||
<label class="col-3" for="collaborateur-personalMail">Collaborateur personalMail </label> |
||||
<input id="collaborateur-personalMail" [(ngModel)]="collaborateur.personalMail" placeholder="personalMail"> |
||||
|
||||
<label class="col-3" for="collaborateur-apsideMail">Collaborateur apsideMail </label> |
||||
<input id="collaborateur-apsideMail" [(ngModel)]="collaborateur.apsideMail" placeholder="apsideMail"> |
||||
|
||||
<label class="col-3" for="collaborateur-resignationDate">Collaborateur resignationDate </label> |
||||
<input id="collaborateur-resignationDate" [(ngModel)]="collaborateur.resignationDate" placeholder="resignationDate"> |
||||
|
||||
<label class="col-3" for="collaborateur-referrerId">Collaborateur referrerId </label> |
||||
<input id="collaborateur-referrerId" [(ngModel)]="collaborateur.referrerId" placeholder="referrerId"> |
||||
|
||||
<label class="col-3" for="collaborateur-businessUnitId">Collaborateur businessUnitId </label> |
||||
<input id="collaborateur-businessUnitId" [(ngModel)]="collaborateur.businessUnitId" placeholder="businessUnitId"> |
||||
</div> |
||||
|
||||
<button class="add-button" (click)="add(collaborateur)"> |
||||
Ajouter un Collaborateur |
||||
</button> |
||||
</div> |
@ -0,0 +1,25 @@ |
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { CollaborateurComponent } from './collaborateur.component'; |
||||
|
||||
describe('CollaborateurComponent', () => { |
||||
let component: CollaborateurComponent; |
||||
let fixture: ComponentFixture<CollaborateurComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ CollaborateurComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(CollaborateurComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,36 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
import {HttpClient} from "@angular/common/http"; |
||||
import {CollaborateurService} from "../collaborateur.service"; |
||||
import {Collaborateur} from "../collaborateur"; |
||||
|
||||
@Component({ |
||||
selector: 'app-collaborateur', |
||||
templateUrl: './collaborateur.component.html', |
||||
styleUrls: ['./collaborateur.component.css'] |
||||
}) |
||||
export class CollaborateurComponent implements OnInit { |
||||
collaborateurs : Collaborateur[] = []; |
||||
collaborateur = {} as Collaborateur ; |
||||
|
||||
constructor( |
||||
private http : HttpClient, |
||||
private collaborateurService: CollaborateurService, |
||||
) { } |
||||
|
||||
ngOnInit(): void { |
||||
this.getCollaborateurs(); |
||||
} |
||||
|
||||
getCollaborateurs():void { |
||||
this.collaborateurService.getCollaborateurs() |
||||
.subscribe(collaborateurs => this.collaborateurs = collaborateurs); |
||||
} |
||||
|
||||
add(collaborateur: Collaborateur): void { |
||||
this.collaborateurService.addCollaborateur(collaborateur) |
||||
.subscribe(collaborateur => { |
||||
this.collaborateurs.push(collaborateur); |
||||
}); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
import { TestBed } from '@angular/core/testing'; |
||||
|
||||
import { MessageService } from './message.service'; |
||||
|
||||
describe('MessageService', () => { |
||||
let service: MessageService; |
||||
|
||||
beforeEach(() => { |
||||
TestBed.configureTestingModule({}); |
||||
service = TestBed.inject(MessageService); |
||||
}); |
||||
|
||||
it('should be created', () => { |
||||
expect(service).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,20 @@ |
||||
import { Injectable } from '@angular/core'; |
||||
|
||||
@Injectable({ |
||||
providedIn: 'root' |
||||
}) |
||||
export class MessageService { |
||||
|
||||
messages : string[] = []; |
||||
|
||||
add(message: string){ |
||||
this.messages.push(message) |
||||
} |
||||
|
||||
clear(){ |
||||
this.messages = []; |
||||
} |
||||
|
||||
constructor() { } |
||||
|
||||
} |
@ -0,0 +1,17 @@ |
||||
button { |
||||
padding: 5px; |
||||
text-decoration: none; |
||||
margin: 2px; |
||||
display: inline-block; |
||||
background-color: #E77620; |
||||
color: white; |
||||
border-radius: 4px; |
||||
} |
||||
button:hover { |
||||
background-color: #42545C; |
||||
} |
||||
button:disabled { |
||||
background-color: #eee; |
||||
color: #ccc; |
||||
cursor: auto; |
||||
} |
@ -0,0 +1,11 @@ |
||||
<div *ngIf="messageService.messages.length"> |
||||
|
||||
<h2>Messages</h2> |
||||
|
||||
<button (click)="messageService.clear()">Clear messages</button> |
||||
|
||||
<div *ngFor='let message of messageService.messages'> |
||||
{{message}} |
||||
</div> |
||||
|
||||
</div> |
@ -0,0 +1,25 @@ |
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { MessagesComponent } from './messages.component'; |
||||
|
||||
describe('MessagesComponent', () => { |
||||
let component: MessagesComponent; |
||||
let fixture: ComponentFixture<MessagesComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ MessagesComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(MessagesComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,16 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
import { MessageService} from "../message.service"; |
||||
|
||||
@Component({ |
||||
selector: 'app-messages', |
||||
templateUrl: './messages.component.html', |
||||
styleUrls: ['./messages.component.css'] |
||||
}) |
||||
export class MessagesComponent implements OnInit { |
||||
|
||||
constructor(public messageService : MessageService) { } |
||||
|
||||
ngOnInit(): void { |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue