From bf8e6f1273ddbaeb2b0e882b68546d366a122c48 Mon Sep 17 00:00:00 2001 From: Abhay Chawla Date: Sun, 12 Aug 2018 15:45:48 +0530 Subject: [PATCH] refractor: app module and settings (#293) * Refractor settings component. * Improve responsiveness of settings component. * Add comments. Fixes #292 --- src/app/app-routing.module.ts | 10 +++- src/app/app.module.ts | 40 ++++++++----- src/app/self-service/self-service.module.ts | 2 - src/app/settings/settings-routing.module.ts | 15 ++++- src/app/settings/settings.component.html | 64 ++++++++++++++------- src/app/settings/settings.component.scss | 3 + src/app/settings/settings.component.ts | 13 ++++- src/app/settings/settings.module.ts | 17 ++++-- src/app/shared/shared.module.ts | 3 +- src/app/web-app.component.ts | 49 ++++++++++++++-- 10 files changed, 159 insertions(+), 57 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ad0e2d47d..032e1ca58 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,7 +1,10 @@ +/** Angular Imports */ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -// Fallback when no prior route is matched +/** + * Fallback to this route when no prior route is matched. + */ const routes: Routes = [ { path: '**', @@ -10,6 +13,11 @@ const routes: Routes = [ } ]; +/** + * App Routing Module. + * + * Configures the fallback route. + */ @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule], diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 967752a2c..0035548c7 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,56 +1,66 @@ +/** Angular Imports */ +import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NgModule } from '@angular/core'; -import { FormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; import { ServiceWorkerModule } from '@angular/service-worker'; +/** Tanslation Imports */ import { TranslateModule } from '@ngx-translate/core'; + +/** Chart Imports */ import { NgxChartsModule } from '@swimlane/ngx-charts'; +/** Environment Configuration */ import { environment } from 'environments/environment'; +/** Main Component */ import { WebAppComponent } from './web-app.component'; +/** Custom Modules */ import { CoreModule } from './core/core.module'; -import { NavigationModule } from './navigation/navigation.module'; import { HomeModule } from './home/home.module'; -import { AboutModule } from './about/about.module'; import { LoginModule } from './login/login.module'; +import { SettingsModule } from './settings/settings.module'; +import { AboutModule } from './about/about.module'; // TODO: Remove redundant module. +import { NavigationModule } from './navigation/navigation.module'; import { ClientsModule} from './clients/clients.module'; +import { GroupsModule } from './groups/groups.module'; +import { CentersModule } from './centers/centers.module'; import { AccountingModule } from './accounting/accounting.module'; import { SelfServiceModule } from './self-service/self-service.module'; -import { CentersModule } from './centers/centers.module'; -import { GroupsModule } from './groups/groups.module'; +/** Main Routing Module */ import { AppRoutingModule } from './app-routing.module'; -import { SettingsModule } from './settings/settings.module'; +/** + * App Module + * + * Core module and all feature modules should be imported here in proper order. + */ @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, - FormsModule, HttpClientModule, ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }), TranslateModule.forRoot(), NgxChartsModule, CoreModule, HomeModule, - NavigationModule, - AboutModule, LoginModule, + SettingsModule, + AboutModule, + NavigationModule, ClientsModule, + GroupsModule, + CentersModule, AccountingModule, SelfServiceModule, - SettingsModule, - CentersModule, - GroupsModule, AppRoutingModule ], declarations: [WebAppComponent], - providers: [ - ], + providers: [], bootstrap: [WebAppComponent] }) export class AppModule { } diff --git a/src/app/self-service/self-service.module.ts b/src/app/self-service/self-service.module.ts index 95c85d8d9..0095a623a 100644 --- a/src/app/self-service/self-service.module.ts +++ b/src/app/self-service/self-service.module.ts @@ -1,6 +1,5 @@ /** Angular Imports */ import { NgModule } from '@angular/core'; -import { FormsModule } from '@angular/forms'; /** Custom Modules */ import { SharedModule } from '../shared/shared.module'; @@ -23,7 +22,6 @@ import { TaskManagementComponent } from './task-management/task-management.compo @NgModule({ imports: [ SharedModule, - FormsModule, SelfServiceRoutingModule ], declarations: [ diff --git a/src/app/settings/settings-routing.module.ts b/src/app/settings/settings-routing.module.ts index a967adc9c..14c564320 100644 --- a/src/app/settings/settings-routing.module.ts +++ b/src/app/settings/settings-routing.module.ts @@ -1,9 +1,17 @@ +/** Angular Imports */ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -import { Route, extract } from '../core'; +/** Routing Imports */ +import { Route } from '../core'; + +/** Translation Imports */ +import { extract } from '../core'; + +/** Custom Components */ import { SettingsComponent } from './settings.component'; +/** Settings Routes */ const routes: Routes = [ Route.withShell([ { @@ -14,6 +22,11 @@ const routes: Routes = [ ]) ]; +/** + * Settings Routing Module + * + * Configures the settings and web app configuration routes. + */ @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule], diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 05b05f8c0..7a6830a9f 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -1,4 +1,7 @@ - + + + +
@@ -13,29 +16,34 @@
- + Name of the Organisation + - + Description + - + Summary + - - - {{ language.viewValue }} + Default Language + + + {{ language }} - - - {{ dateFormat.viewValue }} + Default Date Format + + + {{ dateFormat }} @@ -54,10 +62,17 @@
- Favicon - Cover Image - Logo - Logo with Organisation Name + Favicon + + + Cover Image + + + Logo + + + Logo with Organisation Name +
@@ -73,12 +88,14 @@
- Theme + Theme + - - - {{ font.viewValue }} + Default Font + + + {{ font }} @@ -98,15 +115,18 @@
- + Website + - + Email + - + Contact No +
@@ -115,4 +135,4 @@ - +
diff --git a/src/app/settings/settings.component.scss b/src/app/settings/settings.component.scss index e69de29bb..4fdf5e8ec 100644 --- a/src/app/settings/settings.component.scss +++ b/src/app/settings/settings.component.scss @@ -0,0 +1,3 @@ +.header { + font-weight: 500; +} diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index 3a7d111e8..f34624697 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -1,5 +1,9 @@ +/** Angular Imports */ import { Component, OnInit } from '@angular/core'; +/** + * Settings component. + */ @Component({ selector: 'mifosx-settings', templateUrl: './settings.component.html', @@ -7,9 +11,12 @@ import { Component, OnInit } from '@angular/core'; }) export class SettingsComponent implements OnInit { - languages: string[]; - dateFormats: string[]; - fonts: string[]; + /** Placeholder for languages. */ + languages: any; + /** Placeholder for date formats. */ + dateFormats: any; + /** Placeholder for fonts. */ + fonts: any; constructor() { } diff --git a/src/app/settings/settings.module.ts b/src/app/settings/settings.module.ts index 5371b95cd..e87b04bdb 100644 --- a/src/app/settings/settings.module.ts +++ b/src/app/settings/settings.module.ts @@ -1,15 +1,20 @@ +/** Angular Imports */ import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { CoreModule } from '../core'; -import { SettingsRoutingModule } from './settings-routing.module'; -import { SettingsComponent } from './settings.component'; +/** Custom Modules */ import { SharedModule } from '../shared/shared.module'; +import { SettingsRoutingModule } from './settings-routing.module'; +/** Custom Components */ +import { SettingsComponent } from './settings.component'; + +/** + * Settings Module + * + * All components related to settings and web app configuration should be declared here. + */ @NgModule({ imports: [ - CommonModule, - CoreModule, SharedModule, SettingsRoutingModule ], diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index f1a9115ec..d4fc9deaf 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -1,7 +1,7 @@ /** Angular Imports */ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { ReactiveFormsModule } from '@angular/forms'; +import { ReactiveFormsModule, FormsModule } from '@angular/forms'; /** Custom Components */ import { DeleteDialogComponent } from './delete-dialog/delete-dialog.component'; @@ -41,6 +41,7 @@ import { MaterialModule } from './material.module'; CommonModule, IconsModule, MaterialModule, + FormsModule, ReactiveFormsModule ], entryComponents: [ diff --git a/src/app/web-app.component.ts b/src/app/web-app.component.ts index b218b0225..087b91d15 100644 --- a/src/app/web-app.component.ts +++ b/src/app/web-app.component.ts @@ -1,20 +1,34 @@ +/** Angular Imports */ import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { MatSnackBar } from '@angular/material'; -import { TranslateService } from '@ngx-translate/core'; +/** rxjs Imports */ import { merge } from 'rxjs'; import { filter, map, mergeMap } from 'rxjs/operators'; +/** Translation Imports */ +import { TranslateService } from '@ngx-translate/core'; + +/** Environment Configuration */ import { environment } from 'environments/environment'; -import { I18nService } from './core/i18n/i18n.service'; + +/** Custom Services */ import { Logger } from './core/logger/logger.service'; +import { I18nService } from './core/i18n/i18n.service'; import { ThemeStorageService } from './shared/theme-picker/theme-storage.service'; import { AlertService } from './core/alert/alert.service'; +/** Custom Models */ +import { Alert } from './core/alert/alert.model'; + +/** Initialize Logger */ const log = new Logger('MifosX'); +/** + * Main web app component. + */ @Component({ selector: 'mifosx-web-app', templateUrl: './web-app.component.html', @@ -22,6 +36,16 @@ const log = new Logger('MifosX'); }) export class WebAppComponent implements OnInit { + /** + * @param {Router} router Router for navigation. + * @param {ActivatedRoute} activatedRoute Activated Route. + * @param {Title} titleService Title Service. + * @param {TranslateService} translateService Translate Service. + * @param {I18nService} i18nService I18n Service. + * @param {ThemeStorageService} themeStorageService Theme Storage Service. + * @param {MatSnackBar} snackBar Material Snackbar for notifications. + * @param {AlertService} alertService Alert Service. + */ constructor(private router: Router, private activatedRoute: ActivatedRoute, private titleService: Title, @@ -31,20 +55,31 @@ export class WebAppComponent implements OnInit { public snackBar: MatSnackBar, private alertService: AlertService) { } + /** + * Initial Setup: + * + * 1) Logger + * + * 2) Language and Translations + * + * 3) Page Title + * + * 4) Theme + * + * 5) Alerts + */ ngOnInit() { // Setup logger if (environment.production) { Logger.enableProductionMode(); } - log.debug('init'); // Setup translations this.i18nService.init(environment.defaultLanguage, environment.supportedLanguages); - const onNavigationEnd = this.router.events.pipe(filter(event => event instanceof NavigationEnd)); - // Change page title on navigation or language change, based on route data + const onNavigationEnd = this.router.events.pipe(filter(event => event instanceof NavigationEnd)); merge(this.translateService.onLangChange, onNavigationEnd) .pipe( map(() => { @@ -64,12 +99,14 @@ export class WebAppComponent implements OnInit { } }); + // Setup theme const theme = this.themeStorageService.getTheme(); if (theme) { this.themeStorageService.installTheme(theme); } - this.alertService.alertEvent.subscribe((alertEvent: any) => { + // Setup alerts + this.alertService.alertEvent.subscribe((alertEvent: Alert) => { this.snackBar.open(`${alertEvent.message}`, 'Close', { duration: 2000, horizontalPosition: 'right',