diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/event-filter.interface.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/event-filter.interface.ts index 7cabb0f188187d0f45a3a01902c6ec127f883bd9..bbb95ddca15107362c733725ae07bb6d85748525 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/event-filter.interface.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/event-filter.interface.ts @@ -35,7 +35,7 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ export interface EventFilter { - type?: 'INGEST' | 'ELIMINATION' | 'MASTERDATA'; + type?: Array<string>; status?: 'RUNNING' | 'ERROR' | 'DONE'; dateRange?: { startDate: Date, endDate: Date }; } diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-constants.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-constants.ts new file mode 100644 index 0000000000000000000000000000000000000000..79f8884e2b136bf0ea8affa2a8cc2f20da53a1ad --- /dev/null +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-constants.ts @@ -0,0 +1,20 @@ +import {Option} from 'ui-frontend-common'; + +export const LOGBOOK_OPERATION_CATEGORIES: Option[] = [ + {key: 'AUDIT', label: 'Audit', info: ''}, + {key: 'MASTERDATA', label: 'Données de base', info: ''}, + {key: 'ELIMINATION', label: 'Élimination', info: ''}, + {key: 'INGEST', label: 'Entrée', info: ''}, + {key: 'EXPORT_DIP', label: 'Export DIP', info: ''}, + {key: 'UPDATE', label: 'Mise à jour', info: ''}, + {key: 'PRESERVATION', label: 'Préservation', info: ''}, + {key: 'RECLASSIFICATION', label: 'Réorganisation', info: ''}, + {key: 'STORAGE_BACKUP', label: 'Sauvegarde d\'écriture', info: ''}, + {key: 'TRACEABILITY', label: 'Sécurisation', info: ''}, + {key: 'CHECK', label: 'Vérification', info: ''}, + {key: 'EXTERNAL_LOGBOOK', label: 'Journalisation externe', info: ''} +]; + +export const NULL_TYPE: Option[] = [ + {key: null, label: 'Tous', info: ''} +]; diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.html b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.html index 7e244dad4816a91a35ae08d5dd34e1ddfb359bb0..c2294640629a98b8674b1f5b5da1363bfd0d97bb 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.html +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.html @@ -11,6 +11,28 @@ </div> </th> + <th> + <div class="vitamui-table-header"> + + <button class="vitamui-filter-button" [vitamuiCommonTableFilter]="operationCategoriesFilterTemplate" + [class.active]="filterMap['operationCategories'] && filterMap['operationCategories'].length > 0"> + <i class="material-icons vitamui-row-icon">filter_list</i> + </button> + + <ng-template #operationCategoriesFilterTemplate> + <vitamui-common-table-filter-search + [(filter)]="filterMap['operationCategories']" + [options]="operationCategoriesFilterOptions" + (filterChange)="onFilterChange('operationCategories', $event)" + (filterClose)="operationCategoriesFilterTrigger?.close()" + i18n-emptyValueOption="@@userListLevelFilterEmpty" + ></vitamui-common-table-filter-search> + </ng-template> + + <span i18n="@@logbookOperationListOperationHeader">Catégorie d'opération</span> + </div> + </th> + <th> <div class="vitamui-table-header"> <span i18n="@@logbookOperationListOperationHeader">Opération</span> @@ -19,13 +41,13 @@ <th> <div class="vitamui-table-header"> - <span i18n="@@logbookOperationListStartDateHeader">Date de création</span> + <span i18n="@@logbookOperationListStartDateHeader">Date de début</span> </div> </th> <th> <div class="vitamui-table-header"> - <span i18n="@@logbookOperationListEndDateHeader">Fin d'exécution</span> + <span i18n="@@logbookOperationListEndDateHeader">Date de fin</span> </div> </th> @@ -37,7 +59,7 @@ <th> <div class="vitamui-table-header"> - <span i18n="@@logbookOperationListStepHeader">Etape</span> + <span i18n="@@logbookOperationListStepHeader">Étape</span> </div> </th> @@ -53,6 +75,7 @@ </div> </td> <td><div class="vitamui-cell-content break-content" [title]="event.id">{{ event.id }}</div></td> + <td><div class="vitamui-cell-content" [ngClass]="event | eventTypeColorClass"><vitamui-common-event-type-label [key]="event.typeProc"></vitamui-common-event-type-label></div></td> <td><div class="vitamui-cell-content" [ngClass]="event | eventTypeColorClass"><vitamui-common-event-type-label [key]="event.type"></vitamui-common-event-type-label></div></td> <td> <div class="vitamui-cell-content">{{ event.dateTime | date:'dd/MM/yyyy' }}</div> diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.ts index 5f64ca2cf8b3241780e848b412c7093a816f8ef7..0048c47c3322ebe1416a8bae0ef46e64de59c5c2 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation-list/logbook-operation-list.component.ts @@ -34,54 +34,152 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import { DEFAULT_PAGE_SIZE, Direction, Event, InfiniteScrollTable, PageRequest } from 'ui-frontend-common'; +import {animate, state, style, transition, trigger} from '@angular/animations'; +import {DEFAULT_PAGE_SIZE, Direction, Event, InfiniteScrollTable, PageRequest} from 'ui-frontend-common'; import { - Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges + Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, TemplateRef, ViewChild } from '@angular/core'; -import { EventFilter } from '../event-filter.interface'; -import { LogbookSearchService } from '../logbook-search.service'; +import {merge, Subject} from 'rxjs'; +import {debounceTime} from 'rxjs/operators'; +import {EventFilter} from '../event-filter.interface'; +import {LOGBOOK_OPERATION_CATEGORIES} from '../logbook-operation-constants'; +import {LogbookSearchService} from '../logbook-search.service'; + +const FILTER_DEBOUNCE_TIME_MS = 400; @Component({ selector: 'app-logbook-operation-list', templateUrl: './logbook-operation-list.component.html', - styleUrls: ['./logbook-operation-list.component.scss'] + styleUrls: ['./logbook-operation-list.component.scss'], + animations: [ + trigger('expansion', [ + state('collapsed', style({height: '0px', visibility: 'hidden'})), + state('expanded', style({height: '*', visibility: 'visible'})), + transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4,0.0,0.2,1)')), + ]), + + trigger('arrow', [ + state('collapsed', style({transform: 'rotate(180deg)'})), + state('expanded', style({transform: 'none'})), + transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4,0.0,0.2,1)')), + ]), + ] }) export class LogbookOperationListComponent extends InfiniteScrollTable<Event> implements OnInit, OnChanges { @Input() tenantIdentifier: number; - @Input() filters: Readonly<EventFilter>; + + // tslint:disable-next-line:no-input-rename + @Input('search') + set searchText(searchText: string) { + this._searchText = searchText; + this.searchChange.next(searchText); + } + + // tslint:disable-next-line:no-input-rename + @Input('filters') + set searchFilters(searchFilters: Readonly<EventFilter>) { + this._searchFilters = searchFilters; + this.searchFiltersChange.next(searchFilters); + } + + // tslint:disable-next-line:variable-name + private _searchText: string; + // tslint:disable-next-line:variable-name + private _searchFilters: Readonly<EventFilter>; + + @ViewChild('filterTemplate', {static: false}) filterTemplate: TemplateRef<LogbookOperationListComponent>; + @ViewChild('filterButton', {static: false}) filterButton: ElementRef; @Output() eventClick = new EventEmitter<Event>(); orderBy = 'name'; direction = Direction.ASCENDANT; + private readonly searchFiltersChange = new Subject<Readonly<EventFilter>>(); + private readonly filterChange = new Subject<{[key: string]: any[]}>(); + private readonly searchChange = new Subject<string>(); + private readonly orderChange = new Subject<string>(); + + filterMap: {[key: string]: any[]} = { + operationCategories: null, + }; + operationCategoriesFilterOptions: Array<{value: string, label: string}> = []; + constructor(public logbookSearchService: LogbookSearchService) { super(logbookSearchService); } ngOnInit() { + this.pending = true; + const searchCriteriaChange = merge(this.searchChange, this.filterChange, this.orderChange, this.searchFiltersChange) + .pipe(debounceTime(FILTER_DEBOUNCE_TIME_MS)); + + searchCriteriaChange.subscribe(() => { + this.refreshList(); + }); + + this.refreshOperationCategoriesOptions(); this.refreshList(); } + buildCriteriaFromSearch() { + const criteria: any = {}; + if (this._searchText !== undefined && this._searchText.length > 0) { + criteria.evId = this._searchText; + } + + if (this._searchFilters && this._searchFilters.dateRange) { + if (this._searchFilters.dateRange.startDate) { + criteria.evDateTime_Start = this._searchFilters.dateRange.startDate; + } + if (this._searchFilters.dateRange.endDate) { + criteria.evDateTime_End = this._searchFilters.dateRange.endDate; + } + } + + if (this.filterMap && this.filterMap.operationCategories) { + criteria.types = this.filterMap.operationCategories; + } + + console.log('criteria.types'); + console.log(criteria.types); + + return criteria; + } + ngOnChanges(changes: SimpleChanges) { if (changes.tenantIdentifier || changes.filters) { this.refreshList(); } } + refreshOperationCategoriesOptions() { + this.operationCategoriesFilterOptions = LOGBOOK_OPERATION_CATEGORIES. + map((operationCategory) => ({value: operationCategory.key, label: operationCategory.label})); + } + refreshList() { const pageRequest = new PageRequest(0, DEFAULT_PAGE_SIZE, this.orderBy, this.direction); - const query = JSON.stringify(LogbookSearchService.buildVitamQuery(pageRequest, this.filters)); + const query = JSON.stringify(LogbookSearchService.buildVitamQuery(pageRequest, this.buildCriteriaFromSearch())); this.search(new PageRequest(0, DEFAULT_PAGE_SIZE, this.orderBy, this.direction, query)); } + onFilterChange(key: string, values: any[]) { + this.filterMap[key] = values; + this.filterChange.next(this.filterMap); + } + + resetFilters() { + this.filterMap.operationCategories = null; + this.filterChange.next(this.filterMap); + } + selectEvent(event: Event) { this.eventClick.emit(event); } - } diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.html b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.html index 3e335c9795d0492e002ee53ba81f83cb162429c5..ecb3f85d90cdc3c81b176aa60175c4be24c0da1d 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.html +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.html @@ -9,16 +9,19 @@ <div class="vitamui-header"> <div class="vitamui-container"> - <vitamui-common-navbar [appId]="appId" [hideTenantMenu]="false" [hideCustomerMenu]="true" (tenantSelect)="changeTenant($event)"></vitamui-common-navbar> + <vitamui-common-navbar [appId]="appId" [hideTenantMenu]="false" [hideCustomerMenu]="true" + (tenantSelect)="changeTenant($event)"></vitamui-common-navbar> <h2 i18n="@@apiSupervisionPageTitle"> <img src="assets/vitamui-logo-small.png"><strong>Journal des Opérations</strong> </h2> - - <div class="controls"> - <vitamui-common-search-bar name="logbook-operation-search" (search)="onSearchSubmit($event)" - placeholder="Nom, ID" i18n-placeholder="@@logbookOperationSearchPlaceholder"> - </vitamui-common-search-bar> + <div class="controls"> + <div class="search-bar-filters"> + <vitamui-common-search-bar name="logbook-operation-search" (search)="onSearchSubmit($event)" + placeholder="Nom, ID" i18n-placeholder="@@logbookOperationSearchPlaceholder"> + </vitamui-common-search-bar> + <div class="reset-filters" (click)="resetFilters()">Effacer les filtres et la recherche</div> + </div> <div class="actions"> <button class="btn secondary" (click)="refreshList()"> @@ -39,48 +42,36 @@ <form [formGroup]="dateRangeFilterForm" class="date-filter-container"> <div class="date-filter-container"> <div class="date-filter"> - <span *ngIf="!dateRangeFilterForm.get('startDate').value;else showStartDate" (click)="pickerStart.open()" - i18n="@@apiSupervisionStartDate">Date de début</span> + <span *ngIf="!dateRangeFilterForm.get('startDate').value;else showStartDate" + (click)="pickerStart.open()" i18n="@@apiSupervisionStartDate">Date de début</span> <ng-template #showStartDate> <span (click)="pickerStart.open()">{{ dateRangeFilterForm.get('startDate').value | date:'dd/MM/yyyy' }}</span> <i class="material-icons clear-date-icon clickable" (click)="clearDate('startDate')">clear</i> </ng-template> - <input class="hidden" size="0" [matDatepicker]="pickerStart" formControlName="startDate" [max]="dateRangeFilterForm.get('endDate').value"> + <input class="hidden" size="0" [matDatepicker]="pickerStart" formControlName="startDate" + [max]="dateRangeFilterForm.get('endDate').value"> <mat-datepicker #pickerStart></mat-datepicker> </div> <div class="date-filter"> <span *ngIf="!dateRangeFilterForm.get('endDate').value; else showEndDate" (click)="pickerEnd.open()" i18n="@@apiSupervisionEndDate">Date de fin</span> <ng-template #showEndDate><span (click)="pickerEnd.open()">{{ dateRangeFilterForm.get('endDate').value - | date:'dd/MM/yyyy' }} </span> <i class="material-icons clear-date-icon clickable" (click)="clearDate('endDate')">clear</i></ng-template> - <input class="hidden" size="0" [matDatepicker]="pickerEnd" formControlName="endDate" [min]="dateRangeFilterForm.get('startDate').value"> + | date:'dd/MM/yyyy' }} </span> <i class="material-icons clear-date-icon clickable" + (click)="clearDate('endDate')">clear</i></ng-template> + <input class="hidden" size="0" [matDatepicker]="pickerEnd" formControlName="endDate" + [min]="dateRangeFilterForm.get('startDate').value"> <mat-datepicker #pickerEnd></mat-datepicker> </div> </div> </form> </div> - - <div class="custom-flex-controls"> - - <button class="btn" (click)="toggleTypeFilter('INGEST')" [class.active]="filters?.type === 'INGEST'"> - <i class="vitamui-icon" i18n="@@apiSupervisionFilterIngest"></i> <span>Entrées</span> - </button> - - <button class="btn" (click)="toggleTypeFilter('ELIMINATION')" [class.active]="filters?.type === 'ELIMINATION'"> - <i class="vitamui-icon" i18n="@@apiSupervisionFilterElimination"></i> <span>Eliminations</span> - </button> - - <button class="btn" (click)="toggleTypeFilter('MASTERDATA')" [class.active]="filters?.type === 'MASTERDATA'"> - <i class="vitamui-icon" i18n="@@apiSupervisionFilterMasterData"></i> <span>Données de base</span> - </button> - </div> - </div> </div> <div class="vitamui-body vitamui-container"> - <app-logbook-operation-list [filters]="filters" [tenantIdentifier]="tenantIdentifier" (eventClick)="openPanel($event)"></app-logbook-operation-list> + <app-logbook-operation-list [filters]="filters" [tenantIdentifier]="tenantIdentifier" [search]="search" + (eventClick)="openPanel($event)"></app-logbook-operation-list> </div> </mat-sidenav-content> diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.scss b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.scss index 68b6d4f71d005b8a82e7cbe1549b94f7ffb2c672..3d73cd8c85c98005b19f1de9a380e57b85e248a1 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.scss +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.scss @@ -30,3 +30,19 @@ display: flex; justify-content: flex-end; } +.search-bar-filters { + width: 100%; + .reset-filters { + padding-right: calc(100% - 700px); + margin-top: 10px; + display: inline-block; + font-family: Roboto; + font-style: normal; + font-weight: normal; + font-size: 11px; + line-height: 13px; + text-decoration-line: underline; + cursor: pointer; + } + } + diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.ts index 5f32f266f5ca24b068dad4b7132edbc61e985382..51cfbbb44f8dbb8c6f2e85b625af70dc4092847b 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.component.ts @@ -34,12 +34,13 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import { GlobalEventService, SidenavPage } from 'ui-frontend-common'; +import { GlobalEventService, SearchBarComponent, SidenavPage } from 'ui-frontend-common'; import { Component, OnInit, ViewChild } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; +import {MatDialog} from '@angular/material/dialog'; import { EventFilter } from './event-filter.interface'; import { LogbookOperationListComponent } from './logbook-operation-list/logbook-operation-list.component'; @@ -50,15 +51,19 @@ import { LogbookOperationListComponent } from './logbook-operation-list/logbook- }) export class LogbookOperationComponent extends SidenavPage<any> implements OnInit { + search = ''; dateRangeFilterForm: FormGroup; tenantIdentifier: number; filters: Readonly<EventFilter> = {}; + + @ViewChild(SearchBarComponent, {static: true}) searchBar: SearchBarComponent; @ViewChild(LogbookOperationListComponent, { static: true }) list: LogbookOperationListComponent; constructor( private route: ActivatedRoute, private router: Router, + public dialog: MatDialog, private formBuilder: FormBuilder, globalEventService: GlobalEventService ) { @@ -90,6 +95,10 @@ export class LogbookOperationComponent extends SidenavPage<any> implements OnIni this.router.navigate(['..', tenantIdentifier], { relativeTo: this.route }); } + onSearchSubmit(search: string) { + this.search = search || ''; + } + clearDate(date: 'startDate' | 'endDate') { if (date === 'startDate') { this.dateRangeFilterForm.get(date).reset(null, { emitEvent: false }); @@ -108,20 +117,10 @@ export class LogbookOperationComponent extends SidenavPage<any> implements OnIni this.list.refreshList(); } - toggleTypeFilter(type: 'INGEST' | 'ELIMINATION' | 'MASTERDATA') { - this.filters = { - type: (!this.filters.type || this.filters.type !== type) ? type : null, - status: this.filters.status, - dateRange: this.filters.dateRange - }; + resetFilters() { + this.clearDate('startDate'); + this.clearDate('endDate'); + this.searchBar.reset(); + this.list.resetFilters(); } - - toggleStatusFilter(status: 'RUNNING' | 'ERROR' | 'DONE') { - this.filters = { - type: this.filters.type, - status: (!this.filters.status || this.filters.status !== status) ? status : null, - dateRange: this.filters.dateRange - }; - } - } diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.module.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.module.ts index 61972b29bff48b197a3be73d42b24b4cd72d806e..c4bf621fc28132314926d2e2d44ba8f18986ac0c 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.module.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-operation.module.ts @@ -34,17 +34,20 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import { VitamUICommonModule } from 'ui-frontend-common'; +import {TableFilterModule, VitamUICommonModule} from 'ui-frontend-common'; -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; -import { ReactiveFormsModule } from '@angular/forms'; +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {ReactiveFormsModule} from '@angular/forms'; +import {MatDialogModule} from '@angular/material/dialog'; import {MatNativeDateModule} from '@angular/material/core'; import {MatDatepickerModule} from '@angular/material/datepicker'; import {MatMenuModule} from '@angular/material/menu'; import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; import {MatSidenavModule} from '@angular/material/sidenav'; import {MatTabsModule} from '@angular/material/tabs'; +import {MatSnackBarModule} from '@angular/material/snack-bar'; +import {MatSelectModule} from '@angular/material/select'; import { LogbookOperationDetailComponent @@ -52,12 +55,12 @@ import { import { LogbookOperationPopupComponent } from './logbook-operation-detail/logbook-operation-popup.component'; -import { EventTypeBadgeClassPipe } from './logbook-operation-list/event-type-badge-class.pipe'; -import { EventTypeColorClassPipe } from './logbook-operation-list/event-type-color-class.pipe'; -import { LastEventPipe } from './logbook-operation-list/last-event.pipe'; -import { LogbookOperationListComponent } from './logbook-operation-list/logbook-operation-list.component'; -import { LogbookOperationRoutingModule } from './logbook-operation-routing.module'; -import { LogbookOperationComponent } from './logbook-operation.component'; +import {EventTypeBadgeClassPipe} from './logbook-operation-list/event-type-badge-class.pipe'; +import {EventTypeColorClassPipe} from './logbook-operation-list/event-type-color-class.pipe'; +import {LastEventPipe} from './logbook-operation-list/last-event.pipe'; +import {LogbookOperationListComponent} from './logbook-operation-list/logbook-operation-list.component'; +import {LogbookOperationRoutingModule} from './logbook-operation-routing.module'; +import {LogbookOperationComponent} from './logbook-operation.component'; @NgModule({ declarations: [ @@ -74,12 +77,16 @@ import { LogbookOperationComponent } from './logbook-operation.component'; MatSidenavModule, MatMenuModule, MatDatepickerModule, + MatDialogModule, MatProgressSpinnerModule, MatTabsModule, + MatSnackBarModule, ReactiveFormsModule, VitamUICommonModule, LogbookOperationRoutingModule, - MatNativeDateModule + MatNativeDateModule, + MatSelectModule, + TableFilterModule ] }) export class LogbookOperationModule { } diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-search.service.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-search.service.ts index 7d7cdb000268e370351731ef0112f89165c8ba97..71682bb0d469576b4496e25f0d2900f961cdc232 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-search.service.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-search.service.ts @@ -42,8 +42,6 @@ import { import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { EventFilter } from './event-filter.interface'; - @Injectable({ providedIn: 'root' }) @@ -53,7 +51,7 @@ export class LogbookSearchService extends SearchService<Event> { super(http, logbookApi); } - static buildVitamQuery(pageRequest: PageRequest, filters: EventFilter): VitamSelectQuery { + static buildVitamQuery(pageRequest: PageRequest, criteria: any): VitamSelectQuery { const baseParameters: Partial<VitamSelectQuery> = { $projection: {}, $filter: { @@ -63,14 +61,14 @@ export class LogbookSearchService extends SearchService<Event> { } }; - if (!filters) { + if (!criteria) { return { $query: {} as VitamSelectOperator, ...baseParameters }; } - const queryOperators = this.buildQueryOperators(filters); + const queryOperators = this.buildQueryOperators(criteria); if (queryOperators.length === 0) { return { @@ -82,30 +80,40 @@ export class LogbookSearchService extends SearchService<Event> { return { $query: { $and: [ - ...this.buildQueryOperators(filters), + ...this.buildQueryOperators(criteria), ] }, ...baseParameters }; } - private static buildQueryOperators(filters: EventFilter): VitamSelectOperator[] { + private static buildQueryOperators(criteria: any): VitamSelectOperator[] { const operators: VitamSelectOperator[] = []; - if (filters.type) { - operators.push({ $eq: { evTypeProc: filters.type } }); + // if (criteria.types) { + // criteria.types.forEach((type: string) => { + // operators.push({ $eq: { evTypeProc: type } }); + // }); + // } + + if (criteria.types && criteria.types.length > 0) { + operators.push({ $in: { evTypeProc: criteria.types } }); } - if (filters.status === 'ERROR') { + if (criteria.status === 'ERROR') { operators.push({ $in: { 'events.outcome': ['KO', 'FATAL'] } }); } - if (filters.dateRange && filters.dateRange.startDate) { - operators.push({ $gte: { evDateTime: filters.dateRange.startDate } }); + if (criteria.evDateTime_Start) { + operators.push({ $gte: { evDateTime: criteria.evDateTime_Start } }); + } + + if (criteria.evDateTime_End) { + operators.push({ $lte: { evDateTime: moment(criteria.evDateTime_End).endOf('day') } }); } - if (filters.dateRange && filters.dateRange.endDate) { - operators.push({ $lte: { evDateTime: moment(filters.dateRange.endDate).endOf('day') } }); + if (criteria.evId) { + operators.push({ $eq: { evId: criteria.evId } }); } return operators;