feat: add user management service (#113)
Add user management service for self service and update http interceptor for progress bar.
This commit is contained in:
@@ -157,6 +157,11 @@ import { BreadcrumbComponent } from './shell/breadcrumb/breadcrumb.component';
|
|||||||
ApiPrefixInterceptor,
|
ApiPrefixInterceptor,
|
||||||
ErrorHandlerInterceptor,
|
ErrorHandlerInterceptor,
|
||||||
CacheInterceptor,
|
CacheInterceptor,
|
||||||
|
{
|
||||||
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
useClass: ProgressInterceptor,
|
||||||
|
multi: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: HttpClient,
|
provide: HttpClient,
|
||||||
useClass: HttpService
|
useClass: HttpService
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
|
||||||
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
|
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
@@ -20,12 +20,14 @@ export class ShellComponent implements OnInit {
|
|||||||
progressBarMode: string;
|
progressBarMode: string;
|
||||||
|
|
||||||
constructor(private breakpointObserver: BreakpointObserver,
|
constructor(private breakpointObserver: BreakpointObserver,
|
||||||
private progressBarService: ProgressBarService) { }
|
private progressBarService: ProgressBarService,
|
||||||
|
private cdr: ChangeDetectorRef) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.sidenavCollapsed = true;
|
this.sidenavCollapsed = true;
|
||||||
this.progressBarService.updateProgressBar.subscribe((mode: string) => {
|
this.progressBarService.updateProgressBar.subscribe((mode: string) => {
|
||||||
this.progressBarMode = mode;
|
this.progressBarMode = mode;
|
||||||
|
this.cdr.detectChanges();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,82 +1,87 @@
|
|||||||
<mat-card class="container m-t-40">
|
<mat-card class="container m-t-40">
|
||||||
|
|
||||||
<!-- <mat-card-header> -->
|
<div fxLayout="row" fxLayoutGap="30px" class="m-b-20">
|
||||||
|
<!-- <mat-card-header> -->
|
||||||
|
|
||||||
<mat-grid-list cols="2" rowHeight="80px">
|
<!-- <mat-grid-list cols="1" rowHeight="80px">
|
||||||
|
|
||||||
<mat-grid-tile>
|
<mat-grid-tile> -->
|
||||||
<mat-form-field>
|
<mat-form-field fxFlex>
|
||||||
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
|
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</mat-grid-tile>
|
<!-- </mat-grid-tile> -->
|
||||||
|
|
||||||
<mat-grid-tile>
|
<!-- <mat-grid-tile> -->
|
||||||
<mat-card-actions>
|
<!-- <mat-card-actions> -->
|
||||||
<button mat-raised-button color="primary"><mat-icon>lock_open</mat-icon> Activate</button>
|
<!-- <button mat-raised-button color="primary"><mat-icon>lock_open</mat-icon> Activate</button> -->
|
||||||
<button mat-raised-button color="primary"><mat-icon>lock</mat-icon> Deactivate</button>
|
<!-- <button mat-raised-button color="primary"><mat-icon>lock</mat-icon> Deactivate</button> -->
|
||||||
<button mat-raised-button color="primary" routerLink="/self-service/users/create"><mat-icon>add</mat-icon> Create User</button>
|
<button mat-raised-button color="primary" routerLink="/self-service/users/create"><mat-icon>add</mat-icon> Create User</button>
|
||||||
</mat-card-actions>
|
<!-- </mat-card-actions> -->
|
||||||
</mat-grid-tile>
|
<!-- </mat-grid-tile> -->
|
||||||
|
|
||||||
</mat-grid-list>
|
<!-- </mat-grid-list> -->
|
||||||
|
|
||||||
<!-- </mat-card-header> -->
|
<!-- </mat-card-header> -->
|
||||||
|
</div>
|
||||||
|
|
||||||
<mat-card-content class="mat-elevation-z8">
|
<mat-card-content class="mat-elevation-z8">
|
||||||
|
|
||||||
<mat-table [dataSource]="dataSource" matSort>
|
<table mat-table [dataSource]="dataSource" matSort>
|
||||||
|
|
||||||
<ng-container matColumnDef="select">
|
<ng-container matColumnDef="select">
|
||||||
<mat-header-cell *matHeaderCellDef>
|
<th mat-header-cell *matHeaderCellDef>
|
||||||
<mat-checkbox (change)="$event ? masterToggle() : null"
|
<mat-checkbox (change)="$event ? masterToggle() : null"
|
||||||
[checked]="selection.hasValue() && isAllSelected()"
|
[checked]="selection.hasValue() && isAllSelected()"
|
||||||
[indeterminate]="selection.hasValue() && !isAllSelected()">
|
[indeterminate]="selection.hasValue() && !isAllSelected()">
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
</mat-header-cell>
|
</th>
|
||||||
<mat-cell *matCellDef="let row">
|
<td mat-cell *matCellDef="let row">
|
||||||
<mat-checkbox (click)="$event.stopPropagation()"
|
<mat-checkbox (click)="$event.stopPropagation()"
|
||||||
(change)="$event ? selection.toggle(row) : null"
|
(change)="$event ? selection.toggle(row) : null"
|
||||||
[checked]="selection.isSelected(row)">
|
[checked]="selection.isSelected(row)">
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
</mat-cell>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
|
||||||
<mat-cell *matCellDef="let user"> {{ user.name }} </mat-cell>
|
<td mat-cell *matCellDef="let user"><span class="mobile-label">Name: </span>{{ user.name }} </td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="userID">
|
<ng-container matColumnDef="id">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> User ID </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> User ID </th>
|
||||||
<mat-cell *matCellDef="let user">{{ user.userID }}</mat-cell>
|
<td mat-cell *matCellDef="let user"><span class="mobile-label">User ID: </span>{{ user.id }}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="emailID">
|
<ng-container matColumnDef="email">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Email ID </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Email ID </th>
|
||||||
<mat-cell *matCellDef="let user">{{ user.emailID }}</mat-cell>
|
<td mat-cell *matCellDef="let user"><span class="mobile-label">Email ID: </span>{{ user.email }}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="status">
|
<ng-container matColumnDef="status">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Status </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header="isSelfServiceUser"> Status </th>
|
||||||
<mat-cell *matCellDef="let user">
|
<td mat-cell *matCellDef="let user">
|
||||||
<mat-icon matTooltip="{{ user.status }}" matTooltipPosition="right">lens</mat-icon>
|
<span class="mobile-label">Status: </span>
|
||||||
</mat-cell>
|
<div [className]="user.isSelfServiceUser === true ? 'active' : 'inactive'">
|
||||||
|
<mat-icon matTooltip="{{ user.isSelfServiceUser === true ? 'Active' : 'Inactive' }}" matTooltipPosition="right">lens</mat-icon>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="office">
|
<ng-container matColumnDef="officeName">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Office </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Office </th>
|
||||||
<mat-cell *matCellDef="let user">{{ user.office }}</mat-cell>
|
<td mat-cell *matCellDef="let user"><span class="mobile-label">Office: </span>{{ user.officeName }}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="staff">
|
<ng-container matColumnDef="staff">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Staff </mat-header-cell>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Staff </th>
|
||||||
<mat-cell *matCellDef="let user">{{ user.staff }}</mat-cell>
|
<td mat-cell *matCellDef="let user"><span class="mobile-label">Staff: </span>{{ user.staff }}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="selection.toggle(row)"></mat-row>
|
<tr mat-row *matRowDef="let row; columns: displayedColumns;" (click)="selection.toggle(row)"></tr>
|
||||||
|
|
||||||
</mat-table>
|
</table>
|
||||||
|
|
||||||
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,45 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mat-form-field {
|
// .mat-form-field {
|
||||||
width: 100%;
|
// width: 100%;
|
||||||
|
// }
|
||||||
|
|
||||||
|
.mobile-label {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.inactive {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @media(max-width: 600px) {
|
||||||
|
// .mobile-label {
|
||||||
|
// width: 80px;
|
||||||
|
// display: inline-block;
|
||||||
|
// font-weight: bold;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// .mat-header-row {
|
||||||
|
// display: none;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// .mat-row {
|
||||||
|
// display: flex;
|
||||||
|
// flex-direction: column;
|
||||||
|
// align-items: start;
|
||||||
|
// padding: 68px 24px;
|
||||||
|
// min-height: 108px;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// .mat-cell {
|
||||||
|
// flex: 1;
|
||||||
|
// display: flex;
|
||||||
|
// align-items: center;
|
||||||
|
// min-height: inherit;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -1,29 +1,17 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { SelectionModel } from '@angular/cdk/collections';
|
import { SelectionModel } from '@angular/cdk/collections';
|
||||||
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
|
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
|
||||||
|
import { UserService } from '../user.service';
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
name: string;
|
name: string;
|
||||||
userID: string;
|
id: number;
|
||||||
emailID: string;
|
email: string;
|
||||||
status: string;
|
isSelfServiceUser: boolean;
|
||||||
office: string;
|
officeName: string;
|
||||||
staff: string;
|
staff: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const USER_DATA: User[] = [
|
|
||||||
{ name: 'Data 1', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 2', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 3', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 4', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 5', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 6', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 7', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 8', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 9', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' },
|
|
||||||
{ name: 'Data 10', userID: 'Data', emailID: 'Data', status: 'Data', office: 'Data', staff: 'Data' }
|
|
||||||
];
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'mifosx-user-management',
|
selector: 'mifosx-user-management',
|
||||||
templateUrl: './user-management.component.html',
|
templateUrl: './user-management.component.html',
|
||||||
@@ -31,20 +19,21 @@ const USER_DATA: User[] = [
|
|||||||
})
|
})
|
||||||
export class UserManagementComponent implements OnInit {
|
export class UserManagementComponent implements OnInit {
|
||||||
|
|
||||||
// page = 1;
|
displayedColumns: string[] = ['select', 'name', 'id', 'email', 'status', 'officeName', 'staff'];
|
||||||
// isCollapsed = true;
|
dataSource: any;
|
||||||
displayedColumns: string[] = ['select', 'name', 'userID', 'emailID', 'status', 'office', 'staff'];
|
|
||||||
dataSource = new MatTableDataSource(USER_DATA);
|
|
||||||
selection = new SelectionModel<User>(true, []);
|
selection = new SelectionModel<User>(true, []);
|
||||||
|
|
||||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||||
@ViewChild(MatSort) sort: MatSort;
|
@ViewChild(MatSort) sort: MatSort;
|
||||||
|
|
||||||
constructor() { }
|
constructor(private userService: UserService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.dataSource.paginator = this.paginator;
|
this.userService.getUsers().subscribe((data: User[]) => {
|
||||||
this.dataSource.sort = this.sort;
|
this.dataSource = new MatTableDataSource(data);
|
||||||
|
this.dataSource.paginator = this.paginator;
|
||||||
|
this.dataSource.sort = this.sort;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(filterValue: string) {
|
applyFilter(filterValue: string) {
|
||||||
@@ -59,8 +48,8 @@ export class UserManagementComponent implements OnInit {
|
|||||||
|
|
||||||
masterToggle() {
|
masterToggle() {
|
||||||
this.isAllSelected() ?
|
this.isAllSelected() ?
|
||||||
this.selection.clear() :
|
this.selection.clear() :
|
||||||
this.dataSource.data.forEach(row => this.selection.select(row));
|
this.dataSource.data.forEach((row: User) => this.selection.select(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
|
describe('UserService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [UserService]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([UserService], (service: UserService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
import { map } from 'rxjs/internal/operators/map';
|
||||||
|
|
||||||
|
const username = 'mifos';
|
||||||
|
const password = 'password';
|
||||||
|
const token = btoa(`${username}:${password}`);
|
||||||
|
|
||||||
|
const httpOptions = {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Basic ${token}`,
|
||||||
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class UserService {
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
getUsers(): Observable<any> {
|
||||||
|
return this.http.get<any>(
|
||||||
|
`https://demo.openmf.org/fineract-provider/api/v1/users?
|
||||||
|
fields=id,firstname,lastname,email,officeName,staff&tenantIdentifier=default&pretty=true`,
|
||||||
|
httpOptions).pipe(
|
||||||
|
map((res) => {
|
||||||
|
res.forEach((user: any) => {
|
||||||
|
user.name = `${user.firstname} ${user.lastname}`;
|
||||||
|
user.staff = user.staff ? `${user.staff.firstname} ${user.staff.lastname}` : '';
|
||||||
|
delete user.firstname;
|
||||||
|
delete user.lastname;
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user