feat: add view user component (#547)

Fixes: #533
This commit is contained in:
Oussema.exe
2020-01-06 23:39:10 +03:00
committed by Abhay Chawla
parent 24dd42ec37
commit 8c56783e97
9 changed files with 247 additions and 3 deletions
@@ -0,0 +1,80 @@
<div class="container m-b-20" fxLayout="row" fxLayout.lt-md="column" fxLayoutAlign="end" fxLayoutGap="2%">
<button mat-raised-button color="primary">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
<button mat-raised-button color="warn" (click)="delete()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Delete
</button>
<button mat-raised-button color="primary">
<fa-icon icon="cog"></fa-icon>&nbsp;&nbsp;
Change Password
</button>
</div>
<div class="container">
<mat-card>
<mat-card-content>
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Login Name
</div>
<div fxFlex="50%">
{{ userData.username }}
</div>
<div fxFlex="50%" class="mat-body-strong">
First Name
</div>
<div fxFlex="50%">
{{ userData.firstname }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Last Name
</div>
<div fxFlex="50%">
{{ userData.lastname }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Email
</div>
<div fxFlex="50%">
{{ userData.email }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Office
</div>
<div fxFlex="50%">
{{ userData.officeName }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Roles
</div>
<div fxFlex="50%">
<span *ngFor="let role of userData.selectedRoles">
{{ role.name }}
</span>
</div>
</div>
</mat-card-content>
</mat-card>
</div>
@@ -0,0 +1,14 @@
.container {
max-width: 37rem;
.content {
div {
margin: 1rem 0;
word-wrap: break-word;
span {
display: block;
}
}
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ViewUserComponent } from './view-user.component';
describe('ViewUserComponent', () => {
let component: ViewUserComponent;
let fixture: ComponentFixture<ViewUserComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewUserComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ViewUserComponent);
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 { UsersService } from '../users.service';
/** Custom Components */
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/**
* View user component.
*/
@Component({
selector: 'mifosx-view-user',
templateUrl: './view-user.component.html',
styleUrls: ['./view-user.component.scss']
})
export class ViewUserComponent implements OnInit {
/** User Data. */
userData: any;
/**
* Retrieves the user data from `resolve`.
* @param {UsersService} usersService Users Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private usersService: UsersService,
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog) {
this.route.data.subscribe((data: { user: any }) => {
this.userData = data.user;
});
}
ngOnInit() {
}
/**
* Deletes the user and redirects to users.
*/
delete() {
const deleteUserDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `user ${this.userData.id}` }
});
deleteUserDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.usersService.deleteUser(this.userData.id)
.subscribe(() => {
this.router.navigate(['/users']);
});
}
});
}
}