Format date fields without patch form
This commit is contained in:
committed by
Arnold Gálovics
parent
9d43181cea
commit
6ea3d97538
@@ -2,12 +2,12 @@
|
||||
import { Component, OnInit, AfterViewInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from '../groups.service';
|
||||
import { ClientsService } from '../../clients/clients.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/**
|
||||
* Create Group component.
|
||||
@@ -43,7 +43,7 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {ClientsService} clientsService CentersService.
|
||||
* @param {GroupsService} groupService GroupsService.
|
||||
* @param {DatePipe} datePipe Date Pipe to format date.
|
||||
* @param {Dates} dateUtils Date Utils to format date.
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
@@ -51,7 +51,7 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
|
||||
private router: Router,
|
||||
private clientsService: ClientsService,
|
||||
private groupService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private settingsService: SettingsService) {
|
||||
this.route.data.subscribe( (data: {offices: any} ) => {
|
||||
this.officeData = data.offices;
|
||||
@@ -149,20 +149,25 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
|
||||
* if successful redirects to groups.
|
||||
*/
|
||||
submit() {
|
||||
const groupFormData = this.groupForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const submittedOnDate: Date = this.groupForm.value.submittedOnDate;
|
||||
const activationDate: Date = this.groupForm.value.activationDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
this.groupForm.patchValue({
|
||||
submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat),
|
||||
activationDate: this.datePipe.transform(activationDate, dateFormat)
|
||||
});
|
||||
const group = this.groupForm.value;
|
||||
group.locale = this.settingsService.language.code;
|
||||
group.dateFormat = dateFormat;
|
||||
group.clientMembers = [];
|
||||
this.clientMembers.forEach((client: any) => group.clientMembers.push(client.id));
|
||||
this.groupService.createGroup(group).subscribe((response: any) => {
|
||||
if (groupFormData.submittedOnDate instanceof Date) {
|
||||
groupFormData.submittedOnDate = this.dateUtils.formatDate(submittedOnDate, dateFormat);
|
||||
}
|
||||
if (groupFormData.activationDate instanceof Date) {
|
||||
groupFormData.activationDate = this.dateUtils.formatDate(activationDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...groupFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
data.clientMembers = [];
|
||||
this.clientMembers.forEach((client: any) => data.clientMembers.push(client.id));
|
||||
this.groupService.createGroup(data).subscribe((response: any) => {
|
||||
this.router.navigate(['../groups']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from '../groups.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/**
|
||||
* Edit Group component.
|
||||
@@ -37,14 +37,14 @@ export class EditGroupComponent implements OnInit {
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {GroupsService} groupService GroupsService.
|
||||
* @param {DatePipe} datePipe Date Pipe to format date.
|
||||
* @param {Dates} dateUtils Date Utils to format date.
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private groupService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private settingsService: SettingsService) {
|
||||
this.route.data.subscribe( (data: { groupAndTemplateData: any, groupViewData: any } ) => {
|
||||
this.staffData = data.groupAndTemplateData.staffOptions;
|
||||
@@ -96,18 +96,23 @@ export class EditGroupComponent implements OnInit {
|
||||
* if successful redirects to groups.
|
||||
*/
|
||||
submit() {
|
||||
const editGroupFormData = this.editGroupForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const submittedOnDate: Date = this.editGroupForm.value.submittedOnDate;
|
||||
const activationDate: Date = this.editGroupForm.value.activationDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
this.editGroupForm.patchValue({
|
||||
submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat),
|
||||
activationDate: activationDate && this.datePipe.transform(activationDate, dateFormat)
|
||||
});
|
||||
const group = this.editGroupForm.value;
|
||||
group.locale = this.settingsService.language.code;
|
||||
group.dateFormat = dateFormat;
|
||||
this.groupService.updateGroup(group, this.groupData.id).subscribe((response: any) => {
|
||||
if (editGroupFormData.submittedOnDate instanceof Date) {
|
||||
editGroupFormData.submittedOnDate = this.dateUtils.formatDate(submittedOnDate, dateFormat);
|
||||
}
|
||||
if (editGroupFormData.activationDate instanceof Date) {
|
||||
editGroupFormData.activationDate = this.dateUtils.formatDate(activationDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...editGroupFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
this.groupService.updateGroup(data, this.groupData.id).subscribe((response: any) => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export class MultiRowComponent implements OnInit, OnChanges {
|
||||
/**
|
||||
* Fetches group Id from parent route params.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {DatePipe} datePipe Date Pipe.
|
||||
* @param {DatePipe} datePipe Date Utils.
|
||||
* @param {GroupsService} groupsService Groups Service.
|
||||
* @param {MatDialog} dialog Mat Dialog.
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
|
||||
@@ -40,7 +40,7 @@ export class SingleRowComponent implements OnInit {
|
||||
/**
|
||||
* Fetches group Id from parent route params.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {DatePipe} datePipe Date Pipe.
|
||||
* @param {DatePipe} datePipe Date Utils.
|
||||
* @param {GroupsService} groupsService Groups Service.
|
||||
* @param {MatDialog} dialog Mat Dialog.
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from 'app/groups/groups.service';
|
||||
@@ -30,14 +30,14 @@ export class ActivateGroupComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {groupsService} groupsService Groups Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private groupsService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -62,15 +62,15 @@ export class ActivateGroupComponent implements OnInit {
|
||||
* if successful redirects to the group.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const activateGroupFormData = this.activateGroupForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevactivationDate: Date = this.activateGroupForm.value.activationDate;
|
||||
this.activateGroupForm.patchValue({
|
||||
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
|
||||
});
|
||||
if (activateGroupFormData.activationDate instanceof Date) {
|
||||
activateGroupFormData.activationDate = this.dateUtils.formatDate(prevactivationDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.activateGroupForm.value,
|
||||
...activateGroupFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+8
-8
@@ -1,8 +1,8 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from 'app/groups/groups.service';
|
||||
@@ -39,14 +39,14 @@ export class AttachGroupMeetingComponent implements OnInit {
|
||||
* Fetches Calendar Template from `resolve`
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {GroupsService} groupsService Shares Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private groupsService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -114,17 +114,17 @@ export class AttachGroupMeetingComponent implements OnInit {
|
||||
* Submits the form and attatches the meeting.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const groupMeetingFormData = this.groupMeetingForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const title = `groups_${this.groupId}_CollectionMeeting`;
|
||||
const typeId = '1';
|
||||
const prevStartDate: Date = this.groupMeetingForm.value.startDate;
|
||||
this.groupMeetingForm.patchValue({
|
||||
startDate: this.datePipe.transform(prevStartDate, dateFormat),
|
||||
});
|
||||
if (groupMeetingFormData.startDate instanceof Date) {
|
||||
groupMeetingFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.groupMeetingForm.value,
|
||||
...groupMeetingFormData,
|
||||
title,
|
||||
typeId,
|
||||
dateFormat,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from 'app/groups/groups.service';
|
||||
@@ -32,14 +32,14 @@ export class CloseGroupComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {GroupsService} groupsService Shares Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private groupsService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -67,15 +67,15 @@ export class CloseGroupComponent implements OnInit {
|
||||
* Submits the form and closes the group.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const closeGroupFormData = this.closeGroupForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevClosedDate: Date = this.closeGroupForm.value.closureDate;
|
||||
this.closeGroupForm.patchValue({
|
||||
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
|
||||
});
|
||||
if (closeGroupFormData.closureDate instanceof Date) {
|
||||
closeGroupFormData.closureDate = this.dateUtils.formatDate(prevClosedDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.closeGroupForm.value,
|
||||
...closeGroupFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
+11
-9
@@ -1,8 +1,8 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from 'app/groups/groups.service';
|
||||
@@ -37,14 +37,14 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
|
||||
* Fetches Calendar Template from `resolve`
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {GroupsService} groupsService Shares Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private groupsService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -74,18 +74,20 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
|
||||
* Submits the form and updates the meeting.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const groupEditMeetingScheduleFormData = this.groupEditMeetingScheduleForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const reschedulebasedOnMeetingDates = true;
|
||||
const prevOldDate: Date = new Date(this.groupEditMeetingScheduleForm.value.presentMeetingDate);
|
||||
const prevNewDate: Date = this.groupEditMeetingScheduleForm.value.newMeetingDate;
|
||||
this.groupEditMeetingScheduleForm.patchValue({
|
||||
'presentMeetingDate': this.datePipe.transform(prevOldDate, dateFormat),
|
||||
'newMeetingDate': this.datePipe.transform(prevNewDate, dateFormat)
|
||||
});
|
||||
if (groupEditMeetingScheduleFormData.presentMeetingDate instanceof Date) {
|
||||
groupEditMeetingScheduleFormData.presentMeetingDate = this.dateUtils.formatDate(prevOldDate, dateFormat);
|
||||
}
|
||||
if (groupEditMeetingScheduleFormData.newMeetingDate instanceof Date) {
|
||||
groupEditMeetingScheduleFormData.newMeetingDate = this.dateUtils.formatDate(prevNewDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.groupEditMeetingScheduleForm.value,
|
||||
...groupEditMeetingScheduleFormData,
|
||||
reschedulebasedOnMeetingDates,
|
||||
dateFormat,
|
||||
locale
|
||||
|
||||
+8
-8
@@ -1,8 +1,8 @@
|
||||
/** 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';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from 'app/groups/groups.service';
|
||||
@@ -41,14 +41,14 @@ export class EditGroupMeetingComponent implements OnInit {
|
||||
* Fetches Calendar Template from `resolve`
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {GroupsService} groupsService Shares Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService SettingsService
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private groupsService: GroupsService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -119,17 +119,17 @@ export class EditGroupMeetingComponent implements OnInit {
|
||||
* Submits the form and updates the meeting.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const groupEditMeetingFormData = this.groupEditMeetingForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const title = `groups_${this.groupId}_CollectionMeeting`;
|
||||
const typeId = '1';
|
||||
const prevStartDate: Date = this.groupEditMeetingForm.value.startDate;
|
||||
this.groupEditMeetingForm.patchValue({
|
||||
startDate: this.datePipe.transform(prevStartDate, dateFormat),
|
||||
});
|
||||
if (groupEditMeetingFormData.startDate instanceof Date) {
|
||||
groupEditMeetingFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.groupEditMeetingForm.value,
|
||||
...groupEditMeetingFormData,
|
||||
repeating: true,
|
||||
title,
|
||||
typeId,
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export class GroupAttendanceComponent implements OnInit {
|
||||
/**
|
||||
* Retrieves the group members data from `resolve`.
|
||||
* @param {ActivatedRoute} route Route
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {DatePipe} datePipe Date Utils
|
||||
* @param {Router} router Router
|
||||
* @param {GroupsService} groupsService Groups Service
|
||||
* @param {MatDialog} dialog Mat Dialog
|
||||
|
||||
Reference in New Issue
Block a user