@@ -0,0 +1,31 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { TemplatesService } from './templates.service';
|
||||
|
||||
/**
|
||||
* Template data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TemplateResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {TemplatesService} templatesService Templates service.
|
||||
*/
|
||||
constructor(private templatesService: TemplatesService) {}
|
||||
|
||||
/**
|
||||
* Returns the Template data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const templateId = route.paramMap.get('id');
|
||||
return this.templatesService.getTemplate(templateId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,11 @@ import { extract } from '../core/i18n/i18n.service';
|
||||
|
||||
/** Custom Components */
|
||||
import { TemplatesComponent } from './templates.component';
|
||||
import { ViewTemplateComponent } from './view-template/view-template.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { TemplatesResolver } from './templates.resolver';
|
||||
import { TemplateResolver } from './template.resolver';
|
||||
|
||||
/** Templates Routes */
|
||||
const routes: Routes = [
|
||||
@@ -27,6 +29,19 @@ const routes: Routes = [
|
||||
resolve: {
|
||||
templates: TemplatesResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
data: { title: extract('View Template'), routeResolveBreadcrumb: ['template', 'name'] },
|
||||
resolve: {
|
||||
template: TemplateResolver
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: ViewTemplateComponent,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -42,7 +57,8 @@ const routes: Routes = [
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
TemplatesResolver
|
||||
TemplatesResolver,
|
||||
TemplateResolver
|
||||
]
|
||||
})
|
||||
export class TemplatesRoutingModule { }
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]" class="select-row"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
table {
|
||||
width: 100%;
|
||||
|
||||
.select-row:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { TemplatesRoutingModule } from './templates-routing.module';
|
||||
|
||||
/** Custom Components */
|
||||
import { TemplatesComponent } from './templates.component';
|
||||
import { ViewTemplateComponent } from './view-template/view-template.component';
|
||||
|
||||
/**
|
||||
* Templates Module
|
||||
@@ -19,7 +20,8 @@ import { TemplatesComponent } from './templates.component';
|
||||
TemplatesRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
TemplatesComponent
|
||||
TemplatesComponent,
|
||||
ViewTemplateComponent,
|
||||
]
|
||||
})
|
||||
export class TemplatesModule { }
|
||||
|
||||
@@ -25,4 +25,20 @@ export class TemplatesService {
|
||||
return this.http.get('/templates');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateId Template ID.
|
||||
* @returns {Observable<any>} Fetches Template.
|
||||
*/
|
||||
getTemplate(templateId: string): Observable<any> {
|
||||
return this.http.get(`/templates/${templateId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateId Template ID.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
deleteTemplate(templateId: string): Observable<any> {
|
||||
return this.http.delete(`/templates/${templateId}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
|
||||
<button mat-raised-button color="primary">
|
||||
<fa-icon icon="edit"></fa-icon>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
<button mat-raised-button color="warn" (click)="delete()">
|
||||
<fa-icon icon="trash"></fa-icon>
|
||||
Delete
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="row wrap" class="content">
|
||||
|
||||
<div fxFlex="50%" class="mat-body-strong">
|
||||
Entity
|
||||
</div>
|
||||
|
||||
<div fxFlex="50%">
|
||||
{{ templateData.entity }}
|
||||
</div>
|
||||
|
||||
<div fxFlex="50%" class="mat-body-strong">
|
||||
Type
|
||||
</div>
|
||||
|
||||
<div fxFlex="50%">
|
||||
{{ templateData.type }}
|
||||
</div>
|
||||
|
||||
<div fxFlex="50%" class="mat-body-strong">
|
||||
Text
|
||||
</div>
|
||||
|
||||
<div fxFlex="50%" [innerHTML]="templateData.text"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
|
||||
.content {
|
||||
div {
|
||||
margin: 1rem 0;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ViewTemplateComponent } from './view-template.component';
|
||||
|
||||
describe('ViewTemplateComponent', () => {
|
||||
let component: ViewTemplateComponent;
|
||||
let fixture: ComponentFixture<ViewTemplateComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ViewTemplateComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ViewTemplateComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
/** Custom Services */
|
||||
import { TemplatesService } from '../templates.service';
|
||||
|
||||
/** Custom Components */
|
||||
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||
|
||||
/**
|
||||
* View Template Component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-view-template',
|
||||
templateUrl: './view-template.component.html',
|
||||
styleUrls: ['./view-template.component.scss']
|
||||
})
|
||||
export class ViewTemplateComponent implements OnInit {
|
||||
|
||||
/** Template Data */
|
||||
templateData: any;
|
||||
|
||||
/**
|
||||
* Retrieves the template data from `resolve`.
|
||||
* @param {TemplateService} templateService Accounting Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {MatDialog} dialog Dialog reference.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private templatesService: TemplatesService,
|
||||
private router: Router,
|
||||
private dialog: MatDialog) {
|
||||
this.route.data.subscribe((data: { template: any }) => {
|
||||
this.templateData = data.template;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the template and redirects to templates.
|
||||
*/
|
||||
delete() {
|
||||
const deleteTemplateDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||
data: { deleteContext: `template ${this.templateData.id}` }
|
||||
});
|
||||
deleteTemplateDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.delete) {
|
||||
this.templatesService.deleteTemplate(this.templateData.id)
|
||||
.subscribe(() => {
|
||||
this.router.navigate(['/templates']);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user