committed by
Abhay Chawla
parent
24dd42ec37
commit
8c56783e97
@@ -0,0 +1,30 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
/**
|
||||
* User data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class UserResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {UsersService} usersService Users service.
|
||||
*/
|
||||
constructor(private usersService: UsersService) {}
|
||||
|
||||
/**
|
||||
* Returns the user data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const userId = route.paramMap.get('id');
|
||||
return this.usersService.getUser(userId);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,12 @@ import { extract } from '../core/i18n/i18n.service';
|
||||
/** Custom Components */
|
||||
import { UsersComponent } from './users.component';
|
||||
import { CreateUserComponent } from './create-user/create-user.component';
|
||||
import { ViewUserComponent } from './view-user/view-user.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { UsersResolver } from './users.resolver';
|
||||
import { UsersTemplateResolver } from './users-template.resolver';
|
||||
import { UserResolver } from './user.resolver';
|
||||
|
||||
/** Users Routes */
|
||||
const routes: Routes = [
|
||||
@@ -37,6 +39,19 @@ const routes: Routes = [
|
||||
resolve: {
|
||||
usersTemplate: UsersTemplateResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
data: { title: extract('View User'), routeResolveBreadcrumb: ['user', 'username'] },
|
||||
resolve: {
|
||||
user: UserResolver
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: ViewUserComponent
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -53,7 +68,8 @@ const routes: Routes = [
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
UsersResolver,
|
||||
UsersTemplateResolver
|
||||
UsersTemplateResolver,
|
||||
UserResolver
|
||||
]
|
||||
})
|
||||
export class UsersRoutingModule { }
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]" class="select-row"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { UsersRoutingModule } from './users-routing.module';
|
||||
/** Custom Components */
|
||||
import { UsersComponent } from './users.component';
|
||||
import { CreateUserComponent } from './create-user/create-user.component';
|
||||
import { ViewUserComponent } from './view-user/view-user.component';
|
||||
|
||||
/**
|
||||
* Users Module
|
||||
@@ -21,7 +22,8 @@ import { CreateUserComponent } from './create-user/create-user.component';
|
||||
],
|
||||
declarations: [
|
||||
UsersComponent,
|
||||
CreateUserComponent
|
||||
CreateUserComponent,
|
||||
ViewUserComponent
|
||||
]
|
||||
})
|
||||
export class UsersModule { }
|
||||
|
||||
@@ -40,6 +40,22 @@ export class UsersService {
|
||||
return this.http.post('/users', user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} userId user ID of user.
|
||||
* @returns {Observable<any>} User.
|
||||
*/
|
||||
getUser(userId: string): Observable<any> {
|
||||
return this.http.get(`/users/${userId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} userId user ID of user.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
deleteUser(userId: string): Observable<any> {
|
||||
return this.http.delete(`/users/${userId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} officeId ID of office to retrieve staff from.
|
||||
* @returns {Observable<any>} Staff data.
|
||||
|
||||
@@ -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>
|
||||
Edit
|
||||
</button>
|
||||
<button mat-raised-button color="warn" (click)="delete()">
|
||||
<fa-icon icon="trash"></fa-icon>
|
||||
Delete
|
||||
</button>
|
||||
<button mat-raised-button color="primary">
|
||||
<fa-icon icon="cog"></fa-icon>
|
||||
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']);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user