mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
Merge pull request #23 from steven-zou/fix/issue_1874
fix issue 1874: support metrics refresh
This commit is contained in:
commit
403f4da994
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user