Simplify the operations a bit, fix number comparison stuff
This commit is contained in:
parent
301e875308
commit
c4842954d8
@ -24,7 +24,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #dateValue let-atom="atom">
|
||||
<ng-template #comparisonValueTemplate let-atom="atom">
|
||||
@if (getCustomFieldByID(atom.field)?.data_type === CustomFieldDataType.Date) {
|
||||
<input class="form-control" placeholder="yyyy-mm-dd"
|
||||
[(ngModel)]="atom.value"
|
||||
@ -33,6 +33,8 @@
|
||||
<button class="btn btn-sm btn-outline-secondary rounded-end" (click)="d.toggle()" type="button">
|
||||
<i-bs name="calendar-event"></i-bs>
|
||||
</button>
|
||||
} @else if (getCustomFieldByID(atom.field)?.data_type === CustomFieldDataType.Float || getCustomFieldByID(atom.field)?.data_type === CustomFieldDataType.Integer) {
|
||||
<input class="w-25 form-control rounded-end" type="number" [(ngModel)]="atom.value" [disabled]="disabled">
|
||||
} @else {
|
||||
<input class="w-25 form-control rounded-end" type="text" [(ngModel)]="atom.value" [disabled]="disabled">
|
||||
}
|
||||
@ -65,10 +67,16 @@
|
||||
</select>
|
||||
}
|
||||
@case (CustomFieldQueryOperator.GreaterThanOrEqual) {
|
||||
<ng-container *ngTemplateOutlet="dateValue; context: { atom: atom }"></ng-container>
|
||||
<ng-container *ngTemplateOutlet="comparisonValueTemplate; context: { atom: atom }"></ng-container>
|
||||
}
|
||||
@case (CustomFieldQueryOperator.LessThanOrEqual) {
|
||||
<ng-container *ngTemplateOutlet="dateValue; context: { atom: atom }"></ng-container>
|
||||
<ng-container *ngTemplateOutlet="comparisonValueTemplate; context: { atom: atom }"></ng-container>
|
||||
}
|
||||
@case (CustomFieldQueryOperator.GreaterThan) {
|
||||
<ng-container *ngTemplateOutlet="comparisonValueTemplate; context: { atom: atom }"></ng-container>
|
||||
}
|
||||
@case (CustomFieldQueryOperator.LessThan) {
|
||||
<ng-container *ngTemplateOutlet="comparisonValueTemplate; context: { atom: atom }"></ng-container>
|
||||
}
|
||||
@default {
|
||||
<input class="w-25 form-control rounded-end" type="text" [(ngModel)]="atom.value" [disabled]="disabled">
|
||||
|
@ -15,8 +15,6 @@ export enum CustomFieldQueryOperator {
|
||||
Exists = 'exists',
|
||||
Contains = 'contains',
|
||||
IContains = 'icontains',
|
||||
IStartsWith = 'istartswith',
|
||||
IEndsWith = 'iendswith',
|
||||
GreaterThan = 'gt',
|
||||
GreaterThanOrEqual = 'gte',
|
||||
LessThan = 'lt',
|
||||
@ -31,8 +29,6 @@ export const CUSTOM_FIELD_QUERY_OPERATOR_LABELS = {
|
||||
[CustomFieldQueryOperator.Exists]: $localize`Exists`,
|
||||
[CustomFieldQueryOperator.Contains]: $localize`Contains`,
|
||||
[CustomFieldQueryOperator.IContains]: $localize`Contains (case-insensitive)`,
|
||||
[CustomFieldQueryOperator.IStartsWith]: $localize`Starts with (case-insensitive)`,
|
||||
[CustomFieldQueryOperator.IEndsWith]: $localize`Ends with (case-insensitive)`,
|
||||
[CustomFieldQueryOperator.GreaterThan]: $localize`Greater than`,
|
||||
[CustomFieldQueryOperator.GreaterThanOrEqual]: $localize`Greater than or equal to`,
|
||||
[CustomFieldQueryOperator.LessThan]: $localize`Less than`,
|
||||
@ -45,21 +41,18 @@ export enum CustomFieldQueryOperatorGroups {
|
||||
String = 'string',
|
||||
Arithmetic = 'arithmetic',
|
||||
Containment = 'containment',
|
||||
Subset = 'subset',
|
||||
Date = 'date',
|
||||
}
|
||||
|
||||
// Modified from filters.py > SUPPORTED_EXPR_OPERATORS
|
||||
export const CUSTOM_FIELD_QUERY_OPERATORS_BY_GROUP = {
|
||||
[CustomFieldQueryOperatorGroups.Basic]: [
|
||||
CustomFieldQueryOperator.Exact,
|
||||
CustomFieldQueryOperator.In,
|
||||
CustomFieldQueryOperator.IsNull,
|
||||
CustomFieldQueryOperator.Exists,
|
||||
CustomFieldQueryOperator.IsNull,
|
||||
CustomFieldQueryOperator.Exact,
|
||||
],
|
||||
[CustomFieldQueryOperatorGroups.String]: [
|
||||
CustomFieldQueryOperator.IContains,
|
||||
CustomFieldQueryOperator.IStartsWith,
|
||||
CustomFieldQueryOperator.IEndsWith,
|
||||
],
|
||||
[CustomFieldQueryOperatorGroups.String]: [CustomFieldQueryOperator.IContains],
|
||||
[CustomFieldQueryOperatorGroups.Arithmetic]: [
|
||||
CustomFieldQueryOperator.GreaterThan,
|
||||
CustomFieldQueryOperator.GreaterThanOrEqual,
|
||||
@ -69,6 +62,7 @@ export const CUSTOM_FIELD_QUERY_OPERATORS_BY_GROUP = {
|
||||
[CustomFieldQueryOperatorGroups.Containment]: [
|
||||
CustomFieldQueryOperator.Contains,
|
||||
],
|
||||
[CustomFieldQueryOperatorGroups.Subset]: [CustomFieldQueryOperator.In],
|
||||
[CustomFieldQueryOperatorGroups.Date]: [
|
||||
CustomFieldQueryOperator.GreaterThanOrEqual,
|
||||
CustomFieldQueryOperator.LessThanOrEqual,
|
||||
@ -106,7 +100,10 @@ export const CUSTOM_FIELD_QUERY_OPERATOR_GROUPS_BY_TYPE = {
|
||||
CustomFieldQueryOperatorGroups.Basic,
|
||||
CustomFieldQueryOperatorGroups.Containment,
|
||||
],
|
||||
[CustomFieldDataType.Select]: [CustomFieldQueryOperatorGroups.Basic],
|
||||
[CustomFieldDataType.Select]: [
|
||||
CustomFieldQueryOperatorGroups.Basic,
|
||||
CustomFieldQueryOperatorGroups.Subset,
|
||||
],
|
||||
}
|
||||
|
||||
export const CUSTOM_FIELD_QUERY_VALUE_TYPES_BY_OPERATOR = {
|
||||
@ -114,15 +111,13 @@ export const CUSTOM_FIELD_QUERY_VALUE_TYPES_BY_OPERATOR = {
|
||||
[CustomFieldQueryOperator.IsNull]: 'boolean',
|
||||
[CustomFieldQueryOperator.Exists]: 'boolean',
|
||||
[CustomFieldQueryOperator.IContains]: 'string',
|
||||
[CustomFieldQueryOperator.GreaterThanOrEqual]: 'string',
|
||||
[CustomFieldQueryOperator.LessThanOrEqual]: 'string',
|
||||
[CustomFieldQueryOperator.GreaterThanOrEqual]: 'string|number',
|
||||
[CustomFieldQueryOperator.LessThanOrEqual]: 'string|number',
|
||||
[CustomFieldQueryOperator.GreaterThan]: 'number',
|
||||
[CustomFieldQueryOperator.LessThan]: 'number',
|
||||
// TODO: Implement these
|
||||
// [CustomFieldQueryOperator.In]: 'array',
|
||||
// [CustomFieldQueryOperator.Contains]: 'string',
|
||||
// [CustomFieldQueryOperator.IStartsWith]: 'string',
|
||||
// [CustomFieldQueryOperator.IEndsWith]: 'string',
|
||||
// [CustomFieldQueryOperator.GreaterThan]: 'number',
|
||||
// [CustomFieldQueryOperator.LessThan]: 'number',
|
||||
// [CustomFieldQueryOperator.Range]: 'array',
|
||||
}
|
||||
|
||||
@ -189,23 +184,46 @@ export class CustomFieldQueryAtom extends CustomFieldQueryElement {
|
||||
}
|
||||
|
||||
override set operator(operator: string) {
|
||||
const newType: string = CUSTOM_FIELD_QUERY_VALUE_TYPES_BY_OPERATOR[operator]
|
||||
if (typeof this.value !== newType) {
|
||||
switch (newType) {
|
||||
const newTypes: string[] =
|
||||
CUSTOM_FIELD_QUERY_VALUE_TYPES_BY_OPERATOR[operator]?.split('|')
|
||||
if (!newTypes) {
|
||||
this.value = null
|
||||
}
|
||||
if (!newTypes.includes(typeof this.value)) {
|
||||
if (newTypes.length === 1) {
|
||||
switch (newTypes[0]) {
|
||||
case 'string':
|
||||
this.value = ''
|
||||
break
|
||||
case 'boolean':
|
||||
this.value = 'true'
|
||||
break
|
||||
// TODO: Implement these
|
||||
case 'number':
|
||||
try {
|
||||
this.value = parseFloat(this.value as string).toString()
|
||||
} catch (e) {
|
||||
this.value = null
|
||||
}
|
||||
break
|
||||
// TODO: Implement all
|
||||
default:
|
||||
this.value = null
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if (newTypes.includes('number')) {
|
||||
try {
|
||||
this.value = parseFloat(this.value as string).toString()
|
||||
} catch (e) {
|
||||
this.value = null
|
||||
}
|
||||
} else {
|
||||
this.value = null
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
['true', 'false'].includes(this.value as string) &&
|
||||
newType === 'string'
|
||||
newTypes.includes('string')
|
||||
) {
|
||||
this.value = ''
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user