Merge pull request #7323 from zhoumeina/replication_ng

modify filter to show all the filters in once
This commit is contained in:
Wenkai Yin 2019-04-09 20:54:44 +08:00 committed by GitHub
commit dba9822477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 22 deletions

View File

@ -64,7 +64,7 @@
<div class="filterSelect" *ngFor="let filter of filters.controls; let i=index"> <div class="filterSelect" *ngFor="let filter of filters.controls; let i=index">
<div [formGroupName]="i"> <div [formGroupName]="i">
<div class="width-70"> <div class="width-70">
<label>{{"REPLICATION." + supportedFilters[i].type.toUpperCase() | translate}}:</label> <label>{{"REPLICATION." + supportedFilters[i]?.type.toUpperCase() | translate}}:</label>
</div> </div>
<label *ngIf="supportedFilters[i]?.style==='input'" aria-haspopup="true" role="tooltip" class="tooltip tooltip-validation tooltip-md tooltip-bottom-left" <label *ngIf="supportedFilters[i]?.style==='input'" aria-haspopup="true" role="tooltip" class="tooltip tooltip-validation tooltip-md tooltip-bottom-left"
[class.invalid]='(filter.value.dirty || filter.value.touched) && filter.value.invalid'> [class.invalid]='(filter.value.dirty || filter.value.touched) && filter.value.invalid'>
@ -76,12 +76,9 @@
<option *ngFor="let value of supportedFilters[i]?.values;" value="{{value}}">{{value}}</option> <option *ngFor="let value of supportedFilters[i]?.values;" value="{{value}}">{{value}}</option>
</select> </select>
</div> </div>
<clr-icon *ngIf="i=== filters.length-1" shape="times-circle" class="is-solid" (click)="deleteFilter(i)"></clr-icon>
</div> </div>
</div> </div>
</div> </div>
<clr-icon id="add-label-list" shape="plus-circle" class="is-solid mr-t-11" [hidden]="isFilterHide" (click)="addNewFilter()"></clr-icon>
</div> </div>
<!--destination registry--> <!--destination registry-->
<div *ngIf="isPushMode" class="form-group form-group-override"> <div *ngIf="isPushMode" class="form-group form-group-override">

View File

@ -94,6 +94,10 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
initRegistryInfo(id: number): void { initRegistryInfo(id: number): void {
this.repService.getRegistryInfo(id).subscribe(adapter => { this.repService.getRegistryInfo(id).subscribe(adapter => {
this.supportedFilters = adapter.supported_resource_filters; this.supportedFilters = adapter.supported_resource_filters;
this.supportedFilters.forEach(element => {
this.filters.push(this.initFilter(element.type));
});
this.supportedTriggers = adapter.supported_triggers; this.supportedTriggers = adapter.supported_triggers;
this.ruleForm.get("trigger").get("type").setValue(this.supportedTriggers[0]); this.ruleForm.get("trigger").get("type").setValue(this.supportedTriggers[0]);
}); });
@ -230,10 +234,29 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
enabled: rule.enabled enabled: rule.enabled
}); });
this.noSelectedEndpoint = false; // reset the filter list.
let filters = [];
for (let i = 0; i < this.supportedFilters.length; i++) {
let findTag: boolean = false;
if (rule.filters) { if (rule.filters) {
this.setFilter(rule.filters); rule.filters.forEach((ruleItem, j) => {
if (this.supportedFilters[i].type === ruleItem.type) {
filters.push(ruleItem);
findTag = true;
} }
});
}
if (!findTag) {
filters.push({ type: this.supportedFilters[i].type, value: "" });
}
}
this.noSelectedEndpoint = false;
this.setFilter(filters);
// end of reset the filter list.
// Force refresh view // Force refresh view
let hnd = setInterval(() => this.ref.markForCheck(), 100); let hnd = setInterval(() => this.ref.markForCheck(), 100);
setTimeout(() => clearInterval(hnd), 2000); setTimeout(() => clearInterval(hnd), 2000);
@ -285,20 +308,6 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
return this.filters.length; return this.filters.length;
} }
addNewFilter(): void {
let index = this.getCurrentIndex();
this.filters.push(this.initFilter(this.supportedFilters[index].type));
if (index + 1 >= this.supportedFilters.length) {
this.isFilterHide = true;
}
}
// delete a filter
deleteFilter(i: number): void {
this.filters.removeAt(i);
this.isFilterHide = false;
}
// Replication Schedule select value exchange // Replication Schedule select value exchange
selectSchedule($event: any): void { selectSchedule($event: any): void {
@ -326,6 +335,13 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy {
} else { } else {
copyRuleForm.dest_registry = null; copyRuleForm.dest_registry = null;
} }
let filters: any = copyRuleForm.filters;
// remove the filters which user not set.
for (let i = filters.length - 1; i >= 0; i--) {
if (filters[i].value === "") {
copyRuleForm.filters.splice(i, 1);
}
}
if (this.policyId < 0) { if (this.policyId < 0) {
this.repService this.repService

View File

@ -118,6 +118,7 @@ export interface ReplicationRule extends Base {
export class Filter { export class Filter {
type: string; type: string;
value?: string;
constructor(type: string) { constructor(type: string) {
this.type = type; this.type = type;
} }