Merge pull request #8638 from jwangyangls/quota-color-yellow

Add the warning color in quota when used/hard >0.7
This commit is contained in:
jwangyangls 2019-08-14 12:28:38 +08:00 committed by GitHub
commit 679bab9f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 63 additions and 25 deletions

View File

@ -25,8 +25,8 @@
<span class="tooltip-content">{{'PROJECT.QUOTA_UNLIMIT_TIP' | translate }}</span> <span class="tooltip-content">{{'PROJECT.QUOTA_UNLIMIT_TIP' | translate }}</span>
</a> </a>
<div class="progress-block progress-min-width progress-div" *ngIf="!defaultTextsObj.isSystemDefaultQuota"> <div class="progress-block progress-min-width progress-div" *ngIf="!defaultTextsObj.isSystemDefaultQuota">
<div class="progress success" <div class="progress success" [class.warning]="isWarningColor(+quotaHardLimitValue.countLimit, quotaHardLimitValue.countUsed)"
[class.danger]="getDangerStyle(+quotaHardLimitValue.countLimit, quotaHardLimitValue.countUsed)"> [class.danger]="isDangerColor(+quotaHardLimitValue.countLimit, quotaHardLimitValue.countUsed)">
<progress value="{{countInput.invalid || +quotaHardLimitValue.countLimit===-1?0:quotaHardLimitValue.countUsed}}" <progress value="{{countInput.invalid || +quotaHardLimitValue.countLimit===-1?0:quotaHardLimitValue.countUsed}}"
max="{{countInput.invalid?100:quotaHardLimitValue.countLimit}}" data-displayval="100%"></progress> max="{{countInput.invalid?100:quotaHardLimitValue.countLimit}}" data-displayval="100%"></progress>
</div> </div>
@ -60,8 +60,9 @@
<span class="tooltip-content">{{'PROJECT.QUOTA_UNLIMIT_TIP' | translate }}</span> <span class="tooltip-content">{{'PROJECT.QUOTA_UNLIMIT_TIP' | translate }}</span>
</a> </a>
<div class="progress-block progress-min-width progress-div" *ngIf="!defaultTextsObj.isSystemDefaultQuota"> <div class="progress-block progress-min-width progress-div" *ngIf="!defaultTextsObj.isSystemDefaultQuota">
<div class="progress success" [class.danger]="getDangerStyle(+quotaHardLimitValue.storageLimit,quotaHardLimitValue.storageUsed, quotaHardLimitValue.storageUnit)"> <div class="progress success" [class.danger]="isDangerColor(+quotaHardLimitValue.storageLimit,quotaHardLimitValue.storageUsed, quotaHardLimitValue.storageUnit)"
<progress value="{{storageInput.invalid?0:quotaHardLimitValue.storageUsed}}" [class.warning]="isWarningColor(+quotaHardLimitValue.storageLimit,quotaHardLimitValue.storageUsed, quotaHardLimitValue.storageUnit)">
<progress value="{{storageInput.invalid || +quotaHardLimitValue.storageLimit === -1 ?0:quotaHardLimitValue.storageUsed}}"
max="{{storageInput.invalid?0:getByte(+quotaHardLimitValue.storageLimit, quotaHardLimitValue.storageUnit)}}" max="{{storageInput.invalid?0:getByte(+quotaHardLimitValue.storageLimit, quotaHardLimitValue.storageUnit)}}"
data-displayval="100%"></progress> data-displayval="100%"></progress>
</div> </div>

View File

@ -1,21 +1,25 @@
::ng-deep .modal-dialog { ::ng-deep .modal-dialog {
width: 25rem; width: 25rem;
} }
.modal-body { .modal-body {
padding-top: 0.8rem; padding-top: 0.8rem;
overflow-y: visible; overflow-y: visible;
overflow-x: visible; overflow-x: visible;
.clr-form-compact { .clr-form-compact {
div.form-group { div.form-group {
padding-left: 8.5rem; padding-left: 8.5rem;
.mr-3px { .mr-3px {
margin-right: 3px; margin-right: 3px;
} }
.quota-input { .quota-input {
width: 2rem; width: 2rem;
padding-right: 0.8rem; padding-right: 0.8rem;
} }
.select-div { .select-div {
width: 2.5rem; width: 2.5rem;
@ -51,6 +55,22 @@
width: 9rem; width: 9rem;
} }
::ng-deep {
.progress {
&.warning>progress {
color: orange;
&::-webkit-progress-value {
background-color: orange;
}
&::-moz-progress-bar {
background-color: orange;
}
}
}
}
.progress-label { .progress-label {
position: absolute; position: absolute;
right: -2.3rem; right: -2.3rem;

View File

@ -6,13 +6,10 @@ import {
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { NgForm, Validators } from '@angular/forms'; import { NgForm, Validators } from '@angular/forms';
import { ActivatedRoute } from "@angular/router";
import { TranslateService } from '@ngx-translate/core';
import { InlineAlertComponent } from '../../../inline-alert/inline-alert.component'; import { InlineAlertComponent } from '../../../inline-alert/inline-alert.component';
import { QuotaUnits, QuotaUnlimited } from "../../../shared/shared.const"; import { QuotaUnits, QuotaUnlimited, QUOTA_DANGER_COEFFICIENT, QUOTA_WARNING_COEFFICIENT } from "../../../shared/shared.const";
import { clone, getSuitableUnit, getByte, GetIntegerAndUnit, validateLimit } from '../../../utils'; import { clone, getSuitableUnit, getByte, GetIntegerAndUnit, validateLimit } from '../../../utils';
import { EditQuotaQuotaInterface, QuotaHardLimitInterface } from '../../../service'; import { EditQuotaQuotaInterface, QuotaHardLimitInterface } from '../../../service';
@ -47,9 +44,9 @@ export class EditProjectQuotasComponent implements OnInit {
@ViewChild('quotaForm') @ViewChild('quotaForm')
currentForm: NgForm; currentForm: NgForm;
@Output() confirmAction = new EventEmitter(); @Output() confirmAction = new EventEmitter();
constructor( quotaDangerCoefficient: number = QUOTA_DANGER_COEFFICIENT;
private translateService: TranslateService, quotaWarningCoefficient: number = QUOTA_WARNING_COEFFICIENT;
private route: ActivatedRoute) { } constructor() { }
ngOnInit() { ngOnInit() {
} }
@ -134,10 +131,18 @@ export class EditProjectQuotasComponent implements OnInit {
} }
return 0; return 0;
} }
getDangerStyle(limit: number | string, used: number | string, unit?: string) { isDangerColor(limit: number | string, used: number | string, unit?: string) {
if (unit) { if (unit) {
return limit !== QuotaUnlimited ? +used / getByte(+limit, unit) > 0.9 : false; return limit !== QuotaUnlimited ? +used / getByte(+limit, unit) >= this.quotaDangerCoefficient : false;
} }
return limit !== QuotaUnlimited ? +used / +limit > 0.9 : false; return limit !== QuotaUnlimited ? +used / +limit >= this.quotaDangerCoefficient : false;
}
isWarningColor(limit: number | string, used: number | string, unit?: string) {
if (unit) {
return limit !== QuotaUnlimited ?
+used / getByte(+limit, unit) >= this.quotaWarningCoefficient && +used / getByte(+limit, unit) <= this.quotaDangerCoefficient : false;
}
return limit !== QuotaUnlimited ?
+used / +limit >= this.quotaWarningCoefficient && +used / +limit <= this.quotaDangerCoefficient : false;
} }
} }

View File

@ -37,7 +37,9 @@
<clr-dg-cell> <clr-dg-cell>
<div class="progress-block progress-min-width"> <div class="progress-block progress-min-width">
<div class="progress success" <div class="progress success"
[class.danger]="quota.hard.count!==-1?quota.used.count/quota.hard.count>0.9:false"> [class.danger]="quota.hard.count!==-1?quota.used.count/quota.hard.count>quotaDangerCoefficient:false"
[class.warning]="quota.hard.count!==-1?quota.used.count/quota.hard.count<=quotaDangerCoefficient &&quota.used.count/quota.hard.count>=quotaWarningCoefficient:false"
>
<progress value="{{quota.hard.count===-1? 0 : quota.used.count}}" <progress value="{{quota.hard.count===-1? 0 : quota.used.count}}"
max="{{quota.hard.count}}" data-displayval="100%"></progress> max="{{quota.hard.count}}" data-displayval="100%"></progress>
</div> </div>
@ -48,7 +50,9 @@
<clr-dg-cell> <clr-dg-cell>
<div class="progress-block progress-min-width"> <div class="progress-block progress-min-width">
<div class="progress success" <div class="progress success"
[class.danger]="quota.hard.storage!==-1?quota.used.storage/quota.hard.storage>0.9:false"> [class.danger]="quota.hard.storage!==-1?quota.used.storage/quota.hard.storage>quotaDangerCoefficient:false"
[class.warning]="quota.hard.storage!==-1?quota.used.storage/quota.hard.storage>=quotaWarningCoefficient&&quota.used.storage/quota.hard.storage<=quotaDangerCoefficient:false"
>
<progress value="{{quota.hard.storage===-1? 0 : quota.used.storage}}" <progress value="{{quota.hard.storage===-1? 0 : quota.used.storage}}"
max="{{quota.hard.storage}}" data-displayval="100%"></progress> max="{{quota.hard.storage}}" data-displayval="100%"></progress>
</div> </div>

View File

@ -8,7 +8,7 @@ import {
, getByte, GetIntegerAndUnit , getByte, GetIntegerAndUnit
} from '../../utils'; } from '../../utils';
import { ErrorHandler } from '../../error-handler/index'; import { ErrorHandler } from '../../error-handler/index';
import { QuotaUnits, QuotaUnlimited } from '../../shared/shared.const'; import { QuotaUnits, QuotaUnlimited, QUOTA_DANGER_COEFFICIENT, QUOTA_WARNING_COEFFICIENT } from '../../shared/shared.const';
import { EditProjectQuotasComponent } from './edit-project-quotas/edit-project-quotas.component'; import { EditProjectQuotasComponent } from './edit-project-quotas/edit-project-quotas.component';
import { import {
ConfigurationService ConfigurationService
@ -46,6 +46,8 @@ export class ProjectQuotasComponent implements OnChanges {
currentPage = 1; currentPage = 1;
totalCount = 0; totalCount = 0;
pageSize = 15; pageSize = 15;
quotaDangerCoefficient: number = QUOTA_DANGER_COEFFICIENT;
quotaWarningCoefficient: number = QUOTA_WARNING_COEFFICIENT;
@Input() @Input()
get allConfig(): Configuration { get allConfig(): Configuration {
return this.config; return this.config;

View File

@ -122,6 +122,8 @@ export const CONFIG_AUTH_MODE = {
OIDC_AUTH: "oidc_auth", OIDC_AUTH: "oidc_auth",
UAA_AUTH: "uaa_auth" UAA_AUTH: "uaa_auth"
}; };
export const QUOTA_DANGER_COEFFICIENT = 0.9;
export const QUOTA_WARNING_COEFFICIENT = 0.7;
export const PROJECT_ROOTS = [ export const PROJECT_ROOTS = [
{ {
NAME: "admin", NAME: "admin",

View File

@ -35,7 +35,8 @@
<div> <div>
<div class="progress-block progress-min-width progress-div"> <div class="progress-block progress-min-width progress-div">
<div class="progress success" [class.danger]="summaryInformation?.quota?.hard?.count!==-1?summaryInformation?.quota?.used?.count/summaryInformation?.quota?.hard?.count>0.9:false"> <div class="progress success" [class.danger]="summaryInformation?.quota?.hard?.count!==-1?summaryInformation?.quota?.used?.count/summaryInformation?.quota?.hard?.count>quotaDangerCoefficient:false"
[class.warning]="summaryInformation?.quota?.hard?.count!==-1?summaryInformation?.quota?.used?.count/summaryInformation?.quota?.hard?.count<=quotaDangerCoefficient&&summaryInformation?.quota?.used?.count/summaryInformation?.quota?.hard?.count>=quotaWarningCoefficient:false">
<progress <progress
value="{{summaryInformation?.quota?.hard?.count===-1? 0 : summaryInformation?.quota?.used?.count}}" value="{{summaryInformation?.quota?.hard?.count===-1? 0 : summaryInformation?.quota?.used?.count}}"
max="{{summaryInformation?.quota?.hard?.count}}" data-displayval="100%"></progress> max="{{summaryInformation?.quota?.hard?.count}}" data-displayval="100%"></progress>
@ -58,7 +59,8 @@
<div> <div>
<div class="progress-block progress-min-width progress-div"> <div class="progress-block progress-min-width progress-div">
<div class="progress success" <div class="progress success"
[class.danger]="summaryInformation?.quota?.hard?.storage!==-1?summaryInformation?.quota?.used?.storage/summaryInformation?.quota?.hard?.storage>0.9:false"> [class.danger]="summaryInformation?.quota?.hard?.storage!==-1?summaryInformation?.quota?.used?.storage/summaryInformation?.quota?.hard?.storage>quotaDangerCoefficient:false"
[class.warning]="summaryInformation?.quota?.hard?.storage!==-1?summaryInformation?.quota?.used?.storage/summaryInformation?.quota?.hard?.storage<=quotaDangerCoefficient&&summaryInformation?.quota?.used?.storage/summaryInformation?.quota?.hard?.storage>=quotaWarningCoefficient:false">
<progress <progress
value="{{summaryInformation?.quota?.hard?.storage===-1? 0 : summaryInformation?.quota?.used?.storage}}" value="{{summaryInformation?.quota?.hard?.storage===-1? 0 : summaryInformation?.quota?.used?.storage}}"
max="{{summaryInformation?.quota?.hard?.storage}}" data-displayval="100%"></progress> max="{{summaryInformation?.quota?.hard?.storage}}" data-displayval="100%"></progress>

View File

@ -1,9 +1,9 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ProjectService, clone, QuotaUnits, getSuitableUnit, ErrorHandler, GetIntegerAndUnit } from '@harbor/ui'; import { ProjectService, clone, QuotaUnits, getSuitableUnit, ErrorHandler, GetIntegerAndUnit
import { Router, ActivatedRoute } from '@angular/router'; , QUOTA_DANGER_COEFFICIENT, QUOTA_WARNING_COEFFICIENT } from '@harbor/ui';
import { forkJoin } from 'rxjs'; import { ActivatedRoute } from '@angular/router';
import { AppConfigService } from "../../app-config.service"; import { AppConfigService } from "../../app-config.service";
export const riskRatio = 0.9;
@Component({ @Component({
selector: 'summary', selector: 'summary',
templateUrl: './summary.component.html', templateUrl: './summary.component.html',
@ -12,6 +12,8 @@ export const riskRatio = 0.9;
export class SummaryComponent implements OnInit { export class SummaryComponent implements OnInit {
projectId: number; projectId: number;
summaryInformation: any; summaryInformation: any;
quotaDangerCoefficient: number = QUOTA_DANGER_COEFFICIENT;
quotaWarningCoefficient: number = QUOTA_WARNING_COEFFICIENT;
constructor( constructor(
private projectService: ProjectService, private projectService: ProjectService,
private errorHandler: ErrorHandler, private errorHandler: ErrorHandler,