Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div *ngIf="displayMode$; else noDisplayMode">
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$, displayMode$ }"></component-mapper>
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$: formattedValue$, displayMode$ }"></component-mapper>
</div>
<ng-template #noDisplayMode>
<div *ngIf="!bReadonly$ && bHasForm$; else noEdit">
Expand All @@ -12,8 +12,7 @@
[attr.data-test-id]="testId"
[placeholder]="placeholder"
[formControl]="fieldControl"
(blur)="fieldOnBlur($event)"
(dateTimeChange)="fieldOnDateChange()"
(dateTimeChange)="fieldOnDateChange($event)"
[value]="value$"
[required]="bRequired$"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ComponentMapperComponent } from '../../../_bridge/component-mapper/comp
import { dateFormatInfoDefault, getDateFormatInfo } from '../../../_helpers/date-format-utils';
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
import { handleEvent } from '../../../_helpers/event-util';
import { format } from '../../../_helpers/formatters';

interface DateTimeProps extends PConnFieldProps {
// If any, enter additional props that only exist on DateTime here
Expand Down Expand Up @@ -66,6 +67,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
placeholder: string;
actionsApi: Object;
propName: string;
formattedValue$: any;

constructor(
private angularPConnect: AngularPConnectService,
Expand Down Expand Up @@ -139,6 +141,12 @@ export class DateTimeComponent implements OnInit, OnDestroy {
this.cdRef.detectChanges();
});

if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
this.formattedValue$ = format(this.value$, 'datetime', {
format: `${this.theDateFormat.dateFormatString} hh:mm a`
});
}

if (this.configProps$.visibility != null) {
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
}
Expand Down Expand Up @@ -174,19 +182,13 @@ export class DateTimeComponent implements OnInit, OnDestroy {
}
}

fieldOnDateChange() {
this.pConn$.clearErrorMessages({
property: this.propName
});
}

fieldOnBlur(event: any) {
fieldOnDateChange(event: any) {
// this comes from the date pop up
if (typeof event.value === 'object') {
// convert date to pega "date" format
event.value = event.value?.toISOString();
}
const value = event?.target?.value;
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
handleEvent(this.actionsApi, 'changeNblur', this.propName, event.value);
}

getErrorMessage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div *ngIf="displayMode$; else noDisplayMode">
<component-mapper
*ngIf="bVisible$ !== false"
name="FieldValueList"
[props]="{ label$, value$: getFormattedValue(), displayMode$ }"
></component-mapper>
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$: formattedValue$, displayMode$ }"></component-mapper>
</div>
<ng-template #noDisplayMode>
<div *ngIf="!bReadonly$ && bHasForm$; else noEdit">
Expand All @@ -21,7 +17,6 @@
[required]="bRequired$"
[formControl]="fieldControl"
(dateChange)="fieldOnDateChange($event)"
(blur)="fieldOnBlur($event)"
/>
<mat-datepicker-toggle matSuffix [for]="pegadate"></mat-datepicker-toggle>
<mat-datepicker #pegadate [startAt]="value$"></mat-datepicker>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-classes-per-file */
import { Component, OnInit, Input, ChangeDetectorRef, forwardRef, Inject, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
Expand Down Expand Up @@ -87,6 +86,7 @@ export class DateComponent implements OnInit, OnDestroy {
theDateFormat = getDateFormatInfo();
actionsApi: Object;
propName: string;
formattedValue$: any;

constructor(
private angularPConnect: AngularPConnectService,
Expand Down Expand Up @@ -149,21 +149,7 @@ export class DateComponent implements OnInit, OnDestroy {
// moved this from ngOnInit() and call this from there instead...
this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as DateProps;

if (this.configProps$.value != undefined) {
let sDateValue: any = '';
sDateValue = this.configProps$.value;

if (sDateValue != '') {
if (typeof sDateValue === 'object') {
sDateValue = sDateValue.toISOString();
} else if (sDateValue.indexOf('/') < 0) {
// if we have the "pega" format, then for display, convert to standard format (US)
// sDateValue = this.formatDate(sDateValue);
sDateValue = this.utils.generateDate(sDateValue, 'Date-Long-Custom-YYYY');
}
this.value$ = new Date(sDateValue);
}
}
this.value$ = this.configProps$.value;
this.testId = this.configProps$.testId;
this.label$ = this.configProps$.label;
this.displayMode$ = this.configProps$.displayMode;
Expand All @@ -181,6 +167,12 @@ export class DateComponent implements OnInit, OnDestroy {
this.cdRef.detectChanges();
});

if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
this.formattedValue$ = format(this.value$, 'date', {
format: this.theDateFormat.dateFormatString
});
}

if (this.configProps$.visibility != null) {
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
}
Expand Down Expand Up @@ -215,27 +207,13 @@ export class DateComponent implements OnInit, OnDestroy {

fieldOnDateChange(event: any) {
// this comes from the date pop up
if (typeof event.value === 'object') {
// convert date to pega "date" format
event.value = event.value?.toISOString();
}
const value = event?.target?.value;
const value = event?.target?.value.format('YYYY-MM-DD');
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
this.pConn$.clearErrorMessages({
property: this.propName
});
}

fieldOnBlur(event: any) {
// PConnect wants to use eventHandler for onBlur
if (typeof event.value === 'object') {
// convert date to pega "date" format
event.value = event.value?.toISOString();
}
const value = event?.target?.value;
handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
}

hasErrors() {
return this.fieldControl.status === 'INVALID';
}
Expand All @@ -254,10 +232,4 @@ export class DateComponent implements OnInit, OnDestroy {
}
return errMessage;
}

getFormattedValue() {
return format(this.value$, 'date', {
format: this.theDateFormat.dateFormatString
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div *ngIf="displayMode$; else noDisplayMode">
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$, displayMode$ }"></component-mapper>
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$: formattedValue$, displayMode$ }"></component-mapper>
</div>
<ng-template #noDisplayMode>
<div *ngIf="!bReadonly$ && bHasForm$; else noEdit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Utils } from '../../../_helpers/utils';
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
import { handleEvent } from '../../../_helpers/event-util';
import { format } from '../../../_helpers/formatters';

interface TimeProps extends PConnFieldProps {
// If any, enter additional props that only exist on Time here
Expand Down Expand Up @@ -46,6 +47,7 @@ export class TimeComponent implements OnInit, OnDestroy {
fieldControl = new FormControl('', null);
actionsApi: Object;
propName: string;
formattedValue$: any;

constructor(
private angularPConnect: AngularPConnectService,
Expand Down Expand Up @@ -125,6 +127,12 @@ export class TimeComponent implements OnInit, OnDestroy {
this.cdRef.detectChanges();
});

if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
this.formattedValue$ = format(this.value$, 'timeonly', {
format: 'hh:mm a'
});
}

if (this.configProps$.visibility != null) {
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export function getLocale(locale: string = '') {
return Intl.DateTimeFormat().resolvedOptions().locale;
}

export function getCurrentTimezone(timezone: string = 'America/New_York') {
if (timezone) return timezone;
return PCore?.getLocaleUtils?.().getTimeZoneInUse?.();
export function getCurrentTimezone() {
return PCore?.getEnvironmentInfo?.().getTimeZone?.();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function TimeFormatter(value, options) {
tempDate.setHours(hours);
tempDate.setMinutes(minutes);
tempDate.setSeconds(seconds);
return tempDate.toLocaleTimeString(locale);
return tempDate.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' });
}
return DateFormatter(value, options);
}
Expand All @@ -53,9 +53,9 @@ export default {
'DateTime-Since': value => DateFormatter(value, { type: 'fromNow' }),
'Time-Only': (value, options) =>
TimeFormatter(value, {
...options,
type: 'customFormat',
format: 'hh:mm:ss A'
format: 'hh:mm:ss A',
...options
}),
convertToTimezone: (value, options) => {
return value && options && options.timezone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export default {
};

function getDateObject(text): Date {
if (text instanceof Date) return text;

// TODO - cleanup formatters util functions as DX APIs are returning values per ISO std now.
const timeStamp = text.replace(/-/g, '');
const isDateTime = timeStamp.indexOf('GMT') !== -1;
Expand Down Expand Up @@ -127,6 +125,17 @@ export function format(value, type, options = {}): string {
break;
}

case 'timeonly': {
const defaultOptions = {
locale: getLocale(),
format: 'hh:mm A',
timezone: getCurrentTimezone()
};
const params = { ...defaultOptions, ...options };
formattedValue = DateFormatter['Time-Only'](value, params);
break;
}

default:
formattedValue = value;
}
Expand Down
Loading