Commit 833658b4 authored by wangqinghua's avatar wangqinghua

优化速度

parent 2da166ae
......@@ -26,7 +26,6 @@ import {
} from './layouts';
import {AppComponent} from "./app.component";
import {RouterModule} from "@angular/router";
import {DEBUG_INFO_ENABLED} from "./app.constants";
import { route } from "./app.route";
import {LoginGuard} from "./shared/common/loginGuard";
import {AppMainModule} from './app.main.module';
......
import { ITEMS_PER_PAGE } from '../../shared';
import { Injectable } from '@angular/core';
import { NgbPaginationConfig} from '@ng-bootstrap/ng-bootstrap';
......@@ -8,7 +8,6 @@ export class PaginationConfig {
constructor(private config: NgbPaginationConfig) {
config.boundaryLinks = true;
config.maxSize = 5;
config.pageSize = ITEMS_PER_PAGE;
config.size = 'sm';
}
}
import { Component, OnInit } from '@angular/core';
import { ProfileService } from './profile.service';
import { ProfileInfo } from './profile-info.model';
@Component({
selector: 'jhi-page-ribbon',
template: ``,
styleUrls: [
'page-ribbon.css'
]
})
export class PageRibbonComponent implements OnInit {
profileInfo: ProfileInfo;
ribbonEnv: string;
constructor(private profileService: ProfileService) {}
ngOnInit() {
// this.profileService.getProfileInfo().then((profileInfo) => {
// this.profileInfo = profileInfo;
// this.ribbonEnv = profileInfo.ribbonEnv;
// });
}
}
/* ==========================================================================
Developement Ribbon
========================================================================== */
.ribbon {
background-color: rgba(170, 0, 0, 0.5);
left: -3.5em;
moz-transform: rotate(-45deg);
ms-transform: rotate(-45deg);
o-transform: rotate(-45deg);
webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
overflow: hidden;
position: absolute;
top: 40px;
white-space: nowrap;
width: 15em;
z-index: 9999;
pointer-events: none;
opacity: 0.75;
}
.ribbon a {
color: #fff;
display: block;
font-weight: 400;
margin: 1px 0;
padding: 10px 50px;
text-align: center;
text-decoration: none;
text-shadow: 0 0 5px #444;
pointer-events: none;
}
export class ProfileInfo {
activeProfiles: string[];
ribbonEnv: string;
inProduction: boolean;
swaggerEnabled: boolean;
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { SERVER_API_URL } from '../../app.constants';
import { ProfileInfo } from './profile-info.model';
@Injectable()
export class ProfileService {
private profileInfoUrl = SERVER_API_URL + 'api/profile-info';
private profileInfo: Promise<ProfileInfo>;
constructor(private http: HttpClient) { }
getProfileInfo(): Promise<ProfileInfo> {
if (!this.profileInfo) {
this.profileInfo = this.http.get<ProfileInfo>(this.profileInfoUrl, { observe: 'response' })
.map((res: HttpResponse<ProfileInfo>) => {
const data = res.body;
const pi = new ProfileInfo();
pi.activeProfiles = data.activeProfiles;
pi.ribbonEnv = data.ribbonEnv;
pi.inProduction = data.activeProfiles.includes('prod') ;
pi.swaggerEnabled = data.activeProfiles.includes('swagger');
return pi;
}).toPromise();
}
return this.profileInfo;
}
}
import { Component, OnDestroy } from '@angular/core';
import { JhiEventManager, JhiAlertService } from 'ng-jhipster';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'jhi-alert-error',
template: `
<div class="alerts" role="alert">
<div *ngFor="let alert of alerts" [ngClass]="{\'alert.position\': true, \'toast\': alert.toast}">
<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-next-line: no-unused-variable
constructor(private alertService: JhiAlertService, private eventManager: JhiEventManager) {
this.alerts = [];
this.cleanHttpErrorListener = eventManager.subscribe('bootappApp.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.endsWith('app-error')) {
errorHeader = httpErrorResponse.headers.get(entry);
} else if (entry.endsWith('app-params')) {
entityKey = httpErrorResponse.headers.get(entry);
}
});
if (errorHeader) {
const entityName = 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];
// 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 = convertedField.charAt(0).toUpperCase() +
convertedField.slice(1);
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);
}
}
});
}
ngOnDestroy() {
if (this.cleanHttpErrorListener !== undefined && this.cleanHttpErrorListener !== null) {
this.eventManager.destroy(this.cleanHttpErrorListener);
this.alerts = [];
}
}
addErrorAlert(message, key?, data?) {
this.alerts.push(
this.alertService.addAlert(
{
type: 'danger',
msg: message,
timeout: 5000,
toast: this.alertService.isToast(),
scoped: true
},
this.alerts
)
);
}
}
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]="{\'alert.position\': true, \'toast\': alert.toast}">
<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();
}
ngOnDestroy() {
this.alerts = [];
}
}
export const PROBLEM_BASE_URL = '';
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';
export * from './constants/error.constants';
export * from './constants/pagination.constants';
export * from './alert/alert.component';
export * from './alert/alert-error.component';
export * from './auth/csrf.service';
export * from './auth/state-storage.service';
export * from './auth/account.service';
......@@ -11,11 +7,6 @@ export * from './auth/has-any-authority.directive';
export * from './auth/user-route-access-service';
export * from './login/login.component';
export * from './login/login.service';
export * from './user/account.model';
export * from './user/user.model';
export * from './user/user.service';
export * from './model/request-util';
export * from './model/base-entity';
export * from './shared-libs.module';
export * from './shared-common.module';
export * from './shared.module';
export interface BaseEntity {
// using type any to avoid methods complaining of invalid type
id?: any;
}
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;
};
export class Account {
constructor(
public activated: boolean,
public authorities: string[],
public email: string,
public firstName: string,
public langKey: string,
public lastName: string,
public login: string,
public imageUrl: string
) { }
}
export class User {
public id?: any;
public login?: string;
public firstName?: string;
public lastName?: string;
public email?: string;
public activated?: Boolean;
public langKey?: string;
public authorities?: any[];
public createdBy?: string;
public createdDate?: Date;
public lastModifiedBy?: string;
public lastModifiedDate?: Date;
public password?: string;
constructor(
id?: any,
login?: string,
firstName?: string,
lastName?: string,
email?: string,
activated?: Boolean,
langKey?: string,
authorities?: any[],
createdBy?: string,
createdDate?: Date,
lastModifiedBy?: string,
lastModifiedDate?: Date,
password?: string
) {
this.id = id ? id : null;
this.login = login ? login : null;
this.firstName = firstName ? firstName : null;
this.lastName = lastName ? lastName : null;
this.email = email ? email : null;
this.activated = activated ? activated : false;
this.langKey = langKey ? langKey : null;
this.authorities = authorities ? authorities : null;
this.createdBy = createdBy ? createdBy : null;
this.createdDate = createdDate ? createdDate : null;
this.lastModifiedBy = lastModifiedBy ? lastModifiedBy : null;
this.lastModifiedDate = lastModifiedDate ? lastModifiedDate : null;
this.password = password ? password : null;
}
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';
import { User } from './user.model';
import { createRequestOption } from '../model/request-util';
@Injectable()
export class UserService {
private resourceUrl = SERVER_API_URL + 'api/users';
constructor(private http: HttpClient) { }
create(user: User): Observable<HttpResponse<User>> {
return this.http.post<User>(this.resourceUrl, user, { observe: 'response' });
}
update(user: User): Observable<HttpResponse<User>> {
return this.http.put<User>(this.resourceUrl, user, { observe: 'response' });
}
find(login: string): Observable<HttpResponse<User>> {
return this.http.get<User>(`${this.resourceUrl}/${login}`, { observe: 'response' });
}
query(req?: any): Observable<HttpResponse<User[]>> {
const options = createRequestOption(req);
return this.http.get<User[]>(this.resourceUrl, { params: options, observe: 'response' });
}
delete(login: string): Observable<HttpResponse<any>> {
return this.http.delete(`${this.resourceUrl}/${login}`, { observe: 'response' });
}
authorities(): Observable<string[]> {
return this.http.get<string[]>(SERVER_API_URL + 'api/users/authorities');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment