mirror of https://github.com/goharbor/harbor.git
Improve double star validator on UI (#14345)
Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
10ceaf5bc5
commit
5cae2d5d9a
|
@ -208,21 +208,27 @@ export class AddP2pPolicyComponent implements OnInit, OnDestroy {
|
|||
policy.provider_id = +policy.provider_id;
|
||||
const filters: any[] = [];
|
||||
if (this.repos) {
|
||||
if (this.repos.indexOf(",") !== -1) {
|
||||
if (this.repos.indexOf(",") !== -1
|
||||
&& this.repos.indexOf('{') === -1
|
||||
&& this.repos.indexOf('}') === -1) {
|
||||
filters.push({type: FILTER_TYPE.REPOS, value: `{${this.repos}}`});
|
||||
} else {
|
||||
filters.push({type: FILTER_TYPE.REPOS, value: this.repos});
|
||||
}
|
||||
}
|
||||
if (this.tags) {
|
||||
if (this.tags.indexOf(",") !== -1) {
|
||||
if (this.tags.indexOf(",") !== -1
|
||||
&& this.tags.indexOf('{') === -1
|
||||
&& this.tags.indexOf('}') === -1) {
|
||||
filters.push({type: FILTER_TYPE.TAG, value: `{${this.tags}}`});
|
||||
} else {
|
||||
filters.push({type: FILTER_TYPE.TAG, value: this.tags});
|
||||
}
|
||||
}
|
||||
if (this.labels) {
|
||||
if (this.labels.indexOf(",") !== -1) {
|
||||
if (this.labels.indexOf(",") !== -1
|
||||
&& this.labels.indexOf('{') === -1
|
||||
&& this.labels.indexOf('}') === -1) {
|
||||
filters.push({type: FILTER_TYPE.LABEL, value: `{${this.labels}}`});
|
||||
} else {
|
||||
filters.push({type: FILTER_TYPE.LABEL, value: this.labels});
|
||||
|
|
|
@ -258,6 +258,9 @@ export class PolicyComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
editPolicy() {
|
||||
if (this.selectedRow) {
|
||||
this.addP2pPolicyComponent.repos = null;
|
||||
this.addP2pPolicyComponent.tags = null;
|
||||
this.addP2pPolicyComponent.labels = null;
|
||||
this.addP2pPolicyComponent.isOpen = true;
|
||||
this.addP2pPolicyComponent.isEdit = true;
|
||||
this.addP2pPolicyComponent.inlineAlert.close();
|
||||
|
@ -266,13 +269,25 @@ export class PolicyComponent implements OnInit, OnDestroy {
|
|||
if (filter && filter.length) {
|
||||
filter.forEach(item => {
|
||||
if (item.type === FILTER_TYPE.REPOS && item.value) {
|
||||
this.addP2pPolicyComponent.repos = item.value.replace(/[{}]/g, "");
|
||||
let str: string = item.value;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
this.addP2pPolicyComponent.repos = str;
|
||||
}
|
||||
if (item.type === FILTER_TYPE.TAG && item.value) {
|
||||
this.addP2pPolicyComponent.tags = item.value.replace(/[{}]/g, "");
|
||||
let str: string = item.value;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
this.addP2pPolicyComponent.tags = str;
|
||||
}
|
||||
if (item.type === FILTER_TYPE.LABEL && item.value) {
|
||||
this.addP2pPolicyComponent.labels = item.value.replace(/[{}]/g, "");
|
||||
let str: string = item.value;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
this.addP2pPolicyComponent.labels = str;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -433,7 +448,11 @@ export class PolicyComponent implements OnInit, OnDestroy {
|
|||
if (arr && arr.length) {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i].type === type && arr[i].value) {
|
||||
return (arr[i].value + "").replace(/[{}]/g, "");
|
||||
let str: string = arr[i].value;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,8 @@ export class AddImmutableRuleComponent implements OnInit, OnDestroy {
|
|||
set repositories(repositories) {
|
||||
if (this.rule && this.rule.scope_selectors && this.rule.scope_selectors.repository
|
||||
&& this.rule.scope_selectors.repository[0]) {
|
||||
if (repositories.indexOf(",") !== -1) {
|
||||
if (repositories.indexOf(",") !== -1
|
||||
&& repositories.indexOf("{") === -1 && repositories.indexOf("}") === -1) {
|
||||
this.rule.scope_selectors.repository[0].pattern = "{" + repositories + "}";
|
||||
} else {
|
||||
this.rule.scope_selectors.repository[0].pattern = repositories;
|
||||
|
@ -65,7 +66,11 @@ export class AddImmutableRuleComponent implements OnInit, OnDestroy {
|
|||
get repositories() {
|
||||
if (this.rule && this.rule.scope_selectors && this.rule.scope_selectors.repository
|
||||
&& this.rule.scope_selectors.repository[0] && this.rule.scope_selectors.repository[0].pattern) {
|
||||
return this.rule.scope_selectors.repository[0].pattern.replace(/[{}]/g, "");
|
||||
let str: string = this.rule.scope_selectors.repository[0].pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -85,7 +90,8 @@ export class AddImmutableRuleComponent implements OnInit, OnDestroy {
|
|||
|
||||
set tagsInput(tagsInput) {
|
||||
if (this.rule && this.rule.tag_selectors && this.rule.tag_selectors[0]) {
|
||||
if (tagsInput.indexOf(",") !== -1) {
|
||||
if (tagsInput.indexOf(",") !== -1
|
||||
&& tagsInput.indexOf("{") === -1 && tagsInput.indexOf("}") === -1) {
|
||||
this.rule.tag_selectors[0].pattern = "{" + tagsInput + "}";
|
||||
} else {
|
||||
this.rule.tag_selectors[0].pattern = tagsInput;
|
||||
|
@ -95,7 +101,11 @@ export class AddImmutableRuleComponent implements OnInit, OnDestroy {
|
|||
|
||||
get tagsInput() {
|
||||
if (this.rule && this.rule.tag_selectors && this.rule.tag_selectors[0] && this.rule.tag_selectors[0].pattern) {
|
||||
return this.rule.tag_selectors[0].pattern.replace(/[{}]/g, "");
|
||||
let str: string = this.rule.tag_selectors[0].pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -161,7 +161,11 @@ export class ImmutableTagComponent implements OnInit {
|
|||
}
|
||||
|
||||
formatPattern(pattern: string): string {
|
||||
return pattern.replace(/[{}]/g, "");
|
||||
let str: string = pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
getI18nKey(str: string) {
|
||||
|
|
|
@ -92,7 +92,8 @@ export class AddRuleComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
set repositories(repositories) {
|
||||
if (repositories.indexOf(",") !== -1) {
|
||||
if (repositories.indexOf(",") !== -1
|
||||
&& repositories.indexOf("{") === -1 && repositories.indexOf("}") === -1) {
|
||||
this.rule.scope_selectors.repository[0].pattern = "{" + repositories + "}";
|
||||
} else {
|
||||
this.rule.scope_selectors.repository[0].pattern = repositories;
|
||||
|
@ -100,7 +101,11 @@ export class AddRuleComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
get repositories() {
|
||||
return this.rule.scope_selectors.repository[0].pattern.replace(/[{}]/g, "");
|
||||
let str: string = this.rule.scope_selectors.repository[0].pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
get tagsSelect() {
|
||||
|
@ -112,7 +117,8 @@ export class AddRuleComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
set tagsInput(tagsInput) {
|
||||
if (tagsInput.indexOf(",") !== -1) {
|
||||
if (tagsInput.indexOf(",") !== -1
|
||||
&& tagsInput.indexOf("{") === -1 && tagsInput.indexOf("}") === -1) {
|
||||
this.rule.tag_selectors[0].pattern = "{" + tagsInput + "}";
|
||||
} else {
|
||||
this.rule.tag_selectors[0].pattern = tagsInput;
|
||||
|
@ -120,7 +126,11 @@ export class AddRuleComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
get tagsInput() {
|
||||
return this.rule.tag_selectors[0].pattern.replace(/[{}]/g, "");
|
||||
let str: string = this.rule.tag_selectors[0].pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
set untagged(untagged) {
|
||||
let extras = JSON.parse(this.rule.tag_selectors[0].extras);
|
||||
|
|
|
@ -467,7 +467,11 @@ export class TagRetentionComponent implements OnInit {
|
|||
}
|
||||
|
||||
formatPattern(pattern: string): string {
|
||||
return pattern.replace(/[{}]/g, "");
|
||||
let str: string = pattern;
|
||||
if (/^{\S+}$/.test(str)) {
|
||||
return str.slice(1, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
getI18nKey(str: string) {
|
||||
|
|
Loading…
Reference in New Issue