Commit 7e766364 authored by AllForNothing's avatar AllForNothing
Browse files

Improve p2p-preheat ui


Signed-off-by: default avatarAllForNothing <sshijun@vmware.com>
parent 3445608e
......@@ -50,7 +50,7 @@ export class AddP2pPolicyComponent implements OnInit {
repos: string;
tags: string;
onlySignedImages: boolean = false;
severity: number = 0;
severity: number;
labels: string;
triggerType: string = TRIGGER.MANUAL;
cron: string ;
......@@ -96,7 +96,6 @@ export class AddP2pPolicyComponent implements OnInit {
resetForAdd() {
this.currentForm.reset({
severity: 0,
triggerType: "manual"
});
this.inlineAlert.close();
......@@ -104,7 +103,7 @@ export class AddP2pPolicyComponent implements OnInit {
this.repos = null;
this.tags = null;
this.onlySignedImages = false;
this.severity = 0;
this.severity = null;
this.labels = null;
this.triggerType = "manual";
this.cron = null;
......@@ -173,7 +172,7 @@ export class AddP2pPolicyComponent implements OnInit {
}
}
if (this.severity === 0 || this.severity > 0) {
filters.push({type: FILTER_TYPE.VULNERABILITY, value: this.severity});
filters.push({type: FILTER_TYPE.VULNERABILITY, value: +this.severity});
}
policy.filters = JSON.stringify(filters);
const trigger: any = {
......
......@@ -29,6 +29,7 @@ import {
} from '../../../../lib/services';
import { ClrLoadingState } from '@clr/angular';
import {
EXECUTION_STATUS,
FILTER_TYPE,
P2pProviderService,
PROJECT_SEVERITY_LEVEL_TO_TEXT_MAP,
......@@ -79,6 +80,7 @@ export class PolicyComponent implements OnInit, OnDestroy {
private _searchSubscription: Subscription;
project: Project;
severity_map: any = PROJECT_SEVERITY_LEVEL_TO_TEXT_MAP;
timeout: any;
constructor(
private route: ActivatedRoute,
private router: Router,
......@@ -104,6 +106,10 @@ export class PolicyComponent implements OnInit, OnDestroy {
this._searchSubscription.unsubscribe();
this._searchSubscription = null;
}
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
}
}
getPermissions() {
const permissionsList: Observable<boolean>[] = [];
......@@ -171,11 +177,13 @@ export class PolicyComponent implements OnInit, OnDestroy {
if (message && message.source === ConfirmationTargets.P2P_PROVIDER_STOP &&
message.state === ConfirmationState.CONFIRMED) {
this.stopLoading = true;
const execution: Execution = clone(this.selectedExecutionRow);
execution.status = EXECUTION_STATUS.STOPPED;
this.preheatService.StopExecution({
projectName: this.projectName,
preheatPolicyName: this.selectedRow.name,
executionId: this.selectedExecutionRow.id,
execution: this.selectedExecutionRow
execution: execution
}).pipe(finalize(() => this.executing = false))
.subscribe(response => {
this.messageHandlerService.showSuccess('P2P_PROVIDER.STOP_SUCCESSFULLY');
......@@ -364,12 +372,14 @@ export class PolicyComponent implements OnInit, OnDestroy {
if (this.executionList && this.executionList.length) {
for (let i = 0; i < this.executionList.length; i++) {
if (this.p2pProviderService.willChangStatus(this.executionList[i].status)) {
setTimeout(() => {
if (!this.timeout) {
this.timeout = setTimeout(() => {
this.clrLoadJobs(null, false);
}, TIME_OUT);
}
}
}
}
}, error => {
this.messageHandlerService.handleError(error);
});
......
......@@ -103,7 +103,11 @@
</clr-tooltip-content>
</clr-tooltip>
</clr-dg-cell>
<clr-dg-cell>{{toJsonString(t.extra_attrs)}}</clr-dg-cell>
<clr-dg-cell>
<span>{{t.extra_attrs?.artifact}}</span>,&nbsp;
<span>{{t.extra_attrs?.digest}}</span>,&nbsp;
<span>{{t.extra_attrs?.kind}}</span>
</clr-dg-cell>
<clr-dg-cell>{{t.start_time | date: 'short'}}</clr-dg-cell>
<clr-dg-cell>{{getDuration(t)}}</clr-dg-cell>
<clr-dg-cell>
......
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { finalize } from 'rxjs/operators';
import { CustomComparator, DEFAULT_PAGE_SIZE, isEmptyObject } from '../../../../lib/utils/utils';
import { clone, CustomComparator, DEFAULT_PAGE_SIZE, isEmptyObject } from '../../../../lib/utils/utils';
import { Task } from '../../../../../ng-swagger-gen/models/task';
import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service';
import { Project } from '../../project';
......@@ -18,7 +18,7 @@ import { ClrLoadingState } from '@clr/angular';
templateUrl: './task-list.component.html',
styleUrls: ['./task-list.component.scss']
})
export class TaskListComponent implements OnInit {
export class TaskListComponent implements OnInit, OnDestroy {
projectId: number;
projectName: string;
isOpenFilterTag: boolean;
......@@ -35,6 +35,7 @@ export class TaskListComponent implements OnInit {
execution: Execution;
hasUpdatePermission: boolean = false;
btnState: ClrLoadingState = ClrLoadingState.DEFAULT;
timeout: any;
constructor(
private translate: TranslateService,
private router: Router,
......@@ -59,6 +60,12 @@ export class TaskListComponent implements OnInit {
}
this.getPermissions();
}
ngOnDestroy(): void {
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
}
}
getPermissions() {
const permissionsList: Observable<boolean>[] = [];
permissionsList.push(this.userPermissionService.getPermission(this.projectId,
......@@ -85,10 +92,12 @@ export class TaskListComponent implements OnInit {
.subscribe(res => {
this.execution = res;
if (!this.execution || this.p2pProviderService.willChangStatus(this.execution.status)) {
setTimeout(() => {
if (!this.timeout) {
this.timeout = setTimeout(() => {
this.getExecutionDetail(false);
}, TIME_OUT);
}
}
},
error => {
this.messageHandlerService.error(error);
......@@ -109,41 +118,44 @@ export class TaskListComponent implements OnInit {
successNum(): number {
if (this.execution && this.execution.metrics) {
return this.execution.metrics.success_task_count;
return this.execution.metrics.success_task_count ? this.execution.metrics.success_task_count : 0;
}
return 0;
}
failedNum(): number {
if (this.execution && this.execution.metrics) {
return this.execution.metrics.error_task_count;
return this.execution.metrics.error_task_count ? this.execution.metrics.error_task_count : 0;
}
return 0;
}
progressNum(): number {
if (this.execution && this.execution.metrics) {
return (this.execution.metrics.pending_task_count ? this.execution.metrics.pending_task_count : 0)
const num: number = (this.execution.metrics.pending_task_count ? this.execution.metrics.pending_task_count : 0)
+ (this.execution.metrics.running_task_count ? this.execution.metrics.running_task_count : 0)
+ (this.execution.metrics.scheduled_task_count ? this.execution.metrics.scheduled_task_count : 0);
return num ? num : 0;
}
return 0;
}
stoppedNum(): number {
if (this.execution && this.execution.metrics) {
return this.execution.metrics.stopped_task_count;
return this.execution.metrics.stopped_task_count ? this.execution.metrics.stopped_task_count : 0;
}
return 0;
}
stopJob() {
this.stopOnGoing = true;
const execution: Execution = clone(this.execution);
execution.status = EXECUTION_STATUS.STOPPED;
this.preheatService.StopExecution({
projectName: this.projectName,
preheatPolicyName: this.preheatPolicyName,
executionId: +this.executionId,
execution: this.execution
execution: execution
})
.subscribe(response => {
this.stopOnGoing = false;
......@@ -199,12 +211,6 @@ export class TaskListComponent implements OnInit {
this.totalCount = 0;
this.clrLoadTasks(true);
}
toJsonString(obj: any) {
if (!isEmptyObject(obj)) {
return JSON.stringify(obj);
}
return '';
}
getDuration(t: Task): string {
return this.p2pProviderService.getDuration(t.start_time, t.end_time);
}
......
......@@ -1536,7 +1536,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
......@@ -1530,7 +1530,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
......@@ -1500,7 +1500,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
......@@ -1528,7 +1528,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
......@@ -1532,7 +1532,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
......@@ -1529,7 +1529,7 @@
"PROVIDER_TYPE": "发起方",
"ID": "执行 ID",
"NO_PROVIDER": "请先添加提供商",
"EXTRA_ATTRS": "额外属性",
"EXTRA_ATTRS": "Artifact, 摘要和类型",
"TASKS": "任务",
"TASKS_PLACEHOLDER": "暂无记录",
"SEVERITY_WARNING": "此处漏洞等级设置与项目设置冲突且将会被项目设置覆盖",
......
......@@ -1516,7 +1516,7 @@
"PROVIDER_TYPE": "Vendor",
"ID": "Execution ID",
"NO_PROVIDER": "Please add a provider first",
"EXTRA_ATTRS": "Extra Attrs",
"EXTRA_ATTRS": "Artifact, Digest and Kind",
"TASKS": "Tasks",
"TASKS_PLACEHOLDER": "We couldn't find any task",
"SEVERITY_WARNING": "Vulnerability settings here conflicts with the relevant project configuration that will override the settings here",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment