Use standard query to search projects by name (#14778)

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Will Sun 2021-04-29 16:29:24 +08:00 committed by GitHub
parent c2ab1769b3
commit 7642519bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -2,21 +2,21 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateProjectComponent } from './create-project.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { MessageHandlerService } from '../../../../shared/services/message-handler.service';
import { ProjectService } from '../../../../shared/services';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
import { SharedTestingModule } from "../../../../shared/shared.module";
import { ProjectService } from "../../../../../../ng-swagger-gen/services/project.service";
describe('CreateProjectComponent', () => {
let component: CreateProjectComponent;
let fixture: ComponentFixture<CreateProjectComponent>;
const mockProjectService = {
checkProjectExists: function(name: string) {
if (name === 'test') {
return of({status: 200}).pipe(delay(10));
listProjects: function(params: ProjectService.ListProjectsParams) {
if (params && params.q === encodeURIComponent('name=test')) {
return of([true]).pipe(delay(10));
} else {
return of({status: 404}).pipe(delay(10));
return of([]).pipe(delay(10));
}
},
createProject: function () {

View File

@ -29,11 +29,12 @@ import { TranslateService } from "@ngx-translate/core";
import { MessageHandlerService } from "../../../../shared/services/message-handler.service";
import { Project } from "../../../project/project";
import { QuotaUnits, QuotaUnlimited } from "../../../../shared/entities/shared.const";
import { ProjectService, QuotaHardInterface } from '../../../../shared/services';
import { QuotaHardInterface } from '../../../../shared/services';
import { clone, getByte, GetIntegerAndUnit, validateLimit } from "../../../../shared/units/utils";
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
import { Registry } from "../../../../../../ng-swagger-gen/models/registry";
import { RegistryService } from "../../../../../../ng-swagger-gen/services/registry.service";
import { ProjectService } from "../../../../../../ng-swagger-gen/services/project.service";
const PAGE_SIZE: number = 100;
@Component({
@ -141,11 +142,13 @@ export class CreateProjectComponent implements OnInit, AfterViewInit, OnChanges
// Check exiting from backend
this.checkOnGoing = true;
this.isNameExisted = false;
return this.projectService.checkProjectExists(name);
return this.projectService.listProjects({
q: encodeURIComponent(`name=${name}`)
});
})).subscribe(response => {
// Project existing
if (!(response && response.status === 404)) {
this.isNameExisted = true;
if (response && response.length) {
this.isNameExisted = true;
}
this.checkOnGoing = false;
}, error => {
@ -215,7 +218,16 @@ export class CreateProjectComponent implements OnInit, AfterViewInit, OnChanges
this.isSubmitOnGoing = true;
const storageByte = +this.storageLimit === QuotaUnlimited ? this.storageLimit : getByte(+this.storageLimit, this.storageLimitUnit);
this.projectService
.createProject(this.project.name, this.project.metadata, +storageByte, this.project.registry_id)
.createProject({
project: {
project_name: this.project.name,
metadata: {
public: this.project.metadata.public ? 'true' : 'false'
},
storage_limit: +storageByte,
registry_id: +this.project.registry_id
}
})
.subscribe(
status => {
this.isSubmitOnGoing = false;