mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-04 17:49:48 +01:00
Merge pull request #7334 from zhoumeina/replication_ng
modify some issues of create replication policy
This commit is contained in:
commit
ba20da5dd4
@ -159,6 +159,7 @@ describe("CreateEditRuleComponent (inline template)", () => {
|
|||||||
description: "",
|
description: "",
|
||||||
src_namespaces: ["namespace1", "namespace2"],
|
src_namespaces: ["namespace1", "namespace2"],
|
||||||
src_registry: {id: 10 },
|
src_registry: {id: 10 },
|
||||||
|
dest_registry: {id: 0 },
|
||||||
trigger: {
|
trigger: {
|
||||||
kind: "Manual",
|
kind: "Manual",
|
||||||
schedule_param: {}
|
schedule_param: {}
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
Output
|
Output
|
||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import { Filter, ReplicationRule, Endpoint } from "../service/interface";
|
import { Filter, ReplicationRule, Endpoint } from "../service/interface";
|
||||||
import { Subject, Subscription } from "rxjs";
|
import { Subject, Subscription, Observable, zip } from "rxjs";
|
||||||
import { debounceTime, distinctUntilChanged } from "rxjs/operators";
|
import { debounceTime, distinctUntilChanged } from "rxjs/operators";
|
||||||
import { FormArray, FormBuilder, FormGroup, Validators, FormControl } from "@angular/forms";
|
import { FormArray, FormBuilder, FormGroup, Validators, FormControl } from "@angular/forms";
|
||||||
import { clone, compareValue, isEmptyObject } from "../utils";
|
import { clone, compareValue, isEmptyObject } from "../utils";
|
||||||
@ -142,6 +142,7 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
modeChange(): void {
|
modeChange(): void {
|
||||||
if (this.isPushMode) {
|
if (this.isPushMode) {
|
||||||
|
this.setFilter([]);
|
||||||
this.initRegistryInfo(0);
|
this.initRegistryInfo(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,6 +151,7 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
sourceChange($event): void {
|
sourceChange($event): void {
|
||||||
this.noSelectedEndpoint = false;
|
this.noSelectedEndpoint = false;
|
||||||
let selectId = this.ruleForm.get('src_registry').value;
|
let selectId = this.ruleForm.get('src_registry').value;
|
||||||
|
this.setFilter([]);
|
||||||
this.initRegistryInfo(selectId.id);
|
this.initRegistryInfo(selectId.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
return this.ruleForm.get("trigger").get("type").value !== this.TRIGGER_TYPES.EVENT_BASED;
|
return this.ruleForm.get("trigger").get("type").value !== this.TRIGGER_TYPES.EVENT_BASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
initForm(): void {
|
formReset(): void {
|
||||||
this.ruleForm.reset({
|
this.ruleForm.reset({
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
@ -216,12 +218,22 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
deletion: false,
|
deletion: false,
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
|
this.isPushMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
initForm(): void {
|
||||||
|
this.formReset();
|
||||||
this.setFilter([]);
|
this.setFilter([]);
|
||||||
this.initRegistryInfo(0);
|
this.initRegistryInfo(0);
|
||||||
this.copyUpdateForm = clone(this.ruleForm.value);
|
this.copyUpdateForm = clone(this.ruleForm.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateForm(rule: ReplicationRule): void {
|
updateForm(rule: ReplicationRule): void {
|
||||||
|
if (rule.dest_registry.id === 0) {
|
||||||
|
this.isPushMode = false;
|
||||||
|
} else {
|
||||||
|
this.isPushMode = true;
|
||||||
|
}
|
||||||
this.ruleForm.reset({
|
this.ruleForm.reset({
|
||||||
name: rule.name,
|
name: rule.name,
|
||||||
description: rule.description,
|
description: rule.description,
|
||||||
@ -233,7 +245,6 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
deletion: rule.deletion,
|
deletion: rule.deletion,
|
||||||
enabled: rule.enabled
|
enabled: rule.enabled
|
||||||
});
|
});
|
||||||
|
|
||||||
// reset the filter list.
|
// reset the filter list.
|
||||||
let filters = [];
|
let filters = [];
|
||||||
for (let i = 0; i < this.supportedFilters.length; i++) {
|
for (let i = 0; i < this.supportedFilters.length; i++) {
|
||||||
@ -256,10 +267,6 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
this.noSelectedEndpoint = false;
|
this.noSelectedEndpoint = false;
|
||||||
this.setFilter(filters);
|
this.setFilter(filters);
|
||||||
// end of reset the filter list.
|
// end of reset the filter list.
|
||||||
|
|
||||||
// Force refresh view
|
|
||||||
let hnd = setInterval(() => this.ref.markForCheck(), 100);
|
|
||||||
setTimeout(() => clearInterval(hnd), 2000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get filters(): FormArray {
|
get filters(): FormArray {
|
||||||
@ -304,9 +311,6 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
deleteNamespace(index: number): void {
|
deleteNamespace(index: number): void {
|
||||||
this.src_namespaces.removeAt(index);
|
this.src_namespaces.removeAt(index);
|
||||||
}
|
}
|
||||||
getCurrentIndex(): number {
|
|
||||||
return this.filters.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replication Schedule select value exchange
|
// Replication Schedule select value exchange
|
||||||
selectSchedule($event: any): void {
|
selectSchedule($event: any): void {
|
||||||
@ -375,7 +379,8 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openCreateEditRule(ruleId?: number | string): void {
|
openCreateEditRule(ruleId?: number | string): void {
|
||||||
this.initForm();
|
this.formReset();
|
||||||
|
this.copyUpdateForm = clone(this.ruleForm.value);
|
||||||
this.inlineAlert.close();
|
this.inlineAlert.close();
|
||||||
this.filterCount = 0;
|
this.filterCount = 0;
|
||||||
this.isFilterHide = false;
|
this.isFilterHide = false;
|
||||||
@ -391,27 +396,40 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
|
|||||||
if (this.targetList.length === 0) {
|
if (this.targetList.length === 0) {
|
||||||
this.noEndpointInfo = "REPLICATION.NO_ENDPOINT_INFO";
|
this.noEndpointInfo = "REPLICATION.NO_ENDPOINT_INFO";
|
||||||
}
|
}
|
||||||
|
let registryObs = this.repService.getRegistryInfo(0);
|
||||||
if (ruleId) {
|
if (ruleId) {
|
||||||
this.policyId = +ruleId;
|
this.policyId = +ruleId;
|
||||||
this.headerTitle = "REPLICATION.EDIT_POLICY_TITLE";
|
this.headerTitle = "REPLICATION.EDIT_POLICY_TITLE";
|
||||||
this.repService.getReplicationRule(ruleId)
|
zip(registryObs, this.repService.getReplicationRule(ruleId))
|
||||||
.subscribe(response => {
|
.subscribe(([adapter, ruleInfo]) => {
|
||||||
this.copyUpdateForm = clone(response);
|
this.setFilterAndTrigger(adapter);
|
||||||
|
this.copyUpdateForm = clone(ruleInfo);
|
||||||
// set filter value is [] if callback filter value is null.
|
// set filter value is [] if callback filter value is null.
|
||||||
this.updateForm(response);
|
this.updateForm(ruleInfo);
|
||||||
// keep trigger same value
|
// keep trigger same value
|
||||||
this.copyUpdateForm.trigger = clone(response.trigger);
|
this.copyUpdateForm.trigger = clone(ruleInfo.trigger);
|
||||||
this.copyUpdateForm.filters = this.copyUpdateForm.filters === null ? [] : this.copyUpdateForm.filters;
|
this.copyUpdateForm.filters = this.copyUpdateForm.filters === null ? [] : this.copyUpdateForm.filters;
|
||||||
}, (error: any) => {
|
}, (error: any) => {
|
||||||
this.inlineAlert.showInlineError(error);
|
this.inlineAlert.showInlineError(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
registryObs.subscribe(adapter => { this.setFilterAndTrigger(adapter); });
|
||||||
this.headerTitle = "REPLICATION.ADD_POLICY";
|
this.headerTitle = "REPLICATION.ADD_POLICY";
|
||||||
this.copyUpdateForm = clone(this.ruleForm.value);
|
this.copyUpdateForm = clone(this.ruleForm.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFilterAndTrigger(adapter) {
|
||||||
|
this.supportedFilters = adapter.supported_resource_filters;
|
||||||
|
this.setFilter([]);
|
||||||
|
this.supportedFilters.forEach(element => {
|
||||||
|
this.filters.push(this.initFilter(element.type));
|
||||||
|
});
|
||||||
|
|
||||||
|
this.supportedTriggers = adapter.supported_triggers;
|
||||||
|
this.ruleForm.get("trigger").get("type").setValue(this.supportedTriggers[0]);
|
||||||
|
}
|
||||||
|
|
||||||
close(): void {
|
close(): void {
|
||||||
this.createEditRuleOpened = false;
|
this.createEditRuleOpened = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user