@magic-xpa/angular 4.1000.0-dev4100.419 → 4.1000.0-dev4100.420

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.
@@ -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';
@@ -3434,6 +3434,170 @@ class MgformatMagicDirective {
3434
3434
  break;
3435
3435
  }
3436
3436
  }
3437
+ onBlurEvent(event) {
3438
+ let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
3439
+ let attr = this._task.Records.list[0].getControlMetadata(this.magicDir.id).dataType;
3440
+ const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
3441
+ if (attr == StorageAttribute.DATE)
3442
+ this.formatDateWithCentury(event.target.value, century, control);
3443
+ }
3444
+ formatDateWithCentury(userInput, century, control) {
3445
+ const dateFormat = this._task.mgInputDateFormat;
3446
+ const separator = userInput.includes('/') ? '/' : "-";
3447
+ let centuryVal = parseInt(century.toString().slice(0, 2));
3448
+ if (userInput.length == 0)
3449
+ return;
3450
+ if ((dateFormat == 'dd/MMM/yyyy' || dateFormat == 'dd-MMM-yyyy')) {
3451
+ const dateArray = userInput.split(separator);
3452
+ const [day, month, year] = this.getDateSegments1(dateArray);
3453
+ const isMonthInNumber = !isNaN(Number(month));
3454
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3455
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3456
+ }
3457
+ }
3458
+ else if ((dateFormat == 'dd/MM/yyyy' || dateFormat == 'dd-MM-yyyy' || dateFormat == 'd/M/yyyy' || dateFormat == 'd-M-yyyy')) {
3459
+ const dateArray = userInput.split(separator);
3460
+ const [day, month, year] = this.getDateSegments1(dateArray);
3461
+ if ((day < 32 && month < 13)) {
3462
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3463
+ }
3464
+ }
3465
+ else if ((dateFormat == 'MM/dd/yyyy' || dateFormat == 'MM-dd-yyyy' || dateFormat == 'M/d/yyyy' || dateFormat == 'M-d-yyyy')) {
3466
+ const dateArray = userInput.split(separator);
3467
+ const [day, month, year] = this.getDateSegments2(dateArray);
3468
+ if ((day < 32 && month < 13)) {
3469
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3470
+ }
3471
+ }
3472
+ else if ((dateFormat == 'MMM/dd/yyyy' || dateFormat == 'MMM-dd-yyyy')) {
3473
+ const dateArray = userInput.split(separator);
3474
+ const [day, month, year] = this.getDateSegments2(dateArray);
3475
+ const isMonthInNumber = !isNaN(Number(month));
3476
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3477
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3478
+ }
3479
+ }
3480
+ else if ((dateFormat == 'yyyy/MM/dd' || dateFormat == 'yyyy-MM-dd')) {
3481
+ const dateArray = userInput.split(separator);
3482
+ const [day, month, year] = this.getDateSegments3(dateArray);
3483
+ if ((day < 32 && month < 13)) {
3484
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3485
+ }
3486
+ }
3487
+ else if ((dateFormat == 'yyyy/dd/MM' || dateFormat == 'yyyy-dd-MM')) {
3488
+ const dateArray = userInput.split(separator);
3489
+ const [day, month, year] = this.getDateSegments4(dateArray);
3490
+ if ((day < 32 && month < 13)) {
3491
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3492
+ }
3493
+ }
3494
+ else if ((dateFormat == 'yyyy/dd/MMM' || dateFormat == 'yyyy-dd-MMM')) {
3495
+ const dateArray = userInput.split(separator);
3496
+ const [day, month, year] = this.getDateSegments4(dateArray);
3497
+ const isMonthInNumber = !isNaN(Number(month));
3498
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3499
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3500
+ }
3501
+ }
3502
+ else if ((dateFormat == 'dd/MM/yy' || dateFormat == 'dd-MM-yy' || dateFormat == 'd/M/yy' || dateFormat == 'd-M-yy')) {
3503
+ const dateArray = userInput.split(separator);
3504
+ const [day, month, year] = this.getDateSegments1(dateArray);
3505
+ if ((day < 32 && month < 13)) {
3506
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3507
+ }
3508
+ }
3509
+ else if ((dateFormat == 'MM/dd/yy' || dateFormat == 'MM-dd-yy' || dateFormat == 'M/d/yy' || dateFormat == 'M-d-yy')) {
3510
+ const dateArray = userInput.split(separator);
3511
+ const [day, month, year] = this.getDateSegments2(dateArray);
3512
+ if ((day < 32 && month < 13)) {
3513
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3514
+ }
3515
+ }
3516
+ else if ((dateFormat == 'yy/MM/dd' || dateFormat == 'yy-MM-dd')) {
3517
+ const dateArray = userInput.split(separator);
3518
+ const [day, month, year] = this.getDateSegments3(dateArray);
3519
+ if ((day < 32 && month < 13)) {
3520
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3521
+ }
3522
+ }
3523
+ else if ((dateFormat == 'yy/dd/MM' || dateFormat == 'yy-dd-MM')) {
3524
+ const dateArray = userInput.split(separator);
3525
+ const [day, month, year] = this.getDateSegments4(dateArray);
3526
+ if ((day < 32 && month < 13)) {
3527
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3528
+ }
3529
+ }
3530
+ else if ((dateFormat == 'dd/MMM/yy' || dateFormat == 'dd-MMM-yy')) {
3531
+ const dateArray = userInput.split(separator);
3532
+ const [day, month, year] = this.getDateSegments1(dateArray);
3533
+ const isMonthInNumber = !isNaN(Number(month));
3534
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3535
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3536
+ }
3537
+ }
3538
+ else if ((dateFormat == 'yy/dd/MMM' || dateFormat == 'yy-dd-MMM')) {
3539
+ const dateArray = userInput.split(separator);
3540
+ const [day, month, year] = this.getDateSegments4(dateArray);
3541
+ const isMonthInNumber = !isNaN(Number(month));
3542
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3543
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3544
+ }
3545
+ }
3546
+ else if ((dateFormat == 'MMM/dd/yy' || dateFormat == 'MMM-dd-yy')) {
3547
+ const dateArray = userInput.split(separator);
3548
+ const [day, month, year] = this.getDateSegments2(dateArray);
3549
+ const isMonthInNumber = !isNaN(Number(month));
3550
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3551
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3552
+ }
3553
+ }
3554
+ else if ((dateFormat == 'yyyy/MMM/dd' || dateFormat == 'yyyy-MMM-dd' || dateFormat == 'yy/MMM/dd' || dateFormat == 'yy-MMM-dd')) {
3555
+ const dateArray = userInput.split(separator);
3556
+ const [day, month, year] = this.getDateSegments3(dateArray);
3557
+ const isMonthInNumber = !isNaN(Number(month));
3558
+ if ((isMonthInNumber && day < 32 && Number(month) < 13) || (!isMonthInNumber && day < 32)) {
3559
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3560
+ }
3561
+ }
3562
+ else if (dateFormat == 'yyyy/MM' || dateFormat == 'yyyy-MM') {
3563
+ const dateArray = userInput.split(separator);
3564
+ const month = dateArray[1];
3565
+ const year = Number(dateArray[0]);
3566
+ if (Number(month) < 13) {
3567
+ this.updateYear(1, month, year, separator, century, centuryVal, control);
3568
+ }
3569
+ }
3570
+ }
3571
+ updateYear(day, month, year, separator, century, centuryVal, control) {
3572
+ let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
3573
+ year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
3574
+ year;
3575
+ control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
3576
+ }
3577
+ getDateSegments1(dateArray) {
3578
+ const day = Number(dateArray[0]);
3579
+ const month = dateArray[1];
3580
+ const year = Number(dateArray[2]);
3581
+ return [day, month, year];
3582
+ }
3583
+ getDateSegments2(dateArray) {
3584
+ const day = Number(dateArray[1]);
3585
+ const month = dateArray[0];
3586
+ const year = Number(dateArray[2]);
3587
+ return [day, month, year];
3588
+ }
3589
+ getDateSegments3(dateArray) {
3590
+ const day = Number(dateArray[2]);
3591
+ const month = dateArray[1];
3592
+ const year = Number(dateArray[0]);
3593
+ return [day, month, year];
3594
+ }
3595
+ getDateSegments4(dateArray) {
3596
+ const day = Number(dateArray[1]);
3597
+ const month = dateArray[2];
3598
+ const year = Number(dateArray[0]);
3599
+ return [day, month, year];
3600
+ }
3437
3601
  calculatePattern() {
3438
3602
  let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
3439
3603
  if (control != null) {
@@ -3615,7 +3779,7 @@ class MgformatMagicDirective {
3615
3779
  }
3616
3780
  MgformatMagicDirective.ɵfac = function MgformatMagicDirective_Factory(t) { return new (t || MgformatMagicDirective)(i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
3617
3781
  MgformatMagicDirective.ɵdir = i0.ɵɵdefineDirective({ type: MgformatMagicDirective, selectors: [["", "mgFormat", ""]], hostBindings: function MgformatMagicDirective_HostBindings(rf, ctx) { if (rf & 1) {
3618
- 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); });
3782
+ 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); });
3619
3783
  } } });
3620
3784
  (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MgformatMagicDirective, [{
3621
3785
  type: Directive,
@@ -3634,6 +3798,9 @@ MgformatMagicDirective.ɵdir = i0.ɵɵdefineDirective({ type: MgformatMagicDirec
3634
3798
  }], onChangeEvent: [{
3635
3799
  type: HostListener,
3636
3800
  args: ['change', ['$event']]
3801
+ }], onBlurEvent: [{
3802
+ type: HostListener,
3803
+ args: ['blur', ['$event']]
3637
3804
  }] }); })();
3638
3805
 
3639
3806
  class TimeMagicPipe extends DatePipe {
@@ -4305,12 +4472,33 @@ const DATE_VALUE_ACCESSOR = {
4305
4472
  multi: true
4306
4473
  };
4307
4474
  class DateValueAccessor {
4308
- constructor(renderer, elementRef) {
4475
+ onBlurEvent(event) {
4476
+ const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
4477
+ let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
4478
+ this.formatDateWithCentury(event.target.value, century, control);
4479
+ }
4480
+ constructor(renderer, elementRef, magicDir, _task) {
4309
4481
  this.renderer = renderer;
4310
4482
  this.elementRef = elementRef;
4483
+ this.magicDir = magicDir;
4484
+ this._task = _task;
4311
4485
  this.onChange = (_) => { };
4312
4486
  this.onTouched = () => { };
4313
4487
  }
4488
+ formatDateWithCentury(userInput, century, control) {
4489
+ const separator = userInput.includes('/') ? '/' : "-";
4490
+ let centuryVal = parseInt(century.toString().slice(0, 2));
4491
+ if (userInput.length == 0)
4492
+ return;
4493
+ const dateArray = userInput.split(separator);
4494
+ const day = Number(dateArray[2]);
4495
+ const month = Number(dateArray[1]);
4496
+ const year = Number(dateArray[0]);
4497
+ let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
4498
+ year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
4499
+ year;
4500
+ control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
4501
+ }
4314
4502
  writeValue(value) {
4315
4503
  if (!value) {
4316
4504
  this.renderer.setProperty(this.elementRef.nativeElement, "value", null);
@@ -4330,9 +4518,9 @@ class DateValueAccessor {
4330
4518
  this.renderer.setProperty(this.elementRef.nativeElement, "disabled", isDisabled);
4331
4519
  }
4332
4520
  }
4333
- DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef)); };
4521
+ DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
4334
4522
  DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, selectors: [["", "dateInput", ""]], hostBindings: function DateValueAccessor_HostBindings(rf, ctx) { if (rf & 1) {
4335
- i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler() { return ctx.onTouched(); });
4523
+ i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler($event) { return ctx.onBlurEvent($event); });
4336
4524
  } }, features: [i0.ɵɵProvidersFeature([DATE_VALUE_ACCESSOR])] });
4337
4525
  (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DateValueAccessor, [{
4338
4526
  type: Directive,
@@ -4340,12 +4528,15 @@ DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, sele
4340
4528
  selector: "[dateInput]",
4341
4529
  providers: [DATE_VALUE_ACCESSOR]
4342
4530
  }]
4343
- }], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }]; }, { onChange: [{
4531
+ }], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: MagicDirective }, { type: TaskMagicService }]; }, { onChange: [{
4344
4532
  type: HostListener,
4345
4533
  args: ["input", ["$event.target.valueAsDate"]]
4346
4534
  }], onTouched: [{
4347
4535
  type: HostListener,
4348
4536
  args: ["blur", []]
4537
+ }], onBlurEvent: [{
4538
+ type: HostListener,
4539
+ args: ['blur', ['$event']]
4349
4540
  }] }); })();
4350
4541
 
4351
4542
  class NonMagicControlDirective {