adb-shared 2.0.7 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/components/date-picker/adb-date-picker.component.mjs +35 -15
- package/esm2020/lib/components/date-picker/adb-date-picker.directive.mjs +46 -26
- package/esm2020/lib/components/date-picker/adb-date-picker.service.mjs +1 -19
- package/fesm2015/adb-shared.mjs +161 -138
- package/fesm2015/adb-shared.mjs.map +1 -1
- package/fesm2020/adb-shared.mjs +159 -137
- package/fesm2020/adb-shared.mjs.map +1 -1
- package/lib/components/date-picker/adb-date-picker.component.d.ts +8 -3
- package/lib/components/date-picker/adb-date-picker.directive.d.ts +7 -3
- package/lib/components/date-picker/adb-date-picker.service.d.ts +3 -15
- package/package.json +1 -1
package/fesm2015/adb-shared.mjs
CHANGED
|
@@ -4,12 +4,12 @@ import * as i0 from '@angular/core';
|
|
|
4
4
|
import { Injectable, Inject, EventEmitter, Component, Output, Input, Directive, HostListener, NgModule, HostBinding, Pipe, forwardRef } from '@angular/core';
|
|
5
5
|
import * as i3 from '@ngx-translate/core';
|
|
6
6
|
import { TranslateModule } from '@ngx-translate/core';
|
|
7
|
-
import { Subscription
|
|
7
|
+
import { Subscription } from 'rxjs';
|
|
8
8
|
import * as i1 from '@angular/common/http';
|
|
9
9
|
import { HttpClientModule } from '@angular/common/http';
|
|
10
10
|
import * as i1$1 from '@angular/router';
|
|
11
11
|
import { RouterModule } from '@angular/router';
|
|
12
|
-
import { startOfDay, subYears, endOfDay, addYears, subMonths, addMonths, getMonth, isSameYear, startOfMonth, endOfMonth, eachWeekOfInterval, getISOWeek, addDays, eachDayOfInterval, getHours, getMinutes, isWithinInterval, isSameDay
|
|
12
|
+
import { isValid, parseISO, startOfDay, subYears, endOfDay, addYears, subMonths, addMonths, getMonth, isSameYear, startOfMonth, endOfMonth, eachWeekOfInterval, getISOWeek, addDays, eachDayOfInterval, getHours, getMinutes, isWithinInterval, isSameDay } from 'date-fns';
|
|
13
13
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
14
14
|
|
|
15
15
|
class EnvironmentService {
|
|
@@ -438,23 +438,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
|
|
|
438
438
|
}] });
|
|
439
439
|
|
|
440
440
|
class AdbDatePickerService {
|
|
441
|
-
constructor() {
|
|
442
|
-
this.dateSubject = new Subject();
|
|
443
|
-
this.date$ = this.dateSubject.asObservable();
|
|
444
|
-
this.hideSubject = new Subject();
|
|
445
|
-
this.hide$ = this.hideSubject.asObservable();
|
|
446
|
-
this.settingSubject = new BehaviorSubject(null);
|
|
447
|
-
this.settings$ = this.settingSubject.asObservable();
|
|
448
|
-
}
|
|
449
|
-
selectDate(date) {
|
|
450
|
-
this.dateSubject.next(date);
|
|
451
|
-
}
|
|
452
|
-
setSetting(settings) {
|
|
453
|
-
this.settingSubject.next(settings);
|
|
454
|
-
}
|
|
455
|
-
hide() {
|
|
456
|
-
this.hideSubject.next();
|
|
457
|
-
}
|
|
458
441
|
}
|
|
459
442
|
/** @nocollapse */ AdbDatePickerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
460
443
|
/** @nocollapse */ AdbDatePickerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerService });
|
|
@@ -462,6 +445,135 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
|
|
|
462
445
|
type: Injectable
|
|
463
446
|
}] });
|
|
464
447
|
|
|
448
|
+
class AdbDatePickerDirective {
|
|
449
|
+
constructor(viewContainerRef, renderer, elementRef, adbDatePickerService, translate) {
|
|
450
|
+
this.viewContainerRef = viewContainerRef;
|
|
451
|
+
this.renderer = renderer;
|
|
452
|
+
this.elementRef = elementRef;
|
|
453
|
+
this.adbDatePickerService = adbDatePickerService;
|
|
454
|
+
this.translate = translate;
|
|
455
|
+
this.autocomplete = false;
|
|
456
|
+
this.subscriptions = new Subscription();
|
|
457
|
+
this.format = 'yyyy-MM-dd';
|
|
458
|
+
this.settings = null;
|
|
459
|
+
//ControlValueAccessor
|
|
460
|
+
this.onChange = () => { };
|
|
461
|
+
this.onTouched = () => { };
|
|
462
|
+
}
|
|
463
|
+
ngOnInit() {
|
|
464
|
+
}
|
|
465
|
+
onClick() {
|
|
466
|
+
if (this.adbDatePickerService.viewRef) {
|
|
467
|
+
this.adbDatePickerService.viewRef.destroy();
|
|
468
|
+
}
|
|
469
|
+
const viewRef = this.viewContainerRef.createComponent(AdbDatePickerComponent);
|
|
470
|
+
viewRef.instance.settings = this.settings;
|
|
471
|
+
viewRef.instance.toLeft = this.toLeft;
|
|
472
|
+
this.id = this.getId();
|
|
473
|
+
viewRef.instance.id = this.id;
|
|
474
|
+
viewRef.instance.selectDate.subscribe((date) => {
|
|
475
|
+
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatDate(date, this.format, this.translate.currentLang));
|
|
476
|
+
this.onChange(date);
|
|
477
|
+
this.onHide();
|
|
478
|
+
});
|
|
479
|
+
viewRef.instance.hide.subscribe(() => {
|
|
480
|
+
this.onHide();
|
|
481
|
+
});
|
|
482
|
+
this.adbDatePickerService.viewRef = viewRef;
|
|
483
|
+
}
|
|
484
|
+
onHide() {
|
|
485
|
+
this.adbDatePickerService.viewRef = null;
|
|
486
|
+
this.viewContainerRef.detach();
|
|
487
|
+
this.viewContainerRef.clear();
|
|
488
|
+
}
|
|
489
|
+
onCheckOutSideClick(target) {
|
|
490
|
+
var _a, _b;
|
|
491
|
+
const nativeElement = (_b = (_a = this.adbDatePickerService.viewRef) === null || _a === void 0 ? void 0 : _a.instance.elementRef.nativeElement) !== null && _b !== void 0 ? _b : null;
|
|
492
|
+
if (nativeElement) {
|
|
493
|
+
if (nativeElement.id === this.id) {
|
|
494
|
+
if (!target.hasAttribute('adbdatepicker')) {
|
|
495
|
+
const clickedInside = nativeElement.contains(target);
|
|
496
|
+
if (!clickedInside) {
|
|
497
|
+
this.onHide();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
ngOnDestroy() {
|
|
504
|
+
this.subscriptions.unsubscribe();
|
|
505
|
+
}
|
|
506
|
+
writeValue(value) {
|
|
507
|
+
if (value) {
|
|
508
|
+
let initialDate = AdbDatePickerDirective.parseDate(value);
|
|
509
|
+
if (initialDate) {
|
|
510
|
+
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatDate(initialDate, this.format, this.translate.currentLang));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
registerOnChange(fn) {
|
|
515
|
+
this.onChange = fn;
|
|
516
|
+
}
|
|
517
|
+
registerOnTouched(fn) {
|
|
518
|
+
this.onTouched = fn;
|
|
519
|
+
}
|
|
520
|
+
setDisabledState(isDisabled) {
|
|
521
|
+
this.viewContainerRef.clear();
|
|
522
|
+
}
|
|
523
|
+
static parseDate(value) {
|
|
524
|
+
if (typeof value === 'string') {
|
|
525
|
+
if (isValid(parseISO(value))) {
|
|
526
|
+
return parseISO(value);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else if (value instanceof Date) {
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
getId() {
|
|
540
|
+
return '' + Math.floor(Math.random() * Date.now());
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/** @nocollapse */ AdbDatePickerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.Renderer2 }, { token: i0.ElementRef }, { token: AdbDatePickerService }, { token: i3.TranslateService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
544
|
+
/** @nocollapse */ AdbDatePickerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerDirective, selector: "input[adbDatepicker]", inputs: { format: "format", toLeft: "toLeft", settings: "settings" }, host: { listeners: { "click": "onClick()", "keyup.esc": "onHide()", "document:click": "onCheckOutSideClick($event.target)" }, properties: { "autocomplete": "this.autocomplete" } }, providers: [{
|
|
545
|
+
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((() => AdbDatePickerDirective)),
|
|
546
|
+
multi: true
|
|
547
|
+
}], ngImport: i0 });
|
|
548
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerDirective, decorators: [{
|
|
549
|
+
type: Directive,
|
|
550
|
+
args: [{
|
|
551
|
+
selector: `input[adbDatepicker]`,
|
|
552
|
+
providers: [{
|
|
553
|
+
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((() => AdbDatePickerDirective)),
|
|
554
|
+
multi: true
|
|
555
|
+
}]
|
|
556
|
+
}]
|
|
557
|
+
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.Renderer2 }, { type: i0.ElementRef }, { type: AdbDatePickerService }, { type: i3.TranslateService }]; }, propDecorators: { autocomplete: [{
|
|
558
|
+
type: HostBinding,
|
|
559
|
+
args: ['autocomplete']
|
|
560
|
+
}], format: [{
|
|
561
|
+
type: Input
|
|
562
|
+
}], toLeft: [{
|
|
563
|
+
type: Input
|
|
564
|
+
}], settings: [{
|
|
565
|
+
type: Input
|
|
566
|
+
}], onClick: [{
|
|
567
|
+
type: HostListener,
|
|
568
|
+
args: ['click']
|
|
569
|
+
}], onHide: [{
|
|
570
|
+
type: HostListener,
|
|
571
|
+
args: ['keyup.esc']
|
|
572
|
+
}], onCheckOutSideClick: [{
|
|
573
|
+
type: HostListener,
|
|
574
|
+
args: ['document:click', ['$event.target']]
|
|
575
|
+
}] } });
|
|
576
|
+
|
|
465
577
|
class AdbDatePickerComponent {
|
|
466
578
|
constructor(adbDatePickerService, elementRef) {
|
|
467
579
|
this.adbDatePickerService = adbDatePickerService;
|
|
@@ -470,15 +582,22 @@ class AdbDatePickerComponent {
|
|
|
470
582
|
this.currentdDate = new Date();
|
|
471
583
|
this.selectedDate = new Date();
|
|
472
584
|
this.weekDays = AdbDatePickerComponent.WEEK_DAYS;
|
|
585
|
+
this.selectDate = new EventEmitter();
|
|
586
|
+
this.hide = new EventEmitter();
|
|
473
587
|
}
|
|
474
588
|
ngOnInit() {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
589
|
+
var _a, _b;
|
|
590
|
+
if (this.settings) {
|
|
591
|
+
if (((_a = this.settings) === null || _a === void 0 ? void 0 : _a.minDate) || ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.maxDate)) {
|
|
592
|
+
const minDate = AdbDatePickerDirective.parseDate(this.settings.minDate);
|
|
593
|
+
const maxDate = AdbDatePickerDirective.parseDate(this.settings.maxDate);
|
|
594
|
+
this.range = {
|
|
595
|
+
start: minDate ? startOfDay(minDate) : subYears(new Date(), 1000),
|
|
596
|
+
end: maxDate ? endOfDay(maxDate) : addYears(new Date(), 1000)
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
this.createCalendar();
|
|
482
601
|
}
|
|
483
602
|
onShowYear() {
|
|
484
603
|
this.months = null;
|
|
@@ -528,14 +647,14 @@ class AdbDatePickerComponent {
|
|
|
528
647
|
}
|
|
529
648
|
}
|
|
530
649
|
// @HostListener('document:click', ['$event.target'])
|
|
531
|
-
// onHide(target:
|
|
650
|
+
// onHide(target:any) {
|
|
532
651
|
// console.log('this.elementRef.nativeElement',this.elementRef.nativeElement);
|
|
533
652
|
// console.log('target',target)
|
|
534
653
|
// const clickedInside = this.elementRef.nativeElement.contains(target);
|
|
535
654
|
// console.log('target.id',target.id);
|
|
536
655
|
// if (!clickedInside) {
|
|
537
656
|
// if (!target.hasAttribute('adbdatepicker')) {
|
|
538
|
-
// this.
|
|
657
|
+
// this.hide.emit();
|
|
539
658
|
// }
|
|
540
659
|
// }
|
|
541
660
|
// }
|
|
@@ -564,7 +683,7 @@ class AdbDatePickerComponent {
|
|
|
564
683
|
this.years = years;
|
|
565
684
|
}
|
|
566
685
|
onSelectDate(day) {
|
|
567
|
-
this.
|
|
686
|
+
this.selectDate.emit(day.value);
|
|
568
687
|
}
|
|
569
688
|
createCalendar() {
|
|
570
689
|
const weeks = [];
|
|
@@ -593,119 +712,23 @@ AdbDatePickerComponent.MONTHS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
|
593
712
|
AdbDatePickerComponent.WEEK_DAYS = ['1', '2', '3', '4', '5', '6', '7'];
|
|
594
713
|
AdbDatePickerComponent.YEAR_INTERVALL = 8;
|
|
595
714
|
/** @nocollapse */ AdbDatePickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerComponent, deps: [{ token: AdbDatePickerService }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
596
|
-
/** @nocollapse */ AdbDatePickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerComponent, selector: "adb-date-picker", ngImport: i0, template: "<nav class=\"bg-white shadow rounded\" style=\"width:350px\">\r\n
|
|
715
|
+
/** @nocollapse */ AdbDatePickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerComponent, selector: "adb-date-picker", inputs: { settings: "settings", toLeft: "toLeft", id: "id" }, outputs: { selectDate: "selectDate", hide: "hide" }, host: { properties: { "id": "this.id" } }, ngImport: i0, template: "<div class=\"position-relative\" [class.to-left]=\"toLeft\">\r\n <nav class=\"bg-white shadow rounded position-absolute\" style=\"width:350px\">\r\n <header class=\"bg-primary p-2 rounded-top d-flex justify-content-between align-items-center gap-1\">\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onPrev()\"><span class=\"fa fa-chevron-left\"></span></button>\r\n <ng-container *ngIf=\"!years&&!months\">\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowMonth();$event.stopPropagation()\">{{selectedDate|adbLocaleDate:'MMM'}}</button>\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowYear();$event.stopPropagation()\">{{selectedDate|date:'yyyy'}}</button>\r\n </ng-container>\r\n <button *ngIf=\"years\" class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"years=null;;$event.stopPropagation()\">{{years[0].title}} - {{years[years.length-1].title}}</button>\r\n <button *ngIf=\"months\" class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowYear();;$event.stopPropagation()\">{{selectedDate|date:'yyyy'}}</button>\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onNext()\"><span class=\"fa fa-chevron-right\"></span></button>\r\n </header>\r\n <div class=\"p-0 border calendar\">\r\n <ul class=\"list-unstyled row\" *ngIf=\"years\">\r\n <li class=\"col-3 text-center px-2 py-3\" *ngFor=\"let year of years\">\r\n <button class=\"btn btn-sm btn-outline-secondary rounded-pill\" (click)=\"onSelectYear(year.value);$event.stopPropagation()\" [class.active]=\"year.hasObservation\" [ngClass]=\"{'border border-secondary':year.isThisYear}\">{{year.title}}</button>\r\n </li>\r\n </ul>\r\n <ul class=\"list-unstyled row\" *ngIf=\"months\">\r\n <li class=\"col-4 text-center px-2 py-3\" *ngFor=\"let month of months\">\r\n <button class=\"btn btn-sm btn-outline-secondary rounded-pill\" (click)=\"onSelectMonth(month.value);$event.stopPropagation()\" [class.active]=\"month.observation\" [ngClass]=\"{'border border-secondary':month.isThisMonth}\">\r\n {{'MONTHS.'+(month.value+1)|translate}}\r\n </button>\r\n </li>\r\n </ul>\r\n <div class=\"days\" *ngIf=\"!years&&!months\">\r\n <div class=\"text-center border-bottom py-2 text-muted\" *ngFor=\"let weekDay of weekDays\">{{'WEEK_DAYS.'+weekDay|translate}}</div>\r\n <ng-container *ngFor=\"let week of weeks\">\r\n <button class=\"btn rounded-circle p-0 m-2\" *ngFor=\"let day of week.days\" (click)=\"onSelectDate(day)\"\r\n [class.border]=\"day.isToday\" [ngClass]=\"{'pe-none text-muted opacity-50':!day.inMonth||!day.isInRange}\">\r\n <small>{{day.value|date:'d'}}</small>\r\n </button>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </nav>\r\n</div>", directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], pipes: { "adbLocaleDate": LocaleDatePipe, "date": i2.DatePipe, "translate": i3.TranslatePipe } });
|
|
597
716
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerComponent, decorators: [{
|
|
598
717
|
type: Component,
|
|
599
|
-
args: [{ selector: 'adb-date-picker', template: "<nav class=\"bg-white shadow rounded\" style=\"width:350px\">\r\n
|
|
600
|
-
}], ctorParameters: function () { return [{ type: AdbDatePickerService }, { type: i0.ElementRef }]; }
|
|
601
|
-
|
|
602
|
-
class AdbDatePickerDirective {
|
|
603
|
-
constructor(viewContainerRef, renderer, elementRef, adbDatePickerService, translate) {
|
|
604
|
-
this.viewContainerRef = viewContainerRef;
|
|
605
|
-
this.renderer = renderer;
|
|
606
|
-
this.elementRef = elementRef;
|
|
607
|
-
this.adbDatePickerService = adbDatePickerService;
|
|
608
|
-
this.translate = translate;
|
|
609
|
-
this.subscriptions = new Subscription();
|
|
610
|
-
this.format = 'yyyy-MM-dd';
|
|
611
|
-
//TODO: convert to getter if this would become dynamic from server
|
|
612
|
-
this.settings = null;
|
|
613
|
-
//ControlValueAccessor
|
|
614
|
-
this.onChange = () => { };
|
|
615
|
-
this.onTouched = () => { };
|
|
616
|
-
}
|
|
617
|
-
ngOnInit() {
|
|
618
|
-
var _a, _b;
|
|
619
|
-
this.subscriptions.add(this.adbDatePickerService.date$.subscribe({
|
|
620
|
-
next: date => {
|
|
621
|
-
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatDate(date, this.format, this.translate.currentLang));
|
|
622
|
-
this.onChange(date);
|
|
623
|
-
this.onHide();
|
|
624
|
-
}
|
|
625
|
-
}));
|
|
626
|
-
this.subscriptions.add(this.adbDatePickerService.hide$.subscribe({
|
|
627
|
-
next: () => {
|
|
628
|
-
this.onHide();
|
|
629
|
-
}
|
|
630
|
-
}));
|
|
631
|
-
if (((_a = this.settings) === null || _a === void 0 ? void 0 : _a.maxDate) || ((_b = this.settings) === null || _b === void 0 ? void 0 : _b.minDate)) {
|
|
632
|
-
this.adbDatePickerService.setSetting({
|
|
633
|
-
minDate: AdbDatePickerDirective.parseDate(this.settings.minDate),
|
|
634
|
-
maxDate: AdbDatePickerDirective.parseDate(this.settings.maxDate)
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
onClick() {
|
|
639
|
-
if (!this.viewRef) {
|
|
640
|
-
this.viewRef = this.viewContainerRef.createComponent(AdbDatePickerComponent);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
onHide() {
|
|
644
|
-
this.viewRef = null;
|
|
645
|
-
this.viewContainerRef.detach();
|
|
646
|
-
this.viewContainerRef.clear();
|
|
647
|
-
}
|
|
648
|
-
ngOnDestroy() {
|
|
649
|
-
this.subscriptions.unsubscribe();
|
|
650
|
-
}
|
|
651
|
-
writeValue(value) {
|
|
652
|
-
if (value) {
|
|
653
|
-
let initialDate = AdbDatePickerDirective.parseDate(value);
|
|
654
|
-
if (initialDate) {
|
|
655
|
-
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatDate(initialDate, this.format, this.translate.currentLang));
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
registerOnChange(fn) {
|
|
660
|
-
this.onChange = fn;
|
|
661
|
-
}
|
|
662
|
-
registerOnTouched(fn) {
|
|
663
|
-
this.onTouched = fn;
|
|
664
|
-
}
|
|
665
|
-
setDisabledState(isDisabled) {
|
|
666
|
-
this.viewContainerRef.clear();
|
|
667
|
-
}
|
|
668
|
-
static parseDate(value) {
|
|
669
|
-
if (typeof value === 'string') {
|
|
670
|
-
if (isValid(parseISO(value))) {
|
|
671
|
-
return parseISO(value);
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
return null;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
else if (value instanceof Date) {
|
|
678
|
-
return value;
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
/** @nocollapse */ AdbDatePickerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.Renderer2 }, { token: i0.ElementRef }, { token: AdbDatePickerService }, { token: i3.TranslateService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
686
|
-
/** @nocollapse */ AdbDatePickerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerDirective, selector: "input[adbDatepicker]", inputs: { format: "format", settings: "settings" }, host: { listeners: { "click": "onClick()", "keyup.esc": "onHide()" } }, providers: [{
|
|
687
|
-
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((() => AdbDatePickerDirective)),
|
|
688
|
-
multi: true
|
|
689
|
-
}], ngImport: i0 });
|
|
690
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerDirective, decorators: [{
|
|
691
|
-
type: Directive,
|
|
692
|
-
args: [{
|
|
693
|
-
selector: `input[adbDatepicker]`,
|
|
694
|
-
providers: [{
|
|
695
|
-
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((() => AdbDatePickerDirective)),
|
|
696
|
-
multi: true
|
|
697
|
-
}]
|
|
698
|
-
}]
|
|
699
|
-
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.Renderer2 }, { type: i0.ElementRef }, { type: AdbDatePickerService }, { type: i3.TranslateService }]; }, propDecorators: { format: [{
|
|
718
|
+
args: [{ selector: 'adb-date-picker', template: "<div class=\"position-relative\" [class.to-left]=\"toLeft\">\r\n <nav class=\"bg-white shadow rounded position-absolute\" style=\"width:350px\">\r\n <header class=\"bg-primary p-2 rounded-top d-flex justify-content-between align-items-center gap-1\">\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onPrev()\"><span class=\"fa fa-chevron-left\"></span></button>\r\n <ng-container *ngIf=\"!years&&!months\">\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowMonth();$event.stopPropagation()\">{{selectedDate|adbLocaleDate:'MMM'}}</button>\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowYear();$event.stopPropagation()\">{{selectedDate|date:'yyyy'}}</button>\r\n </ng-container>\r\n <button *ngIf=\"years\" class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"years=null;;$event.stopPropagation()\">{{years[0].title}} - {{years[years.length-1].title}}</button>\r\n <button *ngIf=\"months\" class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onShowYear();;$event.stopPropagation()\">{{selectedDate|date:'yyyy'}}</button>\r\n <button class=\"btn btn-primary text-white rounded-pill\" type=\"button\" (click)=\"onNext()\"><span class=\"fa fa-chevron-right\"></span></button>\r\n </header>\r\n <div class=\"p-0 border calendar\">\r\n <ul class=\"list-unstyled row\" *ngIf=\"years\">\r\n <li class=\"col-3 text-center px-2 py-3\" *ngFor=\"let year of years\">\r\n <button class=\"btn btn-sm btn-outline-secondary rounded-pill\" (click)=\"onSelectYear(year.value);$event.stopPropagation()\" [class.active]=\"year.hasObservation\" [ngClass]=\"{'border border-secondary':year.isThisYear}\">{{year.title}}</button>\r\n </li>\r\n </ul>\r\n <ul class=\"list-unstyled row\" *ngIf=\"months\">\r\n <li class=\"col-4 text-center px-2 py-3\" *ngFor=\"let month of months\">\r\n <button class=\"btn btn-sm btn-outline-secondary rounded-pill\" (click)=\"onSelectMonth(month.value);$event.stopPropagation()\" [class.active]=\"month.observation\" [ngClass]=\"{'border border-secondary':month.isThisMonth}\">\r\n {{'MONTHS.'+(month.value+1)|translate}}\r\n </button>\r\n </li>\r\n </ul>\r\n <div class=\"days\" *ngIf=\"!years&&!months\">\r\n <div class=\"text-center border-bottom py-2 text-muted\" *ngFor=\"let weekDay of weekDays\">{{'WEEK_DAYS.'+weekDay|translate}}</div>\r\n <ng-container *ngFor=\"let week of weeks\">\r\n <button class=\"btn rounded-circle p-0 m-2\" *ngFor=\"let day of week.days\" (click)=\"onSelectDate(day)\"\r\n [class.border]=\"day.isToday\" [ngClass]=\"{'pe-none text-muted opacity-50':!day.inMonth||!day.isInRange}\">\r\n <small>{{day.value|date:'d'}}</small>\r\n </button>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </nav>\r\n</div>" }]
|
|
719
|
+
}], ctorParameters: function () { return [{ type: AdbDatePickerService }, { type: i0.ElementRef }]; }, propDecorators: { settings: [{
|
|
700
720
|
type: Input
|
|
701
|
-
}],
|
|
721
|
+
}], toLeft: [{
|
|
702
722
|
type: Input
|
|
703
|
-
}],
|
|
704
|
-
type:
|
|
705
|
-
args: ['
|
|
706
|
-
}
|
|
707
|
-
type:
|
|
708
|
-
|
|
723
|
+
}], id: [{
|
|
724
|
+
type: HostBinding,
|
|
725
|
+
args: ['id']
|
|
726
|
+
}, {
|
|
727
|
+
type: Input
|
|
728
|
+
}], selectDate: [{
|
|
729
|
+
type: Output
|
|
730
|
+
}], hide: [{
|
|
731
|
+
type: Output
|
|
709
732
|
}] } });
|
|
710
733
|
|
|
711
734
|
class AdbDatePickerModule {
|