From 59158ac778c6e06ae953081a39175e24a5a5c75c Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Wed, 19 Feb 2020 15:57:06 +0100 Subject: [PATCH] FEAT #13243 TIME 1:30 share folder to all entities --- .../folder-document-list.component.ts | 16 +++- .../folder-update.component.html | 2 +- .../folder-update/folder-update.component.ts | 77 +++++++++++++++---- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/src/frontend/app/folder/document-list/folder-document-list.component.ts b/src/frontend/app/folder/document-list/folder-document-list.component.ts index e7c7a87bd1e..8c542fb357c 100644 --- a/src/frontend/app/folder/document-list/folder-document-list.component.ts +++ b/src/frontend/app/folder/document-list/folder-document-list.component.ts @@ -23,6 +23,7 @@ import { FolderActionListComponent } from '../folder-action-list/folder-action-l import { FiltersListService } from '../../../service/filtersList.service'; import { trigger, transition, style, animate } from '@angular/animations'; import { FoldersService } from '../folders.service'; +import { FunctionsService } from '../../../service/functions.service'; declare function $j(selector: any): any; @@ -118,7 +119,8 @@ export class FolderDocumentListComponent implements OnInit { public overlay: Overlay, public viewContainerRef: ViewContainerRef, public appService: AppService, - private foldersService: FoldersService) { + private foldersService: FoldersService, + public functions: FunctionsService) { $j("link[href='merged_css.php']").remove(); @@ -146,12 +148,22 @@ export class FolderDocumentListComponent implements OnInit { this.http.get('../../rest/folders/' + params['folderId']) .subscribe((data: any) => { + let keywordEntities = [{ + keyword: 'ALL_ENTITIES', + text: this.lang.allEntities, + }]; this.folderInfo = { 'id': params['folderId'], 'label': data.folder.label, 'ownerDisplayName': data.folder.ownerDisplayName, - 'entitiesSharing': data.folder.sharing.entities.map((entity: any) => entity.label), + 'entitiesSharing': data.folder.sharing.entities.map((entity: any) => { + if (!this.functions.empty(entity.label)) { + return entity.label; + } else { + return keywordEntities.filter((element: any) => element.keyword == entity.keyword)[0].text + } + }), }; this.foldersService.setFolder(this.folderInfo); this.headerService.setHeader(this.folderInfo.label, '', 'fa fa-folder-open'); diff --git a/src/frontend/app/folder/folder-update/folder-update.component.html b/src/frontend/app/folder/folder-update/folder-update.component.html index b093d6c7618..6e8208c394e 100644 --- a/src/frontend/app/folder/folder-update/folder-update.component.html +++ b/src/frontend/app/folder/folder-update/folder-update.component.html @@ -27,7 +27,7 @@ <div class="formType-title"> {{lang.parameters}} </div> - <ng-container *ngFor="let entity of entities | sortBy : 'entity_label'"> + <ng-container *ngFor="let entity of entities"> <mat-expansion-panel class="selectedEntities" *ngIf="checkSelectedFolder(entity)" opened> <mat-expansion-panel-header> diff --git a/src/frontend/app/folder/folder-update/folder-update.component.ts b/src/frontend/app/folder/folder-update/folder-update.component.ts index 483618b064f..94faf9949dd 100644 --- a/src/frontend/app/folder/folder-update/folder-update.component.ts +++ b/src/frontend/app/folder/folder-update/folder-update.component.ts @@ -5,6 +5,7 @@ import { map, tap, catchError, exhaustMap, finalize } from 'rxjs/operators'; import { of } from 'rxjs'; import { NotificationService } from '../../notification.service'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { FunctionsService } from '../../../service/functions.service'; declare function $j(selector: any): any; @@ -37,6 +38,7 @@ export class FolderUpdateComponent implements OnInit { public http: HttpClient, private notify: NotificationService, public dialogRef: MatDialogRef<FolderUpdateComponent>, + public functions: FunctionsService, @Inject(MAT_DIALOG_DATA) public data: any ) { } @@ -49,9 +51,24 @@ export class FolderUpdateComponent implements OnInit { tap((data: any) => this.folder = data.folder), exhaustMap(() => this.http.get('../../rest/entities')), map((data: any) => { + let keywordEntities = { + serialId: 'ALL_ENTITIES', + keyword: 'ALL_ENTITIES', + parent: '#', + icon: 'fa fa-hashtag', + allowed: true, + text: this.lang.allEntities, + state: { "opened": false, "selected": false }, + parent_entity_id: '', + id: 'ALL_ENTITIES', + entity_label: this.lang.allEntities + }; + data.entities.unshift(keywordEntities); + this.entities = data.entities; data.entities.forEach((element: any) => { - if (this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(element.serialId) > -1) { + if (this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(element.serialId) > -1 + || this.folder.sharing.entities.map((data: any) => data.keyword).indexOf(element.serialId) > -1) { element.state.selected = true; } element.state.allowed = true; @@ -172,18 +189,33 @@ export class FolderUpdateComponent implements OnInit { } selectEntity(newEntity: any) { - this.folder.sharing.entities.push( - { - entity_id: newEntity.serialId, - edition: false - } - ); + if (!this.functions.empty(newEntity.keyword)) { + this.folder.sharing.entities.push( + { + keyword: newEntity.keyword, + edition: false + } + ); + } else { + this.folder.sharing.entities.push( + { + entity_id: newEntity.serialId, + edition: false + } + ); + } } deselectEntity(entity: any) { - let index = this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId); - this.folder.sharing.entities.splice(index, 1); + if (index > -1) { + this.folder.sharing.entities.splice(index, 1); + } else { + index = this.folder.sharing.entities.map((data: any) => data.keyword).indexOf(entity.serialId) + if (index > -1) { + this.folder.sharing.entities.splice(index, 1); + } + } } onSubmit(): void { @@ -207,7 +239,8 @@ export class FolderUpdateComponent implements OnInit { } checkSelectedFolder(entity: any) { - if (this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId) > -1) { + if (this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId) > -1 + || this.folder.sharing.entities.map((data: any) => data.keyword).indexOf(entity.serialId) > -1) { return true; } else { return false; @@ -221,12 +254,28 @@ export class FolderUpdateComponent implements OnInit { } toggleAdmin(entity: any, ev: any) { - const index = this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId); - this.folder.sharing.entities[index].edition = ev.checked; + let index = this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId); + if (index > -1) { + this.folder.sharing.entities[index].edition = ev.checked; + } else { + index = this.folder.sharing.entities.map((data: any) => data.keyword).indexOf(entity.serialId) + if (index > -1) { + this.folder.sharing.entities[index].edition = ev.checked; + } + } } isAdminEnabled(entity: any) { - const index = this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId); - return this.folder.sharing.entities[index].edition; + let index = this.folder.sharing.entities.map((data: any) => data.entity_id).indexOf(entity.serialId); + if (index > -1) { + return this.folder.sharing.entities[index].edition; + } else { + index = this.folder.sharing.entities.map((data: any) => data.keyword).indexOf(entity.serialId) + if (index > -1) { + return this.folder.sharing.entities[index].edition; + } + } + + return false; } } -- GitLab