2020-10-08 09:21:27 -07:00
|
|
|
import { Utils } from "./utils"
|
|
|
|
|
|
|
|
type FilterCondition = "includes" | "notIncludes" | "isEmpty" | "isNotEmpty"
|
|
|
|
|
|
|
|
class FilterClause {
|
|
|
|
propertyId: string
|
|
|
|
condition: FilterCondition
|
|
|
|
values: string[]
|
|
|
|
|
|
|
|
static filterConditionDisplayString(filterCondition: FilterCondition) {
|
|
|
|
switch (filterCondition) {
|
|
|
|
case "includes": return "includes"
|
|
|
|
case "notIncludes": return "doesn't include"
|
|
|
|
case "isEmpty": return "is empty"
|
|
|
|
case "isNotEmpty": return "is not empty"
|
2020-10-15 11:59:56 -07:00
|
|
|
default: {
|
|
|
|
Utils.assertFailure()
|
|
|
|
return "(unknown)"
|
|
|
|
}
|
2020-10-08 09:21:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(o: any = {}) {
|
|
|
|
this.propertyId = o.propertyId || ""
|
|
|
|
this.condition = o.condition || "includes"
|
|
|
|
this.values = o.values?.slice() || []
|
|
|
|
}
|
|
|
|
|
|
|
|
isEqual(o: FilterClause) {
|
|
|
|
return (
|
|
|
|
this.propertyId === o.propertyId &&
|
|
|
|
this.condition === o.condition &&
|
|
|
|
Utils.arraysEqual(this.values, o.values)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { FilterClause, FilterCondition }
|