refractor: login module (#283)

* Refractor components.
* Shift language and footer component to shared module.
* Replace mat-icons by font-awesome icons.
* Add comments.

Fixes #284
This commit is contained in:
Abhay Chawla
2018-08-09 22:28:17 +05:30
committed by GitHub
parent 9eead37c8c
commit 2330f70f2c
33 changed files with 629 additions and 313 deletions
@@ -13,8 +13,8 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
export class DeleteDialogComponent implements OnInit {
/**
* @param dialogRef Component reference to dialog.
* @param data Provides a deleteContext.
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data Provides a deleteContext.
*/
constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
@@ -21,7 +21,7 @@ export class FileUploadComponent implements OnInit {
/**
* Uploads a file.
* @param {any} $event The file input change event.
* @param {any} event The file input change event.
*/
onFileSelected($event: any) {
this.fileName = $event.target.files[0].name;
@@ -0,0 +1,5 @@
<div fxLayout="column" id="footer" class="m-b-20">
<mat-divider fxFlexAlign="center" class="divider"></mat-divider>
<p fxFlexAlign="center" class="footer-content">Version {{ version }}</p>
<p fxFlexAlign="center" class="footer-content">Mifos X is up to date</p>
</div>
@@ -0,0 +1,10 @@
#footer {
.divider {
margin: 1rem 1rem 0.5rem;
width: 4rem;
}
.footer-content {
margin: 0;
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FooterComponent } from './footer.component';
describe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FooterComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
+25
View File
@@ -0,0 +1,25 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
/** Environment Configuration */
import { environment } from 'environments/environment';
/**
* Footer component.
*/
@Component({
selector: 'mifosx-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class FooterComponent implements OnInit {
/** Mifos X version. */
version: string = environment.version;
constructor() { }
ngOnInit() {
}
}
+15 -2
View File
@@ -5,18 +5,31 @@ import { NgModule } from '@angular/core';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import {
faCheckCircle,
faEye,
faEyeSlash,
faFileUpload,
faSearch
faLock,
faSearch,
faUserCircle,
faUserShield
} from '@fortawesome/free-solid-svg-icons';
/** Add icons to the library for convenient access in other components. */
library.add(
faCheckCircle,
faEye,
faEyeSlash,
faFileUpload,
faSearch
faLock,
faSearch,
faUserCircle,
faUserShield
);
/**
* Icons Module
*
* Angular Font Awesome module is exported here.
*/
@NgModule({
+1 -1
View File
@@ -1,2 +1,2 @@
export * from './shared.module';
export { SharedModule } from './shared.module';
export { DeleteDialogComponent } from './delete-dialog/delete-dialog.component';
@@ -0,0 +1,8 @@
<mat-form-field id="language-selector">
<mat-label>Language</mat-label>
<mat-select [formControl]="languageSelector">
<mat-option *ngFor="let language of languages" [value]="language">
{{ language }}
</mat-option>
</mat-select>
</mat-form-field>
@@ -0,0 +1,3 @@
#language-selector {
max-width: 4rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LanguageSelectorComponent } from './language-selector.component';
describe('LanguageSelectorComponent', () => {
let component: LanguageSelectorComponent;
let fixture: ComponentFixture<LanguageSelectorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LanguageSelectorComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LanguageSelectorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,59 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
/** Custom Services */
import { I18nService } from 'app/core';
/**
* Language selector component.
*
* TODO: Decision to be taken on using ngx-translate or angular-internationalization
* to provide language support in the application.
*/
@Component({
selector: 'mifosx-language-selector',
templateUrl: './language-selector.component.html',
styleUrls: ['./language-selector.component.scss']
})
export class LanguageSelectorComponent implements OnInit {
/** Language selector form control. */
languageSelector = new FormControl();
/**
* Sets the language of the application in the selector on initial setup.
* @param {I18nService} i18nService Internationalization Service.
*/
constructor(private i18nService: I18nService) {
this.languageSelector.setValue(this.currentLanguage);
}
ngOnInit() {
}
/**
* Sets a new language to be used by the application.
* @param {string} language New language.
*/
setLanguage(language: string) {
this.i18nService.language = language;
}
/**
* Returns the current language used by the application.
* @returns {string} Current language.
*/
get currentLanguage(): string {
return this.i18nService.language;
}
/**
* Returns all the languages supported by the application.
* @return {string[]} Supported languages.
*/
get languages(): string[] {
return this.i18nService.supportedLanguages;
}
}
+1
View File
@@ -41,6 +41,7 @@ import {
/**
* Material Module
*
* Angular CDK, Angular Material and Flex Layout modules are exported here.
*/
@NgModule({
+15 -5
View File
@@ -1,34 +1,44 @@
/** Angular Imports */
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
/** Custom Components */
import { FileUploadComponent } from './file-upload/file-upload.component';
import { DeleteDialogComponent } from './delete-dialog/delete-dialog.component';
import { FileUploadComponent } from './file-upload/file-upload.component';
import { FooterComponent } from './footer/footer.component';
import { LanguageSelectorComponent } from './language-selector/language-selector.component';
/** Custom Modules */
import { MaterialModule } from './material.module';
import { IconsModule } from './icons.module';
import { MaterialModule } from './material.module';
/**
* Shared Module
*
* Modules and components that are shared throughout the application should be here.
*/
@NgModule({
imports: [
CommonModule,
IconsModule,
MaterialModule
MaterialModule,
ReactiveFormsModule
],
declarations: [
DeleteDialogComponent,
FileUploadComponent
FileUploadComponent,
FooterComponent,
LanguageSelectorComponent
],
exports: [
FileUploadComponent,
FooterComponent,
LanguageSelectorComponent,
CommonModule,
IconsModule,
MaterialModule
MaterialModule,
ReactiveFormsModule
],
entryComponents: [
DeleteDialogComponent