diff --git a/src/ui_ng/src/app/project/project.component.ts b/src/ui_ng/src/app/project/project.component.ts index 70e740276..fb32fce99 100644 --- a/src/ui_ng/src/app/project/project.component.ts +++ b/src/ui_ng/src/app/project/project.component.ts @@ -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(); } } \ No newline at end of file diff --git a/src/ui_ng/src/app/shared/gauge/gauge.component.ts b/src/ui_ng/src/app/shared/gauge/gauge.component.ts index cdde6616c..398c3e4e3 100644 --- a/src/ui_ng/src/app/shared/gauge/gauge.component.ts +++ b/src/ui_ng/src/app/shared/gauge/gauge.component.ts @@ -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; diff --git a/src/ui_ng/src/app/shared/shared.module.ts b/src/ui_ng/src/app/shared/shared.module.ts index b3806a7cc..f1804fff0 100644 --- a/src/ui_ng/src/app/shared/shared.module.ts +++ b/src/ui_ng/src/app/shared/shared.module.ts @@ -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 { diff --git a/src/ui_ng/src/app/shared/statictics/statistic-handler.service.ts b/src/ui_ng/src/app/shared/statictics/statistic-handler.service.ts new file mode 100644 index 000000000..f22bf64f8 --- /dev/null +++ b/src/ui_ng/src/app/shared/statictics/statistic-handler.service.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@angular/core'; +import { Subject } from 'rxjs/Subject'; + +@Injectable() +export class StatisticHandler { + + private refreshSource = new Subject(); + + refreshChan$ = this.refreshSource.asObservable(); + + refresh() { + this.refreshSource.next(true); + } +} \ No newline at end of file diff --git a/src/ui_ng/src/app/shared/statictics/statistics-panel.component.ts b/src/ui_ng/src/app/shared/statictics/statistics-panel.component.ts index c2cfe37dd..c428fc583 100644 --- a/src/ui_ng/src/app/shared/statictics/statistics-panel.component.ts +++ b/src/ui_ng/src/app/shared/statictics/statistics-panel.component.ts @@ -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); }