mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-19 21:32:24 +01:00
Use standard query to search projects by name (#14778)
Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
c2ab1769b3
commit
7642519bf4
@ -2,21 +2,21 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { CreateProjectComponent } from './create-project.component';
|
import { CreateProjectComponent } from './create-project.component';
|
||||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
import { MessageHandlerService } from '../../../../shared/services/message-handler.service';
|
import { MessageHandlerService } from '../../../../shared/services/message-handler.service';
|
||||||
import { ProjectService } from '../../../../shared/services';
|
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { delay } from 'rxjs/operators';
|
import { delay } from 'rxjs/operators';
|
||||||
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
|
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
|
||||||
import { SharedTestingModule } from "../../../../shared/shared.module";
|
import { SharedTestingModule } from "../../../../shared/shared.module";
|
||||||
|
import { ProjectService } from "../../../../../../ng-swagger-gen/services/project.service";
|
||||||
|
|
||||||
describe('CreateProjectComponent', () => {
|
describe('CreateProjectComponent', () => {
|
||||||
let component: CreateProjectComponent;
|
let component: CreateProjectComponent;
|
||||||
let fixture: ComponentFixture<CreateProjectComponent>;
|
let fixture: ComponentFixture<CreateProjectComponent>;
|
||||||
const mockProjectService = {
|
const mockProjectService = {
|
||||||
checkProjectExists: function(name: string) {
|
listProjects: function(params: ProjectService.ListProjectsParams) {
|
||||||
if (name === 'test') {
|
if (params && params.q === encodeURIComponent('name=test')) {
|
||||||
return of({status: 200}).pipe(delay(10));
|
return of([true]).pipe(delay(10));
|
||||||
} else {
|
} else {
|
||||||
return of({status: 404}).pipe(delay(10));
|
return of([]).pipe(delay(10));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createProject: function () {
|
createProject: function () {
|
||||||
|
@ -29,11 +29,12 @@ import { TranslateService } from "@ngx-translate/core";
|
|||||||
import { MessageHandlerService } from "../../../../shared/services/message-handler.service";
|
import { MessageHandlerService } from "../../../../shared/services/message-handler.service";
|
||||||
import { Project } from "../../../project/project";
|
import { Project } from "../../../project/project";
|
||||||
import { QuotaUnits, QuotaUnlimited } from "../../../../shared/entities/shared.const";
|
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 { clone, getByte, GetIntegerAndUnit, validateLimit } from "../../../../shared/units/utils";
|
||||||
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
|
import { InlineAlertComponent } from "../../../../shared/components/inline-alert/inline-alert.component";
|
||||||
import { Registry } from "../../../../../../ng-swagger-gen/models/registry";
|
import { Registry } from "../../../../../../ng-swagger-gen/models/registry";
|
||||||
import { RegistryService } from "../../../../../../ng-swagger-gen/services/registry.service";
|
import { RegistryService } from "../../../../../../ng-swagger-gen/services/registry.service";
|
||||||
|
import { ProjectService } from "../../../../../../ng-swagger-gen/services/project.service";
|
||||||
|
|
||||||
const PAGE_SIZE: number = 100;
|
const PAGE_SIZE: number = 100;
|
||||||
@Component({
|
@Component({
|
||||||
@ -141,11 +142,13 @@ export class CreateProjectComponent implements OnInit, AfterViewInit, OnChanges
|
|||||||
// Check exiting from backend
|
// Check exiting from backend
|
||||||
this.checkOnGoing = true;
|
this.checkOnGoing = true;
|
||||||
this.isNameExisted = false;
|
this.isNameExisted = false;
|
||||||
return this.projectService.checkProjectExists(name);
|
return this.projectService.listProjects({
|
||||||
|
q: encodeURIComponent(`name=${name}`)
|
||||||
|
});
|
||||||
})).subscribe(response => {
|
})).subscribe(response => {
|
||||||
// Project existing
|
// Project existing
|
||||||
if (!(response && response.status === 404)) {
|
if (response && response.length) {
|
||||||
this.isNameExisted = true;
|
this.isNameExisted = true;
|
||||||
}
|
}
|
||||||
this.checkOnGoing = false;
|
this.checkOnGoing = false;
|
||||||
}, error => {
|
}, error => {
|
||||||
@ -215,7 +218,16 @@ export class CreateProjectComponent implements OnInit, AfterViewInit, OnChanges
|
|||||||
this.isSubmitOnGoing = true;
|
this.isSubmitOnGoing = true;
|
||||||
const storageByte = +this.storageLimit === QuotaUnlimited ? this.storageLimit : getByte(+this.storageLimit, this.storageLimitUnit);
|
const storageByte = +this.storageLimit === QuotaUnlimited ? this.storageLimit : getByte(+this.storageLimit, this.storageLimitUnit);
|
||||||
this.projectService
|
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(
|
.subscribe(
|
||||||
status => {
|
status => {
|
||||||
this.isSubmitOnGoing = false;
|
this.isSubmitOnGoing = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user