Format date fields without patch form

This commit is contained in:
Jose Alberto Hernandez
2022-06-10 10:34:19 +02:00
committed by Arnold Gálovics
parent 9d43181cea
commit 6ea3d97538
191 changed files with 1408 additions and 1173 deletions
@@ -1,11 +1,11 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
/**
@@ -31,14 +31,14 @@ export class ActivateCenterComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder
* @param {centersService} CentersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router) {
this.centerId = this.route.parent.snapshot.params['centerId'];
@@ -65,15 +65,15 @@ export class ActivateCenterComponent implements OnInit {
* if successful redirects to the center.
*/
submit() {
// TODO: Update once language and date settings are setup
const activateCenterData = this.activateCenterForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevactivationDate: Date = this.activateCenterForm.value.activationDate;
this.activateCenterForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
});
if (activateCenterData.activationDate instanceof Date) {
activateCenterData.activationDate = this.dateUtils.formatDate(prevactivationDate, dateFormat);
}
const data = {
...this.activateCenterForm.value,
...activateCenterData,
dateFormat,
locale
};
@@ -1,11 +1,11 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
/**
@@ -40,14 +40,14 @@ export class AttachCenterMeetingComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centersActionData: any }) => {
@@ -114,17 +114,17 @@ export class AttachCenterMeetingComponent implements OnInit {
* Submits the form and attatches the meeting.
*/
submit() {
// TODO: Update once language and date settings are setup
const centerMeetingFormData = this.centerMeetingForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const title = `centers_${this.centerId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.centerMeetingForm.value.startDate;
this.centerMeetingForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
});
if (centerMeetingFormData.startDate instanceof Date) {
centerMeetingFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
const data = {
...this.centerMeetingForm.value,
...centerMeetingFormData,
title,
typeId,
dateFormat,
@@ -48,7 +48,7 @@ export class CenterAttendanceComponent implements OnInit {
/**
* Retrieves the center members data from `resolve`.
* @param {ActivatedRoute} route Route
* @param {DatePipe} datePipe Date Pipe
* @param {DatePipe} datePipe Date Utils
* @param {Router} router Router
* @param {CentersService} centersService Centers Service
* @param {SettingsService} settingsService Settings Service.
@@ -1,11 +1,11 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
/**
@@ -33,14 +33,14 @@ export class CloseCenterComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centeractionData: any }) => {
@@ -67,15 +67,15 @@ export class CloseCenterComponent implements OnInit {
* Submits the form and closes the center.
*/
submit() {
// TODO: Update once language and date settings are setup
const closeCenterFormData = this.closeCenterForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevClosedDate: Date = this.closeCenterForm.value.closureDate;
this.closeCenterForm.patchValue({
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
if (closeCenterFormData.closureDate instanceof Date) {
closeCenterFormData.closureDate = this.dateUtils.formatDate(prevClosedDate, dateFormat);
}
const data = {
...this.closeCenterForm.value,
...closeCenterFormData,
dateFormat,
locale
};
@@ -1,11 +1,11 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
/**
@@ -38,14 +38,14 @@ export class EditCenterMeetingScheduleComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centersActionData: any }) => {
@@ -74,18 +74,20 @@ export class EditCenterMeetingScheduleComponent implements OnInit {
* Submits the form and updates the meeting.
*/
submit() {
// TODO: Update once language and date settings are setup
const centerEditMeetingScheduleFormData = this.centerEditMeetingScheduleForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const reschedulebasedOnMeetingDates = true;
const prevOldDate: Date = new Date(this.centerEditMeetingScheduleForm.value.presentMeetingDate);
if (centerEditMeetingScheduleFormData.startDate instanceof Date) {
centerEditMeetingScheduleFormData.presentMeetingDate = this.dateUtils.formatDate(prevOldDate, dateFormat);
}
const prevNewDate: Date = this.centerEditMeetingScheduleForm.value.newMeetingDate;
this.centerEditMeetingScheduleForm.patchValue({
'presentMeetingDate': this.datePipe.transform(prevOldDate, dateFormat),
'newMeetingDate': this.datePipe.transform(prevNewDate, dateFormat)
});
if (centerEditMeetingScheduleFormData.newMeetingDate instanceof Date) {
centerEditMeetingScheduleFormData.newMeetingDate = this.dateUtils.formatDate(prevNewDate, dateFormat);
}
const data = {
...this.centerEditMeetingScheduleForm.value,
...centerEditMeetingScheduleFormData,
reschedulebasedOnMeetingDates,
dateFormat,
locale
@@ -1,11 +1,11 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
/**
@@ -42,14 +42,14 @@ export class EditCenterMeetingComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {Dates} dateUtils Date Utils
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private dateUtils: Dates,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centersActionData: any }) => {
@@ -119,17 +119,17 @@ export class EditCenterMeetingComponent implements OnInit {
* Submits the form and updates the meeting.
*/
submit() {
// TODO: Update once language and date settings are setup
const centerEditMeetingFormData = this.centerEditMeetingForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const title = `centers_${this.centerId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.centerEditMeetingForm.value.startDate;
this.centerEditMeetingForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
});
if (centerEditMeetingFormData.startDate instanceof Date) {
centerEditMeetingFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
const data = {
...this.centerEditMeetingForm.value,
...centerEditMeetingFormData,
repeating: true,
title,
typeId,
@@ -50,7 +50,7 @@ export class MultiRowComponent implements OnInit, OnChanges {
/**
* Fetches center Id from parent route params.
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Pipe.
* @param {DatePipe} datePipe Date Utils.
* @param {CentersService} centersService Centers Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
@@ -40,7 +40,7 @@ export class SingleRowComponent implements OnInit {
/**
* Fetches center Id from parent route params.
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Pipe.
* @param {DatePipe} datePipe Date Utils.
* @param {CentersService} centersService Centers Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
@@ -150,7 +150,7 @@ export class SingleRowComponent implements OnInit {
/**
* Maps API response to data table form fields.
* @param {any} columns Data Table Columns.
* @param {string[]} dateTransformColumns Columns transformed with date pipe.
* @param {string[]} dateTransformColumns Columns transformed with Date Utils.
* @param {any} dataTableEntryObject Additional data table details.
*/
getFormfields(columns: any, dateTransformColumns: string[], dataTableEntryObject: any) {