@magic-xpa/angular 4.1000.0-dev4100.419 → 4.1000.0-dev4100.422
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/src/ui/directives/magic/form-controls/control-value-accessors/date.cva.directive.mjs +34 -5
- package/esm2020/src/ui/directives/mgformat.magic.directive.mjs +170 -2
- package/fesm2015/magic-xpa-angular.mjs +197 -6
- package/fesm2015/magic-xpa-angular.mjs.map +1 -1
- package/fesm2020/magic-xpa-angular.mjs +197 -6
- package/fesm2020/magic-xpa-angular.mjs.map +1 -1
- package/package.json +3 -3
- package/src/ui/directives/magic/form-controls/control-value-accessors/date.cva.directive.d.ts +8 -2
- package/src/ui/directives/mgformat.magic.directive.d.ts +7 -0
@@ -9,7 +9,7 @@ import { FormGroup, FormControl, Validators, NG_VALIDATORS, NG_VALUE_ACCESSOR, C
|
|
9
9
|
import * as i3 from 'ng-dynamic-component';
|
10
10
|
import { DynamicModule } from 'ng-dynamic-component';
|
11
11
|
import { InteractiveCommandType, HtmlProperties, OverlayType, Styles, GuiConstants, CommandType, PIC, GuiEnvironment, Modifiers } from '@magic-xpa/gui';
|
12
|
-
import { MagicBridge, getGuiEventObj, CookieService } from '@magic-xpa/engine';
|
12
|
+
import { MagicBridge, getGuiEventObj, CookieService, Environment, LastFocusedManager } from '@magic-xpa/engine';
|
13
13
|
import { MagicProperties, Logger, StrUtil, StorageAttribute, PICInterface, BindingLevel, StorageAttributeType, MgControlType } from '@magic-xpa/utils';
|
14
14
|
import { filter, map, debounceTime } from 'rxjs/operators';
|
15
15
|
import { Subject, fromEvent } from 'rxjs';
|
@@ -3524,6 +3524,170 @@ class MgformatMagicDirective {
|
|
3524
3524
|
break;
|
3525
3525
|
}
|
3526
3526
|
}
|
3527
|
+
onBlurEvent(event) {
|
3528
|
+
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
3529
|
+
let attr = this._task.Records.list[0].getControlMetadata(this.magicDir.id).dataType;
|
3530
|
+
const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
|
3531
|
+
if (attr == StorageAttribute.DATE)
|
3532
|
+
this.formatDateWithCentury(event.target.value, century, control);
|
3533
|
+
}
|
3534
|
+
formatDateWithCentury(userInput, century, control) {
|
3535
|
+
const dateFormat = this._task.mgInputDateFormat;
|
3536
|
+
const separator = userInput.includes('/') ? '/' : "-";
|
3537
|
+
let centuryVal = parseInt(century.toString().slice(0, 2));
|
3538
|
+
if (userInput.length == 0)
|
3539
|
+
return;
|
3540
|
+
if ((dateFormat == 'dd/MMM/yyyy' || dateFormat == 'dd-MMM-yyyy')) {
|
3541
|
+
const dateArray = userInput.split(separator);
|
3542
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3543
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3544
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3545
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3546
|
+
}
|
3547
|
+
}
|
3548
|
+
else if ((dateFormat == 'dd/MM/yyyy' || dateFormat == 'dd-MM-yyyy' || dateFormat == 'd/M/yyyy' || dateFormat == 'd-M-yyyy')) {
|
3549
|
+
const dateArray = userInput.split(separator);
|
3550
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3551
|
+
if ((day < 32 && month < 13)) {
|
3552
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3553
|
+
}
|
3554
|
+
}
|
3555
|
+
else if ((dateFormat == 'MM/dd/yyyy' || dateFormat == 'MM-dd-yyyy' || dateFormat == 'M/d/yyyy' || dateFormat == 'M-d-yyyy')) {
|
3556
|
+
const dateArray = userInput.split(separator);
|
3557
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3558
|
+
if ((day < 32 && month < 13)) {
|
3559
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3560
|
+
}
|
3561
|
+
}
|
3562
|
+
else if ((dateFormat == 'MMM/dd/yyyy' || dateFormat == 'MMM-dd-yyyy')) {
|
3563
|
+
const dateArray = userInput.split(separator);
|
3564
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3565
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3566
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3567
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3568
|
+
}
|
3569
|
+
}
|
3570
|
+
else if ((dateFormat == 'yyyy/MM/dd' || dateFormat == 'yyyy-MM-dd')) {
|
3571
|
+
const dateArray = userInput.split(separator);
|
3572
|
+
const [day, month, year] = this.getDateSegments3(dateArray);
|
3573
|
+
if ((day < 32 && month < 13)) {
|
3574
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3575
|
+
}
|
3576
|
+
}
|
3577
|
+
else if ((dateFormat == 'yyyy/dd/MM' || dateFormat == 'yyyy-dd-MM')) {
|
3578
|
+
const dateArray = userInput.split(separator);
|
3579
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3580
|
+
if ((day < 32 && month < 13)) {
|
3581
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3582
|
+
}
|
3583
|
+
}
|
3584
|
+
else if ((dateFormat == 'yyyy/dd/MMM' || dateFormat == 'yyyy-dd-MMM')) {
|
3585
|
+
const dateArray = userInput.split(separator);
|
3586
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3587
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3588
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3589
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3590
|
+
}
|
3591
|
+
}
|
3592
|
+
else if ((dateFormat == 'dd/MM/yy' || dateFormat == 'dd-MM-yy' || dateFormat == 'd/M/yy' || dateFormat == 'd-M-yy')) {
|
3593
|
+
const dateArray = userInput.split(separator);
|
3594
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3595
|
+
if ((day < 32 && month < 13)) {
|
3596
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3597
|
+
}
|
3598
|
+
}
|
3599
|
+
else if ((dateFormat == 'MM/dd/yy' || dateFormat == 'MM-dd-yy' || dateFormat == 'M/d/yy' || dateFormat == 'M-d-yy')) {
|
3600
|
+
const dateArray = userInput.split(separator);
|
3601
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3602
|
+
if ((day < 32 && month < 13)) {
|
3603
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3604
|
+
}
|
3605
|
+
}
|
3606
|
+
else if ((dateFormat == 'yy/MM/dd' || dateFormat == 'yy-MM-dd')) {
|
3607
|
+
const dateArray = userInput.split(separator);
|
3608
|
+
const [day, month, year] = this.getDateSegments3(dateArray);
|
3609
|
+
if ((day < 32 && month < 13)) {
|
3610
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3611
|
+
}
|
3612
|
+
}
|
3613
|
+
else if ((dateFormat == 'yy/dd/MM' || dateFormat == 'yy-dd-MM')) {
|
3614
|
+
const dateArray = userInput.split(separator);
|
3615
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3616
|
+
if ((day < 32 && month < 13)) {
|
3617
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3618
|
+
}
|
3619
|
+
}
|
3620
|
+
else if ((dateFormat == 'dd/MMM/yy' || dateFormat == 'dd-MMM-yy')) {
|
3621
|
+
const dateArray = userInput.split(separator);
|
3622
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3623
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3624
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3625
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3626
|
+
}
|
3627
|
+
}
|
3628
|
+
else if ((dateFormat == 'yy/dd/MMM' || dateFormat == 'yy-dd-MMM')) {
|
3629
|
+
const dateArray = userInput.split(separator);
|
3630
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3631
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3632
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3633
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3634
|
+
}
|
3635
|
+
}
|
3636
|
+
else if ((dateFormat == 'MMM/dd/yy' || dateFormat == 'MMM-dd-yy')) {
|
3637
|
+
const dateArray = userInput.split(separator);
|
3638
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3639
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3640
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3641
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3642
|
+
}
|
3643
|
+
}
|
3644
|
+
else if ((dateFormat == 'yyyy/MMM/dd' || dateFormat == 'yyyy-MMM-dd' || dateFormat == 'yy/MMM/dd' || dateFormat == 'yy-MMM-dd')) {
|
3645
|
+
const dateArray = userInput.split(separator);
|
3646
|
+
const [day, month, year] = this.getDateSegments3(dateArray);
|
3647
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3648
|
+
if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
|
3649
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3650
|
+
}
|
3651
|
+
}
|
3652
|
+
else if (dateFormat == 'yyyy/MM' || dateFormat == 'yyyy-MM') {
|
3653
|
+
const dateArray = userInput.split(separator);
|
3654
|
+
const month = dateArray[1];
|
3655
|
+
const year = Number(dateArray[0]);
|
3656
|
+
if (Number(month) < 13) {
|
3657
|
+
this.updateYear(1, month, year, separator, century, centuryVal, control);
|
3658
|
+
}
|
3659
|
+
}
|
3660
|
+
}
|
3661
|
+
updateYear(day, month, year, separator, century, centuryVal, control) {
|
3662
|
+
let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
|
3663
|
+
year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
|
3664
|
+
year;
|
3665
|
+
control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
|
3666
|
+
}
|
3667
|
+
getDateSegments1(dateArray) {
|
3668
|
+
const day = Number(dateArray[0]);
|
3669
|
+
const month = dateArray[1];
|
3670
|
+
const year = Number(dateArray[2]);
|
3671
|
+
return [day, month, year];
|
3672
|
+
}
|
3673
|
+
getDateSegments2(dateArray) {
|
3674
|
+
const day = Number(dateArray[1]);
|
3675
|
+
const month = dateArray[0];
|
3676
|
+
const year = Number(dateArray[2]);
|
3677
|
+
return [day, month, year];
|
3678
|
+
}
|
3679
|
+
getDateSegments3(dateArray) {
|
3680
|
+
const day = Number(dateArray[2]);
|
3681
|
+
const month = dateArray[1];
|
3682
|
+
const year = Number(dateArray[0]);
|
3683
|
+
return [day, month, year];
|
3684
|
+
}
|
3685
|
+
getDateSegments4(dateArray) {
|
3686
|
+
const day = Number(dateArray[1]);
|
3687
|
+
const month = dateArray[2];
|
3688
|
+
const year = Number(dateArray[0]);
|
3689
|
+
return [day, month, year];
|
3690
|
+
}
|
3527
3691
|
calculatePattern() {
|
3528
3692
|
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
3529
3693
|
if (control != null) {
|
@@ -3706,7 +3870,7 @@ class MgformatMagicDirective {
|
|
3706
3870
|
MgformatMagicDirective.ɵfac = function MgformatMagicDirective_Factory(t) { return new (t || MgformatMagicDirective)(i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
|
3707
3871
|
MgformatMagicDirective.ɵdir = i0.ɵɵdefineDirective({ type: MgformatMagicDirective, selectors: [["", "mgFormat", ""]], hostBindings: function MgformatMagicDirective_HostBindings(rf, ctx) {
|
3708
3872
|
if (rf & 1) {
|
3709
|
-
i0.ɵɵlistener("focus", function MgformatMagicDirective_focus_HostBindingHandler($event) { return ctx.onFocusEvent($event); })("paste", function MgformatMagicDirective_paste_HostBindingHandler($event) { return ctx.onPaste($event); })("input", function MgformatMagicDirective_input_HostBindingHandler($event) { return ctx.onInputEvent($event); })("change", function MgformatMagicDirective_change_HostBindingHandler($event) { return ctx.onChangeEvent($event); });
|
3873
|
+
i0.ɵɵlistener("focus", function MgformatMagicDirective_focus_HostBindingHandler($event) { return ctx.onFocusEvent($event); })("paste", function MgformatMagicDirective_paste_HostBindingHandler($event) { return ctx.onPaste($event); })("input", function MgformatMagicDirective_input_HostBindingHandler($event) { return ctx.onInputEvent($event); })("change", function MgformatMagicDirective_change_HostBindingHandler($event) { return ctx.onChangeEvent($event); })("blur", function MgformatMagicDirective_blur_HostBindingHandler($event) { return ctx.onBlurEvent($event); });
|
3710
3874
|
}
|
3711
3875
|
} });
|
3712
3876
|
(function () {
|
@@ -3727,6 +3891,9 @@ MgformatMagicDirective.ɵdir = i0.ɵɵdefineDirective({ type: MgformatMagicDirec
|
|
3727
3891
|
}], onChangeEvent: [{
|
3728
3892
|
type: HostListener,
|
3729
3893
|
args: ['change', ['$event']]
|
3894
|
+
}], onBlurEvent: [{
|
3895
|
+
type: HostListener,
|
3896
|
+
args: ['blur', ['$event']]
|
3730
3897
|
}] });
|
3731
3898
|
})();
|
3732
3899
|
|
@@ -4471,12 +4638,33 @@ const DATE_VALUE_ACCESSOR = {
|
|
4471
4638
|
multi: true
|
4472
4639
|
};
|
4473
4640
|
class DateValueAccessor {
|
4474
|
-
|
4641
|
+
onBlurEvent(event) {
|
4642
|
+
const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
|
4643
|
+
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
4644
|
+
this.formatDateWithCentury(event.target.value, century, control);
|
4645
|
+
}
|
4646
|
+
constructor(renderer, elementRef, magicDir, _task) {
|
4475
4647
|
this.renderer = renderer;
|
4476
4648
|
this.elementRef = elementRef;
|
4649
|
+
this.magicDir = magicDir;
|
4650
|
+
this._task = _task;
|
4477
4651
|
this.onChange = (_) => { };
|
4478
4652
|
this.onTouched = () => { };
|
4479
4653
|
}
|
4654
|
+
formatDateWithCentury(userInput, century, control) {
|
4655
|
+
const separator = userInput.includes('/') ? '/' : "-";
|
4656
|
+
let centuryVal = parseInt(century.toString().slice(0, 2));
|
4657
|
+
if (userInput.length == 0)
|
4658
|
+
return;
|
4659
|
+
const dateArray = userInput.split(separator);
|
4660
|
+
const day = Number(dateArray[2]);
|
4661
|
+
const month = Number(dateArray[1]);
|
4662
|
+
const year = Number(dateArray[0]);
|
4663
|
+
let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
|
4664
|
+
year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
|
4665
|
+
year;
|
4666
|
+
control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
|
4667
|
+
}
|
4480
4668
|
writeValue(value) {
|
4481
4669
|
if (!value) {
|
4482
4670
|
this.renderer.setProperty(this.elementRef.nativeElement, "value", null);
|
@@ -4496,10 +4684,10 @@ class DateValueAccessor {
|
|
4496
4684
|
this.renderer.setProperty(this.elementRef.nativeElement, "disabled", isDisabled);
|
4497
4685
|
}
|
4498
4686
|
}
|
4499
|
-
DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef)); };
|
4687
|
+
DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
|
4500
4688
|
DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, selectors: [["", "dateInput", ""]], hostBindings: function DateValueAccessor_HostBindings(rf, ctx) {
|
4501
4689
|
if (rf & 1) {
|
4502
|
-
i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler() { return ctx.
|
4690
|
+
i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler($event) { return ctx.onBlurEvent($event); });
|
4503
4691
|
}
|
4504
4692
|
}, features: [i0.ɵɵProvidersFeature([DATE_VALUE_ACCESSOR])] });
|
4505
4693
|
(function () {
|
@@ -4509,12 +4697,15 @@ DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, sele
|
|
4509
4697
|
selector: "[dateInput]",
|
4510
4698
|
providers: [DATE_VALUE_ACCESSOR]
|
4511
4699
|
}]
|
4512
|
-
}], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }]; }, { onChange: [{
|
4700
|
+
}], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: MagicDirective }, { type: TaskMagicService }]; }, { onChange: [{
|
4513
4701
|
type: HostListener,
|
4514
4702
|
args: ["input", ["$event.target.valueAsDate"]]
|
4515
4703
|
}], onTouched: [{
|
4516
4704
|
type: HostListener,
|
4517
4705
|
args: ["blur", []]
|
4706
|
+
}], onBlurEvent: [{
|
4707
|
+
type: HostListener,
|
4708
|
+
args: ['blur', ['$event']]
|
4518
4709
|
}] });
|
4519
4710
|
})();
|
4520
4711
|
|