diff --git a/src/frontend/app/administration/group/group-administration.component.html b/src/frontend/app/administration/group/group-administration.component.html index 22446c46b8694d94c005b534560792174b371b0f..b587345ab5d11fd13c0a377fdb91a39d11d97be7 100755 --- a/src/frontend/app/administration/group/group-administration.component.html +++ b/src/frontend/app/administration/group/group-administration.component.html @@ -151,7 +151,7 @@ </mat-tab> <mat-tab label="Indexation" *ngIf="!creationMode"> <ng-template matTabContent> - <app-indexing-administration></app-indexing-administration> + <app-indexing-administration [groupId]="group.id"></app-indexing-administration> </ng-template> </mat-tab> </mat-tab-group> diff --git a/src/frontend/app/administration/group/indexing/indexing-administration.component.html b/src/frontend/app/administration/group/indexing/indexing-administration.component.html index 026ba38fbf9f18f2153b7485703f5ebb187d888a..ae1a19f23359000d7e01766bbab9e5e3bd5b6e0f 100644 --- a/src/frontend/app/administration/group/indexing/indexing-administration.component.html +++ b/src/frontend/app/administration/group/indexing/indexing-administration.component.html @@ -1,14 +1,23 @@ <div class="row" style="margin:0px;"> + <div class="col-md-12"> + <div *ngIf="!indexingInfo.canIndex" class="alert-message alert-message-danger" role="alert" + style="margin-top: 30px;">Le groupe ne peut pas enregistrer de document. <a + (click)="indexingInfo.canIndex=true">Activer l'indexation pour ce groupe</a></div> + <button *ngIf="indexingInfo.canIndex" color="warn" mat-raised-button (click)="indexingInfo.canIndex=false">Désactiver l'indexation pour ce groupe</button> + </div> <div class="col-md-8"> - <fieldset> - <legend>Action(s) choisie(s)</legend> + <div class="formType"> + <div class="formType-title"> + Action(s) choisie(s) + </div> <mat-form-field appearance="outline"> - <input type="text" placeholder="Associer une nouvelle action" aria-label="Number" matInput [formControl]="myControl" - [matAutocomplete]="auto" (focus)="myControl.setValue('')"> + <input id="addAction" type="text" placeholder="Associer une nouvelle action" aria-label="Number" + matInput [formControl]="myControl" [matAutocomplete]="auto" (focus)="myControl.setValue('')"> <mat-autocomplete #auto="matAutocomplete" (optionSelected)="addAction($event)"> <mat-optgroup *ngIf="actionList.length > 0" label="Action(s) disponible(s)"> - <mat-option *ngFor="let action of filteredActionList | async" [value]="action.id"> - {{action.label}} + <mat-option *ngFor="let action of filteredActionList | async | sortBy: 'label_action'" + [value]="action.id"> + {{action.label_action}} </mat-option> </mat-optgroup> <mat-option *ngIf="actionList.length === 0" disabled> @@ -16,16 +25,26 @@ </mat-option> </mat-autocomplete> </mat-form-field> - <mat-list role="list"> - <mat-list-item role="listitem" *ngFor="let action of indexingInfo.actions">{{action.label}} + <mat-list class="selectedActionList" role="list"> + <mat-list-item class="selectedAction" role="listitem" + *ngFor="let action of indexingInfo.actions;let i=index"> + <div class="actionLabel">{{action.label_action}}</div> + <div> + <button mat-icon-button color="warn" (click)="removeAction(i)"> + <mat-icon class="fa fa-trash"></mat-icon> + </button> + </div> + <mat-divider></mat-divider> </mat-list-item> </mat-list> - </fieldset> + </div> </div> <div class="col-md-4"> - <fieldset> - <legend>Service de destination autorisé</legend> - </fieldset> - <div id="jstree"></div> + <div class="formType"> + <div class="formType-title"> + Service de destination autorisé + </div> + <div #jstree id="jstree"></div> + </div> </div> </div> \ No newline at end of file diff --git a/src/frontend/app/administration/group/indexing/indexing-administration.component.scss b/src/frontend/app/administration/group/indexing/indexing-administration.component.scss index dc5d43f70a7d88430d38c3fe2516e0577f20b366..75b16112ed867f7a9a388aeef93c4f89dddb78f9 100644 --- a/src/frontend/app/administration/group/indexing/indexing-administration.component.scss +++ b/src/frontend/app/administration/group/indexing/indexing-administration.component.scss @@ -1 +1,51 @@ -/deep/.mat-form-field-appearance-outline .mat-form-field-outline-thick { color: #666; } \ No newline at end of file +/deep/.mat-form-field-appearance-outline .mat-form-field-outline-thick { + color: #666; +} + +.selectedActionList { + width: 100%; +} + +.selectedAction { + + height: 70px; + + .actionLabel { + flex: 1; + } +} + +.formType { + display: flex; + flex-direction: column; + margin: 10px; + border-radius: 4px; + border: solid 1px #ccc; + position: relative; + padding: 10px; + + &-title { + white-space: pre; + overflow: hidden; + max-width: 85%; + text-overflow: ellipsis; + z-index: 1; + font-size: 10px; + font-weight: bold; + background: white; + position: absolute; + top: -7px; + left: 10px; + padding: 0px; + margin: 0px; + color: #135f7f; + } +} + +.alert-message { + max-width: 100%; +} + +a { + cursor: pointer; +} \ No newline at end of file diff --git a/src/frontend/app/administration/group/indexing/indexing-administration.component.ts b/src/frontend/app/administration/group/indexing/indexing-administration.component.ts index b7169495a27d0e935ba4f1f6d695fdc6e4252623..468344640b631d855372ae648a520670eac9ded7 100644 --- a/src/frontend/app/administration/group/indexing/indexing-administration.component.ts +++ b/src/frontend/app/administration/group/indexing/indexing-administration.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Input } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { ActivatedRoute, Router } from '@angular/router'; import { LANG } from '../../../translate.component'; @@ -8,6 +8,7 @@ import { exhaustMap, startWith, map } from 'rxjs/operators'; import { FormControl } from '@angular/forms'; import { Observable } from 'rxjs'; import { MatAutocompleteSelectedEvent } from '@angular/material'; +import { LatinisePipe } from 'ngx-pipes'; declare function $j(selector: any): any; @@ -21,22 +22,27 @@ export class IndexingAdministrationComponent implements OnInit { mobileQuery: MediaQueryList; - coreUrl: string; lang: any = LANG; loading: boolean = false; + @Input('groupId') groupId: number; + keywordEntities: any[] = []; actionList: any[] = []; myControl = new FormControl(); indexingInfo: any = { - actions: [] + canIndex: false, + actions: [], + keywords: [], + entities: [] }; filteredActionList: Observable<any[]>; constructor(public http: HttpClient, private notify: NotificationService, + private latinisePipe: LatinisePipe ) { this.keywordEntities = [{ @@ -105,16 +111,19 @@ export class IndexingAdministrationComponent implements OnInit { map(value => this._filter(value)) ); - this.getActions().pipe( - exhaustMap(() => this.getSelectedActionsId()), - tap((data: any) => this.setSelectedActions(data)), - exhaustMap(() => this.getEntities()), + this.getIndexingInformations().pipe( + tap((data: any) => this.indexingInfo.canIndex = data.group.canIndex), + tap((data: any) => this.getActions(data.actions)), + tap((data: any) => this.getSelectedActions(data.group.indexationParameters.actions)), + map((data: any) => this.getEntities(data)), + map((data: any) => this.getSelectedEntities(data)), tap((data: any) => this.initEntitiesTree(data)) ).subscribe(); } initEntitiesTree(entities: any) { + $j('#jstree').jstree({ "checkbox": { "three_state": false //no cascade selection @@ -128,55 +137,56 @@ export class IndexingAdministrationComponent implements OnInit { }, "plugins": ["checkbox", "search"] }); - } - getEntities() { - return this.http.get('../../rest/entities').pipe( - map((data: any) => { - data.entities = this.keywordEntities.concat(data.entities); - data.entities.forEach((entity: any) => { - entity.state = { "opened": true, "selected": false }; - }); - return data.entities; + $j('#jstree') + // listen for event + .on('select_node.jstree', (e: any, data: any) => { + if (isNaN(data.node.id)) { + this.addKeyword(data.node.id); + } else { + this.addEntity(data.node.id); + } + + }).on('deselect_node.jstree', (e: any, data: any) => { + if (isNaN(data.node.id)) { + this.removeKeyword(data.node.id); + } else { + this.removeEntity(data.node.id); + } }) - ) + // create the instance + .jstree(); } - getActions() { - return this.http.get('../../rest/entities').pipe( - tap((data: any) => { - // FOR TEST - this.actionList = [ - { - id: 1, - label: 'toto' - }, - { - id: 2, - label: 'tata' - }, - { - id: 9, - label: 'titi' - } - ]; - }) - ); + getEntities(data: any) { + data.entities = this.keywordEntities.concat(data.entities); + return data; } - getSelectedActionsId() { - return this.http.get('../../rest/entities').pipe( - map((data: any) => { - // FOR TEST - data = [1, 2]; - return data; - }) - ) + getSelectedEntities(data: any) { + this.indexingInfo.entities = [...data.group.indexationParameters.entities]; + data.entities.forEach((entity: any) => { + if (this.indexingInfo.entities.indexOf(entity.id) > -1 ) { + entity.state = { "opened": true, "selected": true }; + } else { + entity.state = { "opened": true, "selected": false }; + } + + }); + return data.entities; } - setSelectedActions(actionsId: number[]) { + getActions(data: any) { + this.actionList = data; + } + + getIndexingInformations() { + return this.http.get('../../rest/groups/' + this.groupId + '/indexing'); + } + + getSelectedActions(data: any) { let index = -1; - actionsId.forEach((actionId: any) => { + data.forEach((actionId: any) => { index = this.actionList.findIndex(action => action.id === actionId); if (index > -1) { this.indexingInfo.actions.push(this.actionList[index]); @@ -185,16 +195,46 @@ export class IndexingAdministrationComponent implements OnInit { }); } + addEntity(entityId: number) { + this.indexingInfo.entities.push(entityId); + console.log(this.indexingInfo.entities); + } + + removeEntity(entityId: number) { + const index = this.indexingInfo.entities.indexOf(entityId); + this.indexingInfo.entities.splice(index, 1); + console.log(this.indexingInfo.entities); + } + + addKeyword(keyword: string) { + this.indexingInfo.keywords.push(keyword); + console.log(this.indexingInfo.keywords); + } + + removeKeyword(keyword: string) { + const index = this.indexingInfo.keywords.indexOf(keyword); + this.indexingInfo.keywords.splice(index, 1); + console.log(this.indexingInfo.keywords); + } + addAction(actionOpt: MatAutocompleteSelectedEvent) { const index = this.actionList.findIndex(action => action.id === actionOpt.option.value); - this.indexingInfo.actions.push(this.actionList[index]); + const action = {...this.actionList[index]}; + this.indexingInfo.actions.push(action); this.actionList.splice(index, 1); + $j('#addAction').blur(); + } + + removeAction(index: number) { + const action = {...this.indexingInfo.actions[index]}; + this.actionList.push(action); + this.indexingInfo.actions.splice(index, 1); } private _filter(value: string): any[] { if (typeof value === 'string') { - const filterValue = value.toLowerCase(); - return this.actionList.filter(option => option.label.toLowerCase().includes(filterValue)); + const filterValue = this.latinisePipe.transform(value.toLowerCase()); + return this.actionList.filter(option => this.latinisePipe.transform(option.label_action.toLowerCase()).includes(filterValue)); } else { return this.actionList; }