@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.
@@ -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';
@@ -3441,9 +3441,10 @@ class MgformatMagicDirective {
3441
3441
  input.setSelectionRange(start, end);
3442
3442
  }
3443
3443
  }
3444
- onChangeEvent($event) {
3444
+ onChangeEvent(event) {
3445
3445
  let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
3446
3446
  let attr = this._task.Records.list[0].getControlMetadata(this.magicDir.id).dataType;
3447
+ const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
3447
3448
  switch (attr) {
3448
3449
  case StorageAttribute.ALPHA:
3449
3450
  case StorageAttribute.UNICODE:
@@ -3452,8 +3453,164 @@ class MgformatMagicDirective {
3452
3453
  case StorageAttribute.BOOLEAN:
3453
3454
  this.formatBoolean(control);
3454
3455
  break;
3456
+ case StorageAttribute.DATE:
3457
+ this.formatDateWithCentury(event.target.value, century, control);
3458
+ break;
3455
3459
  }
3456
3460
  }
3461
+ formatDateWithCentury(userInput, century, control) {
3462
+ const dateFormat = this._task.mgInputDateFormat;
3463
+ const separator = userInput.includes('/') ? '/' : "-";
3464
+ let centuryVal = parseInt(century.toString().slice(0, 2));
3465
+ if (userInput.length == 0)
3466
+ return;
3467
+ if ((dateFormat == 'dd/MMM/yyyy' || dateFormat == 'dd-MMM-yyyy')) {
3468
+ const dateArray = userInput.split(separator);
3469
+ const [day, month, year] = this.getDateSegments1(dateArray);
3470
+ const isMonthInNumber = !isNaN(Number(month));
3471
+ if (isMonthInNumber == true) {
3472
+ if (day < 32 && Number(month) < 13) {
3473
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3474
+ }
3475
+ }
3476
+ else if (day < 32) {
3477
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3478
+ }
3479
+ }
3480
+ else if ((dateFormat == 'dd/MM/yyyy' || dateFormat == 'dd-MM-yyyy')) {
3481
+ const dateArray = userInput.split(separator);
3482
+ const [day, month, year] = this.getDateSegments1(dateArray);
3483
+ if ((day < 32 && month < 13)) {
3484
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3485
+ }
3486
+ }
3487
+ else if ((dateFormat == 'MM/dd/yyyy' || dateFormat == 'MM-dd-yyyy')) {
3488
+ const dateArray = userInput.split(separator);
3489
+ const [day, month, year] = this.getDateSegments2(dateArray);
3490
+ if ((day < 32 && month < 13)) {
3491
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3492
+ }
3493
+ }
3494
+ else if ((dateFormat == 'MMM/dd/yyyy' || dateFormat == 'MMM-dd-yyyy')) {
3495
+ const dateArray = userInput.split(separator);
3496
+ const [day, month, year] = this.getDateSegments2(dateArray);
3497
+ const isMonthInNumber = !isNaN(Number(month));
3498
+ if (isMonthInNumber == true) {
3499
+ if (day < 32 && Number(month) < 13) {
3500
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3501
+ }
3502
+ }
3503
+ else if (day < 32) {
3504
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3505
+ }
3506
+ }
3507
+ else if ((dateFormat == 'yyyy/MM/dd' || dateFormat == 'yyyy-MM-dd')) {
3508
+ const dateArray = userInput.split(separator);
3509
+ const [day, month, year] = this.getDateSegments3(dateArray);
3510
+ if ((day < 32 && month < 13)) {
3511
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3512
+ }
3513
+ }
3514
+ else if ((dateFormat == 'yyyy/dd/MM' || dateFormat == 'yyyy-dd-MM')) {
3515
+ const dateArray = userInput.split(separator);
3516
+ const [day, month, year] = this.getDateSegments4(dateArray);
3517
+ if ((day < 32 && month < 13)) {
3518
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3519
+ }
3520
+ }
3521
+ else if ((dateFormat == 'yyyy/dd/MMM' || dateFormat == 'yyyy-dd-MMM')) {
3522
+ const dateArray = userInput.split(separator);
3523
+ const [day, month, year] = this.getDateSegments4(dateArray);
3524
+ const isMonthInNumber = !isNaN(Number(month));
3525
+ if (isMonthInNumber == true) {
3526
+ if (day < 32 && Number(month) < 13) {
3527
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3528
+ }
3529
+ }
3530
+ else if (day < 32) {
3531
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3532
+ }
3533
+ }
3534
+ else if ((dateFormat == 'dd/MM/yy' || dateFormat == 'dd-MM-yy')) {
3535
+ const dateArray = userInput.split(separator);
3536
+ const [day, month, year] = this.getDateSegments1(dateArray);
3537
+ if ((day < 32 && month < 13)) {
3538
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3539
+ }
3540
+ }
3541
+ else if ((dateFormat == 'MM/dd/yy' || dateFormat == 'MM-dd-yy')) {
3542
+ const dateArray = userInput.split(separator);
3543
+ const [day, month, year] = this.getDateSegments2(dateArray);
3544
+ if ((day < 32 && month < 13)) {
3545
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3546
+ }
3547
+ }
3548
+ else if ((dateFormat == 'yy/MM/dd' || dateFormat == 'yy-MM-dd')) {
3549
+ const dateArray = userInput.split(separator);
3550
+ const [day, month, year] = this.getDateSegments3(dateArray);
3551
+ if ((day < 32 && month < 13)) {
3552
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3553
+ }
3554
+ }
3555
+ else if ((dateFormat == 'yy/dd/MM' || dateFormat == 'yy-dd-MM')) {
3556
+ const dateArray = userInput.split(separator);
3557
+ const [day, month, year] = this.getDateSegments4(dateArray);
3558
+ if ((day < 32 && month < 13)) {
3559
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3560
+ }
3561
+ }
3562
+ else if ((dateFormat == 'dd/MMM/yy' || dateFormat == 'dd-MMM-yy')) {
3563
+ const dateArray = userInput.split(separator);
3564
+ const [day, month, year] = this.getDateSegments1(dateArray);
3565
+ if ((day < 32 && month < 13)) {
3566
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3567
+ }
3568
+ }
3569
+ else if ((dateFormat == 'yy/dd/MMM' || dateFormat == 'yy-dd-MMM')) {
3570
+ const dateArray = userInput.split(separator);
3571
+ const [day, month, year] = this.getDateSegments4(dateArray);
3572
+ if ((day < 32 && month < 13)) {
3573
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3574
+ }
3575
+ }
3576
+ else if ((dateFormat == 'MMM/dd/yy' || dateFormat == 'MMM-dd-yy')) {
3577
+ const dateArray = userInput.split(separator);
3578
+ const [day, month, year] = this.getDateSegments2(dateArray);
3579
+ if ((day < 32 && month < 13)) {
3580
+ this.updateYear(day, month, year, separator, century, centuryVal, control);
3581
+ }
3582
+ }
3583
+ }
3584
+ updateYear(day, month, year, separator, century, centuryVal, control) {
3585
+ let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
3586
+ year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
3587
+ year;
3588
+ control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
3589
+ }
3590
+ getDateSegments1(dateArray) {
3591
+ const day = Number(dateArray[0]);
3592
+ const month = dateArray[1];
3593
+ const year = Number(dateArray[2]);
3594
+ return [day, month, year];
3595
+ }
3596
+ getDateSegments2(dateArray) {
3597
+ const day = Number(dateArray[1]);
3598
+ const month = dateArray[0];
3599
+ const year = Number(dateArray[2]);
3600
+ return [day, month, year];
3601
+ }
3602
+ getDateSegments3(dateArray) {
3603
+ const day = Number(dateArray[2]);
3604
+ const month = dateArray[1];
3605
+ const year = Number(dateArray[0]);
3606
+ return [day, month, year];
3607
+ }
3608
+ getDateSegments4(dateArray) {
3609
+ const day = Number(dateArray[1]);
3610
+ const month = dateArray[2];
3611
+ const year = Number(dateArray[0]);
3612
+ return [day, month, year];
3613
+ }
3457
3614
  calculatePattern() {
3458
3615
  let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
3459
3616
  if (control != null) {
@@ -4261,12 +4418,33 @@ const DATE_VALUE_ACCESSOR = {
4261
4418
  multi: true
4262
4419
  };
4263
4420
  class DateValueAccessor {
4264
- constructor(renderer, elementRef) {
4421
+ onBlurEvent(event) {
4422
+ const century = Environment.Instance.GetCentury(LastFocusedManager.Instance.getCurrTask().getCompIdx());
4423
+ let control = this._task.getFormControl(this.magicDir.rowId, this.magicDir.id);
4424
+ this.formatDateWithCentury(event.target.value, century, control);
4425
+ }
4426
+ constructor(renderer, elementRef, magicDir, _task) {
4265
4427
  this.renderer = renderer;
4266
4428
  this.elementRef = elementRef;
4429
+ this.magicDir = magicDir;
4430
+ this._task = _task;
4267
4431
  this.onChange = (_) => { };
4268
4432
  this.onTouched = () => { };
4269
4433
  }
4434
+ formatDateWithCentury(userInput, century, control) {
4435
+ const separator = userInput.includes('/') ? '/' : "-";
4436
+ let centuryVal = parseInt(century.toString().slice(0, 2));
4437
+ if (userInput.length == 0)
4438
+ return;
4439
+ const dateArray = userInput.split(separator);
4440
+ const day = Number(dateArray[2]);
4441
+ const month = Number(dateArray[1]);
4442
+ const year = Number(dateArray[0]);
4443
+ let updatedYear = year.toString().length === 2 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '' + year :
4444
+ year.toString().length === 1 ? (year < century % 100 ? centuryVal + 1 : centuryVal) + '0' + year :
4445
+ year;
4446
+ control.setValue(new Date(`${updatedYear}${separator}${month}${separator}${day}`));
4447
+ }
4270
4448
  writeValue(value) {
4271
4449
  if (!value) {
4272
4450
  this.renderer.setProperty(this.elementRef.nativeElement, "value", null);
@@ -4286,9 +4464,9 @@ class DateValueAccessor {
4286
4464
  this.renderer.setProperty(this.elementRef.nativeElement, "disabled", isDisabled);
4287
4465
  }
4288
4466
  }
4289
- DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef)); };
4467
+ DateValueAccessor.ɵfac = function DateValueAccessor_Factory(t) { return new (t || DateValueAccessor)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(MagicDirective), i0.ɵɵdirectiveInject(TaskMagicService)); };
4290
4468
  DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, selectors: [["", "dateInput", ""]], hostBindings: function DateValueAccessor_HostBindings(rf, ctx) { if (rf & 1) {
4291
- i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler() { return ctx.onTouched(); });
4469
+ i0.ɵɵlistener("input", function DateValueAccessor_input_HostBindingHandler($event) { return ctx.onChange($event.target.valueAsDate); })("blur", function DateValueAccessor_blur_HostBindingHandler($event) { return ctx.onBlurEvent($event); });
4292
4470
  } }, features: [i0.ɵɵProvidersFeature([DATE_VALUE_ACCESSOR])] });
4293
4471
  (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DateValueAccessor, [{
4294
4472
  type: Directive,
@@ -4296,12 +4474,15 @@ DateValueAccessor.ɵdir = i0.ɵɵdefineDirective({ type: DateValueAccessor, sele
4296
4474
  selector: "[dateInput]",
4297
4475
  providers: [DATE_VALUE_ACCESSOR]
4298
4476
  }]
4299
- }], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }]; }, { onChange: [{
4477
+ }], function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: MagicDirective }, { type: TaskMagicService }]; }, { onChange: [{
4300
4478
  type: HostListener,
4301
4479
  args: ["input", ["$event.target.valueAsDate"]]
4302
4480
  }], onTouched: [{
4303
4481
  type: HostListener,
4304
4482
  args: ["blur", []]
4483
+ }], onBlurEvent: [{
4484
+ type: HostListener,
4485
+ args: ['blur', ['$event']]
4305
4486
  }] }); })();
4306
4487
 
4307
4488
  class NonMagicControlDirective {