From 4390b2f259ffe49aa71412453d530d18d445fa0c Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Thu, 26 Nov 2020 14:39:33 +0800 Subject: [PATCH] Add limitation to artifact tags Signed-off-by: AllForNothing --- .../artifact-list-tab.component.html | 5 ++- .../artifact-list-tab.component.ts | 44 +++++++++++++++---- .../artifact-tag/artifact-tag.component.ts | 14 +++--- .../project/repository/artifact/artifact.ts | 1 + ...rtifact-detail-routing-resolver.service.ts | 2 +- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html index 1d4dbd597..edea7b202 100644 --- a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html +++ b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html @@ -192,7 +192,6 @@
-
@@ -202,7 +201,7 @@ ... - ({{artifact?.tags?.length}}) + ({{artifact?.tagNumber}})
@@ -222,6 +221,7 @@ + {{tag.name}} @@ -237,6 +237,7 @@ {{tag.pull_time === availableTime ? '':(tag.pull_time | date: 'short')}} {{tag.push_time | date: 'short'}} + ... diff --git a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts index f1a99c09c..2b3b18037 100644 --- a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts +++ b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts @@ -58,14 +58,13 @@ import { ArtifactFront as Artifact, mutipleFilter, artifactPullCommands, - artifactDefault + artifactDefault, ArtifactFront } from '../../../artifact/artifact'; import { Project } from "../../../../project"; import { ArtifactService as NewArtifactService } from "../../../../../../../ng-swagger-gen/services/artifact.service"; import { ADDITIONS } from "../../../artifact/artifact-additions/models"; import { Platform } from "../../../../../../../ng-swagger-gen/models/platform"; -import { IconService } from '../../../../../../../ng-swagger-gen/services/icon.service'; -import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; +import { SafeUrl } from '@angular/platform-browser'; export interface LabelState { iconsShow: boolean; label: Label; @@ -91,7 +90,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { @Input() registryUrl: string; @Input() withNotary: boolean; @Input() withAdmiral: boolean; - artifactList: Artifact[] = []; + artifactList: ArtifactFront[] = []; availableTime = AVAILABLE_TIME; showTagManifestOpened: boolean; retagDialogOpened: boolean; @@ -342,8 +341,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { withImmutableStatus: true, withLabel: true, withScanOverview: true, - withSignature: true, - withTag: true + withTag: false }; this.newArtifactService.getArtifact(artifactParam).subscribe( res => { @@ -359,8 +357,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { withImmutableStatus: true, withLabel: true, withScanOverview: true, - withSignature: true, - withTag: true + withTag: false }; platFormAttr.push({platform: child.platform}); observableLists.push(this.newArtifactService.getArtifact(childParams)); @@ -374,6 +371,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { artifact.platform = clone(platFormAttr[index].platform); }); this.getPullCommand(this.artifactList); + this.getArtifactTagsAsync(this.artifactList); this.getIconsFromBackEnd(); }, error => { this.errorHandlerService.error(error); @@ -388,7 +386,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { repositoryName: dbEncodeURIComponent(this.repoName), withLabel: true, withScanOverview: true, - withTag: true + withTag: false }; Object.assign(listArtifactParams, params); this.newArtifactService.listArtifactsResponse(listArtifactParams) @@ -404,6 +402,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { this.artifactList = doSorting(this.artifactList, state); this.getPullCommand(this.artifactList); + this.getArtifactTagsAsync(this.artifactList); this.getIconsFromBackEnd(); }, error => { // error @@ -1012,4 +1011,31 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { getIcon(icon: string): SafeUrl { return this.artifactService.getIcon(icon); } + // get Tags and display less than 9 tags(too many tags will make UI stuck) + getArtifactTagsAsync(artifacts: ArtifactFront[]) { + if (artifacts && artifacts.length) { + artifacts.forEach(item => { + const listTagParams: NewArtifactService.ListTagsParams = { + projectName: this.projectName, + repositoryName: dbEncodeURIComponent(this.repoName), + reference: item.digest, + withSignature: true, + withImmutableStatus: true, + page: 1, + pageSize: 8 + }; + this.newArtifactService.listTagsResponse(listTagParams).subscribe( + res => { + if (res.headers) { + let xHeader: string = res.headers.get("x-total-count"); + if (xHeader) { + item.tagNumber = Number.parseInt(xHeader); + } + } + item.tags = res.body; + } + ); + }); + } + } } diff --git a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts index 40c70a61e..2e7ccfd04 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts @@ -86,21 +86,21 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { .subscribe(systemInfo => this.systemInfo = systemInfo, error => this.errorHandlerService.error(error)); } checkTagName(name) { - let listArtifactParams: ArtifactService.ListArtifactsParams = { + const listTagParams: ArtifactService.ListTagsParams = { projectName: this.projectName, repositoryName: dbEncodeURIComponent(this.repositoryName), - withLabel: true, - withScanOverview: true, - withTag: true, - q: encodeURIComponent(`tags=${name}`) + reference: this.artifactDetails.digest, + withSignature: true, + withImmutableStatus: true, + q: encodeURIComponent(`name=${name}`) }; - return this.artifactService.listArtifacts(listArtifactParams) + return this.artifactService.listTags(listTagParams) .pipe(finalize(() => this.tagNameCheckOnGoing = false)); } invalidCreateTag() { if (!this.tagNameCheckSub) { this.tagNameCheckSub = this.tagNameChecker - .pipe(debounceTime(200)) + .pipe(debounceTime(500)) .pipe(distinctUntilChanged()) .pipe(switchMap(name => { this.tagNameCheckOnGoing = true; diff --git a/src/portal/src/app/project/repository/artifact/artifact.ts b/src/portal/src/app/project/repository/artifact/artifact.ts index adc888cac..c54d36784 100644 --- a/src/portal/src/app/project/repository/artifact/artifact.ts +++ b/src/portal/src/app/project/repository/artifact/artifact.ts @@ -6,6 +6,7 @@ export interface ArtifactFront extends Artifact { showImage?: string; pullCommand?: string; annotationsArray?: Array<{[key: string]: any}>; + tagNumber?: number; } export const mutipleFilter = [ diff --git a/src/portal/src/app/services/routing-resolvers/artifact-detail-routing-resolver.service.ts b/src/portal/src/app/services/routing-resolvers/artifact-detail-routing-resolver.service.ts index 2b0e3834a..620cee9b9 100644 --- a/src/portal/src/app/services/routing-resolvers/artifact-detail-routing-resolver.service.ts +++ b/src/portal/src/app/services/routing-resolvers/artifact-detail-routing-resolver.service.ts @@ -44,7 +44,7 @@ export class ArtifactDetailRoutingResolverService implements Resolve { projectName: project.name, withLabel: true, withScanOverview: true, - withSignature: true, + withTag: false, withImmutableStatus: true }), of(project)]); }),