2021-02-12 12:31:12 +01:00
|
|
|
import {
|
2022-06-09 15:21:43 +02:00
|
|
|
AfterViewInit,
|
|
|
|
ChangeDetectorRef,
|
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,
|
2023-03-10 16:13:33 +01:00
|
|
|
QueryList,
|
2021-02-12 12:31:12 +01:00
|
|
|
SimpleChanges,
|
2023-03-10 16:13:33 +01:00
|
|
|
ViewChild,
|
|
|
|
ViewChildren
|
2021-02-12 12:31:12 +01:00
|
|
|
} from "@angular/core";
|
2023-05-09 14:38:37 +02:00
|
|
|
import {AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup, ValidatorFn} from "@angular/forms";
|
2020-11-12 18:57:32 +01:00
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
2023-03-10 16:13:33 +01:00
|
|
|
import {BehaviorSubject, Subscription} from "rxjs";
|
2022-03-28 00:21:55 +02:00
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {properties} from "../../../../environments/environment";
|
2022-04-13 12:00:40 +02:00
|
|
|
import {ClickEvent} from "../../utils/click/click-outside-or-esc.directive";
|
2023-07-11 15:03:08 +02:00
|
|
|
import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service";
|
|
|
|
import {MobileDropdownComponent} from "../../utils/mobile-dropdown/mobile-dropdown.component";
|
2023-07-19 18:51:54 +02:00
|
|
|
import {MatDatepicker} from "@angular/material/datepicker";
|
2019-12-23 16:17:35 +01:00
|
|
|
|
2023-04-20 13:53:40 +02:00
|
|
|
export type InputType =
|
2023-06-30 13:54:25 +02:00
|
|
|
'text'
|
|
|
|
| 'URL'
|
|
|
|
| 'logoURL'
|
|
|
|
| 'autocomplete'
|
|
|
|
| 'autocomplete_soft'
|
|
|
|
| 'textarea'
|
|
|
|
| 'select'
|
|
|
|
| 'chips'
|
2023-07-19 18:51:54 +02:00
|
|
|
| 'year-range'
|
|
|
|
| 'date';
|
2022-04-04 10:06:34 +02:00
|
|
|
|
2019-12-23 16:17:35 +01:00
|
|
|
export interface Option {
|
|
|
|
icon?: string,
|
|
|
|
iconClass?: string,
|
|
|
|
value: any,
|
2022-04-28 11:13:06 +02:00
|
|
|
label: string,
|
2023-04-20 13:53:40 +02:00
|
|
|
tooltip?: string,
|
2022-08-05 13:59:08 +02:00
|
|
|
disabled?: boolean,
|
|
|
|
hidden?: boolean
|
2019-12-23 16:17:35 +01:00
|
|
|
}
|
|
|
|
|
2022-03-31 15:39:17 +02:00
|
|
|
export interface Placeholder {
|
|
|
|
label: string,
|
2024-06-25 14:26:51 +02:00
|
|
|
static?: boolean,
|
|
|
|
tooltip?: string
|
2022-03-31 15:39:17 +02:00
|
|
|
}
|
|
|
|
|
2023-05-09 14:38:37 +02:00
|
|
|
export interface YearRange {
|
|
|
|
from: ControlConfiguration,
|
|
|
|
to: ControlConfiguration
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ControlConfiguration {
|
|
|
|
control: string,
|
|
|
|
placeholder: string
|
|
|
|
}
|
|
|
|
|
2022-03-30 19:47:47 +02:00
|
|
|
declare var UIkit;
|
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
/**
|
2022-04-11 11:27:10 +02:00
|
|
|
* Autocomplete soft allows values that are not listed in options list. In order to work as expected
|
|
|
|
* avoid providing options with different label and value.
|
|
|
|
*
|
2022-03-28 00:21:55 +02:00
|
|
|
* */
|
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: `
|
2023-06-30 13:54:25 +02:00
|
|
|
<div *ngIf="formControl" [id]="id">
|
|
|
|
<div class="input-wrapper" [class.disabled]="formControl.disabled" [class.opened]="opened"
|
|
|
|
[class.focused]="focused" [ngClass]="inputClass" [class.hint]="hint"
|
2023-07-19 18:51:54 +02:00
|
|
|
[class.active]="!focused && (formAsControl?.value || selectable || type === 'date' || formAsArray?.length > 0 || getLabel(formAsControl?.value) || yearRangeActive)"
|
2023-06-30 13:54:25 +02:00
|
|
|
[class.danger]="(formControl.invalid && (formControl.touched || !!searchControl?.touched)) || (!!searchControl?.invalid && !!searchControl?.touched)">
|
2023-07-19 18:51:54 +02:00
|
|
|
<div #inputBox class="input-box" [class.select]="selectable || type ==='date'" click-outside-or-esc
|
2023-06-30 13:54:25 +02:00
|
|
|
[class.static]="placeholderInfo?.static" (clickOutside)="click($event)">
|
|
|
|
<div *ngIf="!placeholderInfo?.static && placeholderInfo?.label" class="placeholder">
|
2024-06-25 14:26:51 +02:00
|
|
|
<label>{{ placeholderInfo.label }} <sup *ngIf="required">*</sup></label>
|
2023-06-30 13:54:25 +02:00
|
|
|
</div>
|
|
|
|
<div class="uk-flex" [class.uk-flex-middle]="type !== 'textarea'"
|
2024-06-25 14:26:51 +02:00
|
|
|
[attr.uk-tooltip]="placeholderInfo.tooltip?('title: ' + placeholderInfo.tooltip + '; delay: 500; pos: bottom-left'):
|
|
|
|
((tooltip && !focused && type !== 'chips' && type !== 'textarea' && (formControl.value || hint || placeholderInfo?.label))?
|
|
|
|
('title: ' + (formControl.value ?getTooltip(formControl.value):(hint?hint:placeholderInfo?.label)) + '; delay: 500; pos: bottom-left'):null)">
|
2023-06-30 13:54:25 +02:00
|
|
|
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
|
2024-06-25 14:26:51 +02:00
|
|
|
<input #input class="input"
|
|
|
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
2023-06-30 13:54:25 +02:00
|
|
|
[type]="password?'password':'text'" [formControl]="formAsControl"
|
|
|
|
[class.uk-text-truncate]="!focused">
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'textarea'">
|
2024-06-25 14:26:51 +02:00
|
|
|
<textarea #textArea class="input"
|
|
|
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
2023-07-19 18:51:54 +02:00
|
|
|
[rows]="rows" [formControl]="formAsControl"></textarea>
|
2023-06-30 13:54:25 +02:00
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'select'">
|
|
|
|
<ng-container *ngIf="placeholderInfo?.static">
|
|
|
|
<div *ngIf="!getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input placeholder uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ placeholderInfo.label }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
<div *ngIf="getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ getLabel(formControl.value) }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
</ng-container>
|
|
|
|
<ng-container *ngIf="!placeholderInfo?.static">
|
|
|
|
<div *ngIf="!getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ noValueSelected }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
<div *ngIf="getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input uk-width-expand uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ getLabel(formControl.value) }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
</ng-container>
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'autocomplete'">
|
|
|
|
<input *ngIf="focused" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
2024-06-25 14:26:51 +02:00
|
|
|
#searchInput class="input" [formControl]="searchControl"
|
|
|
|
[class.uk-text-truncate]="!focused">
|
2023-06-30 13:54:25 +02:00
|
|
|
<ng-container *ngIf="!focused && !selectable">
|
|
|
|
<div *ngIf="!getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input placeholder uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ placeholderInfo?.static ? placeholderInfo.label : getLabel(formAsControl.value) }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
<div *ngIf="getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ getLabel(formAsControl.value) }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
</ng-container>
|
|
|
|
<ng-container *ngIf="!focused && selectable">
|
2024-06-25 14:26:51 +02:00
|
|
|
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ noValueSelected }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
<div *ngIf="getLabel(formControl.value)"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="input uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ getLabel(formControl.value) }}
|
|
|
|
</div>
|
2023-06-30 13:54:25 +02:00
|
|
|
</ng-container>
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'autocomplete_soft'">
|
2024-06-25 14:26:51 +02:00
|
|
|
<input #input class="input"
|
|
|
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
2023-06-30 13:54:25 +02:00
|
|
|
[formControl]="formAsControl" [class.uk-text-truncate]="!focused">
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'chips'">
|
|
|
|
<div class="uk-grid uk-grid-small uk-grid-row-collapse uk-overflow-auto uk-width-expand"
|
|
|
|
[class.uk-flex-nowrap]="noWrap" [class.uk-overflow-auto]="noWrap" uk-grid>
|
|
|
|
<div *ngFor="let chip of formAsArray.controls; let i=index" #chip
|
|
|
|
[class.uk-hidden]="!focused && i > visibleChips - 1"
|
|
|
|
class="chip">
|
|
|
|
<div class="uk-label uk-label-small uk-text-transform-none uk-flex uk-flex-middle"
|
|
|
|
[attr.uk-tooltip]="(tooltip)?('title: ' + getLabel(chip.value) + '; delay: 500; pos: bottom-left'):null">
|
2024-06-25 14:26:51 +02:00
|
|
|
<span class="uk-text-truncate uk-width-expand">{{ getLabel(chip.value) }}</span>
|
2023-06-30 13:54:25 +02:00
|
|
|
<icon *ngIf="focused" (click)="remove(i, $event)"
|
|
|
|
class="uk-link-text uk-margin-small-left clickable" [flex]="true"
|
|
|
|
name="close" ratio="0.7"></icon>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="searchControl && (focused || formAsArray.length === 0)" #chip
|
|
|
|
class="uk-width-expand search-input uk-flex uk-flex-column uk-flex-center">
|
|
|
|
<input #searchInput class="input" [class.search]="searchControl.value"
|
|
|
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
|
|
|
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
|
|
|
</div>
|
|
|
|
<div *ngIf="!focused && formAsArray.length > visibleChips"
|
|
|
|
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
2024-06-25 14:26:51 +02:00
|
|
|
+ {{ (formAsArray.length - visibleChips) }} more
|
2023-06-30 13:54:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ng-template>
|
|
|
|
<ng-template [ngIf]="type === 'year-range' && yearRange && formAsGroup">
|
|
|
|
<div class="uk-width-2-5">
|
2024-06-25 14:26:51 +02:00
|
|
|
<input #input class="input uk-text-center uk-text-truncate"
|
|
|
|
[attr.placeholder]="yearRange.from.placeholder"
|
|
|
|
maxlength="4" (click)="activeIndex = 0;$event.preventDefault()"
|
|
|
|
[formControl]="getFormByName(yearRange.from.control)">
|
2023-06-30 13:54:25 +02:00
|
|
|
</div>
|
|
|
|
<div class="uk-width-1-5 uk-text-center">-</div>
|
|
|
|
<div class="uk-width-2-5">
|
2024-06-25 14:26:51 +02:00
|
|
|
<input #input class="input uk-text-center uk-text-truncate"
|
|
|
|
[attr.placeholder]="yearRange.to.placeholder"
|
|
|
|
maxlength="4" (click)="activeIndex = 1;$event.preventDefault()"
|
|
|
|
[formControl]="getFormByName(yearRange.to.control)">
|
2023-06-30 13:54:25 +02:00
|
|
|
</div>
|
|
|
|
</ng-template>
|
2023-07-19 18:51:54 +02:00
|
|
|
<ng-template [ngIf]="type === 'date'">
|
2024-06-25 14:26:51 +02:00
|
|
|
<div *ngIf="!formAsControl.getRawValue()" class="input uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ selectADate }}
|
|
|
|
</div>
|
|
|
|
<div *ngIf="formAsControl.getRawValue()" class="input uk-text-truncate"
|
|
|
|
[class.uk-disabled]="formControl.disabled">{{ formAsControl.getRawValue() | date: 'dd-MM-yyyy' }}
|
|
|
|
</div>
|
2023-07-19 18:51:54 +02:00
|
|
|
</ng-template>
|
|
|
|
<div *ngIf="(formControl.disabled && disabledIcon) || icon || (selectable && selectArrow) || type === 'autocomplete' || searchable || type === 'date'"
|
2024-06-25 14:26:51 +02:00
|
|
|
class="uk-margin-small-left icon">
|
2023-06-30 13:54:25 +02:00
|
|
|
<icon *ngIf="formControl.disabled && disabledIcon" [name]="disabledIcon" [flex]="true"></icon>
|
|
|
|
<ng-template [ngIf]="formControl.enabled">
|
|
|
|
<icon *ngIf="!searchControl?.value && icon" [name]="icon" [flex]="true"></icon>
|
2024-06-25 14:26:51 +02:00
|
|
|
<icon *ngIf="!icon && selectable && selectArrow" [name]="selectArrow"
|
|
|
|
[flex]="true"></icon>
|
|
|
|
<button *ngIf="focused && type === 'autocomplete' && (!selectable || searchControl.value)"
|
|
|
|
class="uk-close uk-icon"
|
2023-06-30 13:54:25 +02:00
|
|
|
(click)="resetSearch($event)">
|
|
|
|
<icon [flex]="true" name="close"></icon>
|
|
|
|
</button>
|
2023-07-19 18:51:54 +02:00
|
|
|
<button *ngIf="(!focused && type === 'autocomplete' && !selectable) ||
|
|
|
|
(type !== 'autocomplete' && !searchControl?.value && !!formControl?.value && (searchable || !selectable)) ||
|
|
|
|
(type === 'date' && formAsControl?.value)"
|
|
|
|
class="uk-close uk-icon" (click)="resetValue($event);">
|
2023-06-30 13:54:25 +02:00
|
|
|
<icon [flex]="true" name="close"></icon>
|
|
|
|
</button>
|
|
|
|
</ng-template>
|
|
|
|
</div>
|
|
|
|
<!-- use action-icon class in order to apply css in your icon button-->
|
|
|
|
<ng-content select="[action]"></ng-content>
|
|
|
|
</div>
|
|
|
|
<div class="tools">
|
|
|
|
<ng-content select="[tools]"></ng-content>
|
2022-04-04 12:53:26 +02:00
|
|
|
</div>
|
2022-03-31 15:39:17 +02:00
|
|
|
</div>
|
2022-03-30 19:47:47 +02:00
|
|
|
</div>
|
2024-06-25 14:26:51 +02:00
|
|
|
<div *ngIf="!mobile && type === 'date' && opened" class="uk-dropdown" #calendarBox
|
|
|
|
uk-dropdown="pos: bottom-left; mode: none; flip: false ; shift: false" [attr.target]="'#' + id"
|
|
|
|
[attr.boundary]="'#' + id" (click)="$event.stopPropagation()">
|
|
|
|
<mat-calendar [selected]="selectedDate" [startAt]="selectedDate"
|
|
|
|
(selectedChange)="dateChanged($event)"></mat-calendar>
|
2023-07-19 18:51:54 +02:00
|
|
|
</div>
|
2023-08-29 09:53:51 +02:00
|
|
|
<mobile-dropdown *ngIf="mobile && type === 'date' && opened" (onClose)="focus(false)" #mobileDropdown>
|
2024-06-25 14:26:51 +02:00
|
|
|
<mat-calendar [selected]="selectedDate" [startAt]="selectedDate"
|
|
|
|
(selectedChange)="dateChanged($event)"></mat-calendar>
|
2023-08-29 09:53:51 +02:00
|
|
|
</mobile-dropdown>
|
2024-06-25 14:26:51 +02:00
|
|
|
<div *ngIf="!mobile && filteredOptions && filteredOptions.length > 0 && opened" class="options uk-dropdown"
|
|
|
|
#optionBox
|
2023-08-22 16:08:46 +02:00
|
|
|
uk-dropdown="mode: none; stretch: true; flip: false; shift: false" [attr.boundary]="'#' + id">
|
2023-06-30 13:54:25 +02:00
|
|
|
<ul class="uk-nav uk-dropdown-nav">
|
|
|
|
<li *ngFor="let option of filteredOptions; let i=index" [class.uk-hidden]="option.hidden"
|
|
|
|
[class.uk-active]="(formControl.value === option.value) || selectedIndex === i">
|
|
|
|
<a (click)="selectOption(option, $event)"
|
|
|
|
[class]="option.disabled ? 'uk-disabled uk-text-muted' : ''">
|
2024-06-25 14:26:51 +02:00
|
|
|
<span [attr.uk-tooltip]="(tooltip)?('title: ' + (option.tooltip ? option.tooltip : option.label) + '; delay: 500; pos:bottom-left'):null">{{ option.label }}</span>
|
2023-06-30 13:54:25 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2024-06-25 14:26:51 +02:00
|
|
|
<mobile-dropdown *ngIf="mobile && filteredOptions && filteredOptions.length > 0 && opened"
|
|
|
|
(onClose)="focus(false)" #mobileDropdown>
|
|
|
|
<div *ngIf="placeholderInfo"
|
|
|
|
class="uk-text-emphasis uk-text-bolder uk-text-center uk-padding-small uk-padding-remove-vertical uk-text-uppercase">
|
|
|
|
{{ placeholderInfo.label }}
|
2023-07-11 15:03:08 +02:00
|
|
|
</div>
|
|
|
|
<div class="uk-padding uk-padding-remove-horizontal">
|
|
|
|
<ul class="uk-nav uk-nav-default">
|
|
|
|
<li *ngFor="let option of filteredOptions; let i=index" [class.uk-hidden]="option.hidden"
|
|
|
|
[class.uk-active]="formControl.value === option.value">
|
|
|
|
<a (click)="selectOption(option, $event)"
|
|
|
|
[class]="option.disabled ? 'uk-disabled uk-text-muted' : ''">
|
2024-06-25 14:26:51 +02:00
|
|
|
<span>{{ option.label }}</span>
|
2023-07-11 15:03:08 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</mobile-dropdown>
|
2022-04-04 12:53:26 +02:00
|
|
|
</div>
|
2023-10-12 12:10:02 +02:00
|
|
|
<span *ngIf="formControl?.invalid && formControl?.touched" class="uk-text-small uk-text-danger">
|
2024-06-25 14:26:51 +02:00
|
|
|
<span *ngIf="errors?.error">{{ errors?.error }}</span>
|
2023-10-12 12:10:02 +02:00
|
|
|
<span *ngIf="type === 'URL' || type === 'logoURL'">Please provide a valid URL (e.g. https://example.com)</span>
|
|
|
|
</span>
|
2023-06-30 13:54:25 +02:00
|
|
|
<span class="uk-text-small uk-text-danger">
|
2022-03-28 00:21:55 +02:00
|
|
|
<ng-content select="[error]"></ng-content>
|
|
|
|
</span>
|
2023-06-30 13:54:25 +02:00
|
|
|
<span *ngIf="formControl?.valid" class="uk-text-small uk-text-warning uk-margin-xsmall-top">
|
2022-03-28 00:21:55 +02:00
|
|
|
<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>
|
2023-06-30 13:54:25 +02:00
|
|
|
<i class="uk-text-small uk-text-meta uk-margin-xsmall-top">
|
|
|
|
<ng-content select="[note]"></ng-content>
|
|
|
|
</i>
|
2022-03-31 15:39:17 +02:00
|
|
|
`
|
2019-12-23 14:59:56 +01:00
|
|
|
})
|
2022-03-28 00:21:55 +02:00
|
|
|
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
2022-04-04 12:53:26 +02:00
|
|
|
private static INPUT_COUNTER: number = 0;
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Basic information */
|
|
|
|
@Input('formInput') formControl: AbstractControl;
|
2022-04-04 10:06:34 +02:00
|
|
|
@Input('type') type: InputType = 'text';
|
2023-01-05 09:53:08 +01:00
|
|
|
@Input() password: boolean = false;
|
2022-04-04 10:06:34 +02:00
|
|
|
@Input() validators: ValidatorFn[] | ValidatorFn;
|
|
|
|
@Input() disabled: boolean = false;
|
2022-04-12 16:20:51 +02:00
|
|
|
@Input() disabledIcon: string = 'lock';
|
2022-03-31 15:39:17 +02:00
|
|
|
@Input() value: any | any[];
|
|
|
|
@Output() valueChange = new EventEmitter<any | any[]>();
|
2022-04-17 00:42:10 +02:00
|
|
|
@Input() hint: string;
|
2022-06-06 11:22:01 +02:00
|
|
|
@Input() tooltip: boolean = false;
|
2022-06-09 15:21:43 +02:00
|
|
|
@Input() searchable: boolean = false;
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Text */
|
2023-05-09 14:38:37 +02:00
|
|
|
@ViewChildren('input') input: QueryList<ElementRef>;
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Textarea options */
|
|
|
|
@ViewChild('textArea') textArea: ElementRef;
|
|
|
|
@Input('rows') rows: number = 3;
|
|
|
|
/** Select | Autocomplete | chips available options */
|
2022-04-04 10:06:34 +02:00
|
|
|
@Input() selectArrow: string = 'arrow_drop_down';
|
2022-04-04 15:44:00 +02:00
|
|
|
@Input() selectedIndex: number = 0;
|
2022-05-27 11:22:04 +02:00
|
|
|
@Input() selectable: boolean = false;
|
2022-06-08 13:19:40 +02:00
|
|
|
@Input() noValueSelected: string = 'No option selected';
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Chips && Autocomplete*/
|
|
|
|
public filteredOptions: Option[] = [];
|
2022-09-23 12:25:08 +02:00
|
|
|
public searchControl: UntypedFormControl;
|
2023-03-10 16:13:33 +01:00
|
|
|
public activeElement: BehaviorSubject<ElementRef> = new BehaviorSubject<ElementRef>(null);
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Use modifier's class(es) to change view of your Input */
|
2023-03-22 16:54:54 +01:00
|
|
|
@Input() inputClass: string = 'flat';
|
2022-03-31 15:39:17 +02:00
|
|
|
/** Icon on the input */
|
|
|
|
@Input() icon: string = null;
|
|
|
|
/** Chip options */
|
|
|
|
@Input() addExtraChips: boolean = false;
|
2021-02-24 17:53:31 +01:00
|
|
|
@Input() showOptionsOnEmpty: boolean = true;
|
2023-03-06 12:18:16 +01:00
|
|
|
@Input() visibleChips: number = 1;
|
|
|
|
@Input() separators: string[] = [];
|
2023-03-10 16:13:33 +01:00
|
|
|
@Input() noWrap: boolean = false;
|
2023-05-09 14:38:37 +02:00
|
|
|
/** Year Range Configuration */
|
|
|
|
@Input() yearRange: YearRange;
|
|
|
|
public activeIndex: 0 | 1 | null = null;
|
2023-07-19 18:51:54 +02:00
|
|
|
/** Date Configuration*/
|
|
|
|
@Input() selectADate: string = 'Select a date';
|
|
|
|
public selectedDate: Date;
|
2023-03-10 16:13:33 +01:00
|
|
|
@Input() visibleRows: number = -1;
|
|
|
|
@Input() extendEnter: () => void = null;
|
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 */
|
2022-04-04 12:53:26 +02:00
|
|
|
public id: string;
|
2022-03-31 15:39:17 +02:00
|
|
|
public placeholderInfo: Placeholder = {label: '', static: true};
|
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;
|
2023-07-11 15:03:08 +02:00
|
|
|
public mobile: boolean = false;
|
2022-03-28 00:21:55 +02:00
|
|
|
public properties: EnvProperties = properties;
|
2019-12-23 14:59:56 +01:00
|
|
|
private initValue: any;
|
2022-04-04 15:44:00 +02:00
|
|
|
private optionsArray: Option[] = [];
|
2022-06-20 12:11:21 +02:00
|
|
|
private optionsBreakpoint: number = 6;
|
2022-03-28 00:21:55 +02:00
|
|
|
private subscriptions: any[] = [];
|
|
|
|
@ViewChild('inputBox') inputBox: ElementRef;
|
|
|
|
@ViewChild('optionBox') optionBox: ElementRef;
|
2023-07-19 18:51:54 +02:00
|
|
|
@ViewChild('calendarBox') calendarBox: ElementRef;
|
2023-07-11 15:03:08 +02:00
|
|
|
@ViewChild('mobileDropdown') mobileDropdown: MobileDropdownComponent;
|
2021-02-12 12:31:12 +01:00
|
|
|
@ViewChild('searchInput') searchInput: ElementRef;
|
2023-03-10 16:13:33 +01:00
|
|
|
@ViewChildren('chip') chips: QueryList<ElementRef>;
|
2023-07-19 18:51:54 +02:00
|
|
|
@ViewChild('datepicker') datepicker: MatDatepicker<any>;
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-03-31 15:39:17 +02:00
|
|
|
@Input()
|
|
|
|
set placeholder(placeholder: string | Placeholder) {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.type === 'year-range') {
|
2023-05-09 14:38:37 +02:00
|
|
|
this.placeholderInfo = null;
|
|
|
|
} else if (typeof placeholder === 'string') {
|
2022-03-31 15:39:17 +02:00
|
|
|
this.placeholderInfo = {label: placeholder, static: false};
|
|
|
|
} else {
|
2023-03-10 16:13:33 +01:00
|
|
|
if (placeholder.static && (this.type === 'autocomplete' || this.hint)) {
|
2022-03-31 15:39:17 +02:00
|
|
|
placeholder.static = false;
|
|
|
|
console.debug('Static placeholder is not available in this type of input and if hint is available.');
|
|
|
|
}
|
|
|
|
this.placeholderInfo = placeholder;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-04 15:44:00 +02:00
|
|
|
@Input()
|
2022-06-01 15:28:44 +02:00
|
|
|
set options(options: (Option | string | number) []) {
|
2022-04-04 15:44:00 +02:00
|
|
|
this.optionsArray = options.map(option => {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (option === null) {
|
2024-02-22 08:41:57 +01:00
|
|
|
return {
|
|
|
|
label: this.noValueSelected,
|
|
|
|
value: ''
|
|
|
|
};
|
|
|
|
} else if (typeof option === 'string' || typeof option === 'number') {
|
2022-04-04 15:44:00 +02:00
|
|
|
return {
|
2022-06-01 15:28:44 +02:00
|
|
|
label: option.toString(),
|
2022-04-04 15:44:00 +02:00
|
|
|
value: option
|
2022-04-17 00:42:10 +02:00
|
|
|
};
|
2022-04-04 15:44:00 +02:00
|
|
|
} else {
|
2022-04-17 00:42:10 +02:00
|
|
|
return option;
|
2022-04-04 15:44:00 +02:00
|
|
|
}
|
|
|
|
});
|
2023-04-20 13:53:40 +02:00
|
|
|
if (!this.tooltip) {
|
2022-06-06 16:16:51 +02:00
|
|
|
this.tooltip = this.optionsArray.length > 0;
|
|
|
|
}
|
2023-04-20 13:53:40 +02:00
|
|
|
if (this.type === "select") {
|
2022-06-20 12:11:21 +02:00
|
|
|
if (this.optionsArray.length > this.optionsBreakpoint) {
|
2022-05-27 11:22:04 +02:00
|
|
|
this.type = 'autocomplete';
|
|
|
|
this.showOptionsOnEmpty = true;
|
|
|
|
this.icon = this.selectArrow;
|
|
|
|
}
|
|
|
|
this.selectable = true;
|
|
|
|
}
|
2022-04-04 15:44:00 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-07-11 15:03:08 +02:00
|
|
|
constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef, private layoutService: LayoutService) {
|
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
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-17 14:25:01 +02:00
|
|
|
@HostListener('window:keydown.arrowUp', ['$event'])
|
|
|
|
arrowUp(event: KeyboardEvent) {
|
2023-07-11 15:03:08 +02:00
|
|
|
if (this.opened && this.optionBox) {
|
2022-04-17 14:25:01 +02:00
|
|
|
event.preventDefault();
|
|
|
|
if (this.selectedIndex > 0) {
|
|
|
|
this.selectedIndex--;
|
|
|
|
this.optionBox.nativeElement.scrollBy(0, -34);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-17 14:25:01 +02:00
|
|
|
@HostListener('window:keydown.arrowDown', ['$event'])
|
|
|
|
arrowDown(event: KeyboardEvent) {
|
2023-07-11 15:03:08 +02:00
|
|
|
if (this.opened && this.optionBox) {
|
2022-04-17 14:25:01 +02:00
|
|
|
event.preventDefault();
|
|
|
|
if (this.selectedIndex < (this.filteredOptions.length - 1)) {
|
|
|
|
this.selectedIndex++;
|
|
|
|
this.optionBox.nativeElement.scrollBy(0, 34);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-03-10 16:13:33 +01:00
|
|
|
@HostListener('window:keydown.arrowLeft', ['$event'])
|
|
|
|
arrowLeft(event: KeyboardEvent) {
|
2023-05-16 10:12:14 +02:00
|
|
|
if (this.type === 'chips' && this.focused) {
|
2023-04-20 13:53:40 +02:00
|
|
|
if (this.activeElement.getValue()) {
|
2023-05-16 10:12:14 +02:00
|
|
|
event.preventDefault();
|
2023-03-10 16:13:33 +01:00
|
|
|
let index = this.chips.toArray().indexOf(this.activeElement.getValue());
|
2023-04-20 13:53:40 +02:00
|
|
|
if (index > 0) {
|
2023-03-10 16:13:33 +01:00
|
|
|
this.activeElement.next(this.chips.get(index - 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-03-10 16:13:33 +01:00
|
|
|
@HostListener('window:keydown.arrowRight', ['$event'])
|
|
|
|
arrowRight(event: KeyboardEvent) {
|
2023-05-16 10:12:14 +02:00
|
|
|
if (this.type === 'chips' && this.focused) {
|
2023-04-20 13:53:40 +02:00
|
|
|
if (this.activeElement.getValue()) {
|
2023-05-16 10:12:14 +02:00
|
|
|
event.preventDefault();
|
2023-03-10 16:13:33 +01:00
|
|
|
let index = this.chips.toArray().indexOf(this.activeElement.getValue());
|
2023-04-20 13:53:40 +02:00
|
|
|
if (index < this.chips.length - 1) {
|
2023-03-10 16:13:33 +01:00
|
|
|
this.activeElement.next(this.chips.get(index + 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-17 14:25:01 +02:00
|
|
|
@HostListener('window:keydown.enter', ['$event'])
|
|
|
|
enter(event: KeyboardEvent) {
|
2023-05-12 16:24:27 +02:00
|
|
|
if (this.extendEnter) {
|
|
|
|
this.extendEnter();
|
|
|
|
}
|
2022-06-28 20:13:40 +02:00
|
|
|
if (this.opened && this.optionBox) {
|
2022-04-17 14:25:01 +02:00
|
|
|
event.preventDefault();
|
|
|
|
if (this.filteredOptions[this.selectedIndex]) {
|
|
|
|
this.selectOption(this.filteredOptions[this.selectedIndex], event);
|
2022-04-04 15:44:00 +02:00
|
|
|
}
|
2022-06-09 14:25:24 +02:00
|
|
|
this.open(false);
|
|
|
|
event.stopPropagation();
|
|
|
|
} else {
|
|
|
|
this.focus(false, event);
|
2022-04-04 15:44:00 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-03-06 12:18:16 +01:00
|
|
|
@HostListener('keydown', ['$event'])
|
|
|
|
onKeyDown(event: KeyboardEvent) {
|
2023-03-10 16:13:33 +01:00
|
|
|
if (this.separators.includes(event.key) || this.separators.includes(event.key.toLowerCase())) {
|
2023-03-06 12:18:16 +01:00
|
|
|
event.preventDefault();
|
|
|
|
this.add(event, true);
|
|
|
|
}
|
2022-04-04 15:44:00 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-13 12:00:40 +02:00
|
|
|
click(event: ClickEvent) {
|
2023-06-26 14:09:37 +02:00
|
|
|
this.focus(!event.clicked);
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
ngOnInit() {
|
2023-07-11 15:03:08 +02:00
|
|
|
this.subscriptions.push(this.layoutService.isMobile.subscribe(mobile => {
|
|
|
|
this.mobile = mobile;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
2022-04-04 12:53:26 +02:00
|
|
|
InputComponent.INPUT_COUNTER++;
|
|
|
|
this.id = 'input-' + InputComponent.INPUT_COUNTER;
|
2022-03-30 19:47:47 +02:00
|
|
|
if (!this.formControl) {
|
|
|
|
if (Array.isArray(this.value)) {
|
2022-09-23 12:25:08 +02:00
|
|
|
this.formControl = new UntypedFormArray([]);
|
2022-03-28 00:21:55 +02:00
|
|
|
this.value.forEach(value => {
|
2022-09-23 12:25:08 +02:00
|
|
|
this.formAsArray.push(new UntypedFormControl(value, this.validators));
|
2022-03-28 00:21:55 +02:00
|
|
|
});
|
|
|
|
} else {
|
2023-03-07 11:26:26 +01:00
|
|
|
this.formControl = new UntypedFormControl(this.value, this.validators);
|
2022-03-28 00:21:55 +02:00
|
|
|
}
|
2022-03-30 19:47:47 +02:00
|
|
|
if (this.disabled) {
|
2022-03-28 00:21:55 +02:00
|
|
|
this.formControl.disable();
|
|
|
|
}
|
|
|
|
}
|
2023-03-10 16:13:33 +01:00
|
|
|
this.activeElement.subscribe(element => {
|
2023-04-20 13:53:40 +02:00
|
|
|
if (element) {
|
2023-03-10 16:13:33 +01:00
|
|
|
element.nativeElement.scrollIntoView({behavior: 'smooth'});
|
|
|
|
}
|
|
|
|
})
|
2022-03-28 00:21:55 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-02-08 10:52:11 +01:00
|
|
|
ngAfterViewInit() {
|
2020-10-19 11:06:23 +02:00
|
|
|
this.reset();
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2020-10-19 11:06:23 +02:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
2022-04-17 14:25:01 +02:00
|
|
|
if (this.formControl) {
|
2023-11-15 15:13:45 +01:00
|
|
|
if (changes.value && changes.value.currentValue !== changes.value.previousValue) {
|
2022-04-05 14:33:38 +02:00
|
|
|
this.formControl.setValue(this.value);
|
|
|
|
}
|
2023-04-20 13:53:40 +02:00
|
|
|
if (changes.validators) {
|
2023-03-07 11:26:26 +01:00
|
|
|
this.updateValidators();
|
|
|
|
}
|
2022-04-05 14:33:38 +02:00
|
|
|
if (changes.formControl || changes.validators || changes.options) {
|
|
|
|
this.reset();
|
|
|
|
}
|
2022-04-17 14:25:01 +02:00
|
|
|
if (changes.disabled) {
|
|
|
|
if (this.disabled) {
|
2022-04-12 16:20:51 +02:00
|
|
|
this.formControl.disable();
|
|
|
|
} else {
|
|
|
|
this.formControl.enable();
|
|
|
|
}
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-03-30 19:47:47 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.unsubscribe();
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-05-09 14:38:37 +02:00
|
|
|
getFormByName(name: string): UntypedFormControl {
|
|
|
|
if (this.formControl instanceof UntypedFormGroup) {
|
|
|
|
return <UntypedFormControl>this.formControl.get(name);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-05-09 14:38:37 +02:00
|
|
|
get formAsGroup(): UntypedFormGroup {
|
|
|
|
if (this.formControl instanceof UntypedFormGroup) {
|
|
|
|
return this.formControl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-09-23 12:25:08 +02:00
|
|
|
get formAsControl(): UntypedFormControl {
|
|
|
|
if (this.formControl instanceof UntypedFormControl) {
|
2022-03-28 00:21:55 +02:00
|
|
|
return this.formControl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-09-23 12:25:08 +02:00
|
|
|
get formAsArray(): UntypedFormArray {
|
|
|
|
if (this.formControl instanceof UntypedFormArray) {
|
2022-03-28 00:21:55 +02:00
|
|
|
return this.formControl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-05-09 14:38:37 +02:00
|
|
|
get yearRangeActive(): boolean {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.yearRange) {
|
2023-05-09 14:38:37 +02:00
|
|
|
return this.formAsGroup && (this.getFormByName(this.yearRange.from.control)?.value || this.getFormByName(this.yearRange.to.control)?.value);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-05-09 14:38:37 +02:00
|
|
|
get errors(): any {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.formAsGroup) {
|
2023-05-09 14:38:37 +02:00
|
|
|
return (this.formAsGroup.errors
|
2024-06-25 14:26:51 +02:00
|
|
|
? this.formAsGroup.errors : (this.getFormByName(this.yearRange.from.control).errors
|
|
|
|
? this.getFormByName(this.yearRange.from.control).errors : this.getFormByName(this.yearRange.to.control).errors));
|
|
|
|
} else if (this.formAsControl) {
|
2023-05-09 14:38:37 +02:00
|
|
|
return this.formAsControl.errors;
|
2024-06-25 14:26:51 +02:00
|
|
|
} else if (this.searchControl) {
|
2023-05-09 14:38:37 +02:00
|
|
|
return this.searchControl.errors;
|
2023-07-14 17:27:16 +02:00
|
|
|
} else {
|
|
|
|
return null;
|
2023-05-09 14:38:37 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02: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://'));
|
|
|
|
}
|
2023-05-09 14:38:37 +02:00
|
|
|
if (this.optionsArray?.length > 0) {
|
2022-03-30 19:47:47 +02:00
|
|
|
this.filteredOptions = this.filter('');
|
2022-04-06 09:35:10 +02:00
|
|
|
this.cdr.detectChanges();
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
2021-03-22 16:10:18 +01:00
|
|
|
if (this.type === 'chips' || this.type === 'autocomplete') {
|
2022-04-04 10:06:34 +02:00
|
|
|
if (!this.searchControl) {
|
2022-09-23 12:25:08 +02:00
|
|
|
this.searchControl = new UntypedFormControl('', this.validators);
|
2022-04-04 10:06:34 +02:00
|
|
|
}
|
2022-03-30 19:47:47 +02:00
|
|
|
this.subscriptions.push(this.searchControl.valueChanges.subscribe(value => {
|
|
|
|
this.filteredOptions = this.filter(value);
|
2022-04-06 09:35:10 +02:00
|
|
|
this.cdr.detectChanges();
|
2022-03-30 19:47:47 +02:00
|
|
|
if (this.focused) {
|
|
|
|
this.open(true);
|
2021-03-22 16:10:18 +01:00
|
|
|
setTimeout(() => {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.searchInput) {
|
2023-06-26 14:09:37 +02:00
|
|
|
this.searchInput.nativeElement.focus();
|
|
|
|
this.searchInput.nativeElement.value = value;
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
}, 0);
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
|
|
|
}));
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
2023-07-18 14:27:02 +02:00
|
|
|
if (this.formAsControl?.validator || this.formAsArray?.validator) {
|
2020-06-05 16:48:12 +02:00
|
|
|
let validator = this.formControl.validator({} as AbstractControl);
|
|
|
|
this.required = (validator && validator.required);
|
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.type === 'date') {
|
|
|
|
this.selectedDate = this.formAsControl.getRawValue() ? new Date(this.formAsControl.getRawValue()) : null;
|
2023-07-19 18:51:54 +02:00
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
|
2022-04-17 14:25:01 +02:00
|
|
|
if (this.formControl.enabled) {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.type !== 'year-range') {
|
2023-05-16 10:12:14 +02:00
|
|
|
value = (value === '') ? null : value;
|
|
|
|
if (this.type === 'logoURL') {
|
|
|
|
this.secure = (!value || value.includes('https://'));
|
|
|
|
}
|
|
|
|
if (this.initValue === value || (this.initValue === '' && value === null)) {
|
|
|
|
this.formControl.markAsPristine();
|
|
|
|
} else {
|
|
|
|
this.formControl.markAsDirty();
|
|
|
|
}
|
|
|
|
if (this.type === 'autocomplete_soft') {
|
|
|
|
this.filteredOptions = this.filter(value);
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
if (this.focused) {
|
|
|
|
this.open(true);
|
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
2023-07-19 18:51:54 +02:00
|
|
|
if (this.type === 'date') {
|
2024-06-25 14:26:51 +02:00
|
|
|
this.selectedDate = value ? new Date(value) : null;
|
2023-07-19 18:51:54 +02:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
2022-04-17 14:25:01 +02:00
|
|
|
if ((this.value && value && this.value !== value) || (!this.value && value) || this.value && !value) {
|
2022-04-12 16:20:51 +02:00
|
|
|
this.valueChange.emit(this.formControl.value);
|
2022-04-11 11:27:10 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
}));
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.formAsGroup) {
|
2023-05-16 10:12:14 +02:00
|
|
|
let fromControl = this.formAsGroup.get(this.yearRange.from.control);
|
|
|
|
this.subscriptions.push(fromControl.valueChanges.subscribe(value => {
|
|
|
|
let from = this.initValue[this.yearRange.from.control];
|
|
|
|
if (from === value || (from === '' && value === null)) {
|
|
|
|
fromControl.markAsPristine();
|
|
|
|
} else {
|
|
|
|
fromControl.markAsDirty();
|
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
if (fromControl.valid) {
|
|
|
|
if (this.activeIndex === 0 && value) {
|
2023-05-09 14:38:37 +02:00
|
|
|
this.activeIndex = 1;
|
|
|
|
this.input.get(this.activeIndex).nativeElement.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2023-05-16 10:12:14 +02:00
|
|
|
let toControl = this.formAsGroup.get(this.yearRange.to.control);
|
|
|
|
this.subscriptions.push(toControl.valueChanges.subscribe(value => {
|
|
|
|
let to = this.initValue[this.yearRange.to.control];
|
|
|
|
if (to === value || (to === '' && value === null)) {
|
|
|
|
toControl.markAsPristine();
|
|
|
|
} else {
|
|
|
|
toControl.markAsDirty();
|
|
|
|
}
|
|
|
|
}));
|
2023-05-09 14:38:37 +02:00
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
if (this.input) {
|
2023-05-09 14:38:37 +02:00
|
|
|
this.input.forEach(input => {
|
|
|
|
input.nativeElement.disabled = this.formControl.disabled;
|
|
|
|
});
|
2022-02-08 10:52:11 +01:00
|
|
|
}
|
2020-10-19 11:06:23 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-03-07 11:26:26 +01:00
|
|
|
updateValidators() {
|
2023-04-20 13:53:40 +02:00
|
|
|
if (this.formAsArray) {
|
2023-03-07 11:26:26 +01:00
|
|
|
this.formAsArray.controls.forEach(control => {
|
|
|
|
control.setValidators(this.validators);
|
|
|
|
control.updateValueAndValidity();
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.formControl.setValidators(this.validators);
|
|
|
|
this.formControl.updateValueAndValidity();
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-04 10:06:34 +02:00
|
|
|
remove(index: number, event) {
|
2022-04-17 14:25:01 +02:00
|
|
|
if (this.focused) {
|
2022-04-17 00:42:10 +02:00
|
|
|
this.formAsArray.removeAt(index);
|
|
|
|
this.formAsArray.markAsDirty();
|
|
|
|
this.focus(true);
|
|
|
|
this.searchControl.setValue('');
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2021-01-28 17:33:16 +01:00
|
|
|
private filter(value: string): Option[] {
|
2022-08-05 13:59:08 +02:00
|
|
|
let options = this.optionsArray.filter(option => !option.hidden);
|
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-04-04 15:44:00 +02:00
|
|
|
this.selectedIndex = 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();
|
2023-02-20 19:54:26 +01:00
|
|
|
options = options.filter(option => (option.label && option.label.toLowerCase().indexOf(filterValue) != -1));
|
2022-04-04 15:44:00 +02:00
|
|
|
this.selectedIndex = options.findIndex(option => option.value === this.formControl.value);
|
2022-04-17 14:25:01 +02:00
|
|
|
if (this.selectedIndex === -1) {
|
2022-04-04 15:44:00 +02:00
|
|
|
this.selectedIndex = 0;
|
|
|
|
}
|
|
|
|
return options;
|
2021-01-28 17:33:16 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-03-06 12:18:16 +01:00
|
|
|
add(event, addChips = false) {
|
2023-04-20 13:53:40 +02:00
|
|
|
if (addChips && this.searchControl.value) {
|
|
|
|
this.splitSearchControl();
|
|
|
|
} else if (!this.focused) {
|
2023-03-06 12:18:16 +01:00
|
|
|
this.searchControl.setValue('');
|
2023-04-20 13:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-04-20 13:53:40 +02:00
|
|
|
splitSearchControl() {
|
|
|
|
let values = [this.searchControl.value];
|
|
|
|
this.separators.forEach(separator => {
|
|
|
|
values = ([] as string[]).concat(...values.map(value => {
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
return ([] as string[]).concat(...value.map(element => element.split(separator)));
|
|
|
|
} else {
|
|
|
|
return value.split(separator);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
values.forEach(value => {
|
|
|
|
let control = new UntypedFormControl(value.trim(), this.validators);
|
|
|
|
if (control.valid) {
|
|
|
|
this.formAsArray.push(control);
|
|
|
|
this.formAsArray.markAsDirty();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (this.formAsArray.dirty) {
|
2023-03-10 16:13:33 +01:00
|
|
|
this.activeElement.next(this.chips.last);
|
2023-03-06 12:18:16 +01:00
|
|
|
this.searchControl.setValue('');
|
2021-02-12 12:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-06-08 13:19:40 +02:00
|
|
|
getLabel(value: any): string {
|
2022-05-11 09:17:06 +02:00
|
|
|
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
2022-04-04 10:06:34 +02:00
|
|
|
return (option) ? option.label : (value);
|
2021-02-12 12:31:12 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2023-04-20 13:53:40 +02:00
|
|
|
getTooltip(value: any): string {
|
2022-08-02 15:49:09 +02:00
|
|
|
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
|
|
|
return (option) ? (option.tooltip ? option.tooltip : option.label) : (value);
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-04-04 10:06:34 +02:00
|
|
|
focus(value: boolean, event = null) {
|
2024-06-25 14:26:51 +02:00
|
|
|
if (!this.activeIndex) {
|
2023-05-09 14:38:37 +02:00
|
|
|
this.activeIndex = 0;
|
|
|
|
}
|
2022-04-04 10:06:34 +02:00
|
|
|
if (this.focused) {
|
2022-03-30 19:47:47 +02:00
|
|
|
this.formControl.markAsTouched();
|
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.formControl.enabled) {
|
2023-06-30 13:54:25 +02:00
|
|
|
this.focused = value;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
if (this.focused) {
|
|
|
|
if (this.input?.length > 0) {
|
|
|
|
this.input.get(this.activeIndex).nativeElement.focus();
|
|
|
|
} else if (this.textArea) {
|
|
|
|
this.textArea.nativeElement.focus();
|
|
|
|
} else if (this.searchInput) {
|
|
|
|
this.searchInput.nativeElement.focus();
|
|
|
|
this.activeElement.next(this.chips.last);
|
|
|
|
}
|
2023-07-19 18:51:54 +02:00
|
|
|
if (this.selectArrow || this.datepicker) {
|
2023-06-30 13:54:25 +02:00
|
|
|
this.open(!this.opened);
|
|
|
|
} else if (this.type !== 'autocomplete' || this.showOptionsOnEmpty || !this.formControl.value) {
|
|
|
|
this.open(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.activeIndex = null;
|
|
|
|
this.open(false);
|
|
|
|
if (this.input) {
|
|
|
|
this.input.forEach(input => {
|
|
|
|
input.nativeElement.blur();
|
|
|
|
})
|
|
|
|
} else if (this.textArea) {
|
|
|
|
this.textArea.nativeElement.blur();
|
|
|
|
} else if (this.searchInput) {
|
|
|
|
this.searchInput.nativeElement.blur();
|
|
|
|
}
|
|
|
|
if (this.searchControl) {
|
|
|
|
this.add(event, this.addExtraChips);
|
|
|
|
}
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
this.focusEmitter.emit(this.focused);
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-03-28 00:21:55 +02:00
|
|
|
open(value: boolean) {
|
|
|
|
this.opened = value && this.formControl.enabled;
|
2022-04-04 10:06:34 +02:00
|
|
|
this.cdr.detectChanges();
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.optionBox) {
|
2023-07-11 15:03:08 +02:00
|
|
|
if (this.opened) {
|
|
|
|
this.selectedIndex = this.filteredOptions.findIndex(option => option.value === this.formControl.value);
|
|
|
|
if (this.selectedIndex === -1 && this.type !== 'autocomplete_soft') {
|
|
|
|
this.selectedIndex = 0;
|
|
|
|
}
|
|
|
|
UIkit.dropdown(this.optionBox.nativeElement).show();
|
|
|
|
} else {
|
2022-04-04 10:06:34 +02:00
|
|
|
UIkit.dropdown(this.optionBox.nativeElement).hide();
|
2022-05-30 14:42:54 +02:00
|
|
|
this.focused = false;
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
} else if (this.calendarBox) {
|
2023-07-19 18:51:54 +02:00
|
|
|
if (this.opened) {
|
|
|
|
UIkit.dropdown(this.calendarBox.nativeElement).show();
|
|
|
|
} else {
|
|
|
|
UIkit.dropdown(this.calendarBox.nativeElement).hide();
|
|
|
|
this.focused = false;
|
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
} else if (this.mobileDropdown) {
|
|
|
|
if (this.opened) {
|
2023-07-11 15:03:08 +02:00
|
|
|
this.mobileDropdown.open();
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.searchInput) {
|
2023-07-11 15:03:08 +02:00
|
|
|
this.searchInput.nativeElement.blur();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mobileDropdown.close();
|
|
|
|
}
|
2022-04-04 10:06:34 +02:00
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2021-03-22 16:10:18 +01:00
|
|
|
resetSearch(event: any) {
|
2021-03-19 15:23:47 +01:00
|
|
|
event.stopPropagation();
|
2022-03-30 19:47:47 +02:00
|
|
|
this.searchControl.setValue('');
|
2022-06-09 15:21:43 +02:00
|
|
|
this.focus(true, event);
|
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-06-09 15:21:43 +02:00
|
|
|
resetValue(event: any) {
|
|
|
|
event.stopPropagation();
|
|
|
|
this.formControl.setValue('');
|
|
|
|
this.focus(true, event);
|
2021-03-19 15:23:47 +01:00
|
|
|
}
|
2023-06-30 13:54:25 +02:00
|
|
|
|
2022-03-30 19:47:47 +02:00
|
|
|
selectOption(option: Option, event) {
|
2022-04-04 10:06:34 +02:00
|
|
|
if (this.formControl.enabled) {
|
2022-03-30 19:47:47 +02:00
|
|
|
if (this.formAsControl) {
|
|
|
|
this.formAsControl.setValue(option.value);
|
|
|
|
} else if (this.formAsArray) {
|
2022-09-23 12:25:08 +02:00
|
|
|
this.formAsArray.push(new UntypedFormControl(option.value));
|
2022-03-30 19:47:47 +02:00
|
|
|
this.formAsArray.markAsDirty();
|
|
|
|
event.stopPropagation();
|
|
|
|
this.focus(true);
|
|
|
|
this.searchControl.setValue('');
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
}
|
2024-06-25 14:26:51 +02:00
|
|
|
if (this.mobileDropdown) {
|
2023-07-26 10:49:50 +02:00
|
|
|
this.mobileDropdown.close();
|
|
|
|
}
|
2022-03-28 00:21:55 +02:00
|
|
|
}
|
2023-07-19 18:51:54 +02:00
|
|
|
|
|
|
|
dateChanged(event: Date) {
|
|
|
|
this.focus(false);
|
|
|
|
this.formAsControl.setValue(event.getTime());
|
|
|
|
}
|
2019-12-23 14:59:56 +01:00
|
|
|
}
|