changed event for toggling operator

This commit is contained in:
Michael Shamoon 2021-01-20 16:21:12 -08:00
parent 861b2efb1d
commit 79059b9aa7
2 changed files with 18 additions and 2 deletions

View File

@ -13,7 +13,7 @@
<div class="dropdown-menu py-0 shadow" ngbDropdownMenu attr.aria-labelledby="dropdown{{title}}">
<div class="list-group list-group-flush">
<div *ngIf="!editing && multiple" class="list-group-item d-flex">
<div class="btn-group btn-group-xs btn-group-toggle flex-fill" ngbRadioGroup [(ngModel)]="selectionModel.logicalOperator">
<div class="btn-group btn-group-xs btn-group-toggle flex-fill" ngbRadioGroup [(ngModel)]="selectionModel.logicalOperator" (change)="selectionModel.toggleOperator()">
<label ngbButtonLabel class="btn btn-outline-primary">
<input ngbButton type="radio" name="logicalOperator" value="and"> All
</label>

View File

@ -15,7 +15,8 @@ export class FilterableDropdownSelectionModel {
changed = new Subject<FilterableDropdownSelectionModel>()
multiple = false
logicalOperator = 'and'
private _logicalOperator = 'and'
temporaryLogicalOperator = this._logicalOperator
items: MatchingModel[] = []
@ -91,6 +92,18 @@ export class FilterableDropdownSelectionModel {
return this.selectionStates.get(id) || ToggleableItemState.NotSelected
}
get logicalOperator(): string {
return this.temporaryLogicalOperator
}
set logicalOperator(operator: string) {
this.temporaryLogicalOperator = operator
}
toggleOperator() {
this.changed.next(this)
}
get(id: number) {
return this.temporarySelectionStates.get(id) || ToggleableItemState.NotSelected
}
@ -111,6 +124,8 @@ export class FilterableDropdownSelectionModel {
return true
} else if (!Array.from(this.selectionStates.keys()).every(id => this.selectionStates.get(id) == this.temporarySelectionStates.get(id))) {
return true
} else if (this.temporaryLogicalOperator !== this._logicalOperator) {
return true
} else {
return false
}
@ -130,6 +145,7 @@ export class FilterableDropdownSelectionModel {
this.temporarySelectionStates.forEach((value, key) => {
this.selectionStates.set(key, value)
})
this._logicalOperator = this.temporaryLogicalOperator
}
reset() {