[Validator]: First working version - user selects among 3 hardcoded guidelines, pastes an XML and validates it | Added utils folder for input component (copied by openaireLibrary).

This commit is contained in:
Konstantina Galouni 2022-10-06 15:50:55 +03:00
parent ff07d28632
commit c55af200ea
15 changed files with 848 additions and 137 deletions

View File

@ -30,7 +30,10 @@
"styles": [
"src/styles.less"
],
"scripts": []
"scripts": [
"node_modules/uikit/dist/js/uikit.min.js",
"node_modules/uikit/dist/js/uikit-icons.min.js"
]
},
"configurations": {
"production": {
@ -103,5 +106,8 @@
}
}
}
},
"cli": {
"analytics": false
}
}

View File

@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --disable-host-check --host 0.0.0.0 --port 5100",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"

View File

@ -6,6 +6,9 @@ import { AppComponent } from './app.component';
import { TopmenuComponent } from './shared/topmenu/topmenu.component';
import { SidebarComponent } from './shared/sidebar/sidebar.component';
import { SingleRecordValidatorComponent } from './pages/single-record-validator/single-record-validator.component';
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {HttpClient, HttpClientModule} from "@angular/common/http";
import {InputModule} from "./shared/utils/input/input.module";
@NgModule({
declarations: [
@ -16,7 +19,11 @@ import { SingleRecordValidatorComponent } from './pages/single-record-validator/
],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
InputModule
],
providers: [],
bootstrap: [AppComponent]

View File

@ -1,50 +1,16 @@
<div id="page_content">
<div id="page_content_header" class="uk-blur-background" offset="65">
<div class="uk-container uk-container-large">
<div class="uk-section">
<div class="uk-section" [formGroup]="form">
<h6>1. Select guidelines (*)</h6>
<div class="uk-width-1-2@m uk-grid-margin uk-first-column">
<div input="" type="select">
<div id="input-12">
<div class="input-wrapper inner active" tabindex="0" aria-haspopup="true" aria-expanded="false">
<div click-outside-or-esc="" class="input-box select">
<div class="placeholder"><label>guidelines <sup>*</sup><!----></label></div><!---->
<div class="uk-flex uk-flex-middle" aria-expanded="false" tabindex="0"
uk-tooltip="title: Public; delay: 500; pos: bottom-left" title=""><!----><!----><!----><!---->
<div class="input uk-width-expand uk-text-truncate">Public</div><!----><!----><!----><!----><!---->
<!----><!---->
<div class="uk-margin-small-left icon"><!----><!---->
<div><!----><span class="uk-flex"><span class="material-icons" style="font-size: 20px;">arrow_drop_down</span></span>
<!----><!----></div><!----><!----><!----><!----></div><!----></div>
<div class="tools"></div>
</div>
</div><!----></div><!----><!----><span class="uk-text-danger uk-text-small"></span><span
class="uk-text-warning uk-text-small"><!----></span><!----><span class="uk-text-small"></span></div>
</div>
<div input class="uk-width-large" [formInput]="form.get('guidelines')" placeholder="Select a guideline" [options]="options" type="select"></div>
<h6>2. Paste metadata record (*)</h6>
<div class="uk-width-1-1 uk-grid-margin uk-first-column">
<div input="" placeholder="Description">
<div id="input-11">
<div class="input-wrapper inner">
<div click-outside-or-esc="" class="input-box">
<!-- <div class="placeholder"><label>Metadata record &lt;!&ndash;&ndash;&gt;</label></div>&lt;!&ndash;&ndash;&gt;-->
<div class="uk-flex"><!----><textarea class="input ng-untouched ng-pristine ng-valid"
rows="15"></textarea><!----><!----><!----><!----><!----><!---->
</div>
<div class="tools"></div>
</div>
</div><!----></div><!----><!----><span class="uk-text-danger uk-text-small"></span><span
class="uk-text-warning uk-text-small"><!----></span><!----><span class="uk-text-small"></span></div>
</div>
<div input class="uk-width-1-1 uk-margin-top" [formInput]="form.get('xml')" placeholder="Paste your xml here" type="textarea" [rows]="15"></div>
<div class="uk-margin-medium-top">
<button class="uk-button uk-button-primary uk-flex uk-flex-middle uk-flex-wrap">
<button class="uk-button uk-flex uk-flex-middle uk-flex-wrap"
[class.uk-button-primary]="form.valid" [class.uk-disabled]="!form.valid" (click)="validate()">
<div name="cloud_upload">
<span class="uk-flex"><span class="material-icons" style="font-size: 20px;">check</span></span>
</div>
@ -52,93 +18,16 @@
</button>
</div>
<div class="uk-margin-large-top">
<h6>Validation Results</h6>
<div *ngIf="!result" class="uk-alert uk-alert-primary">
No validated metadata record yet
</div>
<div *ngFor="let resultString of result">
{{resultString}}
</div>
</div>
</div>
</div>
</div>
</div>
<!--<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">-->
<!-- <div class="uk-grid uk-grid-large" uk-grid>-->
<!-- <div class="uk-width-1-2@m">-->
<!-- <div input id="name" [formInput]="stakeholderFb.get('name')"-->
<!-- placeholder="Name"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-2@m">-->
<!-- <div input [formInput]="stakeholderFb.get('alias')"-->
<!-- placeholder="URL Alias"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-3@m">-->
<!-- <div input [formInput]="stakeholderFb.get('index_id')"-->
<!-- placeholder="Index ID"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-3@m">-->
<!-- <div input [formInput]="stakeholderFb.get('index_name')"-->
<!-- placeholder="Index Name"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-3@m">-->
<!-- <div input [formInput]="stakeholderFb.get('index_shortName')"-->
<!-- placeholder="Index Short Name"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-1">-->
<!-- <div input [type]="'textarea'" placeholder="Description"-->
<!-- [rows]="4" [formInput]="stakeholderFb.get('description')"></div>-->
<!-- </div>-->
<!-- <div class="uk-width-1-1">-->
<!-- <input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>-->
<!-- <div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-grid uk-grid-column-large" uk-grid>-->
<!-- <div class="uk-margin-top uk-width-auto@l uk-width-1-1">-->
<!-- <div class="uk-grid uk-grid-column-large uk-flex-middle" uk-grid>-->
<!-- <div class="uk-width-auto@l uk-width-1-1 uk-flex uk-flex-center">-->
<!-- <button class="uk-button uk-button-primary uk-flex uk-flex-middle uk-flex-wrap"-->
<!-- (click)="file.click()">-->
<!-- <icon name="cloud_upload" [flex]="true"></icon>-->
<!-- <span class="uk-margin-small-left">Upload a file</span>-->
<!-- </button>-->
<!-- </div>-->
<!-- <div class="uk-text-center uk-text-bold uk-width-expand">-->
<!-- OR-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'" [formInput]="stakeholderFb.get('logoUrl')"></div>-->
<!-- </div>-->
<!-- <div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">-->
<!-- <div class="uk-card uk-card-default uk-text-center uk-border-circle">-->
<!-- <img class="uk-position-center uk-blend-multiply" [src]="photo">-->
<!-- </div>-->
<!-- <div class="uk-margin-left">-->
<!-- <button (click)="remove()" class="uk-button-danger uk-icon-button uk-icon-button-small">-->
<!-- <icon [flex]="true" ratio="0.8" name="delete"></icon>-->
<!-- </button>-->
<!-- </div>-->
<!-- <div class="uk-margin-small-left">-->
<!-- <button class="uk-button-secondary uk-icon-button uk-icon-button-small" (click)="file.click()">-->
<!-- <icon [flex]="true" ratio="0.8" name="edit"></icon>-->
<!-- </button>-->
<!-- </div>-->
<!-- </div>-->
<!-- &lt;!&ndash; Full width error message &ndash;&gt;-->
<!-- <div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div>-->
<!-- </div>-->
<!-- <div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">-->
<!-- <div input [formInput]="stakeholderFb.get('visibility')"-->
<!-- [placeholder]="'Select a status'"-->
<!-- [options]="stakeholderUtils.statuses" type="select"></div>-->
<!-- </div>-->
<!-- <div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">-->
<!-- <div input [formInput]="stakeholderFb.get('type')"-->
<!-- [placeholder]="'Select a type'"-->
<!-- [options]="types" type="select"></div>-->
<!-- </div>-->
<!-- <ng-container *ngIf="canChooseType">-->
<!-- <div class="uk-width-1-3@m">-->
<!-- <div [placeholder]="'Select a template'"-->
<!-- input [formInput]="stakeholderFb.get('defaultId')"-->
<!-- [options]="defaultStakeholdersOptions" type="select"></div>-->
<!-- </div>-->
<!-- </ng-container>-->
<!-- </div>-->
<!--</form>-->
<!--<div #notify [class.uk-hidden]="!stakeholderFb" notify-form class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div>-->

View File

@ -1,4 +1,7 @@
import { Component, OnInit } from '@angular/core';
import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms";
import {SingleRecordValidatorService} from "./single-record-validator.service";
import {Option} from "../../shared/utils/input/input.component";
@Component({
selector: 'app-single-record-validator',
@ -6,10 +9,28 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./single-record-validator.component.less']
})
export class SingleRecordValidatorComponent implements OnInit {
public options: Option[] = [
{label: 'Data Archive Guidelines V2 Profile', value: 'dataArchiveGuidelinesV2Profile'},
{label: 'Literature Guidelines V3 Profile', value: 'literatureGuidelinesV3Profile'},
{label: 'Literature Guidelines V4 Profile', value: 'literatureGuidelinesV4Profile'}
];
public form: UntypedFormGroup;
public result: any;
constructor() { }
ngOnInit(): void {
constructor(private fb: UntypedFormBuilder, private validator: SingleRecordValidatorService) {
this.form = this.fb.group({
guidelines: this.fb.control("", Validators.required),
xml: this.fb.control('', Validators.required)
});
}
ngOnInit(): void {}
public validate() {
this.validator.validateRecord(this.form.get('xml')?.getRawValue(), this.form.get('guidelines')?.getRawValue()).subscribe(
result => {
this.result = result;
}
)
}
}

View File

@ -0,0 +1,18 @@
import {Injectable} from "@angular/core";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Observable} from "rxjs";
import {environment} from "../../../environments/environment";
@Injectable({
providedIn: "root"
})
export class SingleRecordValidatorService {
constructor(private http: HttpClient) {}
validateRecord(xml: string, guidelinesName: string): Observable<any> {
let url = environment.validatorAPI + "validate?guidelines="+guidelinesName;
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
return this.http.post<any>(url, xml, {headers: headers});
}
}

View File

@ -0,0 +1,33 @@
import {Directive, ElementRef, EventEmitter, HostListener, Output} from '@angular/core';
export interface ClickEvent {
event: any,
clicked: boolean;
}
@Directive({
selector: '[click-outside-or-esc]'
})
export class ClickOutsideOrEsc {
@Output('clickOutside') clickOutside: EventEmitter<ClickEvent> = new EventEmitter<ClickEvent>();
constructor(private elementRef: ElementRef) {}
@HostListener('document:click', ['$event'])
click(event) {
if(event.isTrusted) {
this.clickOutside.emit({
event: event,
clicked: !(this.elementRef && this.elementRef.nativeElement.contains(event.target))
});
}
}
@HostListener('window:keydown.escape', ['$event'])
esc(event: KeyboardEvent) {
this.clickOutside.emit({
event: event,
clicked: true
});
}
}

View File

@ -0,0 +1,14 @@
import {NgModule} from "@angular/core";
import {ClickOutsideOrEsc} from "./click-outside-or-esc.directive";
import {LongClick} from "./long-click.directive";
@NgModule({
imports: [],
declarations: [
ClickOutsideOrEsc, LongClick
],
exports: [
ClickOutsideOrEsc, LongClick
]
})
export class ClickModule {}

View File

@ -0,0 +1,72 @@
import {Directive, EventEmitter, HostListener, Input, Output} from '@angular/core';
@Directive({
selector: '[long-click]'
})
export class LongClick {
@Input() duration: number = 500;
@Output() onLongPress: EventEmitter<any> = new EventEmitter();
@Output() onLongPressing: EventEmitter<any> = new EventEmitter();
@Output() onLongPressEnd: EventEmitter<any> = new EventEmitter();
private pressing: boolean;
private longPressing: boolean;
private timeout: any;
private mouseX: number = 0;
private mouseY: number = 0;
@HostListener('mousedown', ['$event'])
onMouseDown(event) {
// don't do right/middle clicks
if (event.which !== 1) return;
this.mouseX = event.clientX;
this.mouseY = event.clientY;
this.pressing = true;
this.longPressing = false;
this.timeout = setTimeout(() => {
this.longPressing = true;
this.onLongPress.emit(event);
this.loop(event);
}, this.duration);
this.loop(event);
}
@HostListener('mousemove', ['$event'])
onMouseMove(event) {
if (this.pressing && !this.longPressing) {
const xThres = (event.clientX - this.mouseX) > 10;
const yThres = (event.clientY - this.mouseY) > 10;
if (xThres || yThres) {
this.endPress();
}
}
}
loop(event) {
if (this.longPressing) {
this.timeout = setTimeout(() => {
this.onLongPressing.emit(event);
this.loop(event);
}, 50);
}
}
endPress() {
clearTimeout(this.timeout);
this.longPressing = false;
this.pressing = false;
this.onLongPressEnd.emit(true);
}
@HostListener('mouseup')
onMouseUp() {
this.endPress();
}
}

View File

@ -0,0 +1,626 @@
import {
AfterViewInit,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
HostListener,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild
} from "@angular/core";
import {AbstractControl, UntypedFormArray, UntypedFormControl, ValidatorFn} from "@angular/forms";
// import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Subscription} from "rxjs";
import {ClickEvent} from "../click/click-outside-or-esc.directive";
// import {EnvProperties} from "../../utils/properties/env-properties";
// import {properties} from "../../../../environments/environment";
export type InputType = 'text' | 'URL' | 'logoURL' | 'autocomplete' | 'autocomplete_soft' | 'textarea' | 'select' | 'chips';
export interface Option {
icon?: string,
iconClass?: string,
value: any,
label: string,
tooltip?: string,
disabled?: boolean,
hidden?: boolean
}
export interface Placeholder {
label: string,
static?: boolean
}
declare var UIkit;
/**
* WARNING! dashboard-input selector is @deprecated, use input instead
*
* 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.
*
* */
@Component({
selector: '[dashboard-input], [input]',
template: `
<div *ngIf="formControl" [id]="id">
<div class="input-wrapper" [class.disabled]="formControl.disabled" [class.opened]="opened"
[class.focused]="focused" [ngClass]="inputClass" [class.hint]="hint"
[class.active]="(formAsControl?.value || selectable || formAsArray?.length > 0 || getLabel(formAsControl?.value)) && !focused"
[class.danger]="(formControl.invalid && (formControl.touched || !!searchControl?.touched)) || (!!searchControl?.invalid && !!searchControl?.touched)">
<div #inputBox class="input-box" [class.select]="selectable" click-outside-or-esc
[class.static]="placeholderInfo?.static" (clickOutside)="click($event)">
<div *ngIf="!placeholderInfo?.static && placeholderInfo.label" class="placeholder">
<label>{{placeholderInfo.label}} <sup *ngIf="required">*</sup></label>
</div>
<div class="uk-flex" [class.uk-flex-middle]="type !== 'textarea'"
[attr.uk-tooltip]="(tooltip && formControl.value && !focused && type !== 'chips' && type !== 'textarea')?('title: ' + getTooltip(formControl.value) + '; delay: 500; pos: bottom-left'):null">
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
[formControl]="formAsControl" [class.uk-text-truncate]="!focused">
</ng-template>
<ng-template [ngIf]="type === 'textarea'">
<textarea #textArea class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
[rows]="rows" [formControl]="formAsControl"></textarea>
</ng-template>
<ng-template [ngIf]="type === 'select'">
<ng-container *ngIf="placeholderInfo?.static">
<div *ngIf="!getLabel(formControl.value)"
class="input placeholder uk-width-expand uk-text-truncate">{{placeholderInfo.label}}</div>
<div *ngIf="getLabel(formControl.value)"
class="input uk-width-expand uk-text-truncate">{{getLabel(formControl.value)}}</div>
</ng-container>
<ng-container *ngIf="!placeholderInfo?.static">
<div *ngIf="!getLabel(formControl.value)" class="input uk-width-expand uk-text-truncate">{{noValueSelected}}</div>
<div *ngIf="getLabel(formControl.value)"
class="input uk-width-expand uk-text-truncate">{{getLabel(formControl.value)}}</div>
</ng-container>
</ng-template>
<ng-template [ngIf]="type === 'autocomplete'">
<input *ngIf="focused" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
#searchInput class="input" [formControl]="searchControl" [class.uk-text-truncate]="!focused">
<div *ngIf="!focused && !selectable" class="input uk-text-truncate">{{getLabel(formAsControl.value)}}</div>
<ng-container *ngIf="!focused && selectable" >
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate">{{noValueSelected}}</div>
<div *ngIf="getLabel(formControl.value)" class="input uk-text-truncate">{{getLabel(formControl.value)}}</div>
</ng-container>
</ng-template>
<ng-template [ngIf]="type === 'autocomplete_soft'">
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
[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-width-expand" uk-grid>
<div *ngFor="let chip of formAsArray.controls; let i=index" [class.uk-hidden]="!focused && i > 0"
class="chip">
<div class="uk-label uk-label-small uk-flex uk-flex-middle"
[attr.uk-tooltip]="(tooltip)?('title: ' + getLabel(chip.value) + '; delay: 500; pos: bottom-left'):null">
<span class="uk-text-truncate uk-width-expand">{{getLabel(chip.value)}}</span>
<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)"
class="uk-width-small 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 > 1"
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
+ {{(formAsArray.length - 1)}} more
</div>
</div>
</ng-template>
<div *ngIf="(formControl.disabled && disabledIcon) || icon || (selectable && selectArrow) || type === 'autocomplete' || searchable"
class="uk-margin-small-left icon">
<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>
<icon *ngIf="!icon && selectable && selectArrow" [name]="selectArrow" [flex]="true"></icon>
<button *ngIf="!!searchControl?.value && type === 'autocomplete'" class="uk-close uk-icon"
(click)="resetSearch($event)">
<icon [flex]="true" name="close"></icon>
</button>
<button *ngIf="!!formControl?.value && searchable" class="uk-close uk-icon" (click)="resetValue($event)">
<icon [flex]="true" name="close"></icon>
</button>
</ng-template>
</div>
</div>
<div class="tools">
<ng-content select="[tools]"></ng-content>
</div>
</div>
</div>
<div class="options uk-dropdown" *ngIf="filteredOptions && filteredOptions.length > 0 && opened" #optionBox
uk-dropdown="pos: bottom-justify; mode: none; offset: 15; boundary-align: true;" [attr.boundary]="'#' + id">
<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' : ''">
<span [attr.uk-tooltip]="(tooltip)?('title: ' + (option.tooltip ? option.tooltip : option.label) + '; delay: 500; pos:bottom-left'):null">{{option.label}}</span>
</a>
</li>
</ul>
</div>
</div>
<span *ngIf="formControl?.invalid && formControl?.touched" class="uk-text-danger">
<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>
`
})
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
private static INPUT_COUNTER: number = 0;
/** Deprecated options*/
/** @deprecated */
@Input('label') label: string;
/** @deprecated */
@Input() extraLeft: boolean = true;
/** @deprecated */
@Input() gridSmall: boolean = false;
/** @deprecated */
@Input() hideControl: boolean = false;
/** @deprecated */
@Input() flex: 'middle' | 'top' | 'bottom' = 'middle';
/** @deprecated */
@Input() iconLeft: boolean = false;
/** @deprecated */
@Input() removable: boolean = true;
/** @deprecated */
@Input() smallChip: boolean = false;
/** @deprecated */
@Input() panelWidth: number = 300;
/** @deprecated */
@Input() panelClass: string = null;
/** Basic information */
@Input('formInput') formControl: AbstractControl;
@Input('type') type: InputType = 'text';
@Input() validators: ValidatorFn[] | ValidatorFn;
@Input() disabled: boolean = false;
@Input() disabledIcon: string = 'lock';
@Input() value: any | any[];
@Output() valueChange = new EventEmitter<any | any[]>();
@Input() hint: string;
@Input() tooltip: boolean = false;
@Input() searchable: boolean = false;
/** Text */
@ViewChild('input') input: ElementRef;
/** Textarea options */
@ViewChild('textArea') textArea: ElementRef;
@Input('rows') rows: number = 3;
/** Select | Autocomplete | chips available options */
@Input() selectArrow: string = 'arrow_drop_down';
@Input() selectedIndex: number = 0;
@Input() selectable: boolean = false;
@Input() noValueSelected: string = 'No option selected';
/** Chips && Autocomplete*/
public filteredOptions: Option[] = [];
public searchControl: UntypedFormControl;
/** Use modifier's class(es) to change view of your Input */
@Input() inputClass: string = 'inner';
/** Icon on the input */
@Input() icon: string = null;
/** Chip options */
@Input() addExtraChips: boolean = false;
@Input() showOptionsOnEmpty: boolean = true;
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
/** LogoUrl information */
public secure: boolean = true;
/** Internal basic information */
public id: string;
public placeholderInfo: Placeholder = {label: '', static: true};
public required: boolean = false;
public focused: boolean = false;
public opened: boolean = false;
private initValue: any;
private optionsArray: Option[] = [];
private optionsBreakpoint: number = 6;
private subscriptions: any[] = [];
@ViewChild('inputBox') inputBox: ElementRef;
@ViewChild('optionBox') optionBox: ElementRef;
@ViewChild('searchInput') searchInput: ElementRef;
@Input()
set placeholder(placeholder: string | Placeholder) {
if (typeof placeholder === 'string') {
this.placeholderInfo = {label: placeholder, static: false};
} else {
if (placeholder.static && (this.type === 'autocomplete' || this.type === 'chips' || this.hint)) {
placeholder.static = false;
console.debug('Static placeholder is not available in this type of input and if hint is available.');
}
this.placeholderInfo = placeholder;
}
}
@Input()
set options(options: (Option | string | number) []) {
this.optionsArray = options.map(option => {
if (typeof option === 'string' || typeof option === 'number') {
return {
label: option.toString(),
value: option
};
} else {
return option;
}
});
if(!this.tooltip) {
this.tooltip = this.optionsArray.length > 0;
}
if(this.type === "select") {
if (this.optionsArray.length > this.optionsBreakpoint) {
this.type = 'autocomplete';
this.showOptionsOnEmpty = true;
this.icon = this.selectArrow;
}
this.selectable = true;
}
}
constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef) {}
@HostListener('window:keydown.arrowUp', ['$event'])
arrowUp(event: KeyboardEvent) {
if (this.opened) {
event.preventDefault();
if (this.selectedIndex > 0) {
this.selectedIndex--;
this.optionBox.nativeElement.scrollBy(0, -34);
}
}
}
@HostListener('window:keydown.arrowDown', ['$event'])
arrowDown(event: KeyboardEvent) {
if (this.opened) {
event.preventDefault();
if (this.selectedIndex < (this.filteredOptions.length - 1)) {
this.selectedIndex++;
this.optionBox.nativeElement.scrollBy(0, 34);
}
}
}
@HostListener('window:keydown.enter', ['$event'])
enter(event: KeyboardEvent) {
if (this.opened && this.optionBox) {
event.preventDefault();
if (this.filteredOptions[this.selectedIndex]) {
this.selectOption(this.filteredOptions[this.selectedIndex], event);
}
this.open(false);
event.stopPropagation();
} else {
this.focus(false, event);
}
}
click(event: ClickEvent) {
this.focus(!event.clicked, event);
}
ngOnInit() {
InputComponent.INPUT_COUNTER++;
this.id = 'input-' + InputComponent.INPUT_COUNTER;
if (!this.formControl) {
if (Array.isArray(this.value)) {
this.formControl = new UntypedFormArray([]);
this.value.forEach(value => {
this.formAsArray.push(new UntypedFormControl(value, this.validators));
});
} else {
this.formControl = new UntypedFormControl(this.value);
this.formControl.setValidators(this.validators);
}
if (this.disabled) {
this.formControl.disable();
}
}
}
ngAfterViewInit() {
this.reset();
}
ngOnChanges(changes: SimpleChanges) {
if (this.formControl) {
if (changes.value) {
this.formControl.setValue(this.value);
}
if (changes.formControl || changes.validators || changes.options) {
this.reset();
}
if (changes.disabled) {
if (this.disabled) {
this.formControl.disable();
} else {
this.formControl.enable();
}
}
}
}
ngOnDestroy(): void {
this.unsubscribe();
}
get formAsControl(): UntypedFormControl {
if (this.formControl instanceof UntypedFormControl) {
return this.formControl;
} else {
return null;
}
}
get formAsArray(): UntypedFormArray {
if (this.formControl instanceof UntypedFormArray) {
return this.formControl;
} else {
return null;
}
}
reset() {
this.secure = true;
this.unsubscribe();
this.initValue = this.copy(this.formControl.value);
if (this.type === 'logoURL') {
this.secure = (!this.initValue || this.initValue.includes('https://'));
}
if (this.optionsArray) {
this.filteredOptions = this.filter('');
this.cdr.detectChanges();
}
if (this.type === 'chips' || this.type === 'autocomplete') {
if (!this.searchControl) {
this.searchControl = new UntypedFormControl('', this.validators);
}
this.subscriptions.push(this.searchControl.valueChanges.subscribe(value => {
this.filteredOptions = this.filter(value);
this.cdr.detectChanges();
if (this.focused) {
this.open(true);
setTimeout(() => {
this.searchInput.nativeElement.focus();
this.searchInput.nativeElement.value = value;
}, 0);
}
}));
}
if (this.formControl.validator) {
let validator = this.formControl.validator({} as AbstractControl);
this.required = (validator && validator.required);
}
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
if (this.formControl.enabled) {
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);
}
}
if ((this.value && value && this.value !== value) || (!this.value && value) || this.value && !value) {
this.valueChange.emit(this.formControl.value);
}
}
}));
if (this.input) {
this.input.nativeElement.disabled = this.formControl.disabled;
}
}
unsubscribe() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscription) {
subscription.unsubscribe();
}
});
}
remove(index: number, event) {
if (this.focused) {
this.formAsArray.removeAt(index);
this.formAsArray.markAsDirty();
this.focus(true);
this.searchControl.setValue('');
event.stopPropagation();
}
}
private filter(value: string): Option[] {
let options = this.optionsArray.filter(option => !option.hidden);
if (this.type === "chips") {
options = options.filter(option => !this.formAsArray.value.find(value => this.equals(option.value, value)));
}
if ((!value || value.length == 0)) {
this.selectedIndex = 0;
return (this.showOptionsOnEmpty) ? options : [];
}
const filterValue = value.toString().toLowerCase();
options = options.filter(option => option.label.toLowerCase().indexOf(filterValue) != -1);
this.selectedIndex = options.findIndex(option => option.value === this.formControl.value);
if (this.selectedIndex === -1) {
this.selectedIndex = 0;
}
return options;
}
add(event) {
if (this.addExtraChips && this.searchControl.value && this.searchControl.valid) {
if (event && event.stopPropagation) {
event.stopPropagation();
}
this.formAsArray.push(new UntypedFormControl(this.searchControl.value, this.validators));
this.formAsArray.markAsDirty();
}
this.searchControl.setValue('');
}
getLabel(value: any): string {
let option = this.optionsArray.find(option => this.equals(option.value, value));
return (option) ? option.label : (value);
}
getTooltip(value: any): string {
let option = this.optionsArray.find(option => this.equals(option.value, value));
return (option) ? (option.tooltip ? option.tooltip : option.label) : (value);
}
focus(value: boolean, event = null) {
if (this.focused) {
this.formControl.markAsTouched();
}
this.focused = value;
this.cdr.detectChanges();
if (this.focused) {
if (this.input) {
this.input.nativeElement.focus();
} else if (this.textArea) {
this.textArea.nativeElement.focus();
} else if (this.searchInput) {
this.searchInput.nativeElement.focus();
}
if (this.selectArrow) {
this.open(!this.opened);
} else if (this.type !== 'autocomplete' || this.showOptionsOnEmpty || !this.formControl.value) {
this.open(true);
}
} else {
this.open(false);
if (this.input) {
this.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.focusEmitter.emit(this.focused);
}
open(value: boolean) {
this.opened = value && this.formControl.enabled;
this.cdr.detectChanges();
if (this.optionBox && 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 {
if (this.optionBox) {
UIkit.dropdown(this.optionBox.nativeElement).hide();
this.focused = false;
}
}
}
resetSearch(event: any) {
event.stopPropagation();
this.searchControl.setValue('');
this.focus(true, event);
}
resetValue(event: any) {
event.stopPropagation();
this.formControl.setValue('');
this.focus(true, event);
}
selectOption(option: Option, event) {
if (this.formControl.enabled) {
if (this.formAsControl) {
this.formAsControl.setValue(option.value);
} else if (this.formAsArray) {
this.formAsArray.push(new UntypedFormControl(option.value));
this.formAsArray.markAsDirty();
event.stopPropagation();
this.focus(true);
this.searchControl.setValue('');
}
}
}
// External Helper Methods
public equals(object1, object2) {
return object1 === object2 || JSON.stringify(object1) === JSON.stringify(object2);
}
public copy(obj: any): any {
let copy;
// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;
// Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}
// Handle Array
if (obj instanceof Array) {
copy = [];
for (let i = 0, len = obj.length; i < len; i++) {
copy[i] = this.copy(obj[i]);
}
return copy;
}
// Handle Map
if (obj instanceof Map) {
return new Map(obj.entries());
}
// Handle Object
if (obj instanceof Object) {
copy = {};
for (let attr in obj) {
if (obj.hasOwnProperty(attr)) {
copy[attr] = this.copy(obj[attr]);
}
}
return copy;
}
throw new Error("Unable to copy obj! Its type isn't supported.");
}
}

View File

@ -0,0 +1,24 @@
import {NgModule} from '@angular/core';
import {InputComponent} from "./input.component";
import {CommonModule} from "@angular/common";
import {RouterModule} from "@angular/router";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {ClickModule} from "../click/click.module";
@NgModule({
imports: [
CommonModule,
RouterModule,
FormsModule,
ReactiveFormsModule,
ClickModule
],
exports: [
InputComponent
],
declarations: [
InputComponent
]
})
export class InputModule {
}

@ -1 +1 @@
Subproject commit c645362896b10ae00563f38337aa0011c640cb20
Subproject commit 936fac297322fa252af930cab3c0e69efe57c1a5

@ -1 +1 @@
Subproject commit 8b8db18d0b34ed61d76936f0e44ef856a5f6df5c
Subproject commit 8bb758b340d05b50b65da48863ff7ed69fdc122b

View File

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
validatorAPI: "http://duffy.di.uoa.gr:8080/uoa-validator-api/"
};
/*

View File

@ -5,9 +5,9 @@
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"strict": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
@ -27,6 +27,6 @@
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
"strictTemplates": false
}
}