From fe047a2ad3c55b1546d318c739f622174aee803d Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Tue, 10 Mar 2020 12:07:56 +0800 Subject: [PATCH] [OCI] Artifact filter params changes in ui Signed-off-by: Yogi_Wang --- .../artifact-list-tab.component.html | 6 +- .../artifact-list-tab.component.spec.ts | 2 +- .../artifact-list-tab.component.ts | 97 ++++++++++--------- .../project/repository/artifact/artifact.ts | 2 +- .../repository-gridview.component.ts | 4 +- 5 files changed, 57 insertions(+), 54 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 68613ba9c..a77244b5d 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 @@ -31,7 +31,7 @@
-
@@ -59,7 +59,7 @@
-
+
× @@ -146,7 +146,7 @@ - {{'REPOSITORY.ARTIFACTS_COUNT' | translate}} + {{'REPOSITORY.ARTIFACTS_COUNT' | translate}} {{'REPOSITORY.PLATFORM' | translate}} {{'REPOSITORY.TAGS_COUNT' | translate}} diff --git a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.spec.ts b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.spec.ts index 86cc4f5d1..58efd9b4c 100644 --- a/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.spec.ts @@ -370,7 +370,7 @@ describe("ArtifactListTabComponent (inline template)", () => { fixture.detectChanges(); await fixture.whenStable(); filtereName = 'sha256:3e33e3e3'; - comp.doSearchArtifactNames('sha256:3e33e3e3'); + comp.doSearchArtifactByFilter('sha256:3e33e3e3'); fixture.detectChanges(); await fixture.whenStable(); fixture.detectChanges(); 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 9b90fc58e..f2ba877ba 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 @@ -144,7 +144,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { pageSize: number = DEFAULT_PAGE_SIZE; currentPage = 1; totalCount = 0; - currentState: State; + currentState: ClrDatagridStateInterface; hasAddLabelImagePermission: boolean; hasRetagImagePermission: boolean; @@ -163,7 +163,8 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { mutipleFilter = clone(mutipleFilter); filterByType: string = this.mutipleFilter[0].filterBy; openSelectFilterPiece = false; - + // could Pagination filter + filters: string[]; constructor( private errorHandlerService: ErrorHandler, private userPermissionService: UserPermissionService, @@ -282,32 +283,16 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { this.lastFilteredTagName = filterWords; this.currentPage = 1; - let st: State = this.currentState; + let st: ClrDatagridStateInterface = this.currentState; if (!st) { st = { page: {} }; } st.page.size = this.pageSize; st.page.from = 0; st.page.to = this.pageSize - 1; - - st.filters = [{ property: this.filterByType, value: this.lastFilteredTagName }]; - this.clrLoad(st); - } - doSearchArtifactNames(artifactName: string) { - this.lastFilteredTagName = artifactName; - this.currentPage = 1; - - let st: State = this.currentState; - if (!st) { - st = { page: {} }; - } - st.page.size = this.pageSize; - st.page.from = 0; - st.page.to = this.pageSize - 1; - st.filters = [{ property: this.filterByType, value: this.lastFilteredTagName }]; - let selectedLab = this.imageFilterLabels.find(label => label.iconsShow === true); - if (selectedLab) { - st.filters.push({ property: this.filterByType, value: selectedLab.label.id }); + this.filters = []; + if (this.lastFilteredTagName) { + this.filters.push(`${this.filterByType}=~${this.lastFilteredTagName}`); } this.clrLoad(st); } @@ -345,10 +330,12 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { if (sortBy) { params.sort = sortBy; } - if (state.filters && state.filters.length) { - state.filters.forEach(item => { - params[item.property] = item.value; + if (this.filters && this.filters.length) { + let q = ""; + this.filters.forEach(item => { + q += item; }); + params.q = encodeURIComponent(q); } if (this.artifactDigest) { const artifactParam: NewArtifactService.GetArtifactParams = { @@ -422,7 +409,15 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { } refresh() { - this.doSearchArtifactNames(this.lastFilteredTagName); + this.currentPage = 1; + let st: ClrDatagridStateInterface = this.currentState; + if (!st) { + st = { page: {} }; + st.page.size = this.pageSize; + st.page.from = 0; + st.page.to = this.pageSize - 1; + } + this.clrLoad(st); } getArtifactAnnotationsArray(artifactList: Artifact[]) { artifactList.forEach(artifact => { @@ -579,18 +574,15 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { // reload data this.currentPage = 1; - let st: State = this.currentState; + let st: ClrDatagridStateInterface = this.currentState; if (!st) { st = { page: {} }; } st.page.size = this.pageSize; st.page.from = 0; st.page.to = this.pageSize - 1; - if (this.lastFilteredTagName) { - st.filters = [{ property: 'name', value: this.lastFilteredTagName }, { property: 'labels.id', value: labelId }]; - } else { - st.filters = [{ property: 'labels.id', value: labelId }]; - } + + this.filters = [`${this.filterByType}=(${labelId})`]; this.clrLoad(st); } @@ -604,18 +596,15 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { // reload data this.currentPage = 1; - let st: State = this.currentState; + let st: ClrDatagridStateInterface = this.currentState; if (!st) { st = { page: {} }; } st.page.size = this.pageSize; st.page.from = 0; st.page.to = this.pageSize - 1; - if (this.lastFilteredTagName) { - st.filters = [{ property: 'name', value: this.lastFilteredTagName }]; - } else { - st.filters = []; - } + + this.filters = []; this.clrLoad(st); } @@ -920,7 +909,7 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { } selectFilterType() { this.lastFilteredTagName = ''; - if (this.filterByType === 'label.id') { + if (this.filterByType === 'labels') { this.openLabelFilterPanel = true; this.openLabelFilterPiece = true; } else { @@ -931,25 +920,37 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { data.iconsShow = false; }); } - this.doSearchArtifactNames(""); - } - - selectFilter(showItem: string, filterItem: string) { - this.lastFilteredTagName = filterItem; this.currentPage = 1; - - let st: State = this.currentState; + let st: ClrDatagridStateInterface = this.currentState; if (!st) { st = { page: {} }; } st.page.size = this.pageSize; st.page.from = 0; st.page.to = this.pageSize - 1; - st.filters = [{ property: this.filterByType, value: filterItem }]; + this.filters = []; + this.clrLoad(st); + } + + selectFilter(showItem: string, filterItem: string) { + this.lastFilteredTagName = filterItem; + this.currentPage = 1; + + let st: ClrDatagridStateInterface = this.currentState; + if (!st) { + st = { page: {} }; + } + st.page.size = this.pageSize; + st.page.from = 0; + st.page.to = this.pageSize - 1; + this.filters = []; + if (filterItem) { + this.filters.push(`${this.filterByType}=${filterItem}`); + } this.clrLoad(st); } get isFilterReadonly() { - return this.filterByType === 'label.id' ? 'readonly' : null; + return this.filterByType === 'labels' ? 'readonly' : null; } } diff --git a/src/portal/src/app/project/repository/artifact/artifact.ts b/src/portal/src/app/project/repository/artifact/artifact.ts index d2bf966ad..ab2866e8c 100644 --- a/src/portal/src/app/project/repository/artifact/artifact.ts +++ b/src/portal/src/app/project/repository/artifact/artifact.ts @@ -42,7 +42,7 @@ export const mutipleFilter = [ ] }, { - filterBy: 'label.id', + filterBy: 'labels', filterByShowText: 'Label', listItem: [] }, diff --git a/src/portal/src/app/project/repository/repository-gridview.component.ts b/src/portal/src/app/project/repository/repository-gridview.component.ts index 87106a431..9e7599c6d 100644 --- a/src/portal/src/app/project/repository/repository-gridview.component.ts +++ b/src/portal/src/app/project/repository/repository-gridview.component.ts @@ -156,8 +156,10 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit, OnDestroy projectName: this.projectName, page: this.currentPage, pageSize: this.pageSize, - name: this.lastFilteredRepoName }; + if (this.lastFilteredRepoName) { + params.q = encodeURIComponent(`name=~${this.lastFilteredRepoName}`); + } this.loading = true; return this.newRepoService.listRepositoriesResponse(params); })