feat: add templates component (#509)
- Add templates component - Add templates module - Add templates service Fixes: #486
This commit is contained in:
@@ -34,6 +34,7 @@ import { SelfServiceModule } from './self-service/self-service.module';
|
||||
import { SystemModule } from './system/system.module';
|
||||
import { ProductsModule } from './products/products.module';
|
||||
import { OrganizationModule } from './organization/organization.module';
|
||||
import { TemplatesModule } from './templates/templates.module';
|
||||
|
||||
|
||||
|
||||
@@ -66,6 +67,7 @@ import { AppRoutingModule } from './app-routing.module';
|
||||
SystemModule,
|
||||
ProductsModule,
|
||||
OrganizationModule,
|
||||
TemplatesModule,
|
||||
AppRoutingModule,
|
||||
],
|
||||
declarations: [WebAppComponent, NotFoundComponent],
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
<button mat-menu-item [routerLink]="['/organization']">Organization</button>
|
||||
<button mat-menu-item [routerLink]="['/system']">System</button>
|
||||
<button mat-menu-item [routerLink]="['/products']">Products</button>
|
||||
<button mat-menu-item>Templates</button>
|
||||
<button mat-menu-item [routerLink]="['/templates']">Templates</button>
|
||||
</mat-menu>
|
||||
|
||||
<mat-menu #selfServiceMenu="matMenu" [overlapTrigger]="false">
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/** Angular Imports */
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
/** Routing Imports */
|
||||
import { Route } from '../core/route/route.service';
|
||||
|
||||
/** Translation Imports */
|
||||
import { extract } from '../core/i18n/i18n.service';
|
||||
|
||||
/** Custom Components */
|
||||
import { TemplatesComponent } from './templates.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { TemplatesResolver } from './templates.resolver';
|
||||
|
||||
/** Templates Routes */
|
||||
const routes: Routes = [
|
||||
Route.withShell([
|
||||
{
|
||||
path: 'templates',
|
||||
data: { title: extract('Templates'), breadcrumb: 'Templates' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: TemplatesComponent,
|
||||
resolve: {
|
||||
templates: TemplatesResolver
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
];
|
||||
|
||||
/**
|
||||
* Templates Routing Module
|
||||
*
|
||||
* Configures the templates routes.
|
||||
*/
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
TemplatesResolver
|
||||
]
|
||||
})
|
||||
export class TemplatesRoutingModule { }
|
||||
@@ -0,0 +1,45 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Template
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<div fxLayout="row" fxLayoutGap="20px">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Filter</mat-label>
|
||||
<input matInput (keyup)="applyFilter($event.target.value)">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div class="mat-elevation-z8">
|
||||
|
||||
<table mat-table [dataSource]="dataSource" matSort>
|
||||
|
||||
<ng-container matColumnDef="entity">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Entity </th>
|
||||
<td mat-cell *matCellDef="let template"> {{ template.entity }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="type">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Type </th>
|
||||
<td mat-cell *matCellDef="let template"> {{ template.type }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="name">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
|
||||
<td mat-cell *matCellDef="let template"> {{ template.name }} </td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TemplatesComponent } from './templates.component';
|
||||
|
||||
describe('TemplatesComponent', () => {
|
||||
let component: TemplatesComponent;
|
||||
let fixture: ComponentFixture<TemplatesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ TemplatesComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TemplatesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { of } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Templates component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-templates',
|
||||
templateUrl: './templates.component.html',
|
||||
styleUrls: ['./templates.component.scss']
|
||||
})
|
||||
export class TemplatesComponent implements OnInit {
|
||||
|
||||
/** Templates data. */
|
||||
templatesData: any;
|
||||
/** Columns to be displayed in templates table. */
|
||||
displayedColumns: string[] = ['entity', 'type', 'name'];
|
||||
/** Data source for templates table. */
|
||||
dataSource: MatTableDataSource<any>;
|
||||
|
||||
/** Paginator for templates table. */
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
/** Sorter for templates table. */
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
/**
|
||||
* Retrieves the templates data from `resolve`.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute) {
|
||||
this.route.data.subscribe(( data: { templates: any }) => {
|
||||
this.templatesData = data.templates;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters data in templates table based on passed value.
|
||||
* @param {string} filterValue Value to filter data.
|
||||
*/
|
||||
applyFilter(filterValue: string) {
|
||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the templates table.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.setTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the data source, paginator and sorter for templates table.
|
||||
*/
|
||||
setTemplates() {
|
||||
this.dataSource = new MatTableDataSource(this.templatesData);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/** Angular Imports */
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
/** Custom Modules */
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { TemplatesRoutingModule } from './templates-routing.module';
|
||||
|
||||
/** Custom Components */
|
||||
import { TemplatesComponent } from './templates.component';
|
||||
|
||||
/**
|
||||
* Templates Module
|
||||
*
|
||||
* Templates components should be declared here.
|
||||
*/
|
||||
@NgModule({
|
||||
imports: [
|
||||
SharedModule,
|
||||
TemplatesRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
TemplatesComponent
|
||||
]
|
||||
})
|
||||
export class TemplatesModule { }
|
||||
@@ -0,0 +1,30 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { TemplatesService } from './templates.service';
|
||||
|
||||
/**
|
||||
* Templates data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TemplatesResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {TemplatesService} templatesService Templates service.
|
||||
*/
|
||||
constructor(private templatesService: TemplatesService) {}
|
||||
|
||||
/**
|
||||
* Returns the templates data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(): Observable<any> {
|
||||
return this.templatesService.getTemplates();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Templates service.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TemplatesService {
|
||||
|
||||
/**
|
||||
* @param {HttpClient} http Http Client to send requests.
|
||||
*/
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Templates data
|
||||
*/
|
||||
getTemplates(): Observable<any> {
|
||||
return this.http.get('/templates');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user