From 55e9f4c75e759e03a3ce8d2db29776502e73ba68 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Fri, 15 Mar 2019 14:13:43 +0100 Subject: [PATCH] FEAT #9695 add users/entities in diff list --- .../redirect-action.component.ts | 32 +++++++---------- .../diffusions/diffusions-list.component.html | 19 ++++++++-- .../diffusions/diffusions-list.component.ts | 35 +++++++++++++++++-- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/frontend/app/actions/redirect-action/redirect-action.component.ts b/src/frontend/app/actions/redirect-action/redirect-action.component.ts index 69f41160b87..827008ef07f 100644 --- a/src/frontend/app/actions/redirect-action/redirect-action.component.ts +++ b/src/frontend/app/actions/redirect-action/redirect-action.component.ts @@ -47,11 +47,12 @@ export class RedirectActionComponent implements OnInit { ngOnInit(): void { let noEntity = true; this.loading = true; - this.http.get("../../rest/resourcesList/users/" + this.data.currentBasketInfo.ownerId + "/groups/" + this.data.currentBasketInfo.groupId + "/baskets/" + this.data.currentBasketInfo.basketId + "/actions/" + this.data.action.id + "/getRedirect/entity") + this.http.get("../../rest/resourcesList/users/" + this.data.currentBasketInfo.ownerId + "/groups/" + this.data.currentBasketInfo.groupId + "/baskets/" + this.data.currentBasketInfo.basketId + "/actions/" + this.data.action.id + "/getRedirect") .subscribe((data: any) => { console.log(data); - this.injectDatasParam.keepDestForRedirection = data.keepDestForRedirection; this.entities = data['entities']; + this.userListRedirect = data.users; + this.keepDestForRedirection = data.keepDestForRedirection; this.entities.forEach(entity => { if (entity.state.selected) { @@ -62,23 +63,16 @@ export class RedirectActionComponent implements OnInit { } }); - this.http.get("../../rest/resourcesList/users/" + this.data.currentBasketInfo.ownerId + "/groups/" + this.data.currentBasketInfo.groupId + "/baskets/" + this.data.currentBasketInfo.basketId + "/actions/" + this.data.action.id + "/getRedirect/users") - .subscribe((data: any) => { - this.userListRedirect = data.users; - this.keepDestForRedirection = data.keepDestForRedirection; - if (this.userListRedirect.length == 0 && noEntity) { - this.redirectMode = 'none'; - this.loading = false; - } else if (this.userListRedirect.length == 0 && !noEntity) { - this.loadEntities(); - } else if (this.userListRedirect.length > 0 && noEntity) { - this.loadDestUser(); - } else { - this.loading = false; - } - }, () => { - location.href = "index.php"; - }); + if (this.userListRedirect.length == 0 && noEntity) { + this.redirectMode = 'none'; + this.loading = false; + } else if (this.userListRedirect.length == 0 && !noEntity) { + this.loadEntities(); + } else if (this.userListRedirect.length > 0 && noEntity) { + this.loadDestUser(); + } else { + this.loading = false; + } }, () => { location.href = "index.php"; diff --git a/src/frontend/app/diffusions/diffusions-list.component.html b/src/frontend/app/diffusions/diffusions-list.component.html index 45653e1a7f6..f0e68751be2 100644 --- a/src/frontend/app/diffusions/diffusions-list.component.html +++ b/src/frontend/app/diffusions/diffusions-list.component.html @@ -7,7 +7,21 @@ AUCUNE LISTE DE DIFFUSION </div> <mat-form-field *ngIf="injectDatas.editable" appearance="outline" floatLabel="never" [style.fontSize.px]="10"> - <input class="metaSearch" type="text" matInput placeholder="Ajouter une personne / une entité"> + <input class="userDiffList" #autocompleteFilter type="text" placeholder="{{lang.addUserOrEntity}}" matInput [matAutocomplete]="auto" + [formControl]="elementCtrl"> + <mat-autocomplete #auto="matAutocomplete"> + <mat-option *ngFor="let elem of filteredElements | async" [value]="elem.id" (click)="addElem(elem)"> + <p mat-line style="margin:0;"> + <span class="col-xm-1" style="padding-right:5px;"> + <mat-icon color="primary" [class]="elem.type == 'entity' ? 'fa fa-sitemap fa-2x' : 'fa fa-user fa-2x'" style="margin-right:0px;"></mat-icon> + </span> + <span class="col-xm-11"> + {{ elem.idToDisplay }} + <small>{{ elem.otherInfo }}</small> + </span> + </p> + </mat-option> + </mat-autocomplete> </mat-form-field> <div cdkDropListGroup class="roleList"> <ng-container *ngFor="let role of availableRoles"> @@ -20,8 +34,7 @@ </div> <mat-list-item *ngFor="let diffusion of diffList[role.id].items;let i=index" cdkDrag cdkDragBoundary=".roleList" class="columns" [cdkDragDisabled]="diffusion.item_type == 'entity_id' || !injectDatas.editable" [class.notDraggable]="(diffusion.item_type == 'entity_id' || role.id == 'dest') && injectDatas.editable" [class.notEditable]="!injectDatas.editable"> - <mat-icon *ngIf="diffusion.item_type == 'user_id'" mat-list-icon class="fa fa-2x" [ngClass]="[diffusion.item_mode == 'cc' ? 'fa-users' : 'fa-user']" - color="primary"></mat-icon> + <mat-icon *ngIf="diffusion.item_type == 'user_id'" mat-list-icon class="fa fa-user fa-2x" color="primary"></mat-icon> <h4 mat-line *ngIf="diffusion.item_type == 'user_id'">{{diffusion.labelToDisplay}}</h4> <p mat-line *ngIf="diffusion.item_type == 'user_id'" style="opacity:0.5;"> {{diffusion.descriptionToDisplay}} </p> diff --git a/src/frontend/app/diffusions/diffusions-list.component.ts b/src/frontend/app/diffusions/diffusions-list.component.ts index 5d3741b98d8..468cf467b8b 100644 --- a/src/frontend/app/diffusions/diffusions-list.component.ts +++ b/src/frontend/app/diffusions/diffusions-list.component.ts @@ -3,6 +3,9 @@ import { HttpClient } from '@angular/common/http'; import { LANG } from '../translate.component'; import { NotificationService } from '../notification.service'; import { CdkDragDrop, moveItemInArray, transferArrayItem, CdkDrag } from '@angular/cdk/drag-drop'; +import { AutoCompletePlugin } from '../../plugins/autocomplete.plugin'; + +declare function $j(selector: any): any; @Component({ selector: 'app-diffusions-list', @@ -10,7 +13,7 @@ import { CdkDragDrop, moveItemInArray, transferArrayItem, CdkDrag } from '@angul styleUrls: ['diffusions-list.component.scss'], providers: [NotificationService] }) -export class DiffusionsListComponent implements OnInit { +export class DiffusionsListComponent extends AutoCompletePlugin implements OnInit { lang: any = LANG; listinstance: any = []; @@ -23,7 +26,9 @@ export class DiffusionsListComponent implements OnInit { @Input('injectDatas') injectDatas: any; - constructor(public http: HttpClient, private notify: NotificationService) { } + constructor(public http: HttpClient, private notify: NotificationService) { + super(http, ['usersAndEntities']); + } ngOnInit(): void { this.http.get("../../rest/listTemplates/types/entity_id/roles") @@ -149,4 +154,30 @@ export class DiffusionsListComponent implements OnInit { return false; } } + + addElem(element: any) { + + if (this.diffList["copy"].items.map((e: any) => { return e.item_id; }).indexOf(element.id) == -1) { + let itemType = ''; + if (element.type == 'user') { + itemType = 'user_id'; + } else { + itemType = 'entity_id'; + } + + const newElemListModel = { + difflist_type: "entity_id", + item_type: itemType, + item_id: element.id, + labelToDisplay: element.idToDisplay, + descriptionToDisplay: element.otherInfo, + item_mode: "copy" + }; + this.diffList['copy'].items.unshift(newElemListModel); + } + + $j('.userDiffList').val(''); + $j('.userDiffList').blur(); + + } } \ No newline at end of file -- GitLab