From 3e4e5caf59ba80e3f89f023b013ee4ac8b67026f Mon Sep 17 00:00:00 2001 From: Damien Trouillet Date: Tue, 31 Dec 2019 16:08:13 +0100 Subject: [PATCH] Feature/accreditation request (#18) * Show norms names * Add accreditation request support * Refactoring, delete duplicated code --- .../accreditation-request-routing.module.ts | 18 +++ .../accreditation-request.component.html | 23 ++++ .../accreditation-request.component.ts | 56 ++++++++ .../accreditation-request.module.ts | 27 ++++ .../list-accreditation-request.component.html | 3 + .../list-accreditation-request.component.ts | 120 ++++++++++++++++++ src/app/app.component.ts | 8 +- src/app/app.module.ts | 2 + src/app/batchs/batchs.component.ts | 4 +- src/app/core/core.module.ts | 4 +- .../models/accreditation-request.model.ts | 13 ++ .../creation-accreditation-request.model.ts | 5 + src/app/core/models/index.ts | 3 + .../response-accreditation-request.model.ts | 4 + .../accreditation-requests.service.ts | 37 ++++++ src/app/core/services/applications.service.ts | 4 + src/app/core/services/index.ts | 1 + src/app/core/services/norms.service.ts | 4 + src/app/home/home.component.html | 18 +++ src/app/home/home.module.ts | 4 +- .../modal-environment.component.ts | 2 +- 21 files changed, 352 insertions(+), 8 deletions(-) create mode 100644 src/app/accreditation-requests/accreditation-request-routing.module.ts create mode 100644 src/app/accreditation-requests/accreditation-request.component.html create mode 100644 src/app/accreditation-requests/accreditation-request.component.ts create mode 100644 src/app/accreditation-requests/accreditation-request.module.ts create mode 100644 src/app/accreditation-requests/list-accreditation-request.component.html create mode 100644 src/app/accreditation-requests/list-accreditation-request.component.ts create mode 100644 src/app/core/models/accreditation-request.model.ts create mode 100644 src/app/core/models/creation-accreditation-request.model.ts create mode 100644 src/app/core/models/response-accreditation-request.model.ts create mode 100644 src/app/core/services/accreditation-requests.service.ts diff --git a/src/app/accreditation-requests/accreditation-request-routing.module.ts b/src/app/accreditation-requests/accreditation-request-routing.module.ts new file mode 100644 index 000000000..935304c2b --- /dev/null +++ b/src/app/accreditation-requests/accreditation-request-routing.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import {AccreditationRequestComponent} from './accreditation-request.component'; +import {AuthGuard} from '../core/services'; + +const routes: Routes = [ + { + path: '', + component: AccreditationRequestComponent, + canActivate: [AuthGuard] + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class AccreditationRequestRoutingModule {} diff --git a/src/app/accreditation-requests/accreditation-request.component.html b/src/app/accreditation-requests/accreditation-request.component.html new file mode 100644 index 000000000..6deeacb6b --- /dev/null +++ b/src/app/accreditation-requests/accreditation-request.component.html @@ -0,0 +1,23 @@ +
+
+ + + recherche en cours... +
Désolé, les suggestions ne peuvent être chargées.
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/src/app/accreditation-requests/accreditation-request.component.ts b/src/app/accreditation-requests/accreditation-request.component.ts new file mode 100644 index 000000000..9ca4460ac --- /dev/null +++ b/src/app/accreditation-requests/accreditation-request.component.ts @@ -0,0 +1,56 @@ +import {Component, OnInit} from '@angular/core'; +import {AccreditationRequestsService, ApplicationsService} from '../core/services'; +import {Observable, of} from "rxjs"; +import {catchError, debounceTime, distinctUntilChanged, map, switchMap, tap} from "rxjs/operators"; +import {Application, CreationAccreditationRequest} from "../core/models"; +import {Pageable} from "../core/models/pageable.model"; +import {NotifierService} from "angular-notifier"; + +@Component({ + selector: 'app-accreditation-request', + templateUrl: './accreditation-request.component.html' +}) +export class AccreditationRequestComponent implements OnInit { + model: Application; + searching = false; + searchFailed = false; + request: CreationAccreditationRequest = {applicationId: undefined, wantManage: false, wantUse: false}; + + constructor(private accreditationRequestsService: AccreditationRequestsService, + private applicationsService: ApplicationsService, + private notifierService: NotifierService) { + } + + formatter = (result: Application) => result.name; + + + search = (text$: Observable) => + text$.pipe( + debounceTime(300), + distinctUntilChanged(), + tap(() => this.searching = true), + switchMap(term => + this.applicationsService.search(new Pageable(0,10, 'name,asc'), term) + .pipe( + map(value => value.content), + tap(() => this.searchFailed = false), + catchError(() => { + this.searchFailed = true; + return of([]); + })) + ), + tap(() => this.searching = false) + ); + + ngOnInit(): void { + } + + sendRequest(){ + this.request.applicationId = this.model.id; + this.accreditationRequestsService.sendAccreditation(this.request).subscribe( + () => this.notifierService.notify('success', `Votre demande d'accréditation a bien été envoyée`), + (error) => this.notifierService.notify('error', `Votre demande d'accréditation n'a pas pu être envoyée : ${error}`) + ); + } +} + diff --git a/src/app/accreditation-requests/accreditation-request.module.ts b/src/app/accreditation-requests/accreditation-request.module.ts new file mode 100644 index 000000000..92f1e73b8 --- /dev/null +++ b/src/app/accreditation-requests/accreditation-request.module.ts @@ -0,0 +1,27 @@ +import {NgModule} from '@angular/core'; +import {SharedModule} from '../shared'; +import {IconsModule} from '../icons'; +import {NgbPaginationModule, NgbTypeaheadModule} from "@ng-bootstrap/ng-bootstrap"; +import {AccreditationRequestComponent} from "./accreditation-request.component"; +import {AccreditationRequestRoutingModule} from "./accreditation-request-routing.module"; +import {ListAccreditationRequestComponent} from "./list-accreditation-request.component"; + +; + +@NgModule({ + declarations: [AccreditationRequestComponent, ListAccreditationRequestComponent], + imports: [ + AccreditationRequestRoutingModule, + SharedModule, + IconsModule, + NgbPaginationModule, + NgbTypeaheadModule + ], + exports: [ + AccreditationRequestComponent, + ListAccreditationRequestComponent + ], + entryComponents: [] +}) +export class AccreditationRequestModule { +} diff --git a/src/app/accreditation-requests/list-accreditation-request.component.html b/src/app/accreditation-requests/list-accreditation-request.component.html new file mode 100644 index 000000000..25bdef417 --- /dev/null +++ b/src/app/accreditation-requests/list-accreditation-request.component.html @@ -0,0 +1,3 @@ + + + diff --git a/src/app/accreditation-requests/list-accreditation-request.component.ts b/src/app/accreditation-requests/list-accreditation-request.component.ts new file mode 100644 index 000000000..2e1e659a4 --- /dev/null +++ b/src/app/accreditation-requests/list-accreditation-request.component.ts @@ -0,0 +1,120 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {AccreditationRequestsService} from '../core/services'; +import {Pageable} from "../core/models/pageable.model"; +import {Action, ColumnsDefinition, Table} from "../shared/table/table.model"; +import {Constants} from "../shared/Constants"; +import {Observable} from "rxjs"; +import {AccreditationRequest} from "../core/models"; +import {Page} from "../core/models/page.model"; +import {ActionClickEvent} from "../shared/table/action-click-event.model"; +import {NotifierService} from "angular-notifier"; + +@Component({ + selector: 'app-list-accreditation-request', + templateUrl: './list-accreditation-request.component.html' +}) +export class ListAccreditationRequestComponent implements OnInit { + @Input() userOnly: boolean; + title = 'Liste des demandes d\'accréditation à traiter'; + + private idActionAccept = 'accept'; + private idActionReject = 'reject'; + + size = this.constants.numberByPage; + page = 0; + totalSize = 0; + table: Table; + + + constructor(private accreditationRequestsService: AccreditationRequestsService, + private notifierService: NotifierService, + private constants: Constants) { + } + + ngOnInit(): void { + if(this.userOnly){ + this.title = 'Liste des demandes d\'accréditation'; + } + this.showAccreditationRequest(); + } + + listRequest(pageable: Pageable) : Observable> { + if(this.userOnly) { + return this.accreditationRequestsService.getAllMyRequests(pageable); + } + return this.accreditationRequestsService.getAllNeedAnswer(pageable); + } + + refreshAccreditationRequests(pageable: Pageable = new Pageable(0, this.constants.numberByPage, 'id,desc')) { + this.listRequest(pageable).subscribe( + accreditationRequests => { + this.table.items = accreditationRequests.content; + for (let request of this.table.items) { + request.application = request.application.name; + } + this.totalSize = accreditationRequests.totalElements; + } + ); + } + + showAccreditationRequest() { + this.table = new Table(); + this.table.showHeader = true; + this.table.showFooter = true; + + this.table.settings.columnsDefinition.id = new ColumnsDefinition(); + this.table.settings.columnsDefinition.id.title = 'Id'; + this.table.settings.columnsDefinition.id.order = 1; + this.table.settings.columnsDefinition.application = new ColumnsDefinition(); + this.table.settings.columnsDefinition.application.title = 'Nom de l\'application'; + this.table.settings.columnsDefinition.application.order = 2; + this.table.settings.columnsDefinition.wantUse = new ColumnsDefinition(); + this.table.settings.columnsDefinition.wantUse.title = 'Droit d\'utilisation'; + this.table.settings.columnsDefinition.wantUse.order = 3; + this.table.settings.columnsDefinition.wantManage = new ColumnsDefinition(); + this.table.settings.columnsDefinition.wantManage.title = 'Droit de gestion'; + this.table.settings.columnsDefinition.wantManage.order = 4; + this.table.settings.columnsDefinition.state = new ColumnsDefinition(); + this.table.settings.columnsDefinition.state.title = 'Etat'; + this.table.settings.columnsDefinition.state.order = 5; + if(!this.userOnly){ + this.table.settings.actionsDefinition.title = 'Action'; + this.table.settings.actionsDefinition.actions.push(new Action('Accepter', this.idActionAccept)); + this.table.settings.actionsDefinition.actions.push(new Action('Refuser', this.idActionReject)); + } + this.refreshAccreditationRequests(); + } + + onActionClicked(event: ActionClickEvent) { + if (event.id === this.idActionAccept) { + this.accreditationRequestsService.sendResponse({accepted: true, id: event.item.id}).subscribe( + () => { + this.notifierService.notify('success', `Demande acceptée avec succès`); + this.refreshAccreditationRequests(); + }, + (error) => { + this.notifierService.notify('error', `Une erreur est survenue lors de l'acceptation : ${error}`); + this.refreshAccreditationRequests(); + } + ) + } + + if (event.id === this.idActionReject) { + this.accreditationRequestsService.sendResponse({accepted: false, id: event.item.id}).subscribe( + () => { + this.notifierService.notify('success', `Demande rejetée avec succès`); + this.refreshAccreditationRequests(); + }, + (error) => { + this.notifierService.notify('error', `Une erreur est survenue lors du rejet : ${error}`); + this.refreshAccreditationRequests(); + } + ); + } + } + + onPageChange(event) { + this.refreshAccreditationRequests(new Pageable(this.page - 1, this.size, 'id,desc')) + } +} + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index a5345765c..561d91ab3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -31,7 +31,11 @@ export class AppComponent implements OnInit { ); } this.userService.populate(); - this.userService.isAuthenticated.subscribe((result) => this.isAuthenticated = result); - this.globalSettingsService.populateGlobalSetting(); + this.userService.isAuthenticated.subscribe((result) => { + this.isAuthenticated = result; + if(result){ + this.globalSettingsService.populateGlobalSetting(); + } + }); } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f3f27e969..4622e1ba2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,6 +18,7 @@ import {TranslateLoader, TranslateModule} from "@ngx-translate/core"; import {HttpClient} from "@angular/common/http"; import {TranslateHttpLoader} from "@ngx-translate/http-loader"; import { AnonymousComponent } from './anonymous/anonymous.component'; +import {AccreditationRequestModule} from "./accreditation-requests/accreditation-request.module"; export function HttpLoaderFactory(http: HttpClient) { return new TranslateHttpLoader(http, "./assets/i18n/", ".json"); @@ -32,6 +33,7 @@ registerLocaleData(localeFr); BrowserAnimationsModule, CoreModule, SharedModule, + AccreditationRequestModule, AuthModule, IconsModule, NgbModule, diff --git a/src/app/batchs/batchs.component.ts b/src/app/batchs/batchs.component.ts index 8ed0811ef..ffe8f03d9 100644 --- a/src/app/batchs/batchs.component.ts +++ b/src/app/batchs/batchs.component.ts @@ -15,8 +15,6 @@ import {Pageable} from "../core/models/pageable.model"; styleUrls: ['./batchs.component.scss'] }) export class BatchsComponent implements OnInit { - - private idActionRun = 'run'; private idActionRunWithParameter = 'runWithParameter'; environmentSelected: Environment; @@ -51,7 +49,7 @@ export class BatchsComponent implements OnInit { this.showBatch(); } refreshBatchs(pageable?: Pageable) { - this.batchsService.getAllFromEnvironment(this.environmentSelected.id).subscribe( + this.batchsService.getAllFromEnvironment(this.environmentSelected.id, pageable).subscribe( batchs => { this.table.items = batchs.content; this.totalSize = batchs.totalElements; diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index c04a091d0..ca3497f9a 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -4,6 +4,7 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { HttpTokenInterceptor } from './interceptors'; import { + AccreditationRequestsService, ApiService, ApplicationsService, AuthGuard, BatchsService, ChainsService, @@ -40,7 +41,8 @@ import {FileKindsService} from './services/file-kinds.service'; UsersService, NewsService, NotificationsService, - GlobalSettingsService + GlobalSettingsService, + AccreditationRequestsService ], declarations: [] }) diff --git a/src/app/core/models/accreditation-request.model.ts b/src/app/core/models/accreditation-request.model.ts new file mode 100644 index 000000000..1ec2d84d7 --- /dev/null +++ b/src/app/core/models/accreditation-request.model.ts @@ -0,0 +1,13 @@ +import {Environment} from './environment.model'; +import {Audit} from './audit.model'; +import {User} from "./user.model"; +import {Application} from "./application.model"; + +export interface AccreditationRequest extends Audit { + id: number; + user: User; + wantManage: boolean; + wantUse: boolean; + application: Application; + state: string; +} diff --git a/src/app/core/models/creation-accreditation-request.model.ts b/src/app/core/models/creation-accreditation-request.model.ts new file mode 100644 index 000000000..6a038085b --- /dev/null +++ b/src/app/core/models/creation-accreditation-request.model.ts @@ -0,0 +1,5 @@ +export interface CreationAccreditationRequest { + applicationId: number; + wantManage: boolean; + wantUse: boolean; +} diff --git a/src/app/core/models/index.ts b/src/app/core/models/index.ts index aa769593b..72c643982 100644 --- a/src/app/core/models/index.ts +++ b/src/app/core/models/index.ts @@ -22,3 +22,6 @@ export * from './usage-application.model' export * from './notification.model' export * from './roles.model' export * from './global-setting.model' +export * from './creation-accreditation-request.model' +export * from './accreditation-request.model' +export * from './response-accreditation-request.model' diff --git a/src/app/core/models/response-accreditation-request.model.ts b/src/app/core/models/response-accreditation-request.model.ts new file mode 100644 index 000000000..2393ea963 --- /dev/null +++ b/src/app/core/models/response-accreditation-request.model.ts @@ -0,0 +1,4 @@ +export interface ResponseAccreditationRequest { + id: number; + accepted: boolean; +} diff --git a/src/app/core/services/accreditation-requests.service.ts b/src/app/core/services/accreditation-requests.service.ts new file mode 100644 index 000000000..159567463 --- /dev/null +++ b/src/app/core/services/accreditation-requests.service.ts @@ -0,0 +1,37 @@ +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; + +import {ApiService} from './api.service'; +import { + AccreditationRequest, + CreationAccreditationRequest, ResponseAccreditationRequest +} from '../models'; +import {Page} from "../models/page.model"; +import {Pageable} from "../models/pageable.model"; + +@Injectable() +export class AccreditationRequestsService { + private apiName = '/accreditation-requests'; + constructor( + private apiService: ApiService + ) { + } + + getAllNeedAnswer(pageable: Pageable = new Pageable(0,20)): Observable> { + return this.apiService.get(`${this.apiName}/need-answer`, pageable); + } + + getAllMyRequests(pageable: Pageable = new Pageable(0,20)): Observable> { + return this.apiService.get(`${this.apiName}`, pageable); + } + + sendAccreditation(creationAccreditationRequest: CreationAccreditationRequest): Observable { + return this.apiService.put(`${this.apiName}`, creationAccreditationRequest); + } + + sendResponse(responseAccreditationRequest: ResponseAccreditationRequest): Observable { + return this.apiService.post(`${this.apiName}/response`, responseAccreditationRequest); + } + + +} diff --git a/src/app/core/services/applications.service.ts b/src/app/core/services/applications.service.ts index abc558c8e..165d23cff 100644 --- a/src/app/core/services/applications.service.ts +++ b/src/app/core/services/applications.service.ts @@ -22,6 +22,10 @@ export class ApplicationsService { return this.apiService.get(`${this.apiName}`, pageable); } + search(pageable: Pageable = new Pageable(0,20), name: string): Observable> { + return this.apiService.get(`${this.apiName}/search?name=${name}`, pageable); + } + getAllModerable(pageable: Pageable = new Pageable(0,20)): Observable> { return this.apiService.get(`${this.apiName}/write`, pageable); } diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts index d8fce672a..fb10dc766 100644 --- a/src/app/core/services/index.ts +++ b/src/app/core/services/index.ts @@ -18,3 +18,4 @@ export * from './users.service'; export * from './news.service'; export * from './notifications.service' export * from './global-settings.service' +export * from './accreditation-requests.service' diff --git a/src/app/core/services/norms.service.ts b/src/app/core/services/norms.service.ts index 27af40130..1f5cc991f 100644 --- a/src/app/core/services/norms.service.ts +++ b/src/app/core/services/norms.service.ts @@ -17,6 +17,10 @@ export class NormsService { return this.apiService.get(`/norms`, pageable); } + getAllName(pageable: Pageable = new Pageable(0,20)): Observable> { + return this.apiService.get(`/norms/name`, pageable); + } + addNorm(norm: Norme): Observable { return this.apiService.put('/norms', norm); } diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 21ca63b0e..8c61e0e66 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,2 +1,20 @@ +
+
+ +
+
+
+
+
+
Demande d'accréditation
+
+ +
+
+
+
+ +
+
diff --git a/src/app/home/home.module.ts b/src/app/home/home.module.ts index b48144e70..a444b4c84 100644 --- a/src/app/home/home.module.ts +++ b/src/app/home/home.module.ts @@ -4,11 +4,13 @@ import { HomeComponent } from './home.component'; import { HomeAuthResolver } from './home-auth-resolver.service'; import { SharedModule } from '../shared'; import { HomeRoutingModule } from './home-routing.module'; +import {AccreditationRequestModule} from "../accreditation-requests/accreditation-request.module"; @NgModule({ imports: [ SharedModule, - HomeRoutingModule + HomeRoutingModule, + AccreditationRequestModule, ], declarations: [ HomeComponent diff --git a/src/app/manage-environments/modal-environment/modal-environment.component.ts b/src/app/manage-environments/modal-environment/modal-environment.component.ts index 1a3c3cca8..9cfb441a6 100644 --- a/src/app/manage-environments/modal-environment/modal-environment.component.ts +++ b/src/app/manage-environments/modal-environment/modal-environment.component.ts @@ -40,7 +40,7 @@ export class ModalEnvironmentComponent implements OnInit { this.action = `Modifier`; } - this.normesService.getAll(new Pageable(0,1000)).subscribe( + this.normesService.getAllName(new Pageable(0,1000)).subscribe( normes => { this.normes = normes.content; if (this.isUpdate) {