1
0

Initial application generated by JHipster-5.8.2

This commit is contained in:
Michael Hoennig
2019-04-01 13:14:56 +02:00
commit e0b3d2a36d
404 changed files with 49698 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule } from '@angular/router';
import { JhiLanguageService } from 'ng-jhipster';
import { JhiLanguageHelper } from 'app/core';
import { HsadminNgSharedModule } from 'app/shared';
/* jhipster-needle-add-admin-module-import - JHipster will add admin modules imports here */
import {
adminState,
AuditsComponent,
UserMgmtComponent,
UserMgmtDetailComponent,
UserMgmtUpdateComponent,
UserMgmtDeleteDialogComponent,
LogsComponent,
JhiMetricsMonitoringComponent,
JhiHealthModalComponent,
JhiHealthCheckComponent,
JhiConfigurationComponent,
JhiDocsComponent
} from './';
@NgModule({
imports: [
HsadminNgSharedModule,
RouterModule.forChild(adminState)
/* jhipster-needle-add-admin-module - JHipster will add admin modules here */
],
declarations: [
AuditsComponent,
UserMgmtComponent,
UserMgmtDetailComponent,
UserMgmtUpdateComponent,
UserMgmtDeleteDialogComponent,
LogsComponent,
JhiConfigurationComponent,
JhiHealthCheckComponent,
JhiHealthModalComponent,
JhiDocsComponent,
JhiMetricsMonitoringComponent
],
providers: [{ provide: JhiLanguageService, useClass: JhiLanguageService }],
entryComponents: [UserMgmtDeleteDialogComponent, JhiHealthModalComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HsadminNgAdminModule {
constructor(private languageService: JhiLanguageService, private languageHelper: JhiLanguageHelper) {
this.languageHelper.language.subscribe((languageKey: string) => {
if (languageKey !== undefined) {
this.languageService.changeLanguage(languageKey);
}
});
}
}

View File

@@ -0,0 +1,18 @@
import { Routes } from '@angular/router';
import { auditsRoute, configurationRoute, docsRoute, healthRoute, logsRoute, metricsRoute, userMgmtRoute } from './';
import { UserRouteAccessService } from 'app/core';
const ADMIN_ROUTES = [auditsRoute, configurationRoute, docsRoute, healthRoute, logsRoute, ...userMgmtRoute, metricsRoute];
export const adminState: Routes = [
{
path: '',
data: {
authorities: ['ROLE_ADMIN']
},
canActivate: [UserRouteAccessService],
children: ADMIN_ROUTES
}
];

View File

@@ -0,0 +1,3 @@
export class AuditData {
constructor(public remoteAddress: string, public sessionId: string) {}
}

View File

@@ -0,0 +1,5 @@
import { AuditData } from './audit-data.model';
export class Audit {
constructor(public data: AuditData, public principal: string, public timestamp: string, public type: string) {}
}

View File

@@ -0,0 +1,52 @@
<div *ngIf="audits">
<h2 id="audits-page-heading" jhiTranslate="audits.title">Audits</h2>
<div class="row">
<div class="col-md-5">
<h4 jhiTranslate="audits.filter.title">Filter by date</h4>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" jhiTranslate="audits.filter.from">from</span>
</div>
<input type="date" class="form-control" name="start" [(ngModel)]="fromDate" (ngModelChange)="transition()" required/>
<div class="input-group-append">
<span class="input-group-text" jhiTranslate="audits.filter.to">To</span>
</div>
<input type="date" class="form-control" name="end" [(ngModel)]="toDate" (ngModelChange)="transition()" required/>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-sm table-striped">
<thead>
<tr jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="transition.bind(this)">
<th jhiSortBy="auditEventDate"><span jhiTranslate="audits.table.header.date">Date</span><fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="principal"><span jhiTranslate="audits.table.header.principal">User</span><fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="auditEventType"><span jhiTranslate="audits.table.header.status">State</span><fa-icon [icon]="'sort'"></fa-icon></th>
<th><span jhiTranslate="audits.table.header.data">Extra data</span></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let audit of audits">
<td><span>{{audit.timestamp| date:'medium'}}</span></td>
<td><small>{{audit.principal}}</small></td>
<td>{{audit.type}}</td>
<td>
<span *ngIf="audit.data" ng-show="audit.data.message">{{audit.data.message}}</span>
<span *ngIf="audit.data" ng-show="audit.data.remoteAddress"><span jhiTranslate="audits.table.data.remoteAddress">Remote Address</span> {{audit.data.remoteAddress}}</span>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<div class="row justify-content-center">
<jhi-item-count [page]="page" [total]="totalItems" [itemsPerPage]="itemsPerPage"></jhi-item-count>
</div>
<div class="row justify-content-center">
<ngb-pagination [collectionSize]="totalItems" [(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="loadPage(page)"></ngb-pagination>
</div>
</div>
</div>

View File

@@ -0,0 +1,126 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { JhiParseLinks, JhiAlertService } from 'ng-jhipster';
import { ITEMS_PER_PAGE } from 'app/shared';
import { Audit } from './audit.model';
import { AuditsService } from './audits.service';
@Component({
selector: 'jhi-audit',
templateUrl: './audits.component.html'
})
export class AuditsComponent implements OnInit, OnDestroy {
audits: Audit[];
fromDate: string;
itemsPerPage: any;
links: any;
page: number;
routeData: any;
predicate: any;
previousPage: any;
reverse: boolean;
toDate: string;
totalItems: number;
constructor(
private auditsService: AuditsService,
private alertService: JhiAlertService,
private parseLinks: JhiParseLinks,
private activatedRoute: ActivatedRoute,
private datePipe: DatePipe,
private router: Router
) {
this.itemsPerPage = ITEMS_PER_PAGE;
this.routeData = this.activatedRoute.data.subscribe(data => {
this.page = data['pagingParams'].page;
this.previousPage = data['pagingParams'].page;
this.reverse = data['pagingParams'].ascending;
this.predicate = data['pagingParams'].predicate;
});
}
ngOnInit() {
this.today();
this.previousMonth();
this.loadAll();
}
ngOnDestroy() {
this.routeData.unsubscribe();
}
previousMonth() {
const dateFormat = 'yyyy-MM-dd';
let fromDate: Date = new Date();
if (fromDate.getMonth() === 0) {
fromDate = new Date(fromDate.getFullYear() - 1, 11, fromDate.getDate());
} else {
fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth() - 1, fromDate.getDate());
}
this.fromDate = this.datePipe.transform(fromDate, dateFormat);
}
today() {
const dateFormat = 'yyyy-MM-dd';
// Today + 1 day - needed if the current day must be included
const today: Date = new Date();
today.setDate(today.getDate() + 1);
const date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
this.toDate = this.datePipe.transform(date, dateFormat);
}
loadAll() {
this.auditsService
.query({
page: this.page - 1,
size: this.itemsPerPage,
sort: this.sort(),
fromDate: this.fromDate,
toDate: this.toDate
})
.subscribe(
(res: HttpResponse<Audit[]>) => this.onSuccess(res.body, res.headers),
(res: HttpResponse<any>) => this.onError(res.body)
);
}
sort() {
const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')];
if (this.predicate !== 'id') {
result.push('id');
}
return result;
}
loadPage(page: number) {
if (page !== this.previousPage) {
this.previousPage = page;
this.transition();
}
}
transition() {
this.router.navigate(['/admin/audits'], {
queryParams: {
page: this.page,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}
});
this.loadAll();
}
private onSuccess(data, headers) {
this.links = this.parseLinks.parse(headers.get('link'));
this.totalItems = headers.get('X-Total-Count');
this.audits = data;
}
private onError(error) {
this.alertService.error(error.error, error.message, null);
}
}

View File

@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Route } from '@angular/router';
import { JhiPaginationUtil, JhiResolvePagingParams } from 'ng-jhipster';
import { AuditsComponent } from './audits.component';
export const auditsRoute: Route = {
path: 'audits',
component: AuditsComponent,
resolve: {
pagingParams: JhiResolvePagingParams
},
data: {
pageTitle: 'audits.title',
defaultSort: 'auditEventDate,desc'
}
};

View File

@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { createRequestOption } from 'app/shared';
import { SERVER_API_URL } from 'app/app.constants';
import { Audit } from './audit.model';
@Injectable({ providedIn: 'root' })
export class AuditsService {
constructor(private http: HttpClient) {}
query(req: any): Observable<HttpResponse<Audit[]>> {
const params: HttpParams = createRequestOption(req);
params.set('fromDate', req.fromDate);
params.set('toDate', req.toDate);
const requestURL = SERVER_API_URL + 'management/audits';
return this.http.get<Audit[]>(requestURL, {
params,
observe: 'response'
});
}
}

View File

@@ -0,0 +1,46 @@
<div *ngIf="allConfiguration && configuration">
<h2 id="configuration-page-heading" jhiTranslate="configuration.title">Configuration</h2>
<span jhiTranslate="configuration.filter">Filter (by prefix)</span> <input type="text" [(ngModel)]="filter" class="form-control">
<h3>Spring configuration</h3>
<table class="table table-striped table-bordered table-responsive d-table">
<thead>
<tr>
<th class="w-40" (click)="orderProp = 'prefix'; reverse=!reverse"><span jhiTranslate="configuration.table.prefix">Prefix</span></th>
<th class="w-60" (click)="orderProp = 'properties'; reverse=!reverse"><span jhiTranslate="configuration.table.properties">Properties</span></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let entry of (configuration | pureFilter:filter:'prefix' | orderBy:orderProp:reverse)">
<td><span>{{entry.prefix}}</span></td>
<td>
<div class="row" *ngFor="let key of keys(entry.properties)">
<div class="col-md-4">{{key}}</div>
<div class="col-md-8">
<span class="float-right badge-secondary break">{{entry.properties[key] | json}}</span>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div *ngFor="let key of keys(allConfiguration)">
<h4><span>{{key}}</span></h4>
<table class="table table-sm table-striped table-bordered table-responsive d-table">
<thead>
<tr>
<th class="w-40">Property</th>
<th class="w-60">Value</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of allConfiguration[key]">
<td class="break">{{item.key}}</td>
<td class="break">
<span class="float-right badge-secondary break">{{item.val}}</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,43 @@
import { Component, OnInit } from '@angular/core';
import { JhiConfigurationService } from './configuration.service';
@Component({
selector: 'jhi-configuration',
templateUrl: './configuration.component.html'
})
export class JhiConfigurationComponent implements OnInit {
allConfiguration: any = null;
configuration: any = null;
configKeys: any[];
filter: string;
orderProp: string;
reverse: boolean;
constructor(private configurationService: JhiConfigurationService) {
this.configKeys = [];
this.filter = '';
this.orderProp = 'prefix';
this.reverse = false;
}
keys(dict): Array<string> {
return dict === undefined ? [] : Object.keys(dict);
}
ngOnInit() {
this.configurationService.get().subscribe(configuration => {
this.configuration = configuration;
for (const config of configuration) {
if (config.properties !== undefined) {
this.configKeys.push(Object.keys(config.properties));
}
}
});
this.configurationService.getEnv().subscribe(configuration => {
this.allConfiguration = configuration;
});
}
}

View File

@@ -0,0 +1,11 @@
import { Route } from '@angular/router';
import { JhiConfigurationComponent } from './configuration.component';
export const configurationRoute: Route = {
path: 'jhi-configuration',
component: JhiConfigurationComponent,
data: {
pageTitle: 'configuration.title'
}
};

View File

@@ -0,0 +1,67 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { SERVER_API_URL } from 'app/app.constants';
@Injectable({ providedIn: 'root' })
export class JhiConfigurationService {
constructor(private http: HttpClient) {}
get(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/configprops', { observe: 'response' }).pipe(
map((res: HttpResponse<any>) => {
const properties: any[] = [];
const propertiesObject = this.getConfigPropertiesObjects(res.body);
for (const key in propertiesObject) {
if (propertiesObject.hasOwnProperty(key)) {
properties.push(propertiesObject[key]);
}
}
return properties.sort((propertyA, propertyB) => {
return propertyA.prefix === propertyB.prefix ? 0 : propertyA.prefix < propertyB.prefix ? -1 : 1;
});
})
);
}
getConfigPropertiesObjects(res: Object) {
// This code is for Spring Boot 2
if (res['contexts'] !== undefined) {
for (const key in res['contexts']) {
// If the key is not bootstrap, it will be the ApplicationContext Id
// For default app, it is baseName
// For microservice, it is baseName-1
if (!key.startsWith('bootstrap')) {
return res['contexts'][key]['beans'];
}
}
}
// by default, use the default ApplicationContext Id
return res['contexts']['hsadminNg']['beans'];
}
getEnv(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/env', { observe: 'response' }).pipe(
map((res: HttpResponse<any>) => {
const properties: any = {};
const propertySources = res.body['propertySources'];
for (const propertyObject of propertySources) {
const name = propertyObject['name'];
const detailProperties = propertyObject['properties'];
const vals: any[] = [];
for (const keyDetail in detailProperties) {
if (detailProperties.hasOwnProperty(keyDetail)) {
vals.push({ key: keyDetail, val: detailProperties[keyDetail]['value'] });
}
}
properties[name] = vals;
}
return properties;
})
);
}
}

View File

@@ -0,0 +1,2 @@
<iframe src="swagger-ui/index.html" width="100%" height="900" seamless
target="_top" title="Swagger UI" class="border-0"></iframe>

View File

@@ -0,0 +1,9 @@
import { Component } from '@angular/core';
@Component({
selector: 'jhi-docs',
templateUrl: './docs.component.html'
})
export class JhiDocsComponent {
constructor() {}
}

View File

@@ -0,0 +1,11 @@
import { Route } from '@angular/router';
import { JhiDocsComponent } from './docs.component';
export const docsRoute: Route = {
path: 'docs',
component: JhiDocsComponent,
data: {
pageTitle: 'global.menu.admin.apidocs'
}
};

View File

@@ -0,0 +1,36 @@
<div class="modal-header">
<h4 class="modal-title" id="showHealthLabel">
{{'health.indicator.' + baseName(currentHealth.name) | translate}}
{{subSystemName(currentHealth.name)}}
</h4>
<button aria-label="Close" data-dismiss="modal" class="close" type="button" (click)="activeModal.dismiss('closed')"><span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body pad">
<div *ngIf="currentHealth.details">
<h5 jhiTranslate="health.details.properties">Properties</h5>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th class="text-left" jhiTranslate="health.details.name">Name</th>
<th class="text-left" jhiTranslate="health.details.value">Value</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let entry of currentHealth.details.details | keys">
<td class="text-left">{{entry.key}}</td>
<td class="text-left">{{readableValue(entry.value)}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div *ngIf="currentHealth.error">
<h4 jhiTranslate="health.details.error">Error</h4>
<pre>{{currentHealth.error}}</pre>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-secondary float-left" type="button" (click)="activeModal.dismiss('closed')">Done</button>
</div>

View File

@@ -0,0 +1,41 @@
import { Component } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { JhiHealthService } from './health.service';
@Component({
selector: 'jhi-health-modal',
templateUrl: './health-modal.component.html'
})
export class JhiHealthModalComponent {
currentHealth: any;
constructor(private healthService: JhiHealthService, public activeModal: NgbActiveModal) {}
baseName(name) {
return this.healthService.getBaseName(name);
}
subSystemName(name) {
return this.healthService.getSubSystemName(name);
}
readableValue(value: number) {
if (this.currentHealth.name === 'diskSpace') {
// Should display storage space in an human readable unit
const val = value / 1073741824;
if (val > 1) {
// Value
return val.toFixed(2) + ' GB';
} else {
return (value / 1048576).toFixed(2) + ' MB';
}
}
if (typeof value === 'object') {
return JSON.stringify(value);
} else {
return value.toString();
}
}
}

View File

@@ -0,0 +1,34 @@
<div>
<h2>
<span id="health-page-heading" jhiTranslate="health.title">Health Checks</span>
<button class="btn btn-primary float-right" (click)="refresh()">
<fa-icon [icon]="'sync'"></fa-icon> <span jhiTranslate="health.refresh.button">Refresh</span>
</button>
</h2>
<div class="table-responsive">
<table id="healthCheck" class="table table-striped">
<thead>
<tr>
<th jhiTranslate="health.table.service">Service Name</th>
<th class="text-center" jhiTranslate="health.table.status">Status</th>
<th class="text-center" jhiTranslate="health.details.details">Details</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let health of healthData">
<td>{{'health.indicator.' + baseName(health.name) | translate}} {{subSystemName(health.name)}}</td>
<td class="text-center">
<span class="badge" [ngClass]="getBadgeClass(health.status)" jhiTranslate="{{'health.status.' + health.status}}">
{{health.status}}
</span>
</td>
<td class="text-center">
<a class="hand" (click)="showHealth(health)" *ngIf="health.details || health.error">
<fa-icon [icon]="'eye'"></fa-icon>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,66 @@
import { Component, OnInit } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { JhiHealthService } from './health.service';
import { JhiHealthModalComponent } from './health-modal.component';
@Component({
selector: 'jhi-health',
templateUrl: './health.component.html'
})
export class JhiHealthCheckComponent implements OnInit {
healthData: any;
updatingHealth: boolean;
constructor(private modalService: NgbModal, private healthService: JhiHealthService) {}
ngOnInit() {
this.refresh();
}
baseName(name: string) {
return this.healthService.getBaseName(name);
}
getBadgeClass(statusState) {
if (statusState === 'UP') {
return 'badge-success';
} else {
return 'badge-danger';
}
}
refresh() {
this.updatingHealth = true;
this.healthService.checkHealth().subscribe(
health => {
this.healthData = this.healthService.transformHealthData(health);
this.updatingHealth = false;
},
error => {
if (error.status === 503) {
this.healthData = this.healthService.transformHealthData(error.error);
this.updatingHealth = false;
}
}
);
}
showHealth(health: any) {
const modalRef = this.modalService.open(JhiHealthModalComponent);
modalRef.componentInstance.currentHealth = health;
modalRef.result.then(
result => {
// Left blank intentionally, nothing to do here
},
reason => {
// Left blank intentionally, nothing to do here
}
);
}
subSystemName(name: string) {
return this.healthService.getSubSystemName(name);
}
}

View File

@@ -0,0 +1,11 @@
import { Route } from '@angular/router';
import { JhiHealthCheckComponent } from './health.component';
export const healthRoute: Route = {
path: 'jhi-health',
component: JhiHealthCheckComponent,
data: {
pageTitle: 'health.title'
}
};

View File

@@ -0,0 +1,133 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SERVER_API_URL } from 'app/app.constants';
@Injectable({ providedIn: 'root' })
export class JhiHealthService {
separator: string;
constructor(private http: HttpClient) {
this.separator = '.';
}
checkHealth(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/health');
}
transformHealthData(data): any {
const response = [];
this.flattenHealthData(response, null, data.details);
return response;
}
getBaseName(name): string {
if (name) {
const split = name.split('.');
return split[0];
}
}
getSubSystemName(name): string {
if (name) {
const split = name.split('.');
split.splice(0, 1);
const remainder = split.join('.');
return remainder ? ' - ' + remainder : '';
}
}
/* private methods */
private addHealthObject(result, isLeaf, healthObject, name): any {
const healthData: any = {
name
};
const details = {};
let hasDetails = false;
for (const key in healthObject) {
if (healthObject.hasOwnProperty(key)) {
const value = healthObject[key];
if (key === 'status' || key === 'error') {
healthData[key] = value;
} else {
if (!this.isHealthObject(value)) {
details[key] = value;
hasDetails = true;
}
}
}
}
// Add the details
if (hasDetails) {
healthData.details = details;
}
// Only add nodes if they provide additional information
if (isLeaf || hasDetails || healthData.error) {
result.push(healthData);
}
return healthData;
}
private flattenHealthData(result, path, data): any {
for (const key in data) {
if (data.hasOwnProperty(key)) {
const value = data[key];
if (this.isHealthObject(value)) {
if (this.hasSubSystem(value)) {
this.addHealthObject(result, false, value, this.getModuleName(path, key));
this.flattenHealthData(result, this.getModuleName(path, key), value);
} else {
this.addHealthObject(result, true, value, this.getModuleName(path, key));
}
}
}
}
return result;
}
private getModuleName(path, name): string {
let result;
if (path && name) {
result = path + this.separator + name;
} else if (path) {
result = path;
} else if (name) {
result = name;
} else {
result = '';
}
return result;
}
private hasSubSystem(healthObject): boolean {
let result = false;
for (const key in healthObject) {
if (healthObject.hasOwnProperty(key)) {
const value = healthObject[key];
if (value && value.status) {
result = true;
}
}
}
return result;
}
private isHealthObject(healthObject): boolean {
let result = false;
for (const key in healthObject) {
if (healthObject.hasOwnProperty(key)) {
if (key === 'status') {
result = true;
}
}
}
return result;
}
}

View File

@@ -0,0 +1,27 @@
export * from './audits/audits.component';
export * from './audits/audits.service';
export * from './audits/audits.route';
export * from './audits/audit.model';
export * from './audits/audit-data.model';
export * from './configuration/configuration.component';
export * from './configuration/configuration.service';
export * from './configuration/configuration.route';
export * from './docs/docs.component';
export * from './docs/docs.route';
export * from './health/health.component';
export * from './health/health-modal.component';
export * from './health/health.service';
export * from './health/health.route';
export * from './logs/logs.component';
export * from './logs/logs.service';
export * from './logs/logs.route';
export * from './logs/log.model';
export * from './metrics/metrics.component';
export * from './metrics/metrics.service';
export * from './metrics/metrics.route';
export * from './user-management/user-management-update.component';
export * from './user-management/user-management-delete-dialog.component';
export * from './user-management/user-management-detail.component';
export * from './user-management/user-management.component';
export * from './user-management/user-management.route';
export * from './admin.route';

View File

@@ -0,0 +1,3 @@
export class Log {
constructor(public name: string, public level: string) {}
}

View File

@@ -0,0 +1,28 @@
<div class="table-responsive" *ngIf="loggers">
<h2 id="logs-page-heading" jhiTranslate="logs.title">Logs</h2>
<p jhiTranslate="logs.nbloggers" [translateValues]="{total: loggers.length}">There are {{ loggers.length }} loggers.</p>
<span jhiTranslate="logs.filter">Filter</span> <input type="text" [(ngModel)]="filter" class="form-control">
<table class="table table-sm table-striped table-bordered">
<thead>
<tr title="click to order">
<th (click)="orderProp = 'name'; reverse=!reverse"><span jhiTranslate="logs.table.name">Name</span></th>
<th (click)="orderProp = 'level'; reverse=!reverse"><span jhiTranslate="logs.table.level">Level</span></th>
</tr>
</thead>
<tr *ngFor="let logger of (loggers | pureFilter:filter:'name' | orderBy:orderProp:reverse)">
<td><small>{{logger.name | slice:0:140}}</small></td>
<td>
<button (click)="changeLevel(logger.name, 'TRACE')" [ngClass]="(logger.level=='TRACE') ? 'btn-primary' : 'btn-light'" class="btn btn-sm">TRACE</button>
<button (click)="changeLevel(logger.name, 'DEBUG')" [ngClass]="(logger.level=='DEBUG') ? 'btn-success' : 'btn-light'" class="btn btn-sm">DEBUG</button>
<button (click)="changeLevel(logger.name, 'INFO')" [ngClass]="(logger.level=='INFO') ? 'btn-info' : 'btn-light'" class="btn btn-sm">INFO</button>
<button (click)="changeLevel(logger.name, 'WARN')" [ngClass]="(logger.level=='WARN') ? 'btn-warning' : 'btn-light'" class="btn btn-sm">WARN</button>
<button (click)="changeLevel(logger.name, 'ERROR')" [ngClass]="(logger.level=='ERROR') ? 'btn-danger' : 'btn-light'" class="btn btn-sm">ERROR</button>
<button (click)="changeLevel(logger.name, 'OFF')" [ngClass]="(logger.level=='OFF') ? 'btn-secondary' : 'btn-light'" class="btn btn-sm">OFF</button>
</td>
</tr>
</table>
</div>

View File

@@ -0,0 +1,32 @@
import { Component, OnInit } from '@angular/core';
import { Log } from './log.model';
import { LogsService } from './logs.service';
@Component({
selector: 'jhi-logs',
templateUrl: './logs.component.html'
})
export class LogsComponent implements OnInit {
loggers: Log[];
filter: string;
orderProp: string;
reverse: boolean;
constructor(private logsService: LogsService) {
this.filter = '';
this.orderProp = 'name';
this.reverse = false;
}
ngOnInit() {
this.logsService.findAll().subscribe(response => (this.loggers = response.body));
}
changeLevel(name: string, level: string) {
const log = new Log(name, level);
this.logsService.changeLevel(log).subscribe(() => {
this.logsService.findAll().subscribe(response => (this.loggers = response.body));
});
}
}

View File

@@ -0,0 +1,11 @@
import { Route } from '@angular/router';
import { LogsComponent } from './logs.component';
export const logsRoute: Route = {
path: 'logs',
component: LogsComponent,
data: {
pageTitle: 'logs.title'
}
};

View File

@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SERVER_API_URL } from 'app/app.constants';
import { Log } from './log.model';
@Injectable({ providedIn: 'root' })
export class LogsService {
constructor(private http: HttpClient) {}
changeLevel(log: Log): Observable<HttpResponse<any>> {
return this.http.put(SERVER_API_URL + 'management/logs', log, { observe: 'response' });
}
findAll(): Observable<HttpResponse<Log[]>> {
return this.http.get<Log[]>(SERVER_API_URL + 'management/logs', { observe: 'response' });
}
}

View File

@@ -0,0 +1,56 @@
<div>
<h2>
<span id="metrics-page-heading" jhiTranslate="metrics.title">Application Metrics</span>
<button class="btn btn-primary float-right" (click)="refresh()">
<fa-icon [icon]="'sync'"></fa-icon> <span jhiTranslate="metrics.refresh.button">Refresh</span>
</button>
</h2>
<h3 jhiTranslate="metrics.jvm.title">JVM Metrics</h3>
<div class="row" *ngIf="!updatingMetrics">
<jhi-jvm-memory
class="col-md-4"
[updating]="updatingMetrics"
[jvmMemoryMetrics]="metrics.jvm">
</jhi-jvm-memory>
<jhi-jvm-threads class="col-md-4" [threadData]="threadData"></jhi-jvm-threads>
<jhi-metrics-system
class="col-md-4"
[updating]="updatingMetrics"
[systemMetrics]="metrics.processMetrics">
</jhi-metrics-system>
</div>
<div *ngIf="isObjectExisting(metrics, 'garbageCollector')">
<h3 jhiTranslate="metrics.jvm.gc.title">Garbage collector statistics</h3>
<jhi-metrics-garbagecollector [updating]="updatingMetrics" [garbageCollectorMetrics]="metrics.garbageCollector"></jhi-metrics-garbagecollector>
</div>
<div class="well well-lg" *ngIf="updatingMetrics" jhiTranslate="metrics.updating">Updating...</div>
<jhi-metrics-request
*ngIf="isObjectExisting(metrics, 'http.server.requests')"
[updating]="updatingMetrics"
[requestMetrics]="metrics['http.server.requests']">
</jhi-metrics-request>
<div >
<jhi-metrics-endpoints-requests
*ngIf="isObjectExisting(metrics, 'services')"
[updating]="updatingMetrics"
[endpointsRequestsMetrics]="metrics.services">
</jhi-metrics-endpoints-requests>
<jhi-metrics-cache
*ngIf="isObjectExisting(metrics, 'cache')"
[updating]="updatingMetrics"
[cacheMetrics]="metrics.cache">
</jhi-metrics-cache>
<jhi-metrics-datasource
*ngIf="isObjectExistingAndNotEmpty(metrics, 'databases')"
[updating]="updatingMetrics"
[datasourceMetrics]="metrics.databases">
</jhi-metrics-datasource>
</div>

View File

@@ -0,0 +1,42 @@
import { Component, OnInit } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { JhiMetricsService } from './metrics.service';
@Component({
selector: 'jhi-metrics',
templateUrl: './metrics.component.html'
})
export class JhiMetricsMonitoringComponent implements OnInit {
metrics: any = {};
threadData: any = {};
updatingMetrics = true;
JCACHE_KEY: string;
constructor(private modalService: NgbModal, private metricsService: JhiMetricsService) {
this.JCACHE_KEY = 'jcache.statistics';
}
ngOnInit() {
this.refresh();
}
refresh() {
this.updatingMetrics = true;
this.metricsService.getMetrics().subscribe(metrics => {
this.metrics = metrics;
this.metricsService.threadDump().subscribe(data => {
this.threadData = data.threads;
this.updatingMetrics = false;
});
});
}
isObjectExisting(metrics: any, key: string) {
return metrics && metrics[key];
}
isObjectExistingAndNotEmpty(metrics: any, key: string) {
return this.isObjectExisting(metrics, key) && JSON.stringify(metrics[key]) !== '{}';
}
}

View File

@@ -0,0 +1,11 @@
import { Route } from '@angular/router';
import { JhiMetricsMonitoringComponent } from './metrics.component';
export const metricsRoute: Route = {
path: 'jhi-metrics',
component: JhiMetricsMonitoringComponent,
data: {
pageTitle: 'metrics.title'
}
};

View File

@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SERVER_API_URL } from 'app/app.constants';
@Injectable({ providedIn: 'root' })
export class JhiMetricsService {
constructor(private http: HttpClient) {}
getMetrics(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/jhi-metrics');
}
threadDump(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/threaddump');
}
}

View File

@@ -0,0 +1,19 @@
<form name="deleteForm" (ngSubmit)="confirmDelete(user.login)">
<div class="modal-header">
<h4 class="modal-title" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"
(click)="clear()">&times;</button>
</div>
<div class="modal-body">
<jhi-alert-error></jhi-alert-error>
<p jhiTranslate="userManagement.delete.question" [translateValues]="{login: user.login}">Are you sure you want to delete this User?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="clear()">
<fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button type="submit" class="btn btn-danger">
<fa-icon [icon]="'times'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.delete">Delete</span>
</button>
</div>
</form>

View File

@@ -0,0 +1,29 @@
import { Component } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { JhiEventManager } from 'ng-jhipster';
import { User, UserService } from 'app/core';
@Component({
selector: 'jhi-user-mgmt-delete-dialog',
templateUrl: './user-management-delete-dialog.component.html'
})
export class UserMgmtDeleteDialogComponent {
user: User;
constructor(private userService: UserService, public activeModal: NgbActiveModal, private eventManager: JhiEventManager) {}
clear() {
this.activeModal.dismiss('cancel');
}
confirmDelete(login) {
this.userService.delete(login).subscribe(response => {
this.eventManager.broadcast({
name: 'userListModification',
content: 'Deleted a user'
});
this.activeModal.dismiss(true);
});
}
}

View File

@@ -0,0 +1,49 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="user">
<h2>
<span jhiTranslate="userManagement.detail.title">User</span> [<b>{{user.login}}</b>]
</h2>
<dl class="row-md jh-entity-details">
<dt><span jhiTranslate="userManagement.login">Login</span></dt>
<dd>
<span>{{user.login}}</span>
<jhi-boolean
[value]="user.activated"
[textTrue]="'userManagement.activated' | translate"
[textFalse]="'userManagement.deactivated' | translate">
</jhi-boolean>
</dd>
<dt><span jhiTranslate="userManagement.firstName">First Name</span></dt>
<dd>{{user.firstName}}</dd>
<dt><span jhiTranslate="userManagement.lastName">Last Name</span></dt>
<dd>{{user.lastName}}</dd>
<dt><span jhiTranslate="userManagement.email">Email</span></dt>
<dd>{{user.email}}</dd>
<dt><span jhiTranslate="userManagement.langKey">Lang Key</span></dt>
<dd>{{user.langKey}}</dd>
<dt><span jhiTranslate="userManagement.createdBy">Created By</span></dt>
<dd>{{user.createdBy}}</dd>
<dt><span jhiTranslate="userManagement.createdDate">Created Date</span></dt>
<dd>{{user.createdDate | date:'dd/MM/yy HH:mm' }}</dd>
<dt><span jhiTranslate="userManagement.lastModifiedBy">Last Modified By</span></dt>
<dd>{{user.lastModifiedBy}}</dd>
<dt><span jhiTranslate="userManagement.lastModifiedDate">Last Modified Date</span></dt>
<dd>{{user.lastModifiedDate | date:'dd/MM/yy HH:mm'}}</dd>
<dt><span jhiTranslate="userManagement.profiles">Profiles</span></dt>
<dd>
<ul class="list-unstyled">
<li *ngFor="let authority of user.authorities">
<span class="badge badge-info">{{authority}}</span>
</li>
</ul>
</dd>
</dl>
<button type="submit"
routerLink="../../"
class="btn btn-info">
<fa-icon [icon]="'arrow-left'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.back"> Back</span>
</button>
</div>
</div>
</div>

View File

@@ -0,0 +1,20 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { User } from 'app/core';
@Component({
selector: 'jhi-user-mgmt-detail',
templateUrl: './user-management-detail.component.html'
})
export class UserMgmtDetailComponent implements OnInit {
user: User;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.data.subscribe(({ user }) => {
this.user = user.body ? user.body : user;
});
}
}

View File

@@ -0,0 +1,124 @@
<div class="row justify-content-center">
<div class="col-8">
<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">
<h2 id="myUserLabel" jhiTranslate="userManagement.home.createOrEditLabel">
Create or edit a User
</h2>
<div>
<jhi-alert-error></jhi-alert-error>
<div class="form-group" [hidden]="!user.id">
<label jhiTranslate="global.field.id">ID</label>
<input type="text" class="form-control" name="id"
[(ngModel)]="user.id" readonly>
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="userManagement.login">Login</label>
<input type="text" class="form-control" name="login" #loginInput="ngModel"
[(ngModel)]="user.login" required minlength="1" maxlength="50" pattern="^[_.@A-Za-z0-9-]*$">
<div *ngIf="loginInput.dirty && loginInput.invalid">
<small class="form-text text-danger"
*ngIf="loginInput.errors.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
*ngIf="loginInput.errors.maxlength" jhiTranslate="entity.validation.maxlength"
[translateValues]="{max: 50}">
This field cannot be longer than 50 characters.
</small>
<small class="form-text text-danger"
*ngIf="loginInput.errors.pattern" jhiTranslate="entity.validation.patternLogin">
This field can only contain letters, digits and e-mail addresses.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="userManagement.firstName">First Name</label>
<input type="text" class="form-control" name="firstName" #firstNameInput="ngModel"
[(ngModel)]="user.firstName" maxlength="50">
<div *ngIf="firstNameInput.dirty && firstNameInput.invalid">
<small class="form-text text-danger"
*ngIf="firstNameInput.errors.maxlength" jhiTranslate="entity.validation.maxlength"
[translateValues]="{max: 50}">
This field cannot be longer than 50 characters.
</small>
</div>
</div>
<div class="form-group">
<label jhiTranslate="userManagement.lastName">Last Name</label>
<input type="text" class="form-control" name="lastName" #lastNameInput="ngModel"
[(ngModel)]="user.lastName" maxlength="50">
<div *ngIf="lastNameInput.dirty && lastNameInput.invalid">
<small class="form-text text-danger"
*ngIf="lastNameInput.errors.maxlength" jhiTranslate="entity.validation.maxlength"
[translateValues]="{max: 50}">
This field cannot be longer than 50 characters.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="userManagement.email">Email</label>
<input type="email" class="form-control" name="email" #emailInput="ngModel"
[(ngModel)]="user.email" minlength="5" required maxlength="254" email>
<div *ngIf="emailInput.dirty && emailInput.invalid">
<small class="form-text text-danger"
*ngIf="emailInput.errors.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
*ngIf="emailInput.errors.maxlength" jhiTranslate="entity.validation.maxlength"
[translateValues]="{max: 100}">
This field cannot be longer than 100 characters.
</small>
<small class="form-text text-danger"
*ngIf="emailInput.errors.minlength" jhiTranslate="entity.validation.minlength"
[translateValues]="{min: 5}">
This field is required to be at least 5 characters.
</small>
<small class="form-text text-danger"
*ngIf="emailInput.errors.email" jhiTranslate="global.messages.validate.email.invalid">
Your email is invalid.
</small>
</div>
</div>
<div class="form-check">
<label class="form-check-label" for="activated">
<input class="form-check-input" [disabled]="user.id === null" type="checkbox" id="activated" name="activated" [(ngModel)]="user.activated">
<span jhiTranslate="userManagement.activated">Activated</span>
</label>
</div>
<div class="form-group" *ngIf="languages && languages.length > 0">
<label jhiTranslate="userManagement.langKey">Lang Key</label>
<select class="form-control" id="langKey" name="langKey" [(ngModel)]="user.langKey">
<option *ngFor="let language of languages" [value]="language">{{language | findLanguageFromKey}}</option>
</select>
</div>
<div class="form-group">
<label jhiTranslate="userManagement.profiles">Profiles</label>
<select class="form-control" multiple name="authority" [(ngModel)]="user.authorities">
<option *ngFor="let authority of authorities" [value]="authority">{{authority}}</option>
</select>
</div>
</div>
<div>
<button type="button" class="btn btn-secondary" (click)="previousState()">
<fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span
jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
<fa-icon [icon]="'save'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
</button>
</div>
</form>
</div>
</div>

View File

@@ -0,0 +1,58 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { JhiLanguageHelper, User, UserService } from 'app/core';
@Component({
selector: 'jhi-user-mgmt-update',
templateUrl: './user-management-update.component.html'
})
export class UserMgmtUpdateComponent implements OnInit {
user: User;
languages: any[];
authorities: any[];
isSaving: boolean;
constructor(
private languageHelper: JhiLanguageHelper,
private userService: UserService,
private route: ActivatedRoute,
private router: Router
) {}
ngOnInit() {
this.isSaving = false;
this.route.data.subscribe(({ user }) => {
this.user = user.body ? user.body : user;
});
this.authorities = [];
this.userService.authorities().subscribe(authorities => {
this.authorities = authorities;
});
this.languageHelper.getAll().then(languages => {
this.languages = languages;
});
}
previousState() {
window.history.back();
}
save() {
this.isSaving = true;
if (this.user.id !== null) {
this.userService.update(this.user).subscribe(response => this.onSaveSuccess(response), () => this.onSaveError());
} else {
this.userService.create(this.user).subscribe(response => this.onSaveSuccess(response), () => this.onSaveError());
}
}
private onSaveSuccess(result) {
this.isSaving = false;
this.previousState();
}
private onSaveError() {
this.isSaving = false;
}
}

View File

@@ -0,0 +1,79 @@
<div>
<h2>
<span id="user-management-page-heading" jhiTranslate="userManagement.home.title">Users</span>
<button class="btn btn-primary float-right jh-create-entity" [routerLink]="['./new']">
<fa-icon [icon]="'plus'"></fa-icon> <span jhiTranslate="userManagement.home.createLabel">Create a new User</span>
</button>
</h2>
<jhi-alert></jhi-alert>
<div class="table-responsive" *ngIf="users">
<table class="table table-striped">
<thead>
<tr jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="transition.bind(this)">
<th jhiSortBy="id"><span jhiTranslate="global.field.id">ID</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="login"><span jhiTranslate="userManagement.login">Login</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="email"><span jhiTranslate="userManagement.email">Email</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
<th jhiSortBy="langKey"> <span jhiTranslate="userManagement.langKey">Lang Key</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th><span jhiTranslate="userManagement.profiles">Profiles</span></th>
<th jhiSortBy="createdDate"><span jhiTranslate="userManagement.createdDate">Created Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="lastModifiedBy"><span jhiTranslate="userManagement.lastModifiedBy">Last Modified By</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="lastModifiedDate"><span jhiTranslate="userManagement.lastModifiedDate">Last Modified Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th>
</tr>
</thead>
<tbody *ngIf ="users">
<tr *ngFor="let user of users; trackBy: trackIdentity">
<td><a [routerLink]="['./', user.login, 'view']">{{user.id}}</a></td>
<td>{{user.login}}</td>
<td>{{user.email}}</td>
<td>
<button class="btn btn-danger btn-sm" (click)="setActive(user, true)" *ngIf="!user.activated"
jhiTranslate="userManagement.deactivated">Deactivated</button>
<button class="btn btn-success btn-sm" (click)="setActive(user, false)" *ngIf="user.activated"
[disabled]="currentAccount.login === user.login" jhiTranslate="userManagement.activated">Activated</button>
</td>
<td>{{user.langKey}}</td>
<td>
<div *ngFor="let authority of user.authorities">
<span class="badge badge-info">{{ authority }}</span>
</div>
</td>
<td>{{user.createdDate | date:'dd/MM/yy HH:mm'}}</td>
<td>{{user.lastModifiedBy}}</td>
<td>{{user.lastModifiedDate | date:'dd/MM/yy HH:mm'}}</td>
<td class="text-right">
<div class="btn-group flex-btn-group-container">
<button type="submit"
[routerLink]="['./', user.login, 'view']"
class="btn btn-info btn-sm">
<fa-icon [icon]="'eye'"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
</button>
<button type="submit"
[routerLink]="['./', user.login, 'edit']"
queryParamsHandling="merge"
class="btn btn-primary btn-sm">
<fa-icon [icon]="'pencil-alt'"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
</button>
<button type="button" (click)="deleteUser(user)"
class="btn btn-danger btn-sm" [disabled]="currentAccount.login === user.login">
<fa-icon [icon]="'times'"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div *ngIf="users">
<div class="row justify-content-center">
<jhi-item-count [page]="page" [total]="totalItems" [itemsPerPage]="itemsPerPage"></jhi-item-count>
</div>
<div class="row justify-content-center">
<ngb-pagination [collectionSize]="totalItems" [(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="loadPage(page)"></ngb-pagination>
</div>
</div>
</div>

View File

@@ -0,0 +1,144 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ActivatedRoute, Router } from '@angular/router';
import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster';
import { ITEMS_PER_PAGE } from 'app/shared';
import { AccountService, UserService, User } from 'app/core';
import { UserMgmtDeleteDialogComponent } from 'app/admin';
@Component({
selector: 'jhi-user-mgmt',
templateUrl: './user-management.component.html'
})
export class UserMgmtComponent implements OnInit, OnDestroy {
currentAccount: any;
users: User[];
error: any;
success: any;
routeData: any;
links: any;
totalItems: any;
itemsPerPage: any;
page: any;
predicate: any;
previousPage: any;
reverse: any;
constructor(
private userService: UserService,
private alertService: JhiAlertService,
private accountService: AccountService,
private parseLinks: JhiParseLinks,
private activatedRoute: ActivatedRoute,
private router: Router,
private eventManager: JhiEventManager,
private modalService: NgbModal
) {
this.itemsPerPage = ITEMS_PER_PAGE;
this.routeData = this.activatedRoute.data.subscribe(data => {
this.page = data['pagingParams'].page;
this.previousPage = data['pagingParams'].page;
this.reverse = data['pagingParams'].ascending;
this.predicate = data['pagingParams'].predicate;
});
}
ngOnInit() {
this.accountService.identity().then(account => {
this.currentAccount = account;
this.loadAll();
this.registerChangeInUsers();
});
}
ngOnDestroy() {
this.routeData.unsubscribe();
}
registerChangeInUsers() {
this.eventManager.subscribe('userListModification', response => this.loadAll());
}
setActive(user, isActivated) {
user.activated = isActivated;
this.userService.update(user).subscribe(response => {
if (response.status === 200) {
this.error = null;
this.success = 'OK';
this.loadAll();
} else {
this.success = null;
this.error = 'ERROR';
}
});
}
loadAll() {
this.userService
.query({
page: this.page - 1,
size: this.itemsPerPage,
sort: this.sort()
})
.subscribe(
(res: HttpResponse<User[]>) => this.onSuccess(res.body, res.headers),
(res: HttpResponse<any>) => this.onError(res.body)
);
}
trackIdentity(index, item: User) {
return item.id;
}
sort() {
const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')];
if (this.predicate !== 'id') {
result.push('id');
}
return result;
}
loadPage(page: number) {
if (page !== this.previousPage) {
this.previousPage = page;
this.transition();
}
}
transition() {
this.router.navigate(['/admin/user-management'], {
queryParams: {
page: this.page,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}
});
this.loadAll();
}
deleteUser(user: User) {
const modalRef = this.modalService.open(UserMgmtDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.user = user;
modalRef.result.then(
result => {
// Left blank intentionally, nothing to do here
},
reason => {
// Left blank intentionally, nothing to do here
}
);
}
private onSuccess(data, headers) {
this.links = this.parseLinks.parse(headers.get('link'));
this.totalItems = headers.get('X-Total-Count');
this.users = data;
}
private onError(error) {
this.alertService.error(error.error, error.message, null);
}
}

View File

@@ -0,0 +1,68 @@
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes, CanActivate } from '@angular/router';
import { JhiPaginationUtil, JhiResolvePagingParams } from 'ng-jhipster';
import { AccountService, User, UserService } from 'app/core';
import { UserMgmtComponent } from './user-management.component';
import { UserMgmtDetailComponent } from './user-management-detail.component';
import { UserMgmtUpdateComponent } from './user-management-update.component';
@Injectable({ providedIn: 'root' })
export class UserResolve implements CanActivate {
constructor(private accountService: AccountService) {}
canActivate() {
return this.accountService.identity().then(account => this.accountService.hasAnyAuthority(['ROLE_ADMIN']));
}
}
@Injectable({ providedIn: 'root' })
export class UserMgmtResolve implements Resolve<any> {
constructor(private service: UserService) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const id = route.params['login'] ? route.params['login'] : null;
if (id) {
return this.service.find(id);
}
return new User();
}
}
export const userMgmtRoute: Routes = [
{
path: 'user-management',
component: UserMgmtComponent,
resolve: {
pagingParams: JhiResolvePagingParams
},
data: {
pageTitle: 'userManagement.home.title',
defaultSort: 'id,asc'
}
},
{
path: 'user-management/:login/view',
component: UserMgmtDetailComponent,
resolve: {
user: UserMgmtResolve
},
data: {
pageTitle: 'userManagement.home.title'
}
},
{
path: 'user-management/new',
component: UserMgmtUpdateComponent,
resolve: {
user: UserMgmtResolve
}
},
{
path: 'user-management/:login/edit',
component: UserMgmtUpdateComponent,
resolve: {
user: UserMgmtResolve
}
}
];