@magic-xpa/angular 4.1100.0-dev4110.161 → 4.1100.0-dev4110.163
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 +160 -2
- package/fesm2015/magic-xpa-angular.mjs +187 -6
- package/fesm2015/magic-xpa-angular.mjs.map +1 -1
- package/fesm2020/magic-xpa-angular.mjs +187 -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 -1
@@ -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, OverlayType, Styles, HtmlProperties, 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';
|
@@ -3531,9 +3531,10 @@ class MgformatMagicDirective {
|
|
3531
3531
|
input.setSelectionRange(start, end);
|
3532
3532
|
}
|
3533
3533
|
}
|
3534
|
-
onChangeEvent(
|
3534
|
+
onChangeEvent(event) {
|
3535
3535
|
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
3536
3536
|
let attr = this._task.Records.list[0].getControlMetadata(this.magicDir.id).dataType;
|
3537
|
+
const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
|
3537
3538
|
switch (attr) {
|
3538
3539
|
case StorageAttribute.ALPHA:
|
3539
3540
|
case StorageAttribute.UNICODE:
|
@@ -3542,8 +3543,164 @@ class MgformatMagicDirective {
|
|
3542
3543
|
case StorageAttribute.BOOLEAN:
|
3543
3544
|
this.formatBoolean(control);
|
3544
3545
|
break;
|
3546
|
+
case StorageAttribute.DATE:
|
3547
|
+
this.formatDateWithCentury(event.target.value, century, control);
|
3548
|
+
break;
|
3545
3549
|
}
|
3546
3550
|
}
|
3551
|
+
formatDateWithCentury(userInput, century, control) {
|
3552
|
+
const dateFormat = this._task.mgInputDateFormat;
|
3553
|
+
const separator = userInput.includes('/') ? '/' : "-";
|
3554
|
+
let centuryVal = parseInt(century.toString().slice(0, 2));
|
3555
|
+
if (userInput.length == 0)
|
3556
|
+
return;
|
3557
|
+
if ((dateFormat == 'dd/MMM/yyyy' || dateFormat == 'dd-MMM-yyyy')) {
|
3558
|
+
const dateArray = userInput.split(separator);
|
3559
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3560
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3561
|
+
if (isMonthInNumber == true) {
|
3562
|
+
if (day < 32 && Number(month) < 13) {
|
3563
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3564
|
+
}
|
3565
|
+
}
|
3566
|
+
else if (day < 32) {
|
3567
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3568
|
+
}
|
3569
|
+
}
|
3570
|
+
else if ((dateFormat == 'dd/MM/yyyy' || dateFormat == 'dd-MM-yyyy')) {
|
3571
|
+
const dateArray = userInput.split(separator);
|
3572
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3573
|
+
if ((day < 32 && month < 13)) {
|
3574
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3575
|
+
}
|
3576
|
+
}
|
3577
|
+
else if ((dateFormat == 'MM/dd/yyyy' || dateFormat == 'MM-dd-yyyy')) {
|
3578
|
+
const dateArray = userInput.split(separator);
|
3579
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3580
|
+
if ((day < 32 && month < 13)) {
|
3581
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3582
|
+
}
|
3583
|
+
}
|
3584
|
+
else if ((dateFormat == 'MMM/dd/yyyy' || dateFormat == 'MMM-dd-yyyy')) {
|
3585
|
+
const dateArray = userInput.split(separator);
|
3586
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3587
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3588
|
+
if (isMonthInNumber == true) {
|
3589
|
+
if (day < 32 && Number(month) < 13) {
|
3590
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3591
|
+
}
|
3592
|
+
}
|
3593
|
+
else if (day < 32) {
|
3594
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3595
|
+
}
|
3596
|
+
}
|
3597
|
+
else if ((dateFormat == 'yyyy/MM/dd' || dateFormat == 'yyyy-MM-dd')) {
|
3598
|
+
const dateArray = userInput.split(separator);
|
3599
|
+
const [day, month, year] = this.getDateSegments3(dateArray);
|
3600
|
+
if ((day < 32 && month < 13)) {
|
3601
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3602
|
+
}
|
3603
|
+
}
|
3604
|
+
else if ((dateFormat == 'yyyy/dd/MM' || dateFormat == 'yyyy-dd-MM')) {
|
3605
|
+
const dateArray = userInput.split(separator);
|
3606
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3607
|
+
if ((day < 32 && month < 13)) {
|
3608
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3609
|
+
}
|
3610
|
+
}
|
3611
|
+
else if ((dateFormat == 'yyyy/dd/MMM' || dateFormat == 'yyyy-dd-MMM')) {
|
3612
|
+
const dateArray = userInput.split(separator);
|
3613
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3614
|
+
const isMonthInNumber = !isNaN(Number(month));
|
3615
|
+
if (isMonthInNumber == true) {
|
3616
|
+
if (day < 32 && Number(month) < 13) {
|
3617
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3618
|
+
}
|
3619
|
+
}
|
3620
|
+
else if (day < 32) {
|
3621
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3622
|
+
}
|
3623
|
+
}
|
3624
|
+
else if ((dateFormat == 'dd/MM/yy' || dateFormat == 'dd-MM-yy')) {
|
3625
|
+
const dateArray = userInput.split(separator);
|
3626
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3627
|
+
if ((day < 32 && month < 13)) {
|
3628
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3629
|
+
}
|
3630
|
+
}
|
3631
|
+
else if ((dateFormat == 'MM/dd/yy' || dateFormat == 'MM-dd-yy')) {
|
3632
|
+
const dateArray = userInput.split(separator);
|
3633
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3634
|
+
if ((day < 32 && month < 13)) {
|
3635
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3636
|
+
}
|
3637
|
+
}
|
3638
|
+
else if ((dateFormat == 'yy/MM/dd' || dateFormat == 'yy-MM-dd')) {
|
3639
|
+
const dateArray = userInput.split(separator);
|
3640
|
+
const [day, month, year] = this.getDateSegments3(dateArray);
|
3641
|
+
if ((day < 32 && month < 13)) {
|
3642
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3643
|
+
}
|
3644
|
+
}
|
3645
|
+
else if ((dateFormat == 'yy/dd/MM' || dateFormat == 'yy-dd-MM')) {
|
3646
|
+
const dateArray = userInput.split(separator);
|
3647
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3648
|
+
if ((day < 32 && month < 13)) {
|
3649
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3650
|
+
}
|
3651
|
+
}
|
3652
|
+
else if ((dateFormat == 'dd/MMM/yy' || dateFormat == 'dd-MMM-yy')) {
|
3653
|
+
const dateArray = userInput.split(separator);
|
3654
|
+
const [day, month, year] = this.getDateSegments1(dateArray);
|
3655
|
+
if ((day < 32 && month < 13)) {
|
3656
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3657
|
+
}
|
3658
|
+
}
|
3659
|
+
else if ((dateFormat == 'yy/dd/MMM' || dateFormat == 'yy-dd-MMM')) {
|
3660
|
+
const dateArray = userInput.split(separator);
|
3661
|
+
const [day, month, year] = this.getDateSegments4(dateArray);
|
3662
|
+
if ((day < 32 && month < 13)) {
|
3663
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3664
|
+
}
|
3665
|
+
}
|
3666
|
+
else if ((dateFormat == 'MMM/dd/yy' || dateFormat == 'MMM-dd-yy')) {
|
3667
|
+
const dateArray = userInput.split(separator);
|
3668
|
+
const [day, month, year] = this.getDateSegments2(dateArray);
|
3669
|
+
if ((day < 32 && month < 13)) {
|
3670
|
+
this.updateYear(day, month, year, separator, century, centuryVal, control);
|
3671
|
+
}
|
3672
|
+
}
|
3673
|
+
}
|
3674
|
+
updateYear(day, month, year, separator, century, centuryVal, control) {
|
3675
|
+
let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
|
3676
|
+
year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
|
3677
|
+
year;
|
3678
|
+
control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
|
3679
|
+
}
|
3680
|
+
getDateSegments1(dateArray) {
|
3681
|
+
const day = Number(dateArray[0]);
|
3682
|
+
const month = dateArray[1];
|
3683
|
+
const year = Number(dateArray[2]);
|
3684
|
+
return [day, month, year];
|
3685
|
+
}
|
3686
|
+
getDateSegments2(dateArray) {
|
3687
|
+
const day = Number(dateArray[1]);
|
3688
|
+
const month = dateArray[0];
|
3689
|
+
const year = Number(dateArray[2]);
|
3690
|
+
return [day, month, year];
|
3691
|
+
}
|
3692
|
+
getDateSegments3(dateArray) {
|
3693
|
+
const day = Number(dateArray[2]);
|
3694
|
+
const month = dateArray[1];
|
3695
|
+
const year = Number(dateArray[0]);
|
3696
|
+
return [day, month, year];
|
3697
|
+
}
|
3698
|
+
getDateSegments4(dateArray) {
|
3699
|
+
const day = Number(dateArray[1]);
|
3700
|
+
const month = dateArray[2];
|
3701
|
+
const year = Number(dateArray[0]);
|
3702
|
+
return [day, month, year];
|
3703
|
+
}
|
3547
3704
|
calculatePattern() {
|
3548
3705
|
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
3549
3706
|
if (control != null) {
|
@@ -4427,12 +4584,33 @@ const DATE_VALUE_ACCESSOR = {
|
|
4427
4584
|
multi: true
|
4428
4585
|
};
|
4429
4586
|
class DateValueAccessor {
|
4430
|
-
|
4587
|
+
onBlurEvent(event) {
|
4588
|
+
const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
|
4589
|
+
let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
|
4590
|
+
this.formatDateWithCentury(event.target.value, century, control);
|
4591
|
+
}
|
4592
|
+
constructor(renderer, elementRef, magicDir, _task) {
|
4431
4593
|
this.renderer = renderer;
|
4432
4594
|
this.elementRef = elementRef;
|
4595
|
+
this.magicDir = magicDir;
|
4596
|
+
this._task = _task;
|
4433
4597
|
this.onChange = (_) => { };
|
4434
4598
|
this.onTouched = () => { };
|
4435
4599
|
}
|
4600
|
+
formatDateWithCentury(userInput, century, control) {
|
4601
|
+
const separator = userInput.includes('/') ? '/' : "-";
|
4602
|
+
let centuryVal = parseInt(century.toString().slice(0, 2));
|
4603
|
+
if (userInput.length == 0)
|
4604
|
+
return;
|
4605
|
+
const dateArray = userInput.split(separator);
|
4606
|
+
const day = Number(dateArray[2]);
|
4607
|
+
const month = Number(dateArray[1]);
|
4608
|
+
const year = Number(dateArray[0]);
|
4609
|
+
let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
|
4610
|
+
year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
|
4611
|
+
year;
|
4612
|
+
control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
|
4613
|
+
}
|
4436
4614
|
writeValue(value) {
|
4437
4615
|
if (!value) {
|
4438
4616
|
this.renderer.setProperty(this.elementRef.nativeElement, "value", null);
|
@@ -4452,10 +4630,10 @@ class DateValueAccessor {
|
|
4452
4630
|
this.renderer.setProperty(this.elementRef.nativeElement, "disabled", isDisabled);
|
4453
4631
|
}
|
4454
4632
|
}
|
4455
|
-
DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef)); };
|
4633
|
+
DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
|
4456
4634
|
DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, selectors: [["", "dateInput", ""]], hostBindings: function DateValueAccessor_HostBindings(rf, ctx) {
|
4457
4635
|
if (rf & 1) {
|
4458
|
-
i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler() { return ctx.
|
4636
|
+
i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler($event) { return ctx.onBlurEvent($event); });
|
4459
4637
|
}
|
4460
4638
|
}, features: [i0.ɵɵProvidersFeature([DATE_VALUE_ACCESSOR])] });
|
4461
4639
|
(function () {
|
@@ -4465,12 +4643,15 @@ DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, sele
|
|
4465
4643
|
selector: "[dateInput]",
|
4466
4644
|
providers: [DATE_VALUE_ACCESSOR]
|
4467
4645
|
}]
|
4468
|
-
}], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }]; }, { onChange: [{
|
4646
|
+
}], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: MagicDirective }, { type: TaskMagicService }]; }, { onChange: [{
|
4469
4647
|
type: HostListener,
|
4470
4648
|
args: ["input", ["$event.target.valueAsDate"]]
|
4471
4649
|
}], onTouched: [{
|
4472
4650
|
type: HostListener,
|
4473
4651
|
args: ["blur", []]
|
4652
|
+
}], onBlurEvent: [{
|
4653
|
+
type: HostListener,
|
4654
|
+
args: ['blur', ['$event']]
|
4474
4655
|
}] });
|
4475
4656
|
})();
|
4476
4657
|
|