[ACS-5645] card view dateitem parse fix (#9017)

* card view dateitem parse fix

* remove unused prop

* remove dead link from demo shell
This commit is contained in:
Denys Vuika
2023-10-24 15:48:36 +01:00
committed by GitHub
parent 36c6e6d8ea
commit 879c5a6d2c
3 changed files with 4 additions and 13 deletions

View File

@@ -42,8 +42,7 @@ export class AppLayoutComponent {
{ href: '/form', icon: 'poll', title: 'Form' } { href: '/form', icon: 'poll', title: 'Form' }
]}, ]},
{ href: '/login', icon: 'vpn_key', title: 'Login' }, { href: '/login', icon: 'vpn_key', title: 'Login' },
{ href: '/settings-layout', icon: 'settings', title: 'Settings' }, { href: '/settings-layout', icon: 'settings', title: 'Settings' }
{ href: '/treeview', icon: 'nature', title: 'Tree View' }
]; ];
enableRedirect = true; enableRedirect = true;

View File

@@ -61,10 +61,6 @@ describe('CardViewDateItemComponent', () => {
afterEach(() => fixture.destroy()); afterEach(() => fixture.destroy());
it('should pick date format from appConfigService', () => {
expect(component.dateFormat).toEqual('shortDate');
});
it('should render the label and value', () => { it('should render the label and value', () => {
fixture.detectChanges(); fixture.detectChanges();
@@ -319,7 +315,6 @@ describe('CardViewDateItemComponent', () => {
component.property.editable = true; component.property.editable = true;
component.property.default = 'Jul 10 2017 00:01:00'; component.property.default = 'Jul 10 2017 00:01:00';
component.property.key = 'fake-key'; component.property.key = 'fake-key';
component.dateFormat = 'M/d/yy, h:mm a';
component.property.value = new Date('Jul 10 2017 00:01:00'); component.property.value = new Date('Jul 10 2017 00:01:00');
const expectedDate = new Date('Jul 10 2018'); const expectedDate = new Date('Jul 10 2018');
fixture.detectChanges(); fixture.detectChanges();

View File

@@ -20,7 +20,6 @@ import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core';
import { DatetimeAdapter, MAT_DATETIME_FORMATS, MatDatetimepickerComponent, MatDatetimepickerInputEvent } from '@mat-datetimepicker/core'; import { DatetimeAdapter, MAT_DATETIME_FORMATS, MatDatetimepickerComponent, MatDatetimepickerInputEvent } from '@mat-datetimepicker/core';
import { CardViewDateItemModel } from '../../models/card-view-dateitem.model'; import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
import { UserPreferencesService, UserPreferenceValues } from '../../../common/services/user-preferences.service'; import { UserPreferencesService, UserPreferenceValues } from '../../../common/services/user-preferences.service';
import { AppConfigService } from '../../../app-config/app-config.service';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { BaseCardView } from '../base-card-view'; import { BaseCardView } from '../base-card-view';
@@ -41,7 +40,8 @@ import { isValid } from 'date-fns';
selector: 'adf-card-view-dateitem', selector: 'adf-card-view-dateitem',
templateUrl: './card-view-dateitem.component.html', templateUrl: './card-view-dateitem.component.html',
styleUrls: ['./card-view-dateitem.component.scss'], styleUrls: ['./card-view-dateitem.component.scss'],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None,
host: { class: 'adf-card-view-dateitem' }
}) })
export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemModel> implements OnInit, OnDestroy { export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemModel> implements OnInit, OnDestroy {
@Input() @Input()
@@ -60,19 +60,16 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
public datepicker: MatDatetimepickerComponent<any>; public datepicker: MatDatetimepickerComponent<any>;
valueDate: Date; valueDate: Date;
dateFormat: string;
private onDestroy$ = new Subject<boolean>(); private onDestroy$ = new Subject<boolean>();
constructor( constructor(
private dateAdapter: DateAdapter<Date>, private dateAdapter: DateAdapter<Date>,
private userPreferencesService: UserPreferencesService, private userPreferencesService: UserPreferencesService,
private appConfig: AppConfigService,
private clipboardService: ClipboardService, private clipboardService: ClipboardService,
private translateService: TranslationService private translateService: TranslationService
) { ) {
super(); super();
this.dateFormat = this.appConfig.get('dateValues.defaultDateFormat');
} }
ngOnInit() { ngOnInit() {
@@ -91,7 +88,7 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
} }
} else { } else {
if (this.property.value && !Array.isArray(this.property.value)) { if (this.property.value && !Array.isArray(this.property.value)) {
this.valueDate = DateFnsUtils.localToUtc(DateFnsUtils.parseDate(this.property.value, this.dateFormat)); this.valueDate = DateFnsUtils.localToUtc(new Date(this.property.value));
} }
} }
} }