Fix when editting the policy, the source registry isn’t shown

Signed-off-by: FangyuanCheng <fangyuanc@vmware.com>
This commit is contained in:
FangyuanCheng 2019-04-15 15:25:21 +08:00
parent f0fa90d10f
commit a95cf813fb
2 changed files with 57 additions and 47 deletions

View File

@ -33,7 +33,7 @@
<label class="form-group-label-override required">{{'REPLICATION.SOURCE_REGISTRY' | translate}}</label>
<div class="form-select">
<div class="select endpointSelect pull-left">
<select id="src_registry_id" (change)="sourceChange($event)" formControlName="src_registry" [compareWith]="equals" ngModel>
<select id="src_registry_id" (change)="sourceChange($event)" formControlName="src_registry" [compareWith]="equals">
<option *ngFor="let source of sourceList" [ngValue]="source">{{source.name}}-{{source.url}}</option>
</select>
</div>
@ -85,7 +85,7 @@
<label class="form-group-label-override required">{{'REPLICATION.DEST_REGISTRY' | translate}}</label>
<div class="form-select">
<div class="select endpointSelect pull-left">
<select id="dest_registry" (change)="targetChange($event)" formControlName="dest_registry" [compareWith]="equals" ngModel>
<select id="dest_registry" (change)="targetChange($event)" formControlName="dest_registry" [compareWith]="equals">
<option *ngFor="let target of targetList" [ngValue]="target">{{target.name}}-{{target.url}}</option>
</select>
</div>

View File

@ -141,11 +141,9 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
}
modeChange(): void {
if (this.isPushMode) {
this.setFilter([]);
this.initRegistryInfo(0);
}
}
sourceChange($event): void {
@ -166,7 +164,11 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
get src_namespaces(): FormArray { return this.ruleForm.get('src_namespaces') as FormArray; }
get isValid() {
let controlName = this.ruleForm.controls["name"].invalid;
let controlSrcNamespace = this.ruleForm.controls["src_namespaces"].invalid;
return !(
controlName ||
controlSrcNamespace ||
!this.isRuleNameValid ||
this.noSelectedEndpoint ||
this.inProgress
@ -234,6 +236,7 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
} else {
this.isPushMode = true;
}
setTimeout(() => {
this.ruleForm.reset({
name: rule.name,
description: rule.description,
@ -266,6 +269,7 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
this.noSelectedEndpoint = false;
this.setFilter(filters);
}, 100);
// end of reset the filter list.
}
@ -396,23 +400,29 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
if (this.targetList.length === 0) {
this.noEndpointInfo = "REPLICATION.NO_ENDPOINT_INFO";
}
let registryObs = this.repService.getRegistryInfo(0);
if (ruleId) {
this.policyId = +ruleId;
this.headerTitle = "REPLICATION.EDIT_POLICY_TITLE";
zip(registryObs, this.repService.getReplicationRule(ruleId))
.subscribe(([adapter, ruleInfo]) => {
this.repService.getReplicationRule(ruleId)
.subscribe((ruleInfo) => {
let srcRegistryId = ruleInfo.src_registry.id;
this.repService.getRegistryInfo(srcRegistryId)
.subscribe(adapter => {
this.setFilterAndTrigger(adapter);
this.copyUpdateForm = clone(ruleInfo);
// set filter value is [] if callback filter value is null.
this.updateForm(ruleInfo);
// keep trigger same value
this.copyUpdateForm.trigger = clone(ruleInfo.trigger);
this.copyUpdateForm.filters = this.copyUpdateForm.filters === null ? [] : this.copyUpdateForm.filters;
// set filter value is [] if callback filter value is null.
this.updateForm(ruleInfo);
}, (error: any) => {
this.inlineAlert.showInlineError(error);
});
}, (error: any) => {
this.inlineAlert.showInlineError(error);
});
} else {
let registryObs = this.repService.getRegistryInfo(0);
registryObs.subscribe(adapter => { this.setFilterAndTrigger(adapter); });
this.headerTitle = "REPLICATION.ADD_POLICY";
this.copyUpdateForm = clone(this.ruleForm.value);