refactor (df/locale): groups module (#1263)

See: #1213
This commit is contained in:
Abhirup Pal
2020-10-16 20:26:58 +05:30
committed by GitHub
parent 6372656c98
commit 862fb62b26
11 changed files with 63 additions and 31 deletions
@@ -7,6 +7,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */ /** Custom Services */
import { GroupsService } from '../groups.service'; import { GroupsService } from '../groups.service';
import { ClientsService } from '../../clients/clients.service'; import { ClientsService } from '../../clients/clients.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Create Group component. * Create Group component.
@@ -43,13 +44,15 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
* @param {ClientsService} clientsService CentersService. * @param {ClientsService} clientsService CentersService.
* @param {GroupsService} groupService GroupsService. * @param {GroupsService} groupService GroupsService.
* @param {DatePipe} datePipe Date Pipe to format date. * @param {DatePipe} datePipe Date Pipe to format date.
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private clientsService: ClientsService, private clientsService: ClientsService,
private groupService: GroupsService, private groupService: GroupsService,
private datePipe: DatePipe) { private datePipe: DatePipe,
private settingsService: SettingsService) {
this.route.data.subscribe( (data: {offices: any} ) => { this.route.data.subscribe( (data: {offices: any} ) => {
this.officeData = data.offices; this.officeData = data.offices;
}); });
@@ -149,13 +152,13 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
const submittedOnDate: Date = this.groupForm.value.submittedOnDate; const submittedOnDate: Date = this.groupForm.value.submittedOnDate;
const activationDate: Date = this.groupForm.value.activationDate; const activationDate: Date = this.groupForm.value.activationDate;
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
this.groupForm.patchValue({ this.groupForm.patchValue({
submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat), submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat),
activationDate: this.datePipe.transform(activationDate, dateFormat) activationDate: this.datePipe.transform(activationDate, dateFormat)
}); });
const group = this.groupForm.value; const group = this.groupForm.value;
group.locale = 'en'; group.locale = this.settingsService.language.code;
group.dateFormat = dateFormat; group.dateFormat = dateFormat;
group.clientMembers = []; group.clientMembers = [];
this.clientMembers.forEach((client: any) => group.clientMembers.push(client.id)); this.clientMembers.forEach((client: any) => group.clientMembers.push(client.id));
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */ /** Custom Services */
import { GroupsService } from '../groups.service'; import { GroupsService } from '../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Edit Group component. * Edit Group component.
@@ -37,12 +38,14 @@ export class EditGroupComponent implements OnInit {
* @param {Router} router Router for navigation. * @param {Router} router Router for navigation.
* @param {GroupsService} groupService GroupsService. * @param {GroupsService} groupService GroupsService.
* @param {DatePipe} datePipe Date Pipe to format date. * @param {DatePipe} datePipe Date Pipe to format date.
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private groupService: GroupsService, private groupService: GroupsService,
private datePipe: DatePipe) { private datePipe: DatePipe,
private settingsService: SettingsService) {
this.route.data.subscribe( (data: { groupAndTemplateData: any, groupViewData: any } ) => { this.route.data.subscribe( (data: { groupAndTemplateData: any, groupViewData: any } ) => {
this.staffData = data.groupAndTemplateData.staffOptions; this.staffData = data.groupAndTemplateData.staffOptions;
this.groupData = data.groupAndTemplateData; this.groupData = data.groupAndTemplateData;
@@ -96,13 +99,13 @@ export class EditGroupComponent implements OnInit {
const submittedOnDate: Date = this.editGroupForm.value.submittedOnDate; const submittedOnDate: Date = this.editGroupForm.value.submittedOnDate;
const activationDate: Date = this.editGroupForm.value.activationDate; const activationDate: Date = this.editGroupForm.value.activationDate;
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
this.editGroupForm.patchValue({ this.editGroupForm.patchValue({
submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat), submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat),
activationDate: activationDate && this.datePipe.transform(activationDate, dateFormat) activationDate: activationDate && this.datePipe.transform(activationDate, dateFormat)
}); });
const group = this.editGroupForm.value; const group = this.editGroupForm.value;
group.locale = 'en'; group.locale = this.settingsService.language.code;
group.dateFormat = dateFormat; group.dateFormat = dateFormat;
this.groupService.updateGroup(group, this.groupData.id).subscribe((response: any) => { this.groupService.updateGroup(group, this.groupData.id).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route }); this.router.navigate(['../'], { relativeTo: this.route });
@@ -18,6 +18,7 @@ import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicke
/** Custom Services */ /** Custom Services */
import { GroupsService } from '../../../groups.service'; import { GroupsService } from '../../../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Group Multi Row Data Tables * Group Multi Row Data Tables
@@ -52,11 +53,13 @@ export class MultiRowComponent implements OnInit, OnChanges {
* @param {DatePipe} datePipe Date Pipe. * @param {DatePipe} datePipe Date Pipe.
* @param {GroupsService} groupsService Groups Service. * @param {GroupsService} groupsService Groups Service.
* @param {MatDialog} dialog Mat Dialog. * @param {MatDialog} dialog Mat Dialog.
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private datePipe: DatePipe, private datePipe: DatePipe,
private groupsService: GroupsService, private groupsService: GroupsService,
private dialog: MatDialog) { private dialog: MatDialog,
private settingsService: SettingsService) {
this.groupId = this.route.parent.parent.snapshot.paramMap.get('groupId'); this.groupId = this.route.parent.parent.snapshot.paramMap.get('groupId');
} }
@@ -85,7 +88,7 @@ export class MultiRowComponent implements OnInit, OnChanges {
* Adds a new row to the given multi row data table. * Adds a new row to the given multi row data table.
*/ */
add() { add() {
let dataTableEntryObject: any = { locale: 'en' }; let dataTableEntryObject: any = { locale: this.settingsService.language.code };
const dateTransformColumns: string[] = []; const dateTransformColumns: string[] = [];
const columns = this.dataObject.columnHeaders.filter((column: any) => { const columns = this.dataObject.columnHeaders.filter((column: any) => {
return ((column.columnName !== 'id') && (column.columnName !== 'group_id')); return ((column.columnName !== 'id') && (column.columnName !== 'group_id'));
@@ -17,7 +17,7 @@ import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-ba
/** Custom Services */ /** Custom Services */
import { GroupsService } from '../../../groups.service'; import { GroupsService } from '../../../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Groups Single Row Data Tables * Groups Single Row Data Tables
@@ -43,11 +43,13 @@ export class SingleRowComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe. * @param {DatePipe} datePipe Date Pipe.
* @param {GroupsService} groupsService Groups Service. * @param {GroupsService} groupsService Groups Service.
* @param {MatDialog} dialog Mat Dialog. * @param {MatDialog} dialog Mat Dialog.
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private datePipe: DatePipe, private datePipe: DatePipe,
private dialog: MatDialog, private dialog: MatDialog,
private groupsService: GroupsService) { private groupsService: GroupsService,
private settingsService: SettingsService) {
this.groupId = this.route.parent.parent.snapshot.paramMap.get('groupId'); this.groupId = this.route.parent.parent.snapshot.paramMap.get('groupId');
} }
@@ -65,7 +67,7 @@ export class SingleRowComponent implements OnInit {
* Creates a new instance of the given single row data table. * Creates a new instance of the given single row data table.
*/ */
add() { add() {
let dataTableEntryObject: any = { locale: 'en' }; let dataTableEntryObject: any = { locale: this.settingsService.language.code };
const dateTransformColumns: string[] = []; const dateTransformColumns: string[] = [];
const columns = this.dataObject.columnHeaders.filter((column: any) => { const columns = this.dataObject.columnHeaders.filter((column: any) => {
return ((column.columnName !== 'id') && (column.columnName !== 'group_id')); return ((column.columnName !== 'id') && (column.columnName !== 'group_id'));
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Activate Group Component * Activate Group Component
@@ -32,12 +33,14 @@ export class ActivateGroupComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe * @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router * @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService, private groupsService: GroupsService,
private datePipe: DatePipe, private datePipe: DatePipe,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router,
private settingsService: SettingsService) {
this.groupId = this.route.parent.snapshot.params['groupId']; this.groupId = this.route.parent.snapshot.params['groupId'];
} }
@@ -60,8 +63,8 @@ export class ActivateGroupComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const prevactivationDate: Date = this.activateGroupForm.value.activationDate; const prevactivationDate: Date = this.activateGroupForm.value.activationDate;
this.activateGroupForm.patchValue({ this.activateGroupForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat), activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Group Meetings Component * Group Meetings Component
@@ -41,12 +42,14 @@ export class AttachGroupMeetingComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe * @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router * @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService, private groupsService: GroupsService,
private datePipe: DatePipe, private datePipe: DatePipe,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => { this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData; this.calendarTemplate = data.groupActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions; this.frequencyOptions = this.calendarTemplate.frequencyOptions;
@@ -112,8 +115,8 @@ export class AttachGroupMeetingComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const title = `groups_${this.groupId}_CollectionMeeting`; const title = `groups_${this.groupId}_CollectionMeeting`;
const typeId = '1'; const typeId = '1';
const prevStartDate: Date = this.groupMeetingForm.value.startDate; const prevStartDate: Date = this.groupMeetingForm.value.startDate;
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Close Group Component * Close Group Component
@@ -34,12 +35,14 @@ export class CloseGroupComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe * @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router * @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService, private groupsService: GroupsService,
private datePipe: DatePipe, private datePipe: DatePipe,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => { this.route.data.subscribe((data: { groupActionData: any }) => {
this.closureData = data.groupActionData.closureReasons; this.closureData = data.groupActionData.closureReasons;
}); });
@@ -65,8 +68,8 @@ export class CloseGroupComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const prevClosedDate: Date = this.closeGroupForm.value.closureDate; const prevClosedDate: Date = this.closeGroupForm.value.closureDate;
this.closeGroupForm.patchValue({ this.closeGroupForm.patchValue({
closureDate: this.datePipe.transform(prevClosedDate, dateFormat), closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Edit Group Meetings Schedule Component * Edit Group Meetings Schedule Component
@@ -39,12 +40,14 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe * @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router * @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService, private groupsService: GroupsService,
private datePipe: DatePipe, private datePipe: DatePipe,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => { this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData; this.calendarTemplate = data.groupActionData;
this.nextMeetingDates = this.calendarTemplate.nextTenRecurringDates; this.nextMeetingDates = this.calendarTemplate.nextTenRecurringDates;
@@ -72,8 +75,8 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const reschedulebasedOnMeetingDates = true; const reschedulebasedOnMeetingDates = true;
const prevOldDate: Date = new Date(this.groupEditMeetingScheduleForm.value.presentMeetingDate); const prevOldDate: Date = new Date(this.groupEditMeetingScheduleForm.value.presentMeetingDate);
const prevNewDate: Date = this.groupEditMeetingScheduleForm.value.newMeetingDate; const prevNewDate: Date = this.groupEditMeetingScheduleForm.value.newMeetingDate;
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Edit Group Meetings Component * Edit Group Meetings Component
@@ -43,12 +44,14 @@ export class EditGroupMeetingComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe * @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router * @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService, private groupsService: GroupsService,
private datePipe: DatePipe, private datePipe: DatePipe,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => { this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData; this.calendarTemplate = data.groupActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions; this.frequencyOptions = this.calendarTemplate.frequencyOptions;
@@ -117,8 +120,8 @@ export class EditGroupMeetingComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const title = `groups_${this.groupId}_CollectionMeeting`; const title = `groups_${this.groupId}_CollectionMeeting`;
const typeId = '1'; const typeId = '1';
const prevStartDate: Date = this.groupEditMeetingForm.value.startDate; const prevStartDate: Date = this.groupEditMeetingForm.value.startDate;
@@ -7,6 +7,7 @@ import { FormControl } from '@angular/forms';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** Custom Dialogs */ /** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@@ -47,12 +48,14 @@ export class GroupAttendanceComponent implements OnInit {
* @param {Router} router Router * @param {Router} router Router
* @param {GroupsService} groupsService Groups Service * @param {GroupsService} groupsService Groups Service
* @param {MatDialog} dialog Mat Dialog * @param {MatDialog} dialog Mat Dialog
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private datePipe: DatePipe, private datePipe: DatePipe,
private router: Router, private router: Router,
private groupsService: GroupsService, private groupsService: GroupsService,
public dialog: MatDialog) { public dialog: MatDialog,
private settingsService: SettingsService) {
this.route.data.subscribe(( data: { groupActionData: any }) => { this.route.data.subscribe(( data: { groupActionData: any }) => {
this.groupData = data.groupActionData; this.groupData = data.groupActionData;
this.membersData = data.groupActionData.clientMembers; this.membersData = data.groupActionData.clientMembers;
@@ -113,8 +116,8 @@ export class GroupAttendanceComponent implements OnInit {
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
const locale = 'en'; const locale = this.settingsService.language.code;
const dateFormat = 'dd MMMM yyyy'; const dateFormat = this.settingsService.dateFormat;
const prevMeetingDate: Date = new Date(this.meetingDate.value); const prevMeetingDate: Date = new Date(this.meetingDate.value);
this.meetingDate.patchValue(this.datePipe.transform(prevMeetingDate, dateFormat)); this.meetingDate.patchValue(this.datePipe.transform(prevMeetingDate, dateFormat));
const data = { const data = {
@@ -5,6 +5,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { GroupsService } from 'app/groups/groups.service'; import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** /**
* Group Transfer Clients component. * Group Transfer Clients component.
@@ -33,11 +34,13 @@ export class GroupTransferClientsComponent implements OnInit, AfterViewInit {
* @param {ActivatedRoute} route Activated Route. * @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation * @param {Router} router Router for navigation
* @param {GroupsService} groupsService GroupsService. * @param {GroupsService} groupsService GroupsService.
* @param {SettingsService} settingsService SettingsService
*/ */
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private groupsService: GroupsService) { private groupsService: GroupsService,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => { this.route.data.subscribe((data: { groupActionData: any }) => {
this.groupData = data.groupActionData; this.groupData = data.groupActionData;
this.clientMembers = this.groupData.clientMembers; this.clientMembers = this.groupData.clientMembers;
@@ -87,7 +90,7 @@ export class GroupTransferClientsComponent implements OnInit, AfterViewInit {
* if successful redirects to group. * if successful redirects to group.
*/ */
submit() { submit() {
const locale = 'en'; const locale = this.settingsService.language.code;
const data = { const data = {
...this.transferClientsForm.value, ...this.transferClientsForm.value,
destinationGroupId: this.transferClientsForm.get('destinationGroupId').value.id, destinationGroupId: this.transferClientsForm.get('destinationGroupId').value.id,