From 7e7663648ce4af08ea94a6d1d75372d079988784 Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Mon, 27 Jul 2020 14:33:47 +0800 Subject: [PATCH] Improve p2p-preheat ui Signed-off-by: AllForNothing --- .../add-p2p-policy.component.ts | 7 ++-- .../p2p-provider/policy/policy.component.ts | 18 +++++++-- .../task-list/task-list.component.html | 6 ++- .../task-list/task-list.component.ts | 40 +++++++++++-------- src/portal/src/i18n/lang/en-us-lang.json | 2 +- src/portal/src/i18n/lang/es-es-lang.json | 2 +- src/portal/src/i18n/lang/fr-fr-lang.json | 2 +- src/portal/src/i18n/lang/pt-br-lang.json | 2 +- src/portal/src/i18n/lang/tr-tr-lang.json | 2 +- src/portal/src/i18n/lang/zh-cn-lang.json | 2 +- src/portal/src/i18n/lang/zh-tw-lang.json | 2 +- 11 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/portal/src/app/project/p2p-provider/add-p2p-policy/add-p2p-policy.component.ts b/src/portal/src/app/project/p2p-provider/add-p2p-policy/add-p2p-policy.component.ts index e64efd712..abd3c39af 100644 --- a/src/portal/src/app/project/p2p-provider/add-p2p-policy/add-p2p-policy.component.ts +++ b/src/portal/src/app/project/p2p-provider/add-p2p-policy/add-p2p-policy.component.ts @@ -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 = { diff --git a/src/portal/src/app/project/p2p-provider/policy/policy.component.ts b/src/portal/src/app/project/p2p-provider/policy/policy.component.ts index 33183ac5a..edbe4b64c 100644 --- a/src/portal/src/app/project/p2p-provider/policy/policy.component.ts +++ b/src/portal/src/app/project/p2p-provider/policy/policy.component.ts @@ -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[] = []; @@ -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,9 +372,11 @@ 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(() => { - this.clrLoadJobs(null, false); - }, TIME_OUT); + if (!this.timeout) { + this.timeout = setTimeout(() => { + this.clrLoadJobs(null, false); + }, TIME_OUT); + } } } } diff --git a/src/portal/src/app/project/p2p-provider/task-list/task-list.component.html b/src/portal/src/app/project/p2p-provider/task-list/task-list.component.html index ba7269eea..781cb65c4 100644 --- a/src/portal/src/app/project/p2p-provider/task-list/task-list.component.html +++ b/src/portal/src/app/project/p2p-provider/task-list/task-list.component.html @@ -103,7 +103,11 @@ - {{toJsonString(t.extra_attrs)}} + + {{t.extra_attrs?.artifact}},  + {{t.extra_attrs?.digest}},  + {{t.extra_attrs?.kind}} + {{t.start_time | date: 'short'}} {{getDuration(t)}} diff --git a/src/portal/src/app/project/p2p-provider/task-list/task-list.component.ts b/src/portal/src/app/project/p2p-provider/task-list/task-list.component.ts index 6b23c928b..f5dca3a24 100644 --- a/src/portal/src/app/project/p2p-provider/task-list/task-list.component.ts +++ b/src/portal/src/app/project/p2p-provider/task-list/task-list.component.ts @@ -1,8 +1,8 @@ -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[] = []; permissionsList.push(this.userPermissionService.getPermission(this.projectId, @@ -85,9 +92,11 @@ export class TaskListComponent implements OnInit { .subscribe(res => { this.execution = res; if (!this.execution || this.p2pProviderService.willChangStatus(this.execution.status)) { - setTimeout(() => { - this.getExecutionDetail(false); - }, TIME_OUT); + if (!this.timeout) { + this.timeout = setTimeout(() => { + this.getExecutionDetail(false); + }, TIME_OUT); + } } }, 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); } diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index bb72b35e0..b84486bb1 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -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", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index 1f2ab3ee8..3088cc44b 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -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", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 69c3f994e..c7afec2df 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -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", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index cce28d7e2..65db1487b 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -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", diff --git a/src/portal/src/i18n/lang/tr-tr-lang.json b/src/portal/src/i18n/lang/tr-tr-lang.json index 6f3757cce..015b7d137 100644 --- a/src/portal/src/i18n/lang/tr-tr-lang.json +++ b/src/portal/src/i18n/lang/tr-tr-lang.json @@ -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", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index 61a475c8d..1c7658fd4 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -1529,7 +1529,7 @@ "PROVIDER_TYPE": "发起方", "ID": "执行 ID", "NO_PROVIDER": "请先添加提供商", - "EXTRA_ATTRS": "额外属性", + "EXTRA_ATTRS": "Artifact, 摘要和类型", "TASKS": "任务", "TASKS_PLACEHOLDER": "暂无记录", "SEVERITY_WARNING": "此处漏洞等级设置与项目设置冲突且将会被项目设置覆盖", diff --git a/src/portal/src/i18n/lang/zh-tw-lang.json b/src/portal/src/i18n/lang/zh-tw-lang.json index e87fb2954..93e5292e0 100644 --- a/src/portal/src/i18n/lang/zh-tw-lang.json +++ b/src/portal/src/i18n/lang/zh-tw-lang.json @@ -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",