Merge pull request #23 from steven-zou/fix/issue_1874

fix issue 1874: support metrics refresh
This commit is contained in:
Steven Zou 2017-04-01 17:37:55 +08:00 committed by GitHub
commit 403f4da994
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 { AppConfigService } from '../app-config.service';
import { SessionService } from '../shared/session.service'; import { SessionService } from '../shared/session.service';
import { ProjectTypes } from '../shared/shared.const'; import { ProjectTypes } from '../shared/shared.const';
import { StatisticHandler } from '../shared/statictics/statistic-handler.service';
@Component({ @Component({
selector: 'project', selector: 'project',
@ -61,7 +62,8 @@ export class ProjectComponent implements OnInit, OnDestroy {
private messageHandlerService: MessageHandlerService, private messageHandlerService: MessageHandlerService,
private appConfigService: AppConfigService, private appConfigService: AppConfigService,
private sessionService: SessionService, private sessionService: SessionService,
private deletionDialogService: ConfirmationDialogService) { private deletionDialogService: ConfirmationDialogService,
private statisticHandler: StatisticHandler) {
this.subscription = deletionDialogService.confirmationConfirm$.subscribe(message => { this.subscription = deletionDialogService.confirmationConfirm$.subscribe(message => {
if (message && if (message &&
message.state === ConfirmationState.CONFIRMED && message.state === ConfirmationState.CONFIRMED &&
@ -72,8 +74,8 @@ export class ProjectComponent implements OnInit, OnDestroy {
.subscribe( .subscribe(
response => { response => {
this.messageHandlerService.showSuccess('PROJECT.DELETED_SUCCESS'); this.messageHandlerService.showSuccess('PROJECT.DELETED_SUCCESS');
console.log('Successful delete project with ID:' + projectId);
this.retrieve(); this.retrieve();
this.statisticHandler.refresh();
}, },
error =>{ error =>{
if(error && error.status === 412) { if(error && error.status === 412) {
@ -123,7 +125,6 @@ export class ProjectComponent implements OnInit, OnDestroy {
response => { response => {
this.totalRecordCount = response.headers.get('x-total-count'); this.totalRecordCount = response.headers.get('x-total-count');
this.totalPage = Math.ceil(this.totalRecordCount / this.pageSize); this.totalPage = Math.ceil(this.totalRecordCount / this.pageSize);
console.log('TotalRecordCount:' + this.totalRecordCount + ', totalPage:' + this.totalPage);
this.changedProjects = response.json(); this.changedProjects = response.json();
}, },
error => this.messageHandlerService.handleError(error) error => this.messageHandlerService.handleError(error)
@ -138,17 +139,16 @@ export class ProjectComponent implements OnInit, OnDestroy {
if (created) { if (created) {
this.projectName = ''; this.projectName = '';
this.retrieve(); this.retrieve();
this.statisticHandler.refresh();
} }
} }
doSearchProjects(projectName: string): void { doSearchProjects(projectName: string): void {
console.log('Search for project name:' + projectName);
this.projectName = projectName; this.projectName = projectName;
this.retrieve(); this.retrieve();
} }
doFilterProjects(filteredType: number): void { doFilterProjects(filteredType: number): void {
console.log('Filter projects with type:' + this.projectTypes[filteredType]);
this.isPublic = filteredType; this.isPublic = filteredType;
this.currentFilteredType = filteredType; this.currentFilteredType = filteredType;
this.retrieve(); this.retrieve();
@ -162,7 +162,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
.subscribe( .subscribe(
response => { response => {
this.messageHandlerService.showSuccess('PROJECT.TOGGLED_SUCCESS'); this.messageHandlerService.showSuccess('PROJECT.TOGGLED_SUCCESS');
console.log('Successful toggled project_id:' + p.project_id); this.statisticHandler.refresh();
}, },
error => this.messageHandlerService.handleError(error) error => this.messageHandlerService.handleError(error)
); );
@ -182,6 +182,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
refresh(): void { refresh(): void {
this.retrieve(); this.retrieve();
this.statisticHandler.refresh();
} }
} }

View File

@ -154,7 +154,6 @@ export class GaugeComponent implements AfterViewInit {
@ViewChild('barTwo') private barTwo: ElementRef; @ViewChild('barTwo') private barTwo: ElementRef;
private determineColors() { private determineColors() {
console.info(this._used, this._threasHold);
let percent: number = 0; let percent: number = 0;
if (this._threasHold !== 0) { if (this._threasHold !== 0) {
percent = (this._used / this._threasHold) * 100; 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 { MessageHandlerService } from './message-handler/message-handler.service';
import { EmailValidatorDirective } from './email.directive'; import { EmailValidatorDirective } from './email.directive';
import { GaugeComponent } from './gauge/gauge.component'; import { GaugeComponent } from './gauge/gauge.component';
import { StatisticHandler } from './statictics/statistic-handler.service';
@NgModule({ @NgModule({
imports: [ imports: [
@ -97,7 +98,8 @@ import { GaugeComponent } from './gauge/gauge.component';
SignInGuard, SignInGuard,
LeavingConfigRouteDeactivate, LeavingConfigRouteDeactivate,
MemberGuard, MemberGuard,
MessageHandlerService MessageHandlerService,
StatisticHandler
] ]
}) })
export class SharedModule { 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 { StatisticsService } from './statistics.service';
import { Statistics } from './statistics'; import { Statistics } from './statistics';
@ -7,6 +8,7 @@ import { SessionService } from '../session.service';
import { Volumes } from './volumes'; import { Volumes } from './volumes';
import { MessageHandlerService } from '../message-handler/message-handler.service'; import { MessageHandlerService } from '../message-handler/message-handler.service';
import { StatisticHandler } from './statistic-handler.service';
@Component({ @Component({
selector: 'statistics-panel', selector: 'statistics-panel',
@ -15,26 +17,40 @@ import { MessageHandlerService } from '../message-handler/message-handler.servic
providers: [StatisticsService] providers: [StatisticsService]
}) })
export class StatisticsPanelComponent implements OnInit { export class StatisticsPanelComponent implements OnInit, OnDestroy {
private originalCopy: Statistics = new Statistics(); private originalCopy: Statistics = new Statistics();
private volumesInfo: Volumes = new Volumes(); private volumesInfo: Volumes = new Volumes();
refreshSub: Subscription;
constructor( constructor(
private statistics: StatisticsService, private statistics: StatisticsService,
private msgHandler: MessageHandlerService, private msgHandler: MessageHandlerService,
private session: SessionService) { } private session: SessionService,
private statisticHandler: StatisticHandler) {
}
ngOnInit(): void { ngOnInit(): void {
//Refresh
this.refreshSub = this.statisticHandler.refreshChan$.subscribe(clear => {
this.getStatistics();
});
if (this.session.getCurrentUser()) { if (this.session.getCurrentUser()) {
this.getStatistics(); this.getStatistics();
} }
if (this.isValidSession) { if (this.isValidSession) {
this.getVolumes(); this.getVolumes();
} }
} }
ngOnDestroy() {
if (this.refreshSub) {
this.refreshSub.unsubscribe();
}
}
public get totalStorage(): number { public get totalStorage(): number {
return this.getGBFromBytes(this.volumesInfo.storage.total); return this.getGBFromBytes(this.volumesInfo.storage.total);
} }