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 */
import { GroupsService } from '../groups.service';
import { ClientsService } from '../../clients/clients.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Create Group component.
@@ -43,13 +44,15 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
* @param {ClientsService} clientsService CentersService.
* @param {GroupsService} groupService GroupsService.
* @param {DatePipe} datePipe Date Pipe to format date.
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private clientsService: ClientsService,
private groupService: GroupsService,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private settingsService: SettingsService) {
this.route.data.subscribe( (data: {offices: any} ) => {
this.officeData = data.offices;
});
@@ -149,13 +152,13 @@ export class CreateGroupComponent implements OnInit, AfterViewInit {
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 = 'dd MMMM yyyy';
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 = 'en';
group.locale = this.settingsService.language.code;
group.dateFormat = dateFormat;
group.clientMembers = [];
this.clientMembers.forEach((client: any) => group.clientMembers.push(client.id));
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */
import { GroupsService } from '../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Group component.
@@ -37,12 +38,14 @@ export class EditGroupComponent implements OnInit {
* @param {Router} router Router for navigation.
* @param {GroupsService} groupService GroupsService.
* @param {DatePipe} datePipe Date Pipe to format date.
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private groupService: GroupsService,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private settingsService: SettingsService) {
this.route.data.subscribe( (data: { groupAndTemplateData: any, groupViewData: any } ) => {
this.staffData = data.groupAndTemplateData.staffOptions;
this.groupData = data.groupAndTemplateData;
@@ -96,13 +99,13 @@ export class EditGroupComponent implements OnInit {
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 = 'dd MMMM yyyy';
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 = 'en';
group.locale = this.settingsService.language.code;
group.dateFormat = dateFormat;
this.groupService.updateGroup(group, this.groupData.id).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
@@ -18,6 +18,7 @@ import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicke
/** Custom Services */
import { GroupsService } from '../../../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Group Multi Row Data Tables
@@ -52,11 +53,13 @@ export class MultiRowComponent implements OnInit, OnChanges {
* @param {DatePipe} datePipe Date Pipe.
* @param {GroupsService} groupsService Groups Service.
* @param {MatDialog} dialog Mat Dialog.
* @param {SettingsService} settingsService SettingsService
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private groupsService: GroupsService,
private dialog: MatDialog) {
private dialog: MatDialog,
private settingsService: SettingsService) {
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.
*/
add() {
let dataTableEntryObject: any = { locale: 'en' };
let dataTableEntryObject: any = { locale: this.settingsService.language.code };
const dateTransformColumns: string[] = [];
const columns = this.dataObject.columnHeaders.filter((column: any) => {
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 */
import { GroupsService } from '../../../groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Groups Single Row Data Tables
@@ -43,11 +43,13 @@ export class SingleRowComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe.
* @param {GroupsService} groupsService Groups Service.
* @param {MatDialog} dialog Mat Dialog.
* @param {SettingsService} settingsService SettingsService
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private dialog: MatDialog,
private groupsService: GroupsService) {
private groupsService: GroupsService,
private settingsService: SettingsService) {
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.
*/
add() {
let dataTableEntryObject: any = { locale: 'en' };
let dataTableEntryObject: any = { locale: this.settingsService.language.code };
const dateTransformColumns: string[] = [];
const columns = this.dataObject.columnHeaders.filter((column: any) => {
return ((column.columnName !== 'id') && (column.columnName !== 'group_id'));
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Activate Group Component
@@ -32,12 +33,14 @@ export class ActivateGroupComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
private router: Router,
private settingsService: SettingsService) {
this.groupId = this.route.parent.snapshot.params['groupId'];
}
@@ -60,8 +63,8 @@ export class ActivateGroupComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
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),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Group Meetings Component
@@ -41,12 +42,14 @@ export class AttachGroupMeetingComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions;
@@ -112,8 +115,8 @@ export class AttachGroupMeetingComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
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;
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Close Group Component
@@ -34,12 +35,14 @@ export class CloseGroupComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.closureData = data.groupActionData.closureReasons;
});
@@ -65,8 +68,8 @@ export class CloseGroupComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
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),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Group Meetings Schedule Component
@@ -39,12 +40,14 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData;
this.nextMeetingDates = this.calendarTemplate.nextTenRecurringDates;
@@ -72,8 +75,8 @@ export class EditGroupMeetingScheduleComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
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;
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Group Meetings Component
@@ -43,12 +44,14 @@ export class EditGroupMeetingComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
private router: Router,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions;
@@ -117,8 +120,8 @@ export class EditGroupMeetingComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
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;
@@ -7,6 +7,7 @@ import { FormControl } from '@angular/forms';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@@ -47,12 +48,14 @@ export class GroupAttendanceComponent implements OnInit {
* @param {Router} router Router
* @param {GroupsService} groupsService Groups Service
* @param {MatDialog} dialog Mat Dialog
* @param {SettingsService} settingsService SettingsService
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
private groupsService: GroupsService,
public dialog: MatDialog) {
public dialog: MatDialog,
private settingsService: SettingsService) {
this.route.data.subscribe(( data: { groupActionData: any }) => {
this.groupData = data.groupActionData;
this.membersData = data.groupActionData.clientMembers;
@@ -113,8 +116,8 @@ export class GroupAttendanceComponent implements OnInit {
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevMeetingDate: Date = new Date(this.meetingDate.value);
this.meetingDate.patchValue(this.datePipe.transform(prevMeetingDate, dateFormat));
const data = {
@@ -5,6 +5,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Group Transfer Clients component.
@@ -33,11 +34,13 @@ export class GroupTransferClientsComponent implements OnInit, AfterViewInit {
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation
* @param {GroupsService} groupsService GroupsService.
* @param {SettingsService} settingsService SettingsService
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private groupsService: GroupsService) {
private groupsService: GroupsService,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.groupData = data.groupActionData;
this.clientMembers = this.groupData.clientMembers;
@@ -87,7 +90,7 @@ export class GroupTransferClientsComponent implements OnInit, AfterViewInit {
* if successful redirects to group.
*/
submit() {
const locale = 'en';
const locale = this.settingsService.language.code;
const data = {
...this.transferClientsForm.value,
destinationGroupId: this.transferClientsForm.get('destinationGroupId').value.id,