Initial application generated by JHipster-5.8.2
This commit is contained in:
3
src/main/webapp/app/admin/audits/audit-data.model.ts
Normal file
3
src/main/webapp/app/admin/audits/audit-data.model.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export class AuditData {
|
||||
constructor(public remoteAddress: string, public sessionId: string) {}
|
||||
}
|
5
src/main/webapp/app/admin/audits/audit.model.ts
Normal file
5
src/main/webapp/app/admin/audits/audit.model.ts
Normal 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) {}
|
||||
}
|
52
src/main/webapp/app/admin/audits/audits.component.html
Normal file
52
src/main/webapp/app/admin/audits/audits.component.html
Normal 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>
|
126
src/main/webapp/app/admin/audits/audits.component.ts
Normal file
126
src/main/webapp/app/admin/audits/audits.component.ts
Normal 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);
|
||||
}
|
||||
}
|
17
src/main/webapp/app/admin/audits/audits.route.ts
Normal file
17
src/main/webapp/app/admin/audits/audits.route.ts
Normal 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'
|
||||
}
|
||||
};
|
25
src/main/webapp/app/admin/audits/audits.service.ts
Normal file
25
src/main/webapp/app/admin/audits/audits.service.ts
Normal 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'
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user