Skip to content
Snippets Groups Projects
Verified Commit 5be7c549 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #11266 TIME 1 add plugin autocomplete

parent 77dca8e6
No related branches found
No related tags found
No related merge requests found
...@@ -10,21 +10,7 @@ ...@@ -10,21 +10,7 @@
<div class="formType-title"> <div class="formType-title">
Action(s) choisie(s) Action(s) choisie(s)
</div> </div>
<mat-form-field appearance="outline"> <plugin-autocomplete [labelPlaceholder]="'Associer une nouvelle action'" [labelList]="'Action(s) disponible(s)'" [datas]="actionList" [targetSearchKey]="'label_action'" (triggerEvent)="addAction($event)"></plugin-autocomplete>
<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 | sortBy: 'label_action'"
[value]="action.id">
{{action.label_action}}
</mat-option>
</mat-optgroup>
<mat-option *ngIf="actionList.length === 0" disabled>
Aucune action disponible
</mat-option>
</mat-autocomplete>
</mat-form-field>
<mat-list class="selectedActionList" role="list"> <mat-list class="selectedActionList" role="list">
<mat-list-item class="selectedAction" role="listitem" <mat-list-item class="selectedAction" role="listitem"
*ngFor="let action of indexingInfo.actions;let i=index"> *ngFor="let action of indexingInfo.actions;let i=index">
......
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { LANG } from '../../../translate.component'; import { LANG } from '../../../translate.component';
import { NotificationService } from '../../../notification.service'; import { NotificationService } from '../../../notification.service';
import { tap } from 'rxjs/internal/operators/tap'; import { tap } from 'rxjs/internal/operators/tap';
import { exhaustMap, startWith, map } from 'rxjs/operators'; import { 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; declare function $j(selector: any): any;
...@@ -30,19 +25,15 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -30,19 +25,15 @@ export class IndexingAdministrationComponent implements OnInit {
keywordEntities: any[] = []; keywordEntities: any[] = [];
actionList: any[] = []; actionList: any[] = [];
myControl = new FormControl();
indexingInfo: any = { indexingInfo: any = {
canIndex: false, canIndex: false,
actions: [], actions: [],
keywords: [], keywords: [],
entities: [] entities: []
}; };
filteredActionList: Observable<any[]>;
constructor(public http: HttpClient, constructor(public http: HttpClient,
private notify: NotificationService, private notify: NotificationService,
private latinisePipe: LatinisePipe
) { ) {
this.keywordEntities = [{ this.keywordEntities = [{
...@@ -105,12 +96,6 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -105,12 +96,6 @@ export class IndexingAdministrationComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.filteredActionList = this.myControl.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);
this.getIndexingInformations().pipe( this.getIndexingInformations().pipe(
tap((data: any) => this.indexingInfo.canIndex = data.group.canIndex), tap((data: any) => this.indexingInfo.canIndex = data.group.canIndex),
tap((data: any) => this.getActions(data.actions)), tap((data: any) => this.getActions(data.actions)),
...@@ -119,7 +104,6 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -119,7 +104,6 @@ export class IndexingAdministrationComponent implements OnInit {
map((data: any) => this.getSelectedEntities(data)), map((data: any) => this.getSelectedEntities(data)),
tap((data: any) => this.initEntitiesTree(data)) tap((data: any) => this.initEntitiesTree(data))
).subscribe(); ).subscribe();
} }
initEntitiesTree(entities: any) { initEntitiesTree(entities: any) {
...@@ -165,14 +149,14 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -165,14 +149,14 @@ export class IndexingAdministrationComponent implements OnInit {
getSelectedEntities(data: any) { getSelectedEntities(data: any) {
this.indexingInfo.entities = [...data.group.indexationParameters.entities]; this.indexingInfo.entities = [...data.group.indexationParameters.entities];
data.entities.forEach((entity: any) => { /*data.entities.forEach((entity: any) => {
if (this.indexingInfo.entities.indexOf(entity.id) > -1 ) { if (this.indexingInfo.entities.indexOf(entity.id) > -1 ) {
entity.state = { "opened": true, "selected": true }; entity.state = { "opened": true, "selected": true };
} else { } else {
entity.state = { "opened": true, "selected": false }; entity.state = { "opened": true, "selected": false };
} }
}); });*/
return data.entities; return data.entities;
} }
...@@ -217,12 +201,11 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -217,12 +201,11 @@ export class IndexingAdministrationComponent implements OnInit {
console.log(this.indexingInfo.keywords); console.log(this.indexingInfo.keywords);
} }
addAction(actionOpt: MatAutocompleteSelectedEvent) { addAction(actionOpt: any) {
const index = this.actionList.findIndex(action => action.id === actionOpt.option.value); const index = this.actionList.findIndex(action => action.id === actionOpt.id);
const action = {...this.actionList[index]}; const action = {...this.actionList[index]};
this.indexingInfo.actions.push(action); this.indexingInfo.actions.push(action);
this.actionList.splice(index, 1); this.actionList.splice(index, 1);
$j('#addAction').blur();
} }
removeAction(index: number) { removeAction(index: number) {
...@@ -230,13 +213,4 @@ export class IndexingAdministrationComponent implements OnInit { ...@@ -230,13 +213,4 @@ export class IndexingAdministrationComponent implements OnInit {
this.actionList.push(action); this.actionList.push(action);
this.indexingInfo.actions.splice(index, 1); this.indexingInfo.actions.splice(index, 1);
} }
private _filter(value: string): any[] {
if (typeof value === 'string') {
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;
}
}
} }
...@@ -47,6 +47,10 @@ import { BasketHomeComponent } from './basket/basket-home ...@@ -47,6 +47,10 @@ import { BasketHomeComponent } from './basket/basket-home
import { AlertComponent } from '../plugins/modal/alert.component'; import { AlertComponent } from '../plugins/modal/alert.component';
import { ConfirmComponent } from '../plugins/modal/confirm.component'; import { ConfirmComponent } from '../plugins/modal/confirm.component';
/*PLUGIN COMPONENT*/
import { PluginAutocomplete } from '../plugins/autocomplete/autocomplete.component';
export class MyHammerConfig extends HammerGestureConfig { export class MyHammerConfig extends HammerGestureConfig {
overrides = <any> { overrides = <any> {
...@@ -60,6 +64,7 @@ export class MyHammerConfig extends HammerGestureConfig { ...@@ -60,6 +64,7 @@ export class MyHammerConfig extends HammerGestureConfig {
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
FormsModule, FormsModule,
ReactiveFormsModule,
HttpClientModule, HttpClientModule,
RouterModule, RouterModule,
PdfViewerModule, PdfViewerModule,
...@@ -86,7 +91,8 @@ export class MyHammerConfig extends HammerGestureConfig { ...@@ -86,7 +91,8 @@ export class MyHammerConfig extends HammerGestureConfig {
SmdFabSpeedDialTrigger, SmdFabSpeedDialTrigger,
SmdFabSpeedDialActions, SmdFabSpeedDialActions,
AlertComponent, AlertComponent,
ConfirmComponent ConfirmComponent,
PluginAutocomplete
], ],
exports: [ exports: [
CommonModule, CommonModule,
...@@ -115,7 +121,8 @@ export class MyHammerConfig extends HammerGestureConfig { ...@@ -115,7 +121,8 @@ export class MyHammerConfig extends HammerGestureConfig {
SmdFabSpeedDialComponent, SmdFabSpeedDialComponent,
SmdFabSpeedDialTrigger, SmdFabSpeedDialTrigger,
SmdFabSpeedDialActions, SmdFabSpeedDialActions,
DragDropModule DragDropModule,
PluginAutocomplete
], ],
providers: [ providers: [
LatinisePipe, LatinisePipe,
......
<form>
<mat-form-field appearance="outline">
<input type="text" #autoCompleteInput [placeholder]="placeholder" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto" (focus)="myControl.setValue('')">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selectOpt($event)">
<mat-optgroup [label]="optGroupLabel" *ngIf="options.length > 0">
<mat-option *ngFor="let option of filteredOptions | async | sortBy: key" [value]="option">
{{option[key]}}
</mat-option>
</mat-optgroup>
<mat-option *ngIf="options.length === 0" disabled>
Aucun élément disponible
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Input, EventEmitter, Output, ViewChild, ElementRef } from '@angular/core';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { LatinisePipe } from 'ngx-pipes';
@Component({
selector: 'plugin-autocomplete',
templateUrl: 'autocomplete.component.html',
styleUrls: ['autocomplete.component.scss'],
})
export class PluginAutocomplete implements OnInit {
myControl = new FormControl();
@Input('datas') options: any;
@Input('labelPlaceholder') placeholder: string;
@Input('labelList') optGroupLabel: string;
@Input('targetSearchKey') key: string;
@Output('triggerEvent') selectedOpt = new EventEmitter();
@ViewChild('autoCompleteInput') autoCompleteInput: ElementRef;
filteredOptions: Observable<string[]>;
constructor(private latinisePipe: LatinisePipe
) { }
ngOnInit() {
this.optGroupLabel = this.optGroupLabel === undefined ? 'Valeurs disponibles' : this.optGroupLabel;
this.placeholder = this.placeholder === undefined ? 'Choisissez une valeur' : this.placeholder;
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);
}
selectOpt(ev: any) {
this.myControl.setValue('');
this.autoCompleteInput.nativeElement.blur();
this.selectedOpt.emit(ev.option.value);
}
private _filter(value: string): string[] {
if (typeof value === 'string') {
const filterValue = this.latinisePipe.transform(value.toLowerCase());
return this.options.filter((option: any) => this.latinisePipe.transform(option.label_action.toLowerCase()).includes(filterValue));
} else {
return this.options;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment