From 717c3e61e1c22e1385cf3ad3969e9a26048d58d5 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Thu, 23 Jan 2020 18:38:26 +0100 Subject: [PATCH] FEAT #12073 TIME 1:30 add priv history + switch mode full / actions --- .../app/history/history.component.html | 4 +- src/frontend/app/history/history.component.ts | 47 ++++++++++++++++--- .../app/process/process.component.html | 2 +- .../app/process/process.component.scss | 9 +++- src/frontend/app/process/process.component.ts | 12 +++++ 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/frontend/app/history/history.component.html b/src/frontend/app/history/history.component.html index 8d1daff3c81..711fdcef1d6 100644 --- a/src/frontend/app/history/history.component.html +++ b/src/frontend/app/history/history.component.html @@ -28,8 +28,8 @@ </mat-autocomplete> </mat-form-field> </div> - <button color="primary" mat-icon-button title="Afficher tout l'historique"> - <mat-icon class="fas fa-history"></mat-icon> + <button *ngIf="privilegeService.hasCurrentUserPrivilege('view_full_history') && privilegeService.hasCurrentUserPrivilege('view_doc_history')" color="primary" mat-icon-button [title]="!fullHistoryMode ? 'Afficher tout l\'historique' : 'Afficher l\'historique des actions'" (click)="switchHistoryMode()"> + <mat-icon class="fas" [class.fa-exchange-alt]="fullHistoryMode" [class.fa-history]="!fullHistoryMode"></mat-icon> </button> <div class="table-head-tool"> <mat-paginator #paginatorHistoryList [length]="resultsLength" [hidePageSize]="true" [pageSize]="10" diff --git a/src/frontend/app/history/history.component.ts b/src/frontend/app/history/history.component.ts index de89a606fca..fccf8fdee7e 100644 --- a/src/frontend/app/history/history.component.ts +++ b/src/frontend/app/history/history.component.ts @@ -9,6 +9,7 @@ import { takeUntil, startWith, switchMap, map, catchError, filter, exhaustMap, t import { FormControl } from '@angular/forms'; import { FunctionsService } from '../../service/functions.service'; import { LatinisePipe } from 'ngx-pipes'; +import { PrivilegeService } from '../../service/privileges.service'; @Component({ selector: 'app-history-list', @@ -20,6 +21,8 @@ export class HistoryComponent implements OnInit { lang: any = LANG; loading: boolean = false; + fullHistoryMode : boolean = true; + filtersChange = new EventEmitter(); data: any; @@ -28,6 +31,8 @@ export class HistoryComponent implements OnInit { isLoadingResults = true; routeUrl: string = '../../rest/history'; + filterListUrl: string = '../../rest/history/availableFilters'; + extraParamUrl: string = ''; resultListDatabase: HistoryListHttpDao | null; resultsLength = 0; @@ -63,20 +68,46 @@ export class HistoryComponent implements OnInit { private headerService: HeaderService, public dialog: MatDialog, public functions: FunctionsService, - private latinisePipe: LatinisePipe) { } + private latinisePipe: LatinisePipe, + public privilegeService: PrivilegeService) { } ngOnInit(): void { if (this.resId !== null) { - this.routeUrl = '../../rest/history'; this.displayedColumnsHistory = ['event_date', 'info']; + this.fullHistoryMode = !this.privilegeService.hasCurrentUserPrivilege('view_doc_history') } else { - this.routeUrl = '../../rest/history'; this.displayedColumnsHistory = ['event_date', 'userLabel', 'info', 'remote_ip']; } this.loading = true; + this.initHistoryMode(); this.initHistoryList(); } + switchHistoryMode() { + this.fullHistoryMode = !this.fullHistoryMode; + this.initHistoryMode(); + this.refreshDao(); + } + + resetFilter() { + this.loadingFilters = true; + this.filterList = null; + this.filterUsed = {}; + this.filterUrl = ''; + } + + initHistoryMode() { + this.resetFilter(); + + if (this.fullHistoryMode) { + this.extraParamUrl = this.resId !== null ? `&resId=${this.resId}` : ''; + this.filterListUrl = this.resId !== null ? `../../rest/history/availableFilters?resId=${this.resId}` : '../../rest/history/availableFilters'; + } else { + this.extraParamUrl = this.resId !== null ? `&resId=${this.resId}&onlyActions=true` : '&onlyActions=true'; + this.filterListUrl = this.resId !== null ? `../../rest/history/availableFilters?resId=${this.resId}&onlyActions=true` : '../../rest/history/availableFilters?onlyActions=true'; + } + } + initHistoryList() { this.resultListDatabase = new HistoryListHttpDao(this.http); this.paginator.pageIndex = 0; @@ -92,7 +123,7 @@ export class HistoryComponent implements OnInit { switchMap(() => { this.isLoadingResults = true; return this.resultListDatabase!.getRepoIssues( - this.sort.active, this.sort.direction, this.paginator.pageIndex, this.routeUrl, this.filterUrl); + this.sort.active, this.sort.direction, this.paginator.pageIndex, this.routeUrl, this.filterUrl, this.extraParamUrl); }), map(data => { this.isLoadingResults = false; @@ -129,8 +160,10 @@ export class HistoryComponent implements OnInit { if (this.filterList === null) { this.filterList = {}; + this.filterUsed = {}; + this.filterUrl = ''; this.loadingFilters = true; - this.http.get("../../rest/history/availableFilters").pipe( + this.http.get(this.filterListUrl).pipe( map((data: any) => { let deletedActions = data.actions.filter((action: any) => action.label === null).map((action: any) => action.id); let deletedUser = data.users.filter((user: any) => user.label === null).map((user: any) => user.login); @@ -269,10 +302,10 @@ export class HistoryListHttpDao { constructor(private http: HttpClient) { } - getRepoIssues(sort: string, order: string, page: number, href: string, search: string): Observable<HistoryList> { + getRepoIssues(sort: string, order: string, page: number, href: string, search: string, extraParamUrl: string): Observable<HistoryList> { let offset = page * 10; - const requestUrl = `${href}?limit=10&offset=${offset}&order=${order}&orderBy=${sort}${search}`; + const requestUrl = `${href}?limit=10&offset=${offset}&order=${order}&orderBy=${sort}${search}${extraParamUrl}`; return this.http.get<HistoryList>(requestUrl); } diff --git a/src/frontend/app/process/process.component.html b/src/frontend/app/process/process.component.html index 5f699b61544..a0ea7c176e8 100644 --- a/src/frontend/app/process/process.component.html +++ b/src/frontend/app/process/process.component.html @@ -9,7 +9,7 @@ <div class="processTool"> <div class="processTool-module jiggle" *ngFor="let module of processTool" [class.processTool-module-active]="module.id === currentTool" matRipple - (click)="changeTab(module.id)"> + (click)="isToolEnabled(module.id) ? changeTab(module.id) : false" [class.tool-disabled]="!isToolEnabled(module.id)"> <i *ngIf="module.count > 0" class="fas fa-circle haveContent"></i> <i [class]="module.icon"></i> <span>{{module.label}}</span> diff --git a/src/frontend/app/process/process.component.scss b/src/frontend/app/process/process.component.scss index e30a811f455..f4b76d41836 100644 --- a/src/frontend/app/process/process.component.scss +++ b/src/frontend/app/process/process.component.scss @@ -287,7 +287,7 @@ color: $primary; } - &:hover { + &:hover:not(.tool-disabled) { transition: all 0.3s; color: $primary; } @@ -313,7 +313,7 @@ } } -.jiggle:active { +.jiggle:active:not(.tool-disabled) { i { -webkit-animation: jiggle 0.2s; -moz-animation-duration: 0.2s; @@ -414,3 +414,8 @@ .followIcon { color: $secondary; } + +.tool-disabled { + cursor: not-allowed; + opacity: 0.3; +} \ No newline at end of file diff --git a/src/frontend/app/process/process.component.ts b/src/frontend/app/process/process.component.ts index 5ef4c40a469..ae92d4baa6d 100755 --- a/src/frontend/app/process/process.component.ts +++ b/src/frontend/app/process/process.component.ts @@ -583,4 +583,16 @@ export class ProcessComponent implements OnInit { ).subscribe(); } } + + isToolEnabled(id: string) { + if (id === 'history') { + if (!this.privilegeService.hasCurrentUserPrivilege('view_full_history') && !this.privilegeService.hasCurrentUserPrivilege('view_doc_history')) { + return false + } else { + return true; + } + } else { + return true; + } + } } -- GitLab