diff --git a/Dockerfile b/Dockerfile index b132014c3bc22aaa7da13efd1d87024e29b5801f..a0382ac55e64fc1b2397003394871e201c4fc43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,8 +28,6 @@ RUN npm run build:prod FROM ${DEPENDENCY_PROXY}nginx # copy artifact build from the 'build environment' -RUN apt-get update - COPY --from=build /app/dist/fr /usr/share/nginx/html # Add outdated browser page diff --git a/src/app/admin/components/manage-jobs/manage-jobs.component.ts b/src/app/admin/components/manage-jobs/manage-jobs.component.ts index fd7c288a0a3bb5a010e4e056eddaf63d78e7dce1..53e3cd480580d58cba28c8ea1a559bb6754c1b27 100644 --- a/src/app/admin/components/manage-jobs/manage-jobs.component.ts +++ b/src/app/admin/components/manage-jobs/manage-jobs.component.ts @@ -23,6 +23,7 @@ export class ManageJobsComponent implements OnInit { public validatedJobs: Job[] = []; public unvalidatedJobs: Job[] = []; public jobsGroups: JobGroup[] = []; + public jobsGroupsList: JobGroup[] = []; public deleteModalOpened = false; public validatedJobsName: string[] = []; public mergeJobModalOpened = false; @@ -264,7 +265,7 @@ export class ManageJobsComponent implements OnInit { if (arg.oldValue === arg.newValue) { return; } else { - this.adminService.editJob(arg.data._id, arg.data.name, arg.data.hasPersonalOffer).subscribe(() => { + this.adminService.updateJob(arg.data._id, arg.data).subscribe(() => { this.notificationService.showSuccess("L'opération a réussie.", ''); this.findValidatedJobs(); this.findUnvalidatedJobs(); @@ -348,7 +349,8 @@ export class ManageJobsComponent implements OnInit { this.jobsGroupsName = []; this.adminService.getJobsGroupsWithJobs().subscribe((jobsGrps) => { this.jobsGroups = jobsGrps; - jobsGrps.forEach((jobsGroup) => { + this.jobsGroupsList = [{ name: '' }, ...jobsGrps]; + this.jobsGroupsList.forEach((jobsGroup) => { this.jobsGroupsName.push(jobsGroup.name); }); }); @@ -390,8 +392,7 @@ export class ManageJobsComponent implements OnInit { public onJobsGroupChange(arg): void { const selectedJob = this.validatedJobs.find((job) => job._id === arg.data._id); - const selectedJobsGroup = this.jobsGroups.find((jobsGroup) => jobsGroup.name === arg.newValue); - + const selectedJobsGroup = this.jobsGroupsList.find((jobsGroup) => jobsGroup.name === arg.newValue); // The column field is the jobsGroup.name text, we manually assign in selectedJob the full jobsGroup object to be consistent selectedJob.jobsGroup = { ...selectedJobsGroup }; @@ -399,9 +400,13 @@ export class ManageJobsComponent implements OnInit { this.getJobsGroupsWithJobs(); this.newJobsGroupForm.reset(); - this.notificationService.showSuccess( - `Le groupe de fonctions ${selectedJobsGroup.name} a bien été attribuée à la fonction ${arg.data.name}.` - ); + if (selectedJob.jobsGroup?.name === '') { + this.notificationService.showSuccess(`Le groupe de fonctions a bien été enlevé.`); + } else { + this.notificationService.showSuccess( + `Le groupe de fonctions ${selectedJobsGroup.name} a bien été attribuée à la fonction ${arg.data.name}.` + ); + } }); return; diff --git a/src/app/admin/components/manage-users/manage-users.component.html b/src/app/admin/components/manage-users/manage-users.component.html index b3068c14799f66a03f72bf86887791d8109c6b4e..b89005e95ed0131eb3e2b899a1c22fc3d80a514d 100644 --- a/src/app/admin/components/manage-users/manage-users.component.html +++ b/src/app/admin/components/manage-users/manage-users.component.html @@ -69,7 +69,7 @@ (closed)="deleteUser(userToDelete, $event)" /> <app-modal-confirmation - *ngIf="changingJobs" + *ngIf="changingJobs && changingJobs[0] !== null" [opened]="editJobModalOpened" [content]=" 'Voulez-vous vraiment changer la fonction de cet utilisateur ? (' + @@ -81,7 +81,13 @@ (closed)="editJob(changingJobs[0], changingJobs[1], $event, contextRow)" /> <app-modal-confirmation - *ngIf="changingEmployers" + *ngIf="changingJobs && changingJobs[0] === null" + [opened]="editJobModalOpened" + [content]="'Voulez-vous vraiment supprimer la fonction de cet utilisateur ?'" + (closed)="editJob(changingJobs[0], changingJobs[1], $event, contextRow)" +/> +<app-modal-confirmation + *ngIf="changingEmployers && changingEmployers[0] !== null" [opened]="editEmployerModalOpened" [content]=" 'Voulez-vous vraiment changer l\'employeur de cet utilisateur ? (' + @@ -92,3 +98,9 @@ " (closed)="editEmployer(changingEmployers[0], changingEmployers[1], $event, contextRow)" /> +<app-modal-confirmation + *ngIf="changingEmployers && changingEmployers[0] === null" + [opened]="editEmployerModalOpened" + [content]="'Voulez-vous vraiment supprimer l\'employeur de cet utilisateur ?'" + (closed)="editEmployer(changingEmployers[0], changingEmployers[1], $event, contextRow)" +/> diff --git a/src/app/admin/components/manage-users/manage-users.component.ts b/src/app/admin/components/manage-users/manage-users.component.ts index 5c2cf6c9db0c9b236e1ae1e4579242a891936a28..5390bee31a2a712d8ac263d70a57e136e442fd4e 100644 --- a/src/app/admin/components/manage-users/manage-users.component.ts +++ b/src/app/admin/components/manage-users/manage-users.component.ts @@ -155,6 +155,10 @@ export class ManageUsersComponent { public onJobChange(arg): void { const selectedJob = this.validatedJobs.find((job) => job.name === arg.newValue); + if (selectedJob === undefined && arg.oldValue !== undefined) { + this.toggleEditJobModal(null, arg.oldValue, arg); + return; + } if (selectedJob && arg.oldValue === undefined) { // user had no job assigned, and admin selected a job -> call setUserJob without modal this.adminService.setUserJob(selectedJob._id, arg.data.id).subscribe(() => { @@ -175,6 +179,10 @@ export class ManageUsersComponent { public onEmployerChange(arg): void { const selectedEmployer = this.validatedEmployers.find((employ) => employ.name === arg.newValue); + if (selectedEmployer === undefined && arg.oldValue !== undefined) { + this.toggleEditEmployerModal(null, arg.oldValue, arg); + return; + } if (selectedEmployer && arg.oldValue === undefined) { // user had no employer assigned, and admin selected a employer -> call setUserEmployer this.adminService.setUserEmployer(selectedEmployer._id, arg.data.id).subscribe(() => { @@ -206,12 +214,20 @@ export class ManageUsersComponent { public editJob(newJob: Job, oldJob: Job, shouldEdit: boolean, context?): void { this.toggleEditJobModal(newJob, oldJob, context); if (shouldEdit) { - // store newJob otherwise cell will only keep name value - this.adminService.setUserJob(newJob._id, context.node.data._id).subscribe((data) => { - context.node.data[context.colDef.field] = data.job; - context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); - this.notificationService.showSuccess("L'opération a réussie.", ''); - }); + if (newJob) { + // store newJob otherwise cell will only keep name value + this.adminService.setUserJob(newJob._id, context.node.data._id).subscribe((data) => { + context.node.data[context.colDef.field] = data.job; + context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); + this.notificationService.showSuccess("L'opération a réussie.", ''); + }); + } else { + this.adminService.removeUserJob(context.node.data._id).subscribe((data) => { + context.node.data[context.colDef.field] = data.job; + context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); + this.notificationService.showSuccess("L'opération a réussie.", ''); + }); + } } else { if (context.oldValue && context.oldValue.name) { context.node.data[context.colDef.field] = context.oldValue; @@ -223,11 +239,19 @@ export class ManageUsersComponent { public editEmployer(newEmployer: Employer, oldEmployer: Employer, shouldEdit: boolean, context?): void { this.toggleEditEmployerModal(newEmployer, oldEmployer, context); if (shouldEdit) { - this.adminService.setUserEmployer(newEmployer._id, context.node.data._id).subscribe((data) => { - context.node.data[context.colDef.field] = data.employer; - context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); - this.notificationService.showSuccess("L'opération a réussie.", ''); - }); + if (newEmployer) { + this.adminService.setUserEmployer(newEmployer._id, context.node.data._id).subscribe((data) => { + context.node.data[context.colDef.field] = data.employer; + context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); + this.notificationService.showSuccess("L'opération a réussie.", ''); + }); + } else { + this.adminService.removeUserEmployer(context.node.data._id).subscribe((data) => { + context.node.data[context.colDef.field] = data.employer; + context.api.refreshCells({ rowNodes: [context.node], columns: [context.column.colId] }); + this.notificationService.showSuccess("L'opération a réussie.", ''); + }); + } } else { if (context.oldValue && context.oldValue.name) { context.node.data[context.colDef.field] = context.oldValue; @@ -256,6 +280,7 @@ export class ManageUsersComponent { public findValidatedJobs(): void { this.adminService.getJobs().subscribe((jobs) => { this.validatedJobs = jobs; + this.validatedJobsName.push(''); jobs.map((job) => { this.validatedJobsName.push(job.name); }); @@ -265,6 +290,7 @@ export class ManageUsersComponent { public findValidatedEmployers(): void { this.adminService.getEmployers().subscribe((employers) => { this.validatedEmployers = employers; + this.validatedEmployersName.push(''); employers.map((employer) => { this.validatedEmployersName.push(employer.name); }); diff --git a/src/app/admin/services/admin.service.ts b/src/app/admin/services/admin.service.ts index bcbb2b2d517ab686f0277b7f6ea30b6210ab1e8b..7041279ec68fb5b85d24525ac0f1314d4f19a487 100644 --- a/src/app/admin/services/admin.service.ts +++ b/src/app/admin/services/admin.service.ts @@ -51,6 +51,12 @@ export class AdminService { }); } + public removeUserJob(userId: string): Observable<User> { + return this.http.put<User>(`${this.baseUrl}/removeUserJob`, { + userId, + }); + } + public setUserEmployer(employerId: string, userId: string): Observable<User> { return this.http.put<User>(`${this.baseUrl}/setUserEmployer`, { userId, @@ -58,6 +64,12 @@ export class AdminService { }); } + public removeUserEmployer(userId: string): Observable<User> { + return this.http.put<User>(`${this.baseUrl}/removeUserEmployer`, { + userId, + }); + } + // By default return only validated jobs public getJobs(): Observable<Job[]> { return this.http.get<Job[]>(`api/jobs`); @@ -96,7 +108,7 @@ export class AdminService { } public editJobsGroup(id: string, name: string): Observable<JobGroup> { - return this.http.put<Job>(`${this.jobsGroupBaseUrl}/${id}/`, { name }); + return this.http.put<JobGroup>(`${this.jobsGroupBaseUrl}/${id}/`, { name }); } public getUnvalidatedEmployers(): Observable<Employer[]> { @@ -128,7 +140,9 @@ export class AdminService { } public updateJob(id: string, job: Job): Observable<Job> { - return this.http.put<Job>(`${this.jobBaseUrl}/${id}`, job); + const newJob: Job = { ...job }; + if (job.jobsGroup?.name === '') delete newJob.jobsGroup; + return this.http.put<Job>(`${this.jobBaseUrl}/${id}`, newJob); } public createEmployer(name: string): Observable<Employer> { @@ -143,13 +157,6 @@ export class AdminService { return this.http.post<Employer>(`${this.employerBaseUrl}/validate/${id}`, {}); } - public editJob(id: string, name: string, hasPersonalOffer: boolean): Observable<Job> { - return this.http.put<Job>(`${this.jobBaseUrl}/${id}`, { - name, - hasPersonalOffer, - }); - } - public editEmployer(id: string, name: string): Observable<Employer> { return this.http.put<Employer>(`${this.employerBaseUrl}/${id}`, { name,