refactor (df/locale): centers module (#1269)

See: #1213
This commit is contained in:
Devendra Kharolia
2020-11-12 19:34:38 +05:30
committed by GitHub
parent d191d11c10
commit dbd34aaf42
9 changed files with 46 additions and 20 deletions
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Activate Center Component
@@ -29,12 +30,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 {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
@@ -63,8 +66,8 @@ export class ActivateCenterComponent 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.activateCenterForm.value.activationDate;
this.activateCenterForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Center Meetings Component
@@ -38,12 +39,14 @@ export class AttachCenterMeetingComponent implements OnInit {
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
@@ -112,8 +115,8 @@ export class AttachCenterMeetingComponent 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 = `centers_${this.centerId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.centerMeetingForm.value.startDate;
@@ -7,6 +7,7 @@ import { FormControl } from '@angular/forms';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/** Custom Dialogs */
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@@ -50,12 +51,14 @@ export class CenterAttendanceComponent implements OnInit {
* @param {DatePipe} datePipe Date Pipe
* @param {Router} router Router
* @param {CentersService} centersService Centers Service
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private router: Router,
private centersService: CentersService,
private settingsService: SettingsService,
public dialog: MatDialog) {
this.route.data.subscribe(( data: { centersActionData: any }) => {
this.centerData = data.centersActionData;
@@ -119,8 +122,8 @@ export class CenterAttendanceComponent 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 = {
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Close Center Component
@@ -31,12 +32,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 {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
@@ -65,8 +68,8 @@ export class CloseCenterComponent 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.closeCenterForm.value.closureDate;
this.closeCenterForm.patchValue({
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Center Meetings Schedule Component
@@ -36,12 +37,14 @@ export class EditCenterMeetingScheduleComponent implements OnInit {
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
@@ -72,8 +75,8 @@ export class EditCenterMeetingScheduleComponent 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.centerEditMeetingScheduleForm.value.presentMeetingDate);
const prevNewDate: Date = this.centerEditMeetingScheduleForm.value.newMeetingDate;
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Center Meetings Component
@@ -40,12 +41,14 @@ export class EditCenterMeetingComponent implements OnInit {
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {SettingsService} settingsService Settings Service.
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private settingsService: SettingsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
@@ -117,8 +120,8 @@ export class EditCenterMeetingComponent 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 = `centers_${this.centerId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.centerEditMeetingForm.value.startDate;
@@ -18,6 +18,7 @@ import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicke
/** Custom Services */
import { CentersService } from '../../../centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Center Multi Row Data Tables
@@ -51,11 +52,13 @@ export class MultiRowComponent implements OnInit, OnChanges {
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Pipe.
* @param {CentersService} centersService Centers Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private centersService: CentersService,
private settingsService: SettingsService,
private dialog: MatDialog) {
this.centerId = this.route.parent.parent.snapshot.paramMap.get('centerId');
}
@@ -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 !== 'center_id'));
@@ -118,7 +121,7 @@ export class MultiRowComponent implements OnInit, OnChanges {
});
case 'DATE': {
dateTransformColumns.push(column.columnName);
dataTableEntryObject.dateFormat = 'yyyy-MM-dd';
dataTableEntryObject.dateFormat = this.settingsService.dateFormat;
return new DatepickerBase({
controlName: column.columnName,
label: column.columnName,
@@ -17,7 +17,7 @@ import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-ba
/** Custom Services */
import { CentersService } from '../../../centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Centers Single Row Data Tables
@@ -42,11 +42,13 @@ export class SingleRowComponent implements OnInit {
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe Date Pipe.
* @param {CentersService} centersService Centers Service.
* @param {SettingsService} settingsService Settings Service.
* @param {MatDialog} dialog Mat Dialog.
*/
constructor(private route: ActivatedRoute,
private datePipe: DatePipe,
private dialog: MatDialog,
private settingsService: SettingsService,
private centersService: CentersService) {
this.centerId = this.route.parent.parent.snapshot.paramMap.get('centerId');
}
@@ -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 !== 'center_id'));
@@ -95,7 +97,7 @@ export class SingleRowComponent implements OnInit {
* Edits the current instance of single row data table.
*/
edit() {
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 !== 'center_id'));
@@ -180,7 +182,7 @@ export class SingleRowComponent implements OnInit {
});
case 'DATE': {
dateTransformColumns.push(column.columnName);
dataTableEntryObject.dateFormat = 'yyyy-MM-dd';
dataTableEntryObject.dateFormat = this.settingsService.dateFormat;
return new DatepickerBase({
controlName: column.columnName,
label: column.columnName,
@@ -7,6 +7,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
import { CentersService } from '../centers.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Create Center component.
@@ -41,6 +42,7 @@ export class CreateCenterComponent implements OnInit {
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {CentersService} centerService CentersService.
* @param {SettingsService} settingsService Settings Service.
* @param {GroupsService} groupService GroupsService.
* @param {DatePipe} datePipe Date Pipe to format date.
*/
@@ -48,6 +50,7 @@ export class CreateCenterComponent implements OnInit {
private route: ActivatedRoute,
private router: Router,
private centerService: CentersService,
private settingsService: SettingsService,
private groupService: GroupsService,
private datePipe: DatePipe) {
this.route.data.subscribe( (data: { offices: any }) => {
@@ -133,13 +136,13 @@ export class CreateCenterComponent implements OnInit {
const prevSubmittedOnDate: Date = this.centerForm.value.submittedOnDate;
const prevActivationDate: Date = this.centerForm.value.activationDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'dd MMMM yyyy';
const dateFormat = this.settingsService.dateFormat;
this.centerForm.patchValue({
submittedOnDate: this.datePipe.transform(prevSubmittedOnDate, dateFormat),
activationDate: this.datePipe.transform(prevActivationDate, dateFormat)
});
const center = this.centerForm.value;
center.locale = 'en';
center.locale = this.settingsService.language.code;
center.dateFormat = dateFormat;
center.groupMembers = [];
this.groupMembers.forEach((group: any) => center.groupMembers.push(group.id));