2021-02-12 12:31:12 +01:00
|
|
|
import {
|
2022-02-08 10:52:11 +01:00
|
|
|
AfterViewInit,
|
2021-03-22 16:10:18 +01:00
|
|
|
Component,
|
|
|
|
ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
HostListener,
|
2021-02-12 12:31:12 +01:00
|
|
|
Input,
|
|
|
|
OnChanges,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
SimpleChanges,
|
|
|
|
ViewChild
|
|
|
|
} from "@angular/core";
|
2021-04-23 18:25:52 +02:00
|
|
|
import {AbstractControl, FormArray, FormControl, ValidatorFn} from "@angular/forms";
|
2020-11-12 18:57:32 +01:00
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
2021-01-28 17:33:16 +01:00
|
|
|
import {Observable, of, Subscription} from "rxjs";
|
2020-10-19 11:06:23 +02:00
|
|
|
import {MatSelect} from "@angular/material/select";
|
2021-01-28 17:33:16 +01:00
|
|
|
import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
|
|
|
|
import {map, startWith} from "rxjs/operators";
|
2021-03-22 16:10:18 +01:00
|
|
|
import {MatChipInputEvent} from "@angular/material/chips";
|
2022-03-28 00:21:55 +02:00
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {properties} from "../../../../environments/environment";
|
2019-12-23 16:17:35 +01:00
|
|
|
|
|
|
|
export interface Option {
|
|
|
|
icon?: string,
|
|
|
|
iconClass?: string,
|
|
|
|
value: any,
|
|
|
|
label: string
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
/**
|
|
|
|
* WARNING! dashboard-input selector is @deprecated, use input instead
|
|
|
|
*
|
|
|
|
* */
|
2019-12-23 14:59:56 +01:00
|
|
|
@Component({
|
2022-03-28 00:21:55 +02:00
|
|
|
selector: '[dashboard-input], [input]',
|
2019-12-23 14:59:56 +01:00
|
|
|
template: `
|
2022-03-28 00:21:55 +02:00
|
|
|
<div class="input-container" [ngClass]="inputClass" [class.disabled]="formControl.disabled"
|
|
|
|
[class.focused]="(focused && type !== 'select') || formControl.value" [class.opened]="opened">
|
|
|
|
<div #inputBox class="input-wrapper" [class.select]="type === 'select'">
|
|
|
|
<div class="placeholder">
|
|
|
|
<label>{{placeholder}} <sup *ngIf="required">*</sup></label>
|
|
|
|
</div>
|
|
|
|
<div class="uk-flex" [class.uk-flex-middle]="type !== 'textarea'">
|
|
|
|
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
|
|
|
|
<input #input class="input" [formControl]="formAsControl">
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'textarea'">
|
|
|
|
<textarea #textArea class="input" [rows]="rows" [formControl]="formAsControl"></textarea>
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'select'">
|
|
|
|
<div class="input">{{getLabel(formControl.value)}}</div>
|
|
|
|
</ng-template>
|
|
|
|
<div *ngIf="formControl.disabled || icon || type === 'select'" class="uk-margin-small-left uk-margin-right">
|
|
|
|
<icon *ngIf="formControl.disabled" [name]="'lock'" [flex]="true"></icon>
|
|
|
|
<icon *ngIf="formControl.enabled && icon" [name]="icon" [flex]="true"></icon>
|
|
|
|
<icon *ngIf="formControl.enabled && !icon" name="arrow_drop_down" [flex]="true"></icon>
|
2020-10-19 11:06:23 +02:00
|
|
|
</div>
|
2022-03-28 00:21:55 +02:00
|
|
|
</div>
|
|
|
|
<div class="tools">
|
|
|
|
<ng-content select="[tools]"></ng-content>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div #optionBox class="options">
|
|
|
|
<ul *ngIf="options?.length > 1">
|
|
|
|
<li *ngFor="let option of options" [class.uk-active]="formControl.value === option.value">
|
|
|
|
<a (click)="selectOption(option)">{{option.label}}</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!--<ng-template [ngIf]="type === 'select'">
|
|
|
|
<div [ngClass]="inputClass"
|
|
|
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
|
|
|
[class.clickable]="formControl.enabled"
|
|
|
|
[class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
|
|
|
|
<mat-form-field class="uk-width-1-1">
|
|
|
|
<mat-select #select [required]="required" [value]="null"
|
|
|
|
(openedChange)="stopPropagation()" [formControl]="formAsControl"
|
|
|
|
[disableOptionCentering]="true">
|
|
|
|
<mat-option *ngIf="placeholder" class="uk-hidden" [value]="''">{{placeholder}}</mat-option>
|
|
|
|
<mat-option *ngFor="let option of options" [value]="option.value"
|
|
|
|
[attr.uk-tooltip]="(tooltip) ? option.label : null">
|
|
|
|
{{option.label}}
|
|
|
|
</mat-option>
|
|
|
|
</mat-select>
|
|
|
|
</mat-form-field>
|
|
|
|
</div>
|
|
|
|
</ng-template>-->
|
|
|
|
<ng-template [ngIf]="type === 'autocomplete'">
|
|
|
|
<div [ngClass]="inputClass"
|
|
|
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
|
|
|
[class.clickable]="formControl.enabled"
|
|
|
|
[class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
|
|
|
|
<mat-form-field class="uk-width-1-1">
|
|
|
|
<mat-chip-list #chipList>
|
|
|
|
<mat-chip *ngIf="formControl.value" [selectable]="false" [removable]="removable"
|
|
|
|
[attr.uk-tooltip]="getLabel(formControl.value)">
|
2021-03-22 16:10:18 +01:00
|
|
|
<span class="uk-flex uk-flex-middle uk-width-1-1">
|
2022-03-28 00:21:55 +02:00
|
|
|
<span class="uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-text-small]="smallChip">{{getLabel(formControl.value)}}</span>
|
2021-03-19 15:23:47 +01:00
|
|
|
<icon name="remove_circle" class="mat-chip-remove" [flex]="true" [ratio]="smallChip?0.8:1"
|
|
|
|
(click)="resetSearch($event)"></icon>
|
|
|
|
</span>
|
2022-03-28 00:21:55 +02:00
|
|
|
</mat-chip>
|
|
|
|
<div [class.uk-hidden]="formControl.value" class="uk-width-expand uk-position-relative chip-input">
|
|
|
|
<input #searchInput [formControl]="searchControl" [matAutocomplete]="auto"
|
|
|
|
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin">
|
|
|
|
<div *ngIf="placeholder && !searchInput.value" class="placeholder uk-width-1-1"
|
|
|
|
(click)="searchInput.focus()">{{placeholder}}</div>
|
|
|
|
</div>
|
|
|
|
<div class="uk-width-1-1 uk-invisible" matAutocompleteOrigin #origin="matAutocompleteOrigin"></div>
|
|
|
|
</mat-chip-list>
|
|
|
|
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="formControl.setValue($event.option.value)"
|
|
|
|
[class]="panelClass" [panelWidth]="panelWidth">
|
|
|
|
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.value"
|
|
|
|
[attr.uk-tooltip]="option.label">
|
|
|
|
{{option.label}}
|
|
|
|
</mat-option>
|
|
|
|
</mat-autocomplete>
|
|
|
|
</mat-form-field>
|
|
|
|
</div>
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'chips'">
|
|
|
|
<div [ngClass]="inputClass"
|
|
|
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
|
|
|
[class.clickable]="formControl.enabled"
|
|
|
|
[class.uk-form-danger]="formControl.invalid && searchControl.invalid && searchControl.touched"
|
|
|
|
(click)="openSelect()">
|
|
|
|
<mat-form-field class="uk-width-1-1">
|
|
|
|
<mat-chip-list #chipList>
|
|
|
|
<mat-chip *ngFor="let chip of formAsArray.controls; let i=index" [selectable]="false"
|
|
|
|
[removable]="removable" [attr.uk-tooltip]="getLabel(chip.value)">
|
2021-03-22 16:10:18 +01:00
|
|
|
<span class="uk-flex uk-flex-middle uk-width-1-1">
|
2022-03-28 00:21:55 +02:00
|
|
|
<span class="uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-text-small]="smallChip">{{getLabel(chip.value)}}</span>
|
|
|
|
<icon name="remove_circle" class="mat-chip-remove" [flex]="true" [ratio]="smallChip?0.8:1"
|
|
|
|
(click)="removed(i)"></icon>
|
2021-03-04 11:17:30 +01:00
|
|
|
</span>
|
2022-03-28 00:21:55 +02:00
|
|
|
</mat-chip>
|
|
|
|
<div class="uk-width-expand uk-position-relative chip-input">
|
|
|
|
<input #searchInput style="width: calc(100% - 8px) !important;" [formControl]="searchControl"
|
|
|
|
[matAutocomplete]="auto"
|
|
|
|
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin"
|
|
|
|
[matChipInputAddOnBlur]="addExtraChips && searchControl.value"
|
|
|
|
(matChipInputTokenEnd)="add($event)">
|
|
|
|
<div *ngIf="placeholder && !searchControl.value" class="placeholder uk-width-1-1"
|
|
|
|
(click)="searchInput.focus()">{{placeholder}}</div>
|
|
|
|
</div>
|
|
|
|
<div class="uk-width-1-1 uk-invisible" matAutocompleteOrigin #origin="matAutocompleteOrigin"></div>
|
|
|
|
</mat-chip-list>
|
|
|
|
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)" [class]="panelClass"
|
|
|
|
[panelWidth]="panelWidth">
|
|
|
|
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.value"
|
|
|
|
[attr.uk-tooltip]="option.label">
|
|
|
|
{{option.label}}
|
|
|
|
</mat-option>
|
|
|
|
</mat-autocomplete>
|
|
|
|
</mat-form-field>
|
2020-10-19 11:06:23 +02:00
|
|
|
</div>
|
2022-03-28 00:21:55 +02:00
|
|
|
</ng-template>
|
|
|
|
<span *ngIf="formControl.invalid && formControl.touched" class="uk-text-danger input-message">
|
|
|
|
<span *ngIf="formControl.errors.error">{{formControl.errors.error}}</span>
|
|
|
|
<span
|
|
|
|
*ngIf="type === 'URL' || type === 'logoURL'">Please provide a valid URL (e.g. https://example.com)</span>
|
|
|
|
</span>
|
|
|
|
<span class="uk-text-danger uk-text-small">
|
|
|
|
<ng-content select="[error]"></ng-content>
|
|
|
|
</span>
|
|
|
|
<span *ngIf="formControl.valid" class="uk-text-warning uk-text-small">
|
|
|
|
<ng-content select="[warning]"></ng-content>
|
|
|
|
<span *ngIf="!secure">
|
|
|
|
<span class="uk-text-bold">Note:</span> Prefer urls like "<span class="uk-text-bold">https://</span>example.com/my-secure-image.png"
|
|
|
|
instead of "<span class="uk-text-bold">http://</span>example.com/my-image.png".
|
|
|
|
<span class="uk-text-bold">Browsers may not load non secure content.</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="uk-text-small">
|
|
|
|
<ng-content select="[note]"></ng-content>
|
|
|
|
</span>
|
2020-11-01 16:41:02 +01:00
|
|
|
`,
|
|
|
|
styleUrls: ['input.component.css']
|
2019-12-23 14:59:56 +01:00
|
|
|
})
|
2022-03-28 00:21:55 +02:00
|
|
|
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
2021-02-12 12:31:12 +01:00
|
|
|
/** Basic information */
|
2019-12-23 14:59:56 +01:00
|
|
|
@Input('formInput') formControl: AbstractControl;
|
2022-03-28 00:21:55 +02:00
|
|
|
@Input('type') type: 'text' | 'URL' | 'logoURL' | 'autocomplete' | 'textarea' | 'select' | 'chips' = 'text';
|
|
|
|
@Input() value: any | any[];
|
|
|
|
@Output() valueChange = new EventEmitter<any | any[]>();
|
|
|
|
/** @deprecated */
|
2019-12-23 14:59:56 +01:00
|
|
|
@Input('label') label: string;
|
2021-04-09 15:01:07 +02:00
|
|
|
/** Text */
|
|
|
|
@ViewChild('input') input: ElementRef;
|
2021-03-03 19:04:53 +01:00
|
|
|
/** Textarea options */
|
2022-03-28 00:21:55 +02:00
|
|
|
@ViewChild('textArea') textArea: ElementRef;
|
2019-12-23 14:59:56 +01:00
|
|
|
@Input('rows') rows: number = 3;
|
2021-02-12 12:31:12 +01:00
|
|
|
/** Select | chips available options */
|
2021-04-23 18:25:52 +02:00
|
|
|
@Input('options') options: Option[] = [];
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2020-10-19 11:06:23 +02:00
|
|
|
@Input('hint') hint = null;
|
|
|
|
@Input('placeholder') placeholder = '';
|
2022-03-28 00:21:55 +02:00
|
|
|
@Input() inputClass: string = 'inner';
|
2021-02-12 12:31:12 +01:00
|
|
|
/** Extra element Right or Left of the input */
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2020-10-19 11:06:23 +02:00
|
|
|
@Input() extraLeft: boolean = true;
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2021-01-21 16:15:53 +01:00
|
|
|
@Input() gridSmall: boolean = false;
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2020-10-19 17:05:16 +02:00
|
|
|
@Input() hideControl: boolean = false;
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2021-02-12 12:31:12 +01:00
|
|
|
@Input() flex: 'middle' | 'top' | 'bottom' = 'middle';
|
2022-03-28 00:21:55 +02:00
|
|
|
/** Icon on the input */
|
2020-11-01 16:41:02 +01:00
|
|
|
@Input() icon: string = null;
|
2022-03-28 00:21:55 +02:00
|
|
|
/** @deprecated */
|
2020-11-01 16:41:02 +01:00
|
|
|
@Input() iconLeft: boolean = false;
|
2021-02-12 12:31:12 +01:00
|
|
|
/** Chip options */
|
2021-01-28 17:33:16 +01:00
|
|
|
@Input() removable: boolean = true;
|
2021-02-12 12:31:12 +01:00
|
|
|
@Input() addExtraChips: boolean = false;
|
2021-02-17 19:44:02 +01:00
|
|
|
@Input() smallChip: boolean = false;
|
|
|
|
@Input() panelWidth: number = 300;
|
|
|
|
@Input() panelClass: string = null;
|
2021-02-24 17:53:31 +01:00
|
|
|
@Input() showOptionsOnEmpty: boolean = true;
|
2022-01-11 12:15:37 +01:00
|
|
|
@Input() validators: ValidatorFn[] | ValidatorFn;
|
2022-03-28 00:21:55 +02:00
|
|
|
@Input() disabled: boolean = false;
|
2021-02-12 12:31:12 +01:00
|
|
|
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2021-03-03 19:04:53 +01:00
|
|
|
/** LogoUrl information */
|
|
|
|
public secure: boolean = true;
|
2021-02-12 12:31:12 +01:00
|
|
|
/** Internal basic information */
|
2020-06-05 16:48:12 +02:00
|
|
|
public required: boolean = false;
|
2022-03-28 00:21:55 +02:00
|
|
|
public focused: boolean = false;
|
|
|
|
public opened: boolean = false;
|
|
|
|
public properties: EnvProperties = properties;
|
2019-12-23 14:59:56 +01:00
|
|
|
private initValue: any;
|
2022-03-28 00:21:55 +02:00
|
|
|
private subscriptions: any[] = [];
|
2021-03-19 15:23:47 +01:00
|
|
|
/** Chips && Autocomplete*/
|
2021-02-12 12:31:12 +01:00
|
|
|
public filteredOptions: Observable<Option[]>;
|
|
|
|
public searchControl: FormControl;
|
2022-03-28 00:21:55 +02:00
|
|
|
@Input() tooltip: boolean = true;
|
|
|
|
@ViewChild('inputBox') inputBox: ElementRef;
|
|
|
|
@ViewChild('optionBox') optionBox: ElementRef;
|
2021-02-12 12:31:12 +01:00
|
|
|
@ViewChild('searchInput') searchInput: ElementRef;
|
2020-10-19 11:06:23 +02:00
|
|
|
|
2021-02-12 12:31:12 +01:00
|
|
|
constructor(private elementRef: ElementRef) {
|
2022-03-28 00:21:55 +02:00
|
|
|
if (elementRef.nativeElement.hasAttribute('dashboard-input') && this.properties.environment === "development") {
|
|
|
|
console.warn("'dashboard-input' selector is deprecated; use 'input' instead.");
|
|
|
|
}
|
2021-02-12 12:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('document:click', ['$event'])
|
2022-03-28 00:21:55 +02:00
|
|
|
click(event) {
|
|
|
|
this.focused = (this.inputBox && this.inputBox.nativeElement.contains(event.target));
|
|
|
|
if (this.focused) {
|
|
|
|
if(this.input) {
|
|
|
|
this.input.nativeElement.focus();
|
|
|
|
} else if(this.textArea) {
|
|
|
|
this.textArea.nativeElement.focus();
|
|
|
|
}
|
|
|
|
this.open(!this.opened);
|
|
|
|
} else {
|
|
|
|
this.open(false);
|
|
|
|
}
|
2021-02-12 12:31:12 +01:00
|
|
|
this.focusEmitter.emit(this.focused);
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
ngOnInit() {
|
|
|
|
if(!this.formControl) {
|
|
|
|
if(Array.isArray(this.value)) {
|
|
|
|
this.formControl = new FormArray([]);
|
|
|
|
this.value.forEach(value => {
|
|
|
|
this.formAsArray.push(new FormControl(value, this.validators));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.formControl = new FormControl(this.value);
|
|
|
|
this.formControl.setValidators(this.validators);
|
|
|
|
}
|
|
|
|
if(this.disabled) {
|
|
|
|
this.formControl.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 10:52:11 +01:00
|
|
|
ngAfterViewInit() {
|
2022-03-28 00:21:55 +02:00
|
|
|
/** If options are available set max-height base on input-wrapper height */
|
|
|
|
if(this.options && this.options.length > 1) {
|
|
|
|
this.elementRef.nativeElement.style.maxHeight = this.inputBox.nativeElement.clientHeight + 'px';
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
2022-01-11 12:15:37 +01:00
|
|
|
if (changes.formControl || changes.validators) {
|
2020-10-19 11:06:23 +02:00
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
get formAsControl(): FormControl {
|
|
|
|
if (this.formControl instanceof FormControl) {
|
|
|
|
return this.formControl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:33:16 +01:00
|
|
|
get formAsArray(): FormArray {
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.formControl instanceof FormArray) {
|
|
|
|
return this.formControl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-19 11:06:23 +02:00
|
|
|
reset() {
|
2021-03-03 19:04:53 +01:00
|
|
|
this.secure = true;
|
2020-10-19 11:06:23 +02:00
|
|
|
this.unsubscribe();
|
2019-12-23 14:59:56 +01:00
|
|
|
this.initValue = HelperFunctions.copy(this.formControl.value);
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.type === 'logoURL') {
|
2021-03-03 19:04:53 +01:00
|
|
|
this.secure = (!this.initValue || this.initValue.includes('https://'));
|
|
|
|
}
|
2021-03-22 16:10:18 +01:00
|
|
|
if (this.type === 'chips' || this.type === 'autocomplete') {
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.options) {
|
2021-03-22 16:10:18 +01:00
|
|
|
this.filteredOptions = of(this.options);
|
2021-04-23 18:25:52 +02:00
|
|
|
this.searchControl = new FormControl('', this.validators);
|
2021-03-22 16:10:18 +01:00
|
|
|
this.subscriptions.push(this.searchControl.valueChanges.subscribe(value => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.searchInput.nativeElement.focus();
|
|
|
|
this.searchInput.nativeElement.value = value;
|
2022-03-28 00:21:55 +02:00
|
|
|
}, 0);
|
2021-03-22 16:10:18 +01:00
|
|
|
}));
|
|
|
|
this.filteredOptions = this.searchControl.valueChanges.pipe(startWith(''),
|
|
|
|
map(option => this.filter(option)));
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
if (this.formControl && this.formControl.validator) {
|
2020-06-05 16:48:12 +02:00
|
|
|
let validator = this.formControl.validator({} as AbstractControl);
|
|
|
|
this.required = (validator && validator.required);
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
|
2021-02-12 12:31:12 +01:00
|
|
|
value = (value === '') ? null : value;
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.type === 'logoURL') {
|
2021-03-03 19:04:53 +01:00
|
|
|
this.secure = (!value || value.includes('https://'));
|
|
|
|
}
|
2021-02-12 12:31:12 +01:00
|
|
|
if (this.initValue === value || (this.initValue === '' && value === null)) {
|
2019-12-23 14:59:56 +01:00
|
|
|
this.formControl.markAsPristine();
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.searchControl) {
|
2021-03-22 16:10:18 +01:00
|
|
|
this.searchControl.setValue(null);
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
this.value = this.formControl.value;
|
|
|
|
this.valueChange.emit(this.value);
|
2020-10-19 11:06:23 +02:00
|
|
|
}));
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.input) {
|
2022-02-08 10:52:11 +01:00
|
|
|
this.input.nativeElement.disabled = this.formControl.disabled;
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsubscribe() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
2021-02-12 12:31:12 +01:00
|
|
|
if (subscription instanceof Subscription) {
|
2020-10-19 11:06:23 +02:00
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
2019-12-23 14:59:56 +01:00
|
|
|
});
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
|
2019-12-23 14:59:56 +01:00
|
|
|
ngOnDestroy(): void {
|
2020-10-19 11:06:23 +02:00
|
|
|
this.unsubscribe();
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
|
2019-12-23 14:59:56 +01:00
|
|
|
stopPropagation() {
|
2020-10-19 11:06:23 +02:00
|
|
|
event.stopPropagation();
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
|
|
|
removed(index: number) {
|
|
|
|
this.formAsArray.removeAt(index);
|
|
|
|
this.formAsArray.markAsDirty();
|
2021-02-12 12:31:12 +01:00
|
|
|
this.searchControl.setValue('');
|
|
|
|
this.stopPropagation();
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
selected(event: MatAutocompleteSelectedEvent): void {
|
|
|
|
this.formAsArray.push(new FormControl(event.option.value));
|
|
|
|
this.formAsArray.markAsDirty();
|
|
|
|
this.searchControl.setValue('');
|
2021-02-12 12:31:12 +01:00
|
|
|
this.stopPropagation();
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private filter(value: string): Option[] {
|
2021-03-19 15:23:47 +01:00
|
|
|
let options = this.options;
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.type === "chips") {
|
|
|
|
options = options.filter(option => !this.formAsArray.value.find(value => HelperFunctions.equals(option.value, value)));
|
2021-03-19 15:23:47 +01:00
|
|
|
}
|
|
|
|
if ((!value || value.length == 0)) {
|
2022-03-28 00:21:55 +02:00
|
|
|
return (this.showOptionsOnEmpty) ? options : [];
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
|
|
|
const filterValue = value.toString().toLowerCase();
|
|
|
|
return options.filter(option => option.label.toLowerCase().indexOf(filterValue) != -1);
|
|
|
|
}
|
2021-02-12 12:31:12 +01:00
|
|
|
|
|
|
|
add(event: MatChipInputEvent) {
|
2021-04-23 18:25:52 +02:00
|
|
|
if (this.addExtraChips && event.value && this.searchControl.valid) {
|
2021-02-12 12:31:12 +01:00
|
|
|
this.stopPropagation();
|
2021-04-23 18:25:52 +02:00
|
|
|
this.formAsArray.push(new FormControl(event.value, this.validators));
|
2021-02-12 12:31:12 +01:00
|
|
|
this.formAsArray.markAsDirty();
|
|
|
|
this.searchControl.setValue('');
|
|
|
|
this.searchInput.nativeElement.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getLabel(value: any) {
|
2021-04-21 17:28:35 +02:00
|
|
|
let option = this.options.find(option => HelperFunctions.equals(option.value, value));
|
2021-02-12 12:31:12 +01:00
|
|
|
return (option) ? option.label : value;
|
|
|
|
}
|
2021-03-19 15:23:47 +01:00
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
open(value: boolean) {
|
|
|
|
this.opened = value && this.formControl.enabled;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.optionBox.nativeElement.style.overflow = this.opened?'auto':'hidden';
|
|
|
|
}, this.opened?200:0);
|
|
|
|
}
|
|
|
|
|
2021-03-22 16:10:18 +01:00
|
|
|
resetSearch(event: any) {
|
2021-03-19 15:23:47 +01:00
|
|
|
event.stopPropagation();
|
2021-03-22 16:10:18 +01:00
|
|
|
this.searchControl.setValue('');
|
2022-03-28 00:21:55 +02:00
|
|
|
this.formControl.markAsDirty();
|
2021-03-19 15:23:47 +01:00
|
|
|
this.formControl.setValue(null);
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
|
|
|
|
selectOption(option: Option) {
|
|
|
|
if(this.formAsControl) {
|
|
|
|
this.formAsControl.setValue(option.value);
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|