Move out DatePipe to use in one place Dates

This commit is contained in:
Jose Alberto Hernandez
2022-06-29 14:34:01 -05:00
parent 5bc9f0dac0
commit 5eeaed3ee9
75 changed files with 295 additions and 287 deletions
@@ -3,7 +3,6 @@ import { Component, OnChanges, OnInit, Input, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatTable } from '@angular/material/table';
import { MatDialog } from '@angular/material/dialog';
import { DatePipe } from '@angular/common';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@@ -19,6 +18,7 @@ import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicke
/** Custom Services */
import { OrganizationService } from '../../../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Office Multi Row Data Tables
@@ -50,13 +50,13 @@ export class MultiRowComponent implements OnInit, OnChanges {
/**
* Fetches office Id from parent route params.
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Utils.
* @param {Dates} dateUtils Date Utils.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private dialog: MatDialog) {
@@ -151,7 +151,7 @@ export class MultiRowComponent implements OnInit, OnChanges {
addDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
dateTransformColumns.forEach((column) => {
response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat);
response.data.value[column] = this.dateUtils.formatDate(response.data.value[column], dataTableEntryObject.dateFormat);
});
dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject };
this.organizationService.addOfficeDatatableEntry(this.officeId, this.datatableName, dataTableEntryObject).subscribe(() => {
@@ -2,7 +2,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { DatePipe } from '@angular/common';
/** Custom Components */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@@ -18,6 +17,7 @@ import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-ba
/** Custom Services */
import { OrganizationService } from '../../../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Offices Single Row Data Tables
@@ -40,13 +40,13 @@ export class SingleRowComponent implements OnInit {
/**
* Fetches office Id from parent route params.
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Utils.
* @param {Dates} dateUtils Date Utils.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private dateUtils: Dates,
private dialog: MatDialog,
private organizationService: OrganizationService,
private settingsService: SettingsService ) {
@@ -81,7 +81,7 @@ export class SingleRowComponent implements OnInit {
addDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
dateTransformColumns.forEach((column) => {
response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat);
response.data.value[column] = this.dateUtils.formatDate(response.data.value[column], dataTableEntryObject.dateFormat);
});
dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject };
this.organizationService.addOfficeDatatableEntry(this.officeId, this.datatableName, dataTableEntryObject).subscribe(() => {
@@ -116,7 +116,7 @@ export class SingleRowComponent implements OnInit {
editDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
dateTransformColumns.forEach((column) => {
response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat);
response.data.value[column] = this.dateUtils.formatDate(response.data.value[column], dataTableEntryObject.dateFormat);
});
dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject };
this.organizationService.editOfficeDatatableEntry(this.officeId, this.datatableName, dataTableEntryObject).subscribe(() => {
@@ -1,7 +1,6 @@
/** Angular Imports */
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Components */
import { SmsCampaignStepComponent } from '../sms-campaign-stepper/sms-campaign-step/sms-campaign-step.component';
@@ -10,6 +9,7 @@ import { CampaignMessageStepComponent } from '../sms-campaign-stepper/campaign-m
/** Custom Services */
import { OrganizationService } from 'app/organization/organization.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Create SMS Campaign Component
@@ -37,13 +37,13 @@ export class CreateCampaignComponent {
* @param {Router} router Router
* @param {OrganizationService} organizationService Organization Service
* @param {SettingsService} settingsService Settings Service
* @param {DatePipe} datePipe Date Utils
* @param {Dates} dateUtils Date Utils
*/
constructor(private route: ActivatedRoute,
private router: Router,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private datePipe: DatePipe) {
private dateUtils: Dates) {
this.route.data.subscribe((data: { smsCampaignTemplate: any }) => {
this.smsCampaignTemplate = data.smsCampaignTemplate;
});
@@ -85,14 +85,14 @@ export class CreateCampaignComponent {
const smsCampaign = {
...this.smsCampaign,
campaignType: this.smsCampaign.isNotification ? 2 : 1,
submittedOnDate: this.datePipe.transform(new Date(), dateFormat),
submittedOnDate: this.dateUtils.formatDate(new Date(), dateFormat),
dateTimeFormat,
dateFormat,
locale
};
if (this.smsCampaign.triggerType === 2) {
const prevRecurrenceDate: Date = smsCampaign.recurrenceStartDate;
smsCampaign.recurrenceStartDate = this.datePipe.transform(prevRecurrenceDate, dateTimeFormat);
smsCampaign.recurrenceStartDate = this.dateUtils.formatDate(prevRecurrenceDate, dateTimeFormat);
}
this.organizationService.createSmsCampaign(smsCampaign).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
@@ -1,7 +1,7 @@
/** Angular Imports */
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
import { Dates } from 'app/core/utils/dates';
/** Custom Services */
import { OrganizationService } from 'app/organization/organization.service';
@@ -34,13 +34,13 @@ export class EditCampaignComponent {
* Fetches campaign template from `resolve`
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {DatePipe} datePipe Date Utils
* @param {Dates} dateUtils Date Utils
* @param {OrganizationService} organizationService Organiztion Service
* @param {SettingsService} settingsService Settings Service
*/
constructor(private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { smsCampaign: any, smsCampaignTemplate: any }) => {
@@ -87,7 +87,7 @@ export class EditCampaignComponent {
locale
};
if (this.smsCampaign.triggerType.id === 2) {
smsCampaign.recurrenceStartDate = this.datePipe.transform(new Date(this.smsCampaign.recurrenceStartDate), dateTimeFormat);
smsCampaign.recurrenceStartDate = this.dateUtils.formatDate(new Date(this.smsCampaign.recurrenceStartDate), dateTimeFormat);
}
this.organizationService.updateSmsCampaign(smsCampaign, this.smsCampaign.id).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });