Initial application generated by JHipster-5.8.2
This commit is contained in:
114
src/main/webapp/app/shared/alert/alert-error.component.ts
Normal file
114
src/main/webapp/app/shared/alert/alert-error.component.ts
Normal file
@ -0,0 +1,114 @@
|
||||
import { Component, OnDestroy } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { JhiEventManager, JhiAlert, JhiAlertService } from 'ng-jhipster';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-alert-error',
|
||||
template: `
|
||||
<div class="alerts" role="alert">
|
||||
<div *ngFor="let alert of alerts" [ngClass]="setClasses(alert)">
|
||||
<ngb-alert *ngIf="alert && alert.type && alert.msg" [type]="alert.type" (close)="alert.close(alerts)">
|
||||
<pre [innerHTML]="alert.msg"></pre>
|
||||
</ngb-alert>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class JhiAlertErrorComponent implements OnDestroy {
|
||||
alerts: any[];
|
||||
cleanHttpErrorListener: Subscription;
|
||||
/* tslint:disable */
|
||||
constructor(private alertService: JhiAlertService, private eventManager: JhiEventManager, private translateService: TranslateService) {
|
||||
/* tslint:enable */
|
||||
this.alerts = [];
|
||||
|
||||
this.cleanHttpErrorListener = eventManager.subscribe('hsadminNgApp.httpError', response => {
|
||||
let i;
|
||||
const httpErrorResponse = response.content;
|
||||
switch (httpErrorResponse.status) {
|
||||
// connection refused, server not reachable
|
||||
case 0:
|
||||
this.addErrorAlert('Server not reachable', 'error.server.not.reachable');
|
||||
break;
|
||||
|
||||
case 400:
|
||||
const arr = httpErrorResponse.headers.keys();
|
||||
let errorHeader = null;
|
||||
let entityKey = null;
|
||||
arr.forEach(entry => {
|
||||
if (entry.toLowerCase().endsWith('app-error')) {
|
||||
errorHeader = httpErrorResponse.headers.get(entry);
|
||||
} else if (entry.toLowerCase().endsWith('app-params')) {
|
||||
entityKey = httpErrorResponse.headers.get(entry);
|
||||
}
|
||||
});
|
||||
if (errorHeader) {
|
||||
const entityName = translateService.instant('global.menu.entities.' + entityKey);
|
||||
this.addErrorAlert(errorHeader, errorHeader, { entityName });
|
||||
} else if (httpErrorResponse.error !== '' && httpErrorResponse.error.fieldErrors) {
|
||||
const fieldErrors = httpErrorResponse.error.fieldErrors;
|
||||
for (i = 0; i < fieldErrors.length; i++) {
|
||||
const fieldError = fieldErrors[i];
|
||||
if (['Min', 'Max', 'DecimalMin', 'DecimalMax'].includes(fieldError.message)) {
|
||||
fieldError.message = 'Size';
|
||||
}
|
||||
// convert 'something[14].other[4].id' to 'something[].other[].id' so translations can be written to it
|
||||
const convertedField = fieldError.field.replace(/\[\d*\]/g, '[]');
|
||||
const fieldName = translateService.instant('hsadminNgApp.' + fieldError.objectName + '.' + convertedField);
|
||||
this.addErrorAlert('Error on field "' + fieldName + '"', 'error.' + fieldError.message, { fieldName });
|
||||
}
|
||||
} else if (httpErrorResponse.error !== '' && httpErrorResponse.error.message) {
|
||||
this.addErrorAlert(
|
||||
httpErrorResponse.error.message,
|
||||
httpErrorResponse.error.message,
|
||||
httpErrorResponse.error.params
|
||||
);
|
||||
} else {
|
||||
this.addErrorAlert(httpErrorResponse.error);
|
||||
}
|
||||
break;
|
||||
|
||||
case 404:
|
||||
this.addErrorAlert('Not found', 'error.url.not.found');
|
||||
break;
|
||||
|
||||
default:
|
||||
if (httpErrorResponse.error !== '' && httpErrorResponse.error.message) {
|
||||
this.addErrorAlert(httpErrorResponse.error.message);
|
||||
} else {
|
||||
this.addErrorAlert(httpErrorResponse.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setClasses(alert) {
|
||||
return {
|
||||
toast: !!alert.toast,
|
||||
[alert.position]: true
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.cleanHttpErrorListener !== undefined && this.cleanHttpErrorListener !== null) {
|
||||
this.eventManager.destroy(this.cleanHttpErrorListener);
|
||||
this.alerts = [];
|
||||
}
|
||||
}
|
||||
|
||||
addErrorAlert(message, key?, data?) {
|
||||
message = key && key !== null ? key : message;
|
||||
|
||||
const newAlert: JhiAlert = {
|
||||
type: 'danger',
|
||||
msg: message,
|
||||
params: data,
|
||||
timeout: 5000,
|
||||
toast: this.alertService.isToast(),
|
||||
scoped: true
|
||||
};
|
||||
|
||||
this.alerts.push(this.alertService.addAlert(newAlert, this.alerts));
|
||||
}
|
||||
}
|
35
src/main/webapp/app/shared/alert/alert.component.ts
Normal file
35
src/main/webapp/app/shared/alert/alert.component.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { JhiAlertService } from 'ng-jhipster';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-alert',
|
||||
template: `
|
||||
<div class="alerts" role="alert">
|
||||
<div *ngFor="let alert of alerts" [ngClass]="setClasses(alert)">
|
||||
<ngb-alert *ngIf="alert && alert.type && alert.msg" [type]="alert.type" (close)="alert.close(alerts)">
|
||||
<pre [innerHTML]="alert.msg"></pre>
|
||||
</ngb-alert>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class JhiAlertComponent implements OnInit, OnDestroy {
|
||||
alerts: any[];
|
||||
|
||||
constructor(private alertService: JhiAlertService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.alerts = this.alertService.get();
|
||||
}
|
||||
|
||||
setClasses(alert) {
|
||||
return {
|
||||
toast: !!alert.toast,
|
||||
[alert.position]: true
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.alerts = [];
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
|
||||
import { AccountService } from 'app/core/auth/account.service';
|
||||
|
||||
/**
|
||||
* @whatItDoes Conditionally includes an HTML element if current user has any
|
||||
* of the authorities passed as the `expression`.
|
||||
*
|
||||
* @howToUse
|
||||
* ```
|
||||
* <some-element *jhiHasAnyAuthority="'ROLE_ADMIN'">...</some-element>
|
||||
*
|
||||
* <some-element *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_USER']">...</some-element>
|
||||
* ```
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[jhiHasAnyAuthority]'
|
||||
})
|
||||
export class HasAnyAuthorityDirective {
|
||||
private authorities: string[];
|
||||
|
||||
constructor(
|
||||
private accountService: AccountService,
|
||||
private templateRef: TemplateRef<any>,
|
||||
private viewContainerRef: ViewContainerRef
|
||||
) {}
|
||||
|
||||
@Input()
|
||||
set jhiHasAnyAuthority(value: string | string[]) {
|
||||
this.authorities = typeof value === 'string' ? [value] : value;
|
||||
this.updateView();
|
||||
// Get notified each time authentication state changes.
|
||||
this.accountService.getAuthenticationState().subscribe(identity => this.updateView());
|
||||
}
|
||||
|
||||
private updateView(): void {
|
||||
const hasAnyAuthority = this.accountService.hasAnyAuthority(this.authorities);
|
||||
this.viewContainerRef.clear();
|
||||
if (hasAnyAuthority) {
|
||||
this.viewContainerRef.createEmbeddedView(this.templateRef);
|
||||
}
|
||||
}
|
||||
}
|
4
src/main/webapp/app/shared/constants/error.constants.ts
Normal file
4
src/main/webapp/app/shared/constants/error.constants.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const PROBLEM_BASE_URL = 'https://www.jhipster.tech/problem';
|
||||
export const EMAIL_ALREADY_USED_TYPE = PROBLEM_BASE_URL + '/email-already-used';
|
||||
export const LOGIN_ALREADY_USED_TYPE = PROBLEM_BASE_URL + '/login-already-used';
|
||||
export const EMAIL_NOT_FOUND_TYPE = PROBLEM_BASE_URL + '/email-not-found';
|
2
src/main/webapp/app/shared/constants/input.constants.ts
Normal file
2
src/main/webapp/app/shared/constants/input.constants.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const DATE_FORMAT = 'YYYY-MM-DD';
|
||||
export const DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm';
|
@ -0,0 +1 @@
|
||||
export const ITEMS_PER_PAGE = 20;
|
13
src/main/webapp/app/shared/index.ts
Normal file
13
src/main/webapp/app/shared/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export * from './constants/error.constants';
|
||||
export * from './constants/pagination.constants';
|
||||
export * from './constants/input.constants';
|
||||
export * from './alert/alert.component';
|
||||
export * from './alert/alert-error.component';
|
||||
export * from './auth/has-any-authority.directive';
|
||||
export * from './language/find-language-from-key.pipe';
|
||||
export * from './login/login.component';
|
||||
export * from './util/request-util';
|
||||
export * from './shared-libs.module';
|
||||
export * from './shared-common.module';
|
||||
export * from './shared.module';
|
||||
export * from './util/datepicker-adapter';
|
@ -0,0 +1,13 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({ name: 'findLanguageFromKey' })
|
||||
export class FindLanguageFromKeyPipe implements PipeTransform {
|
||||
private languages: any = {
|
||||
en: { name: 'English' },
|
||||
de: { name: 'Deutsch' }
|
||||
// jhipster-needle-i18n-language-key-pipe - JHipster will add/remove languages in this object
|
||||
};
|
||||
transform(lang: string): string {
|
||||
return this.languages[lang].name;
|
||||
}
|
||||
}
|
43
src/main/webapp/app/shared/login/login.component.html
Normal file
43
src/main/webapp/app/shared/login/login.component.html
Normal file
@ -0,0 +1,43 @@
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" jhiTranslate="login.title">Sign in</h4>
|
||||
<button aria-label="Close" data-dismiss="modal" class="close" type="button" (click)="activeModal.dismiss('closed')"><span aria-hidden="true">x</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="alert alert-danger" *ngIf="authenticationError" jhiTranslate="login.messages.error.authentication">
|
||||
<strong>Failed to sign in!</strong> Please check your credentials and try again.
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<form class="form" role="form" (ngSubmit)="login()">
|
||||
<div class="form-group">
|
||||
<label class="username-label" for="username" jhiTranslate="global.form.username">Login</label>
|
||||
<input type="text" class="form-control" name="username" id="username" placeholder="{{'global.form.username.placeholder' | translate}}"
|
||||
[(ngModel)]="username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password" jhiTranslate="login.form.password">Password</label>
|
||||
<input type="password" class="form-control" name="password" id="password" placeholder="{{'login.form.password.placeholder' | translate}}"
|
||||
[(ngModel)]="password">
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<label class="form-check-label" for="rememberMe">
|
||||
<input class="form-check-input" type="checkbox" name="rememberMe" id="rememberMe" [(ngModel)]="rememberMe" checked>
|
||||
<span jhiTranslate="login.form.rememberme">Remember me</span>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" jhiTranslate="login.form.button">Sign in</button>
|
||||
</form>
|
||||
<p></p>
|
||||
<div class="alert alert-warning">
|
||||
<a class="alert-link" (click)="requestResetPassword()" jhiTranslate="login.password.forgot">Did you forget your password?</a>
|
||||
</div>
|
||||
<div class="alert alert-warning">
|
||||
<span jhiTranslate="global.messages.info.register.noaccount">You don't have an account yet?</span>
|
||||
<a class="alert-link" (click)="register()" jhiTranslate="global.messages.info.register.link">Register a new account</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
87
src/main/webapp/app/shared/login/login.component.ts
Normal file
87
src/main/webapp/app/shared/login/login.component.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import { Component, AfterViewInit, Renderer, ElementRef } from '@angular/core';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { JhiEventManager } from 'ng-jhipster';
|
||||
|
||||
import { LoginService } from 'app/core/login/login.service';
|
||||
import { StateStorageService } from 'app/core/auth/state-storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-login-modal',
|
||||
templateUrl: './login.component.html'
|
||||
})
|
||||
export class JhiLoginModalComponent implements AfterViewInit {
|
||||
authenticationError: boolean;
|
||||
password: string;
|
||||
rememberMe: boolean;
|
||||
username: string;
|
||||
credentials: any;
|
||||
|
||||
constructor(
|
||||
private eventManager: JhiEventManager,
|
||||
private loginService: LoginService,
|
||||
private stateStorageService: StateStorageService,
|
||||
private elementRef: ElementRef,
|
||||
private renderer: Renderer,
|
||||
private router: Router,
|
||||
public activeModal: NgbActiveModal
|
||||
) {
|
||||
this.credentials = {};
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => this.renderer.invokeElementMethod(this.elementRef.nativeElement.querySelector('#username'), 'focus', []), 0);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.credentials = {
|
||||
username: null,
|
||||
password: null,
|
||||
rememberMe: true
|
||||
};
|
||||
this.authenticationError = false;
|
||||
this.activeModal.dismiss('cancel');
|
||||
}
|
||||
|
||||
login() {
|
||||
this.loginService
|
||||
.login({
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
rememberMe: this.rememberMe
|
||||
})
|
||||
.then(() => {
|
||||
this.authenticationError = false;
|
||||
this.activeModal.dismiss('login success');
|
||||
if (this.router.url === '/register' || /^\/activate\//.test(this.router.url) || /^\/reset\//.test(this.router.url)) {
|
||||
this.router.navigate(['']);
|
||||
}
|
||||
|
||||
this.eventManager.broadcast({
|
||||
name: 'authenticationSuccess',
|
||||
content: 'Sending Authentication Success'
|
||||
});
|
||||
|
||||
// previousState was set in the authExpiredInterceptor before being redirected to login modal.
|
||||
// since login is successful, go to stored previousState and clear previousState
|
||||
const redirect = this.stateStorageService.getUrl();
|
||||
if (redirect) {
|
||||
this.stateStorageService.storeUrl(null);
|
||||
this.router.navigate([redirect]);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.authenticationError = true;
|
||||
});
|
||||
}
|
||||
|
||||
register() {
|
||||
this.activeModal.dismiss('to state register');
|
||||
this.router.navigate(['/register']);
|
||||
}
|
||||
|
||||
requestResetPassword() {
|
||||
this.activeModal.dismiss('to state requestReset');
|
||||
this.router.navigate(['/reset', 'request']);
|
||||
}
|
||||
}
|
10
src/main/webapp/app/shared/shared-common.module.ts
Normal file
10
src/main/webapp/app/shared/shared-common.module.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { HsadminNgSharedLibsModule, FindLanguageFromKeyPipe, JhiAlertComponent, JhiAlertErrorComponent } from './';
|
||||
|
||||
@NgModule({
|
||||
imports: [HsadminNgSharedLibsModule],
|
||||
declarations: [FindLanguageFromKeyPipe, JhiAlertComponent, JhiAlertErrorComponent],
|
||||
exports: [HsadminNgSharedLibsModule, FindLanguageFromKeyPipe, JhiAlertComponent, JhiAlertErrorComponent]
|
||||
})
|
||||
export class HsadminNgSharedCommonModule {}
|
20
src/main/webapp/app/shared/shared-libs.module.ts
Normal file
20
src/main/webapp/app/shared/shared-libs.module.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { NgJhipsterModule } from 'ng-jhipster';
|
||||
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
|
||||
import { CookieModule } from 'ngx-cookie';
|
||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
|
||||
@NgModule({
|
||||
imports: [NgbModule.forRoot(), InfiniteScrollModule, CookieModule.forRoot(), FontAwesomeModule],
|
||||
exports: [FormsModule, CommonModule, NgbModule, NgJhipsterModule, InfiniteScrollModule, FontAwesomeModule]
|
||||
})
|
||||
export class HsadminNgSharedLibsModule {
|
||||
static forRoot() {
|
||||
return {
|
||||
ngModule: HsadminNgSharedLibsModule
|
||||
};
|
||||
}
|
||||
}
|
21
src/main/webapp/app/shared/shared.module.ts
Normal file
21
src/main/webapp/app/shared/shared.module.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { NgbDateAdapter } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { NgbDateMomentAdapter } from './util/datepicker-adapter';
|
||||
import { HsadminNgSharedLibsModule, HsadminNgSharedCommonModule, JhiLoginModalComponent, HasAnyAuthorityDirective } from './';
|
||||
|
||||
@NgModule({
|
||||
imports: [HsadminNgSharedLibsModule, HsadminNgSharedCommonModule],
|
||||
declarations: [JhiLoginModalComponent, HasAnyAuthorityDirective],
|
||||
providers: [{ provide: NgbDateAdapter, useClass: NgbDateMomentAdapter }],
|
||||
entryComponents: [JhiLoginModalComponent],
|
||||
exports: [HsadminNgSharedCommonModule, JhiLoginModalComponent, HasAnyAuthorityDirective],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
export class HsadminNgSharedModule {
|
||||
static forRoot() {
|
||||
return {
|
||||
ngModule: HsadminNgSharedModule
|
||||
};
|
||||
}
|
||||
}
|
21
src/main/webapp/app/shared/util/datepicker-adapter.ts
Normal file
21
src/main/webapp/app/shared/util/datepicker-adapter.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Angular bootstrap Date adapter
|
||||
*/
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Moment } from 'moment';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class NgbDateMomentAdapter extends NgbDateAdapter<Moment> {
|
||||
fromModel(date: Moment): NgbDateStruct {
|
||||
if (date != null && moment.isMoment(date) && date.isValid()) {
|
||||
return { year: date.year(), month: date.month() + 1, day: date.date() };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
toModel(date: NgbDateStruct): Moment {
|
||||
return date ? moment(date.year + '-' + date.month + '-' + date.day, 'YYYY-MM-DD') : null;
|
||||
}
|
||||
}
|
18
src/main/webapp/app/shared/util/request-util.ts
Normal file
18
src/main/webapp/app/shared/util/request-util.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
|
||||
export const createRequestOption = (req?: any): HttpParams => {
|
||||
let options: HttpParams = new HttpParams();
|
||||
if (req) {
|
||||
Object.keys(req).forEach(key => {
|
||||
if (key !== 'sort') {
|
||||
options = options.set(key, req[key]);
|
||||
}
|
||||
});
|
||||
if (req.sort) {
|
||||
req.sort.forEach(val => {
|
||||
options = options.append('sort', val);
|
||||
});
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
Reference in New Issue
Block a user