@asi-ngtools/lib
Version:
This project is a little components library, simple to use, which will help you to simplify your project.
1,670 lines (1,654 loc) • 298 kB
JavaScript
import { RouterModule } from '@angular/router';
import { cloneDeep } from 'lodash';
import { HttpClient } from '@angular/common/http';
import { DOCUMENT, DomSanitizer } from '@angular/platform-browser';
import { trigger, style, animate, transition } from '@angular/animations';
import { CommonModule, isPlatformBrowser } from '@angular/common';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { FormsModule, ReactiveFormsModule, NG_VALUE_ACCESSOR, FormControl, FormGroupDirective, FormGroupName, Validators } from '@angular/forms';
import moment from 'moment';
import { isObservable, of, from, Subject, Observable, throwError } from 'rxjs';
import { debounceTime, switchMap, tap, map, catchError, first } from 'rxjs/operators';
import { Directive, TemplateRef, Component, Input, EventEmitter, Output, NgModule, Renderer2, ElementRef, forwardRef, Inject, PLATFORM_ID, Injector, ContentChild, ViewChild, HostListener, Injectable, ComponentFactoryResolver, ApplicationRef, NgZone, HostBinding, ContentChildren, ViewContainerRef, Renderer, ChangeDetectorRef, IterableDiffers, ViewChildren, Pipe } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiComponentTemplate {
constructor() {
}
}
AsiComponentTemplate.decorators = [
{ type: Component, args: [{
selector: 'asi-option, asi-tag, asi-selected, asi-empty, asi-header, asi-cell, asi-tree-node, asi-tree-leaf, asi-clear',
template: '<ng-content></ng-content>'
}] }
];
/** @nocollapse */
AsiComponentTemplate.ctorParameters = () => [];
class AsiComponentTemplateOptionDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateOptionDef.decorators = [
{ type: Directive, args: [{
selector: '[asiOptionDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateOptionDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateTagDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateTagDef.decorators = [
{ type: Directive, args: [{
selector: '[asiTagDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateTagDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateSelectedDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateSelectedDef.decorators = [
{ type: Directive, args: [{
selector: '[asiSelectedDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateSelectedDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateEmptyDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateEmptyDef.decorators = [
{ type: Directive, args: [{
selector: '[asiEmptyDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateEmptyDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateClearDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateClearDef.decorators = [
{ type: Directive, args: [{
selector: '[asiClearDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateClearDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateTableHeaderDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateTableHeaderDef.decorators = [
{ type: Directive, args: [{
selector: '[asiTableHeaderDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateTableHeaderDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateTabHeaderDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateTabHeaderDef.decorators = [
{ type: Directive, args: [{
selector: '[asiTabHeaderDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateTabHeaderDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateNavHeaderDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateNavHeaderDef.decorators = [
{ type: Directive, args: [{
selector: '[asiNavHeaderDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateNavHeaderDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateCollapseHeaderDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateCollapseHeaderDef.decorators = [
{ type: Directive, args: [{
selector: '[asiCollapseHeaderDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateCollapseHeaderDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateCellDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateCellDef.decorators = [
{ type: Directive, args: [{
selector: '[asiCellDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateCellDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateColumnDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateColumnDef.decorators = [
{ type: Directive, args: [{
selector: '[asiColumnDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateColumnDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateTreeNodeDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateTreeNodeDef.decorators = [
{ type: Directive, args: [{
selector: '[asiTreeNodeDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateTreeNodeDef.ctorParameters = () => [
{ type: TemplateRef }
];
class AsiComponentTemplateTreeLeafDef {
/**
* @param {?} template
*/
constructor(template) {
this.template = template;
}
}
AsiComponentTemplateTreeLeafDef.decorators = [
{ type: Directive, args: [{
selector: '[asiTreeLeafDef]',
},] }
];
/** @nocollapse */
AsiComponentTemplateTreeLeafDef.ctorParameters = () => [
{ type: TemplateRef }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class DefaultControlValueAccessor {
constructor() {
/**
* is enabled/disabled
*/
this.disabled = false;
/**
* Event emitted when component value changed
*/
this.onValueChange = new EventEmitter();
this.onChange = () => { };
this.onTouched = () => { };
}
/**
* @return {?}
*/
get value() {
return this._value;
}
/**
* @param {?} val
* @return {?}
*/
set value(val) {
this._value = val;
this.onTouched();
this.onChange(val);
this.onValueChange.emit(this.value);
}
/**
* @param {?} fn
* @return {?}
*/
registerOnChange(fn) {
this.onChange = fn;
}
/**
* @param {?} fn
* @return {?}
*/
registerOnTouched(fn) {
this.onTouched = fn;
}
/**
* @param {?} value
* @return {?}
*/
writeValue(value) {
this._value = value;
}
/**
* @param {?} disabled
* @return {?}
*/
setDisabledState(disabled) {
this.disabled = disabled;
}
}
DefaultControlValueAccessor.propDecorators = {
_value: [{ type: Input, args: ['value',] }],
disabled: [{ type: Input }],
onValueChange: [{ type: Output }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiNgToolsBaseModule {
/**
* @return {?}
*/
static forRoot() {
return {
ngModule: AsiNgToolsBaseModule,
providers: [TranslateService]
};
}
}
AsiNgToolsBaseModule.decorators = [
{ type: NgModule, args: [{
declarations: [
AsiComponentTemplateTabHeaderDef,
AsiComponentTemplateTableHeaderDef,
AsiComponentTemplateOptionDef,
AsiComponentTemplateEmptyDef,
AsiComponentTemplateClearDef,
AsiComponentTemplateSelectedDef,
AsiComponentTemplateColumnDef,
AsiComponentTemplateCellDef,
AsiComponentTemplateTagDef,
AsiComponentTemplateTreeNodeDef,
AsiComponentTemplateTreeLeafDef,
AsiComponentTemplateNavHeaderDef,
AsiComponentTemplateCollapseHeaderDef,
AsiComponentTemplate
],
imports: [TranslateModule,
FormsModule,
ReactiveFormsModule,
CommonModule,
RouterModule],
exports: [TranslateModule,
FormsModule,
ReactiveFormsModule,
CommonModule,
RouterModule,
AsiComponentTemplateTabHeaderDef,
AsiComponentTemplateTableHeaderDef,
AsiComponentTemplateOptionDef,
AsiComponentTemplateEmptyDef,
AsiComponentTemplateClearDef,
AsiComponentTemplateSelectedDef,
AsiComponentTemplateTagDef,
AsiComponentTemplateColumnDef,
AsiComponentTemplateCellDef,
AsiComponentTemplateTreeNodeDef,
AsiComponentTemplateTreeLeafDef,
AsiComponentTemplateCollapseHeaderDef,
AsiComponentTemplate],
entryComponents: [],
providers: [TranslateService]
},] }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiButtonComponent {
/**
* @param {?} renderer
* @param {?} elementRef
*/
constructor(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
/**
* html type
*/
this.type = 'button';
/**
* button design
*/
this.design = 'flat';
/**
* button size
*/
this.size = 'standard';
/**
* ensable/disable the button
*/
this.disabled = false;
}
/**
* @return {?}
*/
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, `button-${this.design}`);
this.renderer.addClass(this.elementRef.nativeElement, `button-${this.size}`);
}
/**
* @return {?}
*/
ngOnChanges() {
if (this.disabled) {
this.renderer.addClass(this.elementRef.nativeElement, 'disabled');
}
else {
this.renderer.removeClass(this.elementRef.nativeElement, 'disabled');
}
}
}
AsiButtonComponent.decorators = [
{ type: Component, args: [{
selector: 'asi-button',
host: { 'class': 'asi-component asi-button' },
template: "<button [attr.id]=\"id\" [attr.name]=\"name\" [attr.type]=\"type\" [disabled]=\"disabled\" [attr.disabled]=\"disabled ? 'disabled' : null\">\n <ng-content></ng-content>\n</button>\n"
}] }
];
/** @nocollapse */
AsiButtonComponent.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
AsiButtonComponent.propDecorators = {
id: [{ type: Input }],
name: [{ type: Input }],
type: [{ type: Input }],
design: [{ type: Input }],
size: [{ type: Input }],
disabled: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiLinkButtonComponent {
/**
* @param {?} renderer
* @param {?} elementRef
*/
constructor(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.design = 'flat';
this.href = '';
this.target = '_self';
this.disabled = false;
}
/**
* @return {?}
*/
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, `link-button-${this.design}`);
}
/**
* @return {?}
*/
ngOnChanges() {
if (this.disabled) {
this.renderer.addClass(this.elementRef.nativeElement, 'disabled');
}
else {
this.renderer.removeClass(this.elementRef.nativeElement, 'disabled');
}
}
}
AsiLinkButtonComponent.decorators = [
{ type: Component, args: [{
selector: 'asi-link-button',
host: { 'class': 'asi-component asi-link-button' },
template: "<a [attr.href]=\"href\" [attr.target]=\"target\">\r\n <ng-content></ng-content>\r\n</a>\r\n"
}] }
];
/** @nocollapse */
AsiLinkButtonComponent.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
AsiLinkButtonComponent.propDecorators = {
design: [{ type: Input }],
href: [{ type: Input }],
target: [{ type: Input }],
disabled: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiButtonModule {
/**
* @return {?}
*/
static forRoot() {
return {
ngModule: AsiButtonModule,
providers: []
};
}
}
AsiButtonModule.decorators = [
{ type: NgModule, args: [{
declarations: [AsiButtonComponent, AsiLinkButtonComponent],
imports: [AsiNgToolsBaseModule.forRoot()],
exports: [AsiNgToolsBaseModule, AsiButtonComponent, AsiLinkButtonComponent],
entryComponents: [],
providers: []
},] }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
const months_fr = [
{ num: 1, libelle: 'Janvier' },
{ num: 2, libelle: 'Février' },
{ num: 3, libelle: 'Mars' },
{ num: 4, libelle: 'Avril' },
{ num: 5, libelle: 'Mai' },
{ num: 6, libelle: 'Juin' },
{ num: 7, libelle: 'Juillet' },
{ num: 8, libelle: 'Août' },
{ num: 9, libelle: 'Septembre' },
{ num: 10, libelle: 'Octobre' },
{ num: 11, libelle: 'Novembre' },
{ num: 12, libelle: 'Décembre' },
];
/** @type {?} */
const months_en = [
{ num: 1, libelle: 'January' },
{ num: 2, libelle: 'February' },
{ num: 3, libelle: 'March' },
{ num: 4, libelle: 'April' },
{ num: 5, libelle: 'May' },
{ num: 6, libelle: 'June' },
{ num: 7, libelle: 'July' },
{ num: 8, libelle: 'August' },
{ num: 9, libelle: 'September' },
{ num: 10, libelle: 'October' },
{ num: 11, libelle: 'November' },
{ num: 12, libelle: 'Decemder' }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} array
* @param {?} mapper
* @return {?}
*/
function map$1(array, mapper) {
if (array) {
return array.map(mapper);
}
return array;
}
/**
* @param {?} array
* @param {?} iteratee
* @return {?}
*/
function filter(array, iteratee) {
if (array) {
return array.filter(iteratee);
}
return array;
}
/**
* @param {?} array
* @return {?}
*/
function isArray(array) {
return Array.isArray(array);
}
/**
* @param {?} howManyTimes
* @param {?} iteratee
* @return {?}
*/
function times(howManyTimes, iteratee) {
/** @type {?} */
const res = [];
/** @type {?} */
let index = -1;
while (++index < howManyTimes) {
res.push(iteratee(index));
}
return res;
}
/**
* @param {?} array
* @param {?} iteratee
* @return {?}
*/
function forEach(array, iteratee) {
if (array) {
array.forEach(iteratee);
}
}
/**
* @param {?} array
* @param {?} iteratee
* @return {?}
*/
function remove(array, iteratee) {
/** @type {?} */
let deletedItems = [];
if (array) {
/** @type {?} */
let index = array.length;
while (index--) {
/** @type {?} */
const item = array[index];
if (iteratee(item, index)) {
array.splice(index, 1);
deletedItems.push(item);
}
}
}
return deletedItems;
}
/**
* @param {?} array
* @param {?} index
* @return {?}
*/
function removeAtIndex(array, index) {
if (array) {
array.splice(index, 1);
}
}
/**
* @param {?} object
* @param {?} path
* @param {?=} defaultVal
* @return {?}
*/
function get(object, path, defaultVal) {
/** @type {?} */
const _path = Array.isArray(path)
? path
: path.split('.').filter((index) => index.length);
if (!_path.length) {
return object === undefined ? defaultVal : object;
}
return get(object[_path.shift()], _path, defaultVal);
}
/**
* @param {?} array
* @param {?} finder
* @return {?}
*/
function find(array, finder) {
if (array) {
return array.find(finder);
}
return undefined;
}
/**
* @param {?} value
* @param {?} maxLength
* @return {?}
*/
function truncate(value, maxLength) {
if (value) {
return value.substring(0, maxLength);
}
return value;
}
/**
* @param {?} items
* @param {?} what
* @return {?}
*/
function indexOf(items, what) {
if (items) {
return items.indexOf(what);
}
return -1;
}
/**
* @param {...?} arrays
* @return {?}
*/
function concat(...arrays) {
/** @type {?} */
let newArray = [];
arrays.forEach((array) => {
newArray = newArray.concat(array);
});
return newArray;
}
/**
* @param {?} str
* @param {?} reg
* @param {?} newVal
* @return {?}
*/
function replace(str, reg, newVal) {
if (str) {
return str.replace(reg, newVal);
}
return str;
}
/**
* @param {?} array
* @param {?} key
* @param {?} asc
* @return {?}
*/
function orderByWithoutCase(array, key, asc) {
/** @type {?} */
const order = asc === 'asc' ? -1 : 1;
array.sort((a, b) => {
if (!a[key] && !b[key]) {
return 0;
}
else if (a[key] && !b[key]) {
return -1;
}
else if (!a[key] && b[key]) {
return 1;
}
/** @type {?} */
const value1 = a[key].toLowerCase();
/** @type {?} */
const value2 = b[key].toLowerCase();
if (value1 < value2) {
return order;
}
else if (value1 > value2) {
return -order;
}
return 0;
});
return array;
}
/**
* @param {?} object
* @return {?}
*/
function cloneDeep$1(object) {
return cloneDeep(object);
}
/**
* @param {?} item
* @return {?}
*/
function isEmpty(item) {
return item == null || item.length === 0;
}
/**
* @param {?} items
* @param {?} separator
* @return {?}
*/
function join(items, separator) {
if (items) {
return items.join(separator);
}
return items;
}
/**
* @template T
* @param {?} obs
* @return {?}
*/
function observe(obs) {
if (isObservable(obs)) {
return obs;
}
else if (obs instanceof Promise) {
return from(obs);
}
else {
return of(/** @type {?} */ (obs));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiDmyPickerComponent extends DefaultControlValueAccessor {
/**
* @param {?} platformId
* @param {?} injector
* @param {?} renderer
* @param {?} elementRef
*/
constructor(platformId, injector, renderer, elementRef) {
super();
this.platformId = platformId;
this.injector = injector;
this.renderer = renderer;
this.elementRef = elementRef;
/**
* Label position
*/
this.labelPosition = 'top';
/**
* hide day list
*/
this.dayHidden = false;
this.days = [];
this.months = [];
this.years = [];
}
/**
* @return {?}
*/
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, 'label-' + this.labelPosition);
if (this.isFr()) {
this.months = months_fr;
this.dayLabel = 'Jour';
this.monthLabel = 'Mois';
this.yearLabel = 'Annee';
}
else {
this.months = months_en;
this.dayLabel = 'Day';
this.monthLabel = 'Month';
this.yearLabel = 'Year';
}
this.initDays();
this.initYears();
}
/**
* @return {?}
*/
isFr() {
if (isPlatformBrowser(this.platformId)) {
return navigator.language === 'fr' || navigator.language === 'fr-FR';
}
else {
/** @type {?} */
const request = this.injector.get('request');
if (request && request.asiNgtools) {
/** @type {?} */
const language = request.asiNgtools.language;
if (language) {
return language.substring(0, 2) === 'fr';
}
}
return false;
}
}
/**
* @return {?}
*/
initDays() {
times(31, (time) => {
this.days.push(time + 1);
});
}
/**
* @return {?}
*/
initYears() {
/** @type {?} */
let results = new Array();
/** @type {?} */
let currentYear = new Date().getFullYear();
for (let year = currentYear; year >= 1900; year--) {
results.push(year);
}
this.years = results;
}
/**
* @param {?} month
* @return {?}
*/
onMonthChange(month) {
this.value = { day: this.day, month: month != null ? month.num : null, year: this.year };
}
/**
* @param {?} year
* @return {?}
*/
onYearChange(year) {
this.value = { day: this.day, month: this.month != null ? this.month.num : null, year: year };
}
/**
* @param {?} day
* @return {?}
*/
onDayChange(day) {
this.value = { day: day, month: this.month != null ? this.month.num : null, year: this.year };
}
/**
* @param {?} value
* @return {?}
*/
writeValue(value) {
if (value != null) {
this.day = value.day;
this.month = this.getMontFromNum(value.month);
this.year = value.year;
}
else {
this.day = null;
this.month = null;
this.year = null;
}
this._value = { day: this.day, month: this.month, year: this.year };
}
/**
* @param {?} monthNum
* @return {?}
*/
getMontFromNum(monthNum) {
if (monthNum == null) {
return null;
}
return find(this.months, (month) => {
return month.num === monthNum;
});
}
}
AsiDmyPickerComponent.decorators = [
{ type: Component, args: [{
selector: 'asi-dmypicker',
host: { 'class': 'asi-component asi-dmypicker' },
template: "<label class=\"input-label\" [translate]=\"label\"></label>\r\n<div class=\"asi-dmypicker-container\">\r\n <asi-select class=\"asi-dmy-days\" [disabled]=\"disabled\" [withEmptyValue]=\"true\" [hidden]=\"dayHidden\" [data]=\"days\" [(ngModel)]=\"day\"\r\n (ngModelChange)=\"onDayChange($event)\">\r\n <asi-empty *asiEmptyDef>{{dayLabel}}</asi-empty>\r\n <asi-selected *asiSelectedDef=\"let data\">{{data}}</asi-selected>\r\n <asi-option *asiOptionDef=\"let data\">{{data}}</asi-option>\r\n </asi-select>\r\n <asi-select class=\"asi-dmy-months\" [disabled]=\"disabled\" [withEmptyValue]=\"true\" [data]=\"months\" [(ngModel)]=\"month\" (ngModelChange)=\"onMonthChange($event)\">\r\n <asi-empty *asiEmptyDef>{{monthLabel}}</asi-empty>\r\n <asi-selected *asiSelectedDef=\"let data\">{{data.num + \" - \" + data.libelle}}</asi-selected>\r\n <asi-option *asiOptionDef=\"let data\">{{data.num + \" - \" + data.libelle}}</asi-option>\r\n </asi-select>\r\n <asi-select class=\"asi-dmy-years\" [disabled]=\"disabled\" [withEmptyValue]=\"true\" [data]=\"years\" [(ngModel)]=\"year\" (ngModelChange)=\"onYearChange($event)\">\r\n <asi-empty *asiEmptyDef>{{yearLabel}}</asi-empty>\r\n <asi-selected *asiSelectedDef=\"let data\">{{data}}</asi-selected>\r\n <asi-option *asiOptionDef=\"let data\">{{data}}</asi-option>\r\n </asi-select>\r\n</div>",
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => AsiDmyPickerComponent),
multi: true
}
]
}] }
];
/** @nocollapse */
AsiDmyPickerComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
{ type: Injector },
{ type: Renderer2 },
{ type: ElementRef }
];
AsiDmyPickerComponent.propDecorators = {
label: [{ type: Input }],
labelPosition: [{ type: Input }],
dayHidden: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiCheckboxComponent extends DefaultControlValueAccessor {
/**
* @param {?} renderer
* @param {?} elementRef
*/
constructor(renderer, elementRef) {
super();
this.renderer = renderer;
this.elementRef = elementRef;
/**
* Label position
*/
this.labelPosition = 'top';
/**
* design : checkbox (square) or radio (round)
*/
this.type = 'checkbox';
}
/**
* @return {?}
*/
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, 'label-' + this.labelPosition);
}
/**
* @return {?}
*/
toggleCheck() {
this.value = !this.value;
}
}
AsiCheckboxComponent.decorators = [
{ type: Component, args: [{
selector: 'asi-checkbox',
host: { 'class': 'asi-component asi-checkbox' },
template: "<label class=\"input-label\" *ngIf=\"label != null\">{{label | translate}}</label>\r\n\r\n<button type=\"button\" [disabled]=\"disabled\" (click)=\"toggleCheck()\" class=\"checkbox asi-focus-error\" [ngClass]=\"{ 'checked': value, 'radio' : type == 'radio' }\">\r\n <div><span class=\"checkbox-button\"></span></div>\r\n</button>",
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => AsiCheckboxComponent),
multi: true
}
]
}] }
];
/** @nocollapse */
AsiCheckboxComponent.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
AsiCheckboxComponent.propDecorators = {
label: [{ type: Input }],
labelPosition: [{ type: Input }],
type: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiCheckBoxModule {
/**
* @return {?}
*/
static forRoot() {
return {
ngModule: AsiCheckBoxModule,
providers: []
};
}
}
AsiCheckBoxModule.decorators = [
{ type: NgModule, args: [{
declarations: [AsiCheckboxComponent],
imports: [AsiNgToolsBaseModule.forRoot()],
exports: [AsiNgToolsBaseModule, AsiCheckboxComponent],
entryComponents: [],
providers: []
},] }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiSelectComponent extends DefaultControlValueAccessor {
/**
* @param {?} renderer
* @param {?} elementRef
*/
constructor(renderer, elementRef) {
super();
this.renderer = renderer;
this.elementRef = elementRef;
/**
* Label position
*/
this.labelPosition = 'top';
/**
* Multi selection
*/
this.multiple = false;
/**
* Add an empty value (template must be define)
*/
this.withEmptyValue = false;
this.open = false;
this.allChecked = false;
}
/**
* @return {?}
*/
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, 'label-' + this.labelPosition);
if (this.multiple) {
this.renderer.addClass(this.elementRef.nativeElement, 'multiple');
}
}
/**
* @return {?}
*/
onDropdownClose() {
this.open = false;
}
/**
* @return {?}
*/
isOpened() {
return this.open;
}
/**
* @return {?}
*/
ngOnChanges() {
this.initData();
}
/**
* @return {?}
*/
initData() {
this.selectDatas = [];
this.data = this.data || [];
if (this.withEmptyValue) {
this.selectDatas.push(null);
}
this.data.forEach((data) => {
/** @type {?} */
const proxyData = {
selected: false,
value: data
};
this.selectDatas.push(proxyData);
});
}
/**
* @param {?} value
* @return {?}
*/
checkAll(value) {
this.allChecked = value;
this.selectDatas.forEach((data) => {
if (data != null && (value !== data.selected)) {
this.internalSelectValue(null, data);
}
});
this.onModelChange(this._value);
}
/**
* @return {?}
*/
updateAllChecked() {
this.allChecked = find(this.selectDatas, (data) => {
return data != null ? !data.selected : false;
}) == null;
}
/**
* @param {?} event
* @param {?} data
* @return {?}
*/
selectValue(event, data) {
this.internalSelectValue(event, data);
this.onModelChange(this._value);
}
/**
* @param {?} event
* @param {?} data
* @return {?}
*/
internalSelectValue(event, data) {
if (data == null) {
this.onModelChange(null);
this.open = false;
return;
}
/** @type {?} */
let realValue = data.value;
if (this.multiple) {
if (event != null) {
event.stopPropagation();
}
if (this._value == null) {
this._value = [];
}
/** @type {?} */
let removed = remove(this._value, (value) => {
if (value != null) {
if (this.trackBy != null) {
return value[this.trackBy] === realValue[this.trackBy];
}
else {
return value === realValue;
}
}
return false;
});
if (isEmpty(removed)) {
this.value.push(realValue);
data.selected = true;
}
else {
data.selected = false;
}
if (isEmpty(this._value)) {
this._value = null;
}
if (event != null) {
this.updateAllChecked();
}
}
else {
this.open = false;
this._value = realValue;
}
}
/**
* @return {?}
*/
toggleSelect() {
this.open = !this.open;
}
/**
* @param {?} value
* @return {?}
*/
writeValue(value) {
if (isNaN(value) && isEmpty(value)) {
this._value = null;
}
else {
this._value = value;
}
if (this.multiple) {
if (this._value != null) {
this.selectDatas.forEach((data) => {
if (data != null) {
data.selected = find(this.value, (possibleValue) => {
if (possibleValue != null) {
if (this.trackBy != null) {
return possibleValue[this.trackBy] === data.value[this.trackBy];
}
else {
return possibleValue === data.value;
}
}
return false;
}) != null;
}
});
}
else {
this.selectDatas.forEach((data) => {
if (data != null) {
data.selected = false;
}
});
}
this.updateAllChecked();
}
this.manageHasValue();
}
/**
* @param {?} value
* @return {?}
*/
onModelChange(value) {
this.value = value;
this.manageHasValue();
}
/**
* @return {?}
*/
manageHasValue() {
if (this.value != null) {
this.renderer.addClass(this.elementRef.nativeElement, 'has-value');
}
else {
this.renderer.removeClass(this.elementRef.nativeElement, 'has-value');
}
}
}
AsiSelectComponent.decorators = [
{ type: Component, args: [{
selector: 'asi-select',
host: { 'class': 'asi-component asi-select' },
template: "<label class=\"input-label\" *ngIf=\"label != null\">{{label | translate}}</label>\r\n\r\n<div class=\"asi-select-container\" aria-labelledby=\"select\">\r\n <div class=\"asi-select-header asi-focus-error\" (keyup.esc)=\"toggleSelect()\">\r\n <asi-checkbox *ngIf=\"multiple\" [disabled]=\"disabled\" [ngModel]=\"allChecked\" (onValueChange)=\"checkAll($event)\">\r\n </asi-checkbox>\r\n <button type=\"button\" class=\"item-container\" [disabled]=\"disabled\" (click)=\"toggleSelect()\">\r\n <span>\r\n <div class=\"item\">\r\n <ng-template *ngIf=\"value != null\" [ngTemplateOutlet]=\"selectedDef.template\"\r\n [ngTemplateOutletContext]=\"{$implicit : value}\"></ng-template>\r\n <ng-template *ngIf=\"value == null\" [ngTemplateOutlet]=\"emptyDef?.template\"\r\n [ngTemplateOutletContext]=\"{$implicit : value}\"></ng-template>\r\n </div>\r\n <div class=\"drop-icon-container\">\r\n <span class=\"drop-icon\" [innerHtml]=\"'▼'\"></span>\r\n </div>\r\n </span>\r\n </button>\r\n </div>\r\n\r\n <asi-dropdown [open]=\"open\" (onClose)=\"onDropdownClose()\" dropDownClass=\"asi-select-dropdown\">\r\n <div class=\"drop-down-select\">\r\n <div class=\"drop-down-panel\">\r\n <button type=\"button\" class=\"drop-down-item\" [ngClass]=\"{'empty' : data == null , 'selected' : data?.selected}\"\r\n (keyup.esc)=\"toggleSelect()\" (click)=\"selectValue($event, data)\" *ngFor=\"let data of selectDatas\">\r\n <span class=\"option\">\r\n <asi-checkbox *ngIf=\"multiple && data != null\" [ngModel]=\"data.selected\"\r\n (click)=\"selectValue($event, data)\"></asi-checkbox>\r\n <div class=\"item\" aria-labelledby=\"item\">\r\n <ng-template *ngIf=\"data != null\" [ngTemplateOutlet]=\"optionDef.template\"\r\n [ngTemplateOutletContext]=\"{$implicit : data.value}\"></ng-template>\r\n </div>\r\n </span>\r\n </button>\r\n </div>\r\n </div>\r\n </asi-dropdown>\r\n</div>\r\n",
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => AsiSelectComponent),
multi: true
}
]
}] }
];
/** @nocollapse */
AsiSelectComponent.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
AsiSelectComponent.propDecorators = {
label: [{ type: Input }],
labelPosition: [{ type: Input }],
data: [{ type: Input }],
multiple: [{ type: Input }],
trackBy: [{ type: Input }],
withEmptyValue: [{ type: Input }],
optionDef: [{ type: ContentChild, args: [AsiComponentTemplateOptionDef,] }],
emptyDef: [{ type: ContentChild, args: [AsiComponentTemplateEmptyDef,] }],
selectedDef: [{ type: ContentChild, args: [AsiComponentTemplateSelectedDef,] }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiDropdownContainer {
/**
* @param {?} document
* @param {?} renderer
* @param {?} elementRef
*/
constructor(document, renderer, elementRef) {
this.document = document;
this.renderer = renderer;
this.elementRef = elementRef;
this.calculWidth = true;
this.subjectContainer = new Subject();
}
/**
* @param {?} event
* @return {?}
*/
documentClick(event) {
if (!this.drop.nativeElement.contains(event.target)) {
this.asiDropDownService.canClose(this.index, this.canClose).subscribe(close => {
if (close) {
setTimeout(() => {
this.close();
});
}
});
}
}
/**
* @return {?}
*/
close() {
this.subjectContainer.next(this);
this.subjectContainer.complete();
}
/**
* @return {?}
*/
onClose() {
return this.subjectContainer.asObservable();
}
/**
* Move the container under htmlElement
* @param {?} elementRef
* @return {?}
*/
forElement(elementRef) {
this.referenceElement = elementRef;
/** @type {?} */
const rectPos = elementRef.getBoundingClientRect();
/** @type {?} */
const bodyComputedStyle = getComputedStyle(this.document.body);
/** @type {?} */
const bodyMarginTop = parseInt(bodyComputedStyle.marginTop.slice(0, -2), 10);
/** @type {?} */
const bodyMarginLeft = parseInt(bodyComputedStyle.marginLeft.slice(0, -2), 10);
/** @type {?} */
const topVerticalPosition = rectPos.top + this.getScrollTopValue() - bodyMarginTop;
if (topVerticalPosition > this.document.body.clientHeight / 2) {
// show over the element
this.drop.nativeElement.style.bottom = (this.document.body.clientHeight - topVerticalPosition) + 'px';
this.drop.nativeElement.style.marginBottom = '5px';
}
else {
// show under the element
this.drop.nativeElement.style.top = (topVerticalPosition + elementRef.offsetHeight) + 'px';
this.drop.nativeElement.style.marginTop = '5px';
}
/** @type {?} */
const screenVerticalPosition = rectPos.top - bodyMarginTop;
/** @type {?} */
let bodyVerticalPosition;
if (screenVerticalPosition > this.document.body.clientHeight / 2) {
// show over the element
bodyVerticalPosition = this.document.body.clientHeight - (this.getScrollTopValue() + screenVerticalPosition);
this.drop.nativeElement.style.bottom = bodyVerticalPosition + 'px';
this.drop.nativeElement.style.marginBottom = '2px';
}
else {
// show under the element
bodyVerticalPosition = this.getScrollTopValue() + screenVerticalPosition + elementRef.offsetHeight;
this.drop.nativeElement.style.top = bodyVerticalPosition + 'px';
this.drop.nativeElement.style.marginTop = '2px';
}
this.drop.nativeElement.style.left = rectPos.left + this.getScrollLeftValue() - bodyMarginLeft + 'px';
this.drop.nativeElement.style.width = elementRef.offsetWidth + 'px';
}
/**
* @return {?}
*/
getScrollTopValue() {
return this.document.body.scrollTop + this.document.documentElement.scrollTop;
}
/**
* @return {?}
*/
getScrollLeftValue() {
return this.document.body.scrollLeft + this.document.documentElement.scrollLeft;
}
/**
* @param {?} asiDrownDown
* @return {?}
*/
show(asiDrownDown) {
setTimeout(() => {
this.template = asiDrownDown.contentTemplate;
/** @type {?} */
let visibility = this.drop.nativeElement.style.visibility;
this.drop.nativeElement.style.visibility = 'hidden';
if (asiDrownDown.dropDownClass) {
this.renderer.addClass(this.elementRef.nativeElement, asiDrownDown.dropDownClass);
}
setTimeout(() => {
/** @type {?} */
let dropRight = this.drop.nativeElement.offsetLeft + this.drop.nativeElement.offsetWidth;
if (dropRight > this.document.documentElement.clientWidth) {
this.drop.nativeElement.style.left = this.drop.nativeElement.offsetLeft
+ this.document.documentElement.scrollLeft - (dropRight - this.document.documentElement.clientWidth) + 'px';
}
this.drop.nativeElement.style.visibility = visibility;
});
});
}
/**
* @param {?} service
* @return {?}
*/
injectService(service) {
this.asiDropDownService = service;
}
/**
* @param {?} index
* @return {?}
*/
setIndex(index) {
this.index = index;
this.elementRef.nativeElement.style.zIndex = AsiDropdownContainer.BASE_INDEX + index;
}
/**
* @param {?} calculWidth
* @return {?}
*/
setCalculWidth(calculWidth) {
if (calculWidth) {
this.drop.nativeElement.style.width = this.referenceElement.offsetWidth + 'px';
}
else {
this.drop.nativeElement.style.width = '';
}
}
}
AsiDropdownContainer.BASE_INDEX = 125;
AsiDropdownContainer.decorators = [
{ type: Component, args: [{
selector: 'asi-dropdown-container',
host: { 'class': 'asi-component asi-dropdown-container' },
template: "<div #drop class=\"dropdown-container\">\r\n <ng-template [ngTemplateOutlet]=\"template\"></ng-template>\r\n</div>"
}] }
];
/** @nocollapse */
AsiDropdownContainer.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
{ type: Renderer2 },
{ type: ElementRef }
];
AsiDropdownContainer.propDecorators = {
calculWidth: [{ type: Input }],
drop: [{ type: ViewChild, args: ['drop', { read: ElementRef },] }],
documentClick: [{ type: HostListener, args: ['document:mouseup', ['$event'],] }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiDropdownService {
/**
* @param {?} resolver
* @param {?} appRef
*/
constructor(resolver, appRef) {
this.resolver = resolver;
this.appRef = appRef;
this.containers = [];
}
/**
*
* @param {?} elementRef
* @param {?} asiDropDown
* @return {?}
*/
showDropdown(elementRef, asiDropDown) {
/** @type {?} */
let containerRef = this.getContainer();
containerRef.instance.injectService(this);
containerRef.instance.forElement(elementRef);
containerRef.instance.show(asiDropDown);
containerRef.instance.setIndex(this.containers.length);
containerRef.instance.canClose = asiDropDown.canClose;
containerRef.instance.onClose().subscribe((containerToRemove) => {
remove(this.containers, (container) => {
return containerToRemove.index === container.instance.index;
});
});
this.containers.push(containerRef);
return containerRef;
}
/**
* @param {?} index
* @param {?} canClose
* @return {?}
*/
canClose(index, canClose) {
if (index >= this.containers.length - 1) {
if (canClose) {
return observe(canClose(document.activeElement));
}
else {
return of(true);
}
}
else {
return of(false);
}
}
/**
* @return {?}
*/
getContainer() {
/** @type {?} */
const rootComponent = this.appRef.components[0].instance;
if (!rootComponent.viewContainerRef) {
/** @type {?} */
const appName = this.appRef.componentTypes[0].name;
// tslint:disable-next-line:max-line-length
throw new Error('AsiDropdown : Please add "viewContainerRef : ViewContainerRef" declaration in your root component constructor : ' + appName);
}
/** @type {?} */
const asiDropdownContainerFactory = this.resolver.resolveComponentFactory(AsiDropdownContainer);
/** @type {?} */
let containerRef = rootComponent.viewContainerRef.createComponent(asiDropdownContainerFactory, 0);
return containerRef;
}
}
AsiDropdownService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
AsiDropdownService.ctorParameters = () => [
{ type: ComponentFactoryResolver },
{ type: ApplicationRef }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiDropDown {
/**
* @param {?} asiDropdownService
* @param {?} elementRef
*/
constructor(asiDropdownService, elementRef) {
this.asiDropdownService = asiDropdownService;
this.elementRef = elementRef;
/**
* Change to true to open the drowndrop
*/
this.open = false;
/**
* fix the width to the relative component width
*/
this.calculWidth = true;
/**
* Allow you to add a class to the down drop container
*/
this.dropDownClass = '';
/**
* Event emitted when dropdown is closed (you should put you open var to false to be able to reopen)
*/
this.onClose = new EventEmitter();
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
// To open
if (changes["open"]) {
if (changes["open"].currentValue) {
setTimeout(() => {
if (this.relativeTo == null) {
this.dropdown = this.asiDropdownService.showDropdown(this.elementRef.nativeElement.parentElement, this);
}
else if (this.relativeTo.nativeElement) {
this.dropdown = this.asiDropdownService.showDropdown(this.relativeTo.nativeElement, this);
}
else if (this.relativeTo['elementRef'].nativeElement) {
this.dropdown = this.asiDropdownService.showDropdown(this.relativeTo['elementRef'].nativeElement, this);
}
else {
console.warn('Default choice for the down down cannot find nativeElement on the relativeTo element');
this.dropdown = this.asiDropdownService.showDropdown(this.elementRef.nativeElement.parentElement, this);
}
this.dropdown.instance.setCalculWidth(this.calculWidth);
this.dropdown.instance.onClose().subscribe(() => {
this.destroyDropdown();
});
});
}
else if (this.dropdown) {
this.dropdown.instance.close();
}
}
}
/**
* @return {?}
*/
destroyDropdown() {
this.open = false;
this.onClose.emit();
this.dropdown.destroy();
}
}
AsiDropDown.decorators = [
{ type: Component, args: [{
selector: 'asi-dropdown',
template: '<ng-template><div class="asi-dropdown"><ng-content></ng-content></div></ng-template>'
}] }
];
/** @nocollapse */
AsiDropDown.ctorParameters = () => [
{ type: AsiDropdownService },
{ type: ElementRef }
];
AsiDropDown.propDecorators = {
open: [{ type: Input }],
calculWidth: [{ type: Input }],
relativeTo: [{ type: Input }],
dropDownClass: [{ type: Input }],
onClose: [{ type: Output }],
canClose: [{ type: Input }],
contentTemplate: [{ type: ViewChild, args: [TemplateRef,] }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class AsiDropdownModule {
/**
* @return {?}
*/
static forRoot() {
return {
ngModule: AsiDropdownModule,
providers: [AsiDropdownService]
};
}
}
AsiDro