refractor: shared module
* Delete unused loader component. * Make file upload component responsive. * Add comments.
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
"src-not-empty": true,
|
"src-not-empty": true,
|
||||||
"attr-no-duplication": true,
|
"attr-no-duplication": true,
|
||||||
"title-require": true,
|
"title-require": true,
|
||||||
"tag-self-close": true,
|
"tag-self-close": false,
|
||||||
"head-script-disabled": true,
|
"head-script-disabled": true,
|
||||||
"doctype-html5": true,
|
"doctype-html5": true,
|
||||||
"id-class-value": "dash",
|
"id-class-value": "dash",
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
/** Angular Imports */
|
||||||
import { Component, OnInit, Inject } from '@angular/core';
|
import { Component, OnInit, Inject } from '@angular/core';
|
||||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete dialog component.
|
||||||
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'mifosx-delete-dialog',
|
selector: 'mifosx-delete-dialog',
|
||||||
templateUrl: './delete-dialog.component.html',
|
templateUrl: './delete-dialog.component.html',
|
||||||
@@ -8,6 +12,10 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|||||||
})
|
})
|
||||||
export class DeleteDialogComponent implements OnInit {
|
export class DeleteDialogComponent implements OnInit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dialogRef Component reference to dialog.
|
||||||
|
* @param data Provides a deleteContext.
|
||||||
|
*/
|
||||||
constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,
|
constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
<button mat-button (click)="inputFile.click()">
|
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="2%">
|
||||||
<fa-icon icon="file-upload" size="lg"></fa-icon>
|
<mat-form-field fxFlex="83%">
|
||||||
|
<input matInput [readonly]="true" [value]="fileName" placeholder="No file uploaded">
|
||||||
Upload an image
|
</mat-form-field>
|
||||||
</button>
|
<span fxFlex="13%" fxFlexAlign="center">
|
||||||
{{ filename || 'No File Uploaded' }}
|
<button mat-button (click)="uploadFile.click()">
|
||||||
<input type="file" #inputFile (change)="onFileSelected($event)" [style.display]="'none'" />
|
<fa-icon icon="file-upload" size="lg"></fa-icon>
|
||||||
|
|
||||||
|
Upload a file
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<input type="file" #uploadFile (change)="onFileSelected($event)" [style.display]="'none'">
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
/** Angular Imports */
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom file upload component based on angular material.
|
||||||
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'mifosx-file-upload',
|
selector: 'mifosx-file-upload',
|
||||||
templateUrl: './file-upload.component.html',
|
templateUrl: './file-upload.component.html',
|
||||||
@@ -7,15 +11,20 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class FileUploadComponent implements OnInit {
|
export class FileUploadComponent implements OnInit {
|
||||||
|
|
||||||
filename: string;
|
/** Name of file. */
|
||||||
|
fileName = '';
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a file.
|
||||||
|
* @param {any} $event The file input change event.
|
||||||
|
*/
|
||||||
onFileSelected($event: any) {
|
onFileSelected($event: any) {
|
||||||
this.filename = $event.target.files[0].name;
|
this.fileName = $event.target.files[0].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/** Angular Imports */
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
/** Angular Font Awesome Imports */
|
||||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||||
import { library } from '@fortawesome/fontawesome-svg-core';
|
import { library } from '@fortawesome/fontawesome-svg-core';
|
||||||
import {
|
import {
|
||||||
@@ -7,15 +9,17 @@ import {
|
|||||||
faSearch
|
faSearch
|
||||||
} from '@fortawesome/free-solid-svg-icons';
|
} from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
// Add an icon to the library for convenient access in other components
|
/** Add icons to the library for convenient access in other components. */
|
||||||
library.add(
|
library.add(
|
||||||
faFileUpload,
|
faFileUpload,
|
||||||
faSearch
|
faSearch
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Icons Module
|
||||||
|
* Angular Font Awesome module is exported here.
|
||||||
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [],
|
|
||||||
declarations: [],
|
|
||||||
exports: [FontAwesomeModule]
|
exports: [FontAwesomeModule]
|
||||||
})
|
})
|
||||||
export class IconsModule { }
|
export class IconsModule { }
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export * from './shared.module';
|
export * from './shared.module';
|
||||||
export * from './loader/loader.component';
|
export { DeleteDialogComponent } from './delete-dialog/delete-dialog.component';
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<!-- TODO: Loading Component -->
|
|
||||||
<div [hidden]="!isLoading">
|
|
||||||
<span>{{message}}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { LoaderComponent } from './loader.component';
|
|
||||||
|
|
||||||
describe('LoaderComponent', () => {
|
|
||||||
let component: LoaderComponent;
|
|
||||||
let fixture: ComponentFixture<LoaderComponent>;
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
declarations: [LoaderComponent]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(LoaderComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be visible by default', () => {
|
|
||||||
// Arrange
|
|
||||||
const element = fixture.nativeElement;
|
|
||||||
const div = element.querySelectorAll('div')[0];
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(div.getAttribute('hidden')).not.toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be visible when app is loading', () => {
|
|
||||||
// Arrange
|
|
||||||
const element = fixture.nativeElement;
|
|
||||||
const div = element.querySelectorAll('div')[0];
|
|
||||||
|
|
||||||
// Act
|
|
||||||
fixture.componentInstance.isLoading = true;
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(div.getAttribute('hidden')).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not display a message by default', () => {
|
|
||||||
// Arrange
|
|
||||||
const element = fixture.nativeElement;
|
|
||||||
const span = element.querySelectorAll('span')[0];
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(span.innerText).toBe('');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display specified message', () => {
|
|
||||||
// Arrange
|
|
||||||
const element = fixture.nativeElement;
|
|
||||||
const span = element.querySelectorAll('span')[0];
|
|
||||||
|
|
||||||
// Act
|
|
||||||
fixture.componentInstance.message = 'testing';
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(span.innerText).toBe('testing');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { Component, OnInit, Input } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'mifosx-loader',
|
|
||||||
templateUrl: './loader.component.html',
|
|
||||||
styleUrls: ['./loader.component.scss']
|
|
||||||
})
|
|
||||||
export class LoaderComponent implements OnInit {
|
|
||||||
|
|
||||||
@Input() isLoading = false;
|
|
||||||
@Input() message: string;
|
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
ngOnInit() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
|
/** Angular Imports */
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { LayoutModule } from '@angular/cdk/layout';
|
import { LayoutModule } from '@angular/cdk/layout';
|
||||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||||
import {
|
import {
|
||||||
|
MAT_FORM_FIELD_DEFAULT_OPTIONS,
|
||||||
MatAutocompleteModule,
|
MatAutocompleteModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatButtonToggleModule,
|
MatButtonToggleModule,
|
||||||
@@ -37,9 +39,11 @@ import {
|
|||||||
MatTreeModule
|
MatTreeModule
|
||||||
} from '@angular/material';
|
} from '@angular/material';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Material Module
|
||||||
|
* Angular CDK, Angular Material and Flex Layout modules are exported here.
|
||||||
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [],
|
|
||||||
declarations: [],
|
|
||||||
exports: [
|
exports: [
|
||||||
FlexLayoutModule,
|
FlexLayoutModule,
|
||||||
LayoutModule,
|
LayoutModule,
|
||||||
@@ -76,6 +80,12 @@ import {
|
|||||||
MatToolbarModule,
|
MatToolbarModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
MatTreeModule
|
MatTreeModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
|
||||||
|
useValue: { appearance: 'standard' }
|
||||||
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class MaterialModule { }
|
export class MaterialModule { }
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
/** Angular Imports */
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
import { LoaderComponent } from './loader/loader.component';
|
/** Custom Components */
|
||||||
import { FileUploadComponent } from './file-upload/file-upload.component';
|
import { FileUploadComponent } from './file-upload/file-upload.component';
|
||||||
import { DeleteDialogComponent } from './delete-dialog/delete-dialog.component';
|
import { DeleteDialogComponent } from './delete-dialog/delete-dialog.component';
|
||||||
|
|
||||||
|
/** Custom Modules */
|
||||||
import { MaterialModule } from './material.module';
|
import { MaterialModule } from './material.module';
|
||||||
import { IconsModule } from './icons.module';
|
import { IconsModule } from './icons.module';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared Module
|
||||||
|
* Modules and components that are shared throughout the application should be here.
|
||||||
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@@ -15,15 +21,13 @@ import { IconsModule } from './icons.module';
|
|||||||
MaterialModule
|
MaterialModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
LoaderComponent,
|
DeleteDialogComponent,
|
||||||
FileUploadComponent,
|
FileUploadComponent
|
||||||
DeleteDialogComponent
|
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
CommonModule,
|
|
||||||
FileUploadComponent,
|
FileUploadComponent,
|
||||||
|
CommonModule,
|
||||||
IconsModule,
|
IconsModule,
|
||||||
LoaderComponent,
|
|
||||||
MaterialModule
|
MaterialModule
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
|
|||||||
Reference in New Issue
Block a user