mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[APPS-2133] migration of dependency from moment to date-fns in start-task.component (#8844)
* migration of dependency from moment to date-fns in task-list.component * used parse() instead of format() * [APPS-2133] Migration from moment to date-fns with converter approach * [APPS-2133] Changed varible name to avoid lint issue --------- Co-authored-by: kritagya09 <kritagya.jaiswal@globallogic.com>
This commit is contained in:
@@ -16,12 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
LogService, UserPreferencesService, UserPreferenceValues, FormFieldModel, FormModel,
|
LogService, UserPreferencesService, UserPreferenceValues, FormFieldModel, FormModel, DateFnsUtils
|
||||||
MOMENT_DATE_FORMATS, MomentDateAdapter
|
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDestroy } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDestroy } from '@angular/core';
|
||||||
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core';
|
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core';
|
||||||
import moment, { Moment } from 'moment';
|
|
||||||
import { EMPTY, Observable, Subject } from 'rxjs';
|
import { EMPTY, Observable, Subject } from 'rxjs';
|
||||||
import { Form } from '../models/form.model';
|
import { Form } from '../models/form.model';
|
||||||
import { TaskDetailsModel } from '../models/task-details.model';
|
import { TaskDetailsModel } from '../models/task-details.model';
|
||||||
@@ -29,6 +27,8 @@ import { TaskListService } from './../services/tasklist.service';
|
|||||||
import { switchMap, defaultIfEmpty, takeUntil } from 'rxjs/operators';
|
import { switchMap, defaultIfEmpty, takeUntil } from 'rxjs/operators';
|
||||||
import { UntypedFormBuilder, AbstractControl, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
|
import { UntypedFormBuilder, AbstractControl, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
|
||||||
import { UserProcessModel } from '../../common/models/user-process.model';
|
import { UserProcessModel } from '../../common/models/user-process.model';
|
||||||
|
import { isValid } from 'date-fns';
|
||||||
|
import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns-adapter';
|
||||||
|
|
||||||
const FORMAT_DATE = 'DD/MM/YYYY';
|
const FORMAT_DATE = 'DD/MM/YYYY';
|
||||||
const MAX_LENGTH = 255;
|
const MAX_LENGTH = 255;
|
||||||
@@ -38,8 +38,8 @@ const MAX_LENGTH = 255;
|
|||||||
templateUrl: './start-task.component.html',
|
templateUrl: './start-task.component.html',
|
||||||
styleUrls: ['./start-task.component.scss'],
|
styleUrls: ['./start-task.component.scss'],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: DateAdapter, useClass: MomentDateAdapter },
|
{ provide: DateAdapter, useClass: DateFnsAdapter },
|
||||||
{ provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS }],
|
{ provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS }],
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class StartTaskComponent implements OnInit, OnDestroy {
|
export class StartTaskComponent implements OnInit, OnDestroy {
|
||||||
@@ -75,7 +75,7 @@ export class StartTaskComponent implements OnInit, OnDestroy {
|
|||||||
private onDestroy$ = new Subject<boolean>();
|
private onDestroy$ = new Subject<boolean>();
|
||||||
|
|
||||||
constructor(private taskService: TaskListService,
|
constructor(private taskService: TaskListService,
|
||||||
private dateAdapter: DateAdapter<Moment>,
|
private dateAdapter: DateAdapter<DateFnsAdapter>,
|
||||||
private userPreferencesService: UserPreferencesService,
|
private userPreferencesService: UserPreferencesService,
|
||||||
private formBuilder: UntypedFormBuilder,
|
private formBuilder: UntypedFormBuilder,
|
||||||
private logService: LogService) {
|
private logService: LogService) {
|
||||||
@@ -93,7 +93,7 @@ export class StartTaskComponent implements OnInit, OnDestroy {
|
|||||||
this.userPreferencesService
|
this.userPreferencesService
|
||||||
.select(UserPreferenceValues.Locale)
|
.select(UserPreferenceValues.Locale)
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
.subscribe(locale => this.dateAdapter.setLocale(locale));
|
.subscribe(locale => this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale)));
|
||||||
|
|
||||||
this.loadFormsTask();
|
this.loadFormsTask();
|
||||||
this.buildForm();
|
this.buildForm();
|
||||||
@@ -119,8 +119,8 @@ export class StartTaskComponent implements OnInit, OnDestroy {
|
|||||||
whitespaceValidator(control: UntypedFormControl): any {
|
whitespaceValidator(control: UntypedFormControl): any {
|
||||||
if (control.value) {
|
if (control.value) {
|
||||||
const isWhitespace = (control.value || '').trim().length === 0;
|
const isWhitespace = (control.value || '').trim().length === 0;
|
||||||
const isValid = control.value.length === 0 || !isWhitespace;
|
const isControlValid = control.value.length === 0 || !isWhitespace;
|
||||||
return isValid ? null : { whitespace: true };
|
return isControlValid ? null : { whitespace: true };
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -187,16 +187,16 @@ export class StartTaskComponent implements OnInit, OnDestroy {
|
|||||||
this.dateError = false;
|
this.dateError = false;
|
||||||
|
|
||||||
if (newDateValue) {
|
if (newDateValue) {
|
||||||
let momentDate: moment.Moment;
|
let date: Date;
|
||||||
|
|
||||||
if (typeof newDateValue === 'string') {
|
if (typeof newDateValue === 'string') {
|
||||||
momentDate = moment(newDateValue, FORMAT_DATE, true);
|
date = DateFnsUtils.parseDate(newDateValue, FORMAT_DATE);
|
||||||
} else {
|
} else {
|
||||||
momentDate = newDateValue;
|
date = newDateValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (momentDate.isValid()) {
|
if (isValid(date)) {
|
||||||
this.taskDetailsModel.dueDate = momentDate.toDate();
|
this.taskDetailsModel.dueDate = date;
|
||||||
} else {
|
} else {
|
||||||
this.dateError = true;
|
this.dateError = true;
|
||||||
this.taskDetailsModel.dueDate = null;
|
this.taskDetailsModel.dueDate = null;
|
||||||
|
Reference in New Issue
Block a user