fix issue 1874: support metrics refresh

This commit is contained in:
Steven Zou 2017-04-01 17:37:00 +08:00
parent 05ac2a432c
commit 30c28f9d8d
5 changed files with 44 additions and 12 deletions

View File

@ -25,6 +25,7 @@ import { State } from 'clarity-angular';
import { AppConfigService } from '../app-config.service';
import { SessionService } from '../shared/session.service';
import { ProjectTypes } from '../shared/shared.const';
import { StatisticHandler } from '../shared/statictics/statistic-handler.service';
@Component({
selector: 'project',
@ -61,7 +62,8 @@ export class ProjectComponent implements OnInit, OnDestroy {
private messageHandlerService: MessageHandlerService,
private appConfigService: AppConfigService,
private sessionService: SessionService,
private deletionDialogService: ConfirmationDialogService) {
private deletionDialogService: ConfirmationDialogService,
private statisticHandler: StatisticHandler) {
this.subscription = deletionDialogService.confirmationConfirm$.subscribe(message => {
if (message &&
message.state === ConfirmationState.CONFIRMED &&
@ -72,8 +74,8 @@ export class ProjectComponent implements OnInit, OnDestroy {
.subscribe(
response => {
this.messageHandlerService.showSuccess('PROJECT.DELETED_SUCCESS');
console.log('Successful delete project with ID:' + projectId);
this.retrieve();
this.statisticHandler.refresh();
},
error =>{
if(error && error.status === 412) {
@ -123,7 +125,6 @@ export class ProjectComponent implements OnInit, OnDestroy {
response => {
this.totalRecordCount = response.headers.get('x-total-count');
this.totalPage = Math.ceil(this.totalRecordCount / this.pageSize);
console.log('TotalRecordCount:' + this.totalRecordCount + ', totalPage:' + this.totalPage);
this.changedProjects = response.json();
},
error => this.messageHandlerService.handleError(error)
@ -138,17 +139,16 @@ export class ProjectComponent implements OnInit, OnDestroy {
if (created) {
this.projectName = '';
this.retrieve();
this.statisticHandler.refresh();
}
}
doSearchProjects(projectName: string): void {
console.log('Search for project name:' + projectName);
this.projectName = projectName;
this.retrieve();
}
doFilterProjects(filteredType: number): void {
console.log('Filter projects with type:' + this.projectTypes[filteredType]);
this.isPublic = filteredType;
this.currentFilteredType = filteredType;
this.retrieve();
@ -162,7 +162,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
.subscribe(
response => {
this.messageHandlerService.showSuccess('PROJECT.TOGGLED_SUCCESS');
console.log('Successful toggled project_id:' + p.project_id);
this.statisticHandler.refresh();
},
error => this.messageHandlerService.handleError(error)
);
@ -182,6 +182,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
refresh(): void {
this.retrieve();
this.statisticHandler.refresh();
}
}

View File

@ -154,7 +154,6 @@ export class GaugeComponent implements AfterViewInit {
@ViewChild('barTwo') private barTwo: ElementRef;
private determineColors() {
console.info(this._used, this._threasHold);
let percent: number = 0;
if (this._threasHold !== 0) {
percent = (this._used / this._threasHold) * 100;

View File

@ -40,6 +40,7 @@ import { ListRepositoryROComponent } from './list-repository-ro/list-repository-
import { MessageHandlerService } from './message-handler/message-handler.service';
import { EmailValidatorDirective } from './email.directive';
import { GaugeComponent } from './gauge/gauge.component';
import { StatisticHandler } from './statictics/statistic-handler.service';
@NgModule({
imports: [
@ -97,7 +98,8 @@ import { GaugeComponent } from './gauge/gauge.component';
SignInGuard,
LeavingConfigRouteDeactivate,
MemberGuard,
MessageHandlerService
MessageHandlerService,
StatisticHandler
]
})
export class SharedModule {

View File

@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class StatisticHandler {
private refreshSource = new Subject<boolean>();
refreshChan$ = this.refreshSource.asObservable();
refresh() {
this.refreshSource.next(true);
}
}

View File

@ -1,4 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { StatisticsService } from './statistics.service';
import { Statistics } from './statistics';
@ -7,6 +8,7 @@ import { SessionService } from '../session.service';
import { Volumes } from './volumes';
import { MessageHandlerService } from '../message-handler/message-handler.service';
import { StatisticHandler } from './statistic-handler.service';
@Component({
selector: 'statistics-panel',
@ -15,26 +17,40 @@ import { MessageHandlerService } from '../message-handler/message-handler.servic
providers: [StatisticsService]
})
export class StatisticsPanelComponent implements OnInit {
export class StatisticsPanelComponent implements OnInit, OnDestroy {
private originalCopy: Statistics = new Statistics();
private volumesInfo: Volumes = new Volumes();
refreshSub: Subscription;
constructor(
private statistics: StatisticsService,
private msgHandler: MessageHandlerService,
private session: SessionService) { }
private session: SessionService,
private statisticHandler: StatisticHandler) {
}
ngOnInit(): void {
//Refresh
this.refreshSub = this.statisticHandler.refreshChan$.subscribe(clear => {
this.getStatistics();
});
if (this.session.getCurrentUser()) {
this.getStatistics();
}
if (this.isValidSession) {
this.getVolumes();
}
}
ngOnDestroy() {
if (this.refreshSub) {
this.refreshSub.unsubscribe();
}
}
public get totalStorage(): number {
return this.getGBFromBytes(this.volumesInfo.storage.total);
}