mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-12 04:37:44 +02:00
$size query (#9591)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import core, { AnyAttribute } from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { Context, parseContext, Process, SelectedContext } from '@hcengineering/process'
|
||||
import {
|
||||
AnyComponent,
|
||||
@@ -29,6 +30,7 @@
|
||||
} from '@hcengineering/ui'
|
||||
import view from '@hcengineering/view-resources/src/plugin'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { getContext } from '../../utils'
|
||||
import ContextSelectorPopup from '../attributeEditors/ContextSelectorPopup.svelte'
|
||||
import ContextValue from '../attributeEditors/ContextValue.svelte'
|
||||
|
||||
@@ -39,13 +41,41 @@
|
||||
export let attribute: AnyAttribute
|
||||
export let baseEditor: AnyComponent | undefined
|
||||
|
||||
const client = getClient()
|
||||
|
||||
$: numberContext = getContext(client, process, core.class.TypeNumber, 'attribute')
|
||||
|
||||
const modes: DropdownIntlItem[] = [
|
||||
{ id: 'all', label: view.string.FilterArrayAll },
|
||||
{ id: 'any', label: view.string.FilterArrayAny },
|
||||
{ id: 'notall', label: view.string.NotContains }
|
||||
{ id: 'notall', label: view.string.NotContains },
|
||||
{ id: 'size', label: view.string.ArraySizeEquals },
|
||||
{ id: 'sizeGt', label: view.string.ArraySizeGt },
|
||||
{ id: 'sizeGte', label: view.string.ArraySizeGte },
|
||||
{ id: 'sizeLt', label: view.string.ArraySizeLt },
|
||||
{ id: 'sizeLte', label: view.string.ArraySizeLte }
|
||||
]
|
||||
|
||||
let mode = value == null ? 'all' : value.$all !== undefined ? 'all' : value.$in !== undefined ? 'any' : 'notIncludes'
|
||||
let mode =
|
||||
value == null
|
||||
? 'all'
|
||||
: value.$all !== undefined
|
||||
? 'all'
|
||||
: value.$in !== undefined
|
||||
? 'any'
|
||||
: value.$nin !== undefined
|
||||
? 'notIncludes'
|
||||
: value.$size !== undefined
|
||||
? typeof value.$size === 'object'
|
||||
? Object.keys(value.$size)[0] === '$gt'
|
||||
? 'sizeGt'
|
||||
: Object.keys(value.$size)[0] === '$gte'
|
||||
? 'sizeGte'
|
||||
: Object.keys(value.$size)[0] === '$lt'
|
||||
? 'sizeLt'
|
||||
: 'sizeLte'
|
||||
: 'size'
|
||||
: 'all'
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
@@ -58,7 +88,7 @@
|
||||
{
|
||||
process,
|
||||
masterTag: process.masterTag,
|
||||
context,
|
||||
context: isSize(mode) ? numberContext : context,
|
||||
attribute,
|
||||
onSelect
|
||||
},
|
||||
@@ -78,6 +108,16 @@
|
||||
} else if (value?.$nin !== undefined) {
|
||||
mode = 'notIncludes'
|
||||
val = value.$nin
|
||||
} else if (value?.$size !== undefined) {
|
||||
if (typeof value.$size === 'object') {
|
||||
const operator = Object.keys(value.$size)[0]
|
||||
val = value.$size[operator]
|
||||
mode =
|
||||
operator === '$gt' ? 'sizeGt' : operator === '$gte' ? 'sizeGte' : operator === '$lt' ? 'sizeLt' : 'sizeLte'
|
||||
} else {
|
||||
mode = 'size'
|
||||
val = value.$size
|
||||
}
|
||||
} else {
|
||||
mode = 'all'
|
||||
val = undefined
|
||||
@@ -86,16 +126,14 @@
|
||||
}
|
||||
|
||||
function onSelect (res: SelectedContext | null): void {
|
||||
val = res === null ? undefined : '$' + JSON.stringify(res)
|
||||
buildResult()
|
||||
buildResult(res === null ? undefined : '$' + JSON.stringify(res))
|
||||
}
|
||||
|
||||
function onChange (value: any | undefined): void {
|
||||
val = value
|
||||
buildResult()
|
||||
buildResult(value)
|
||||
}
|
||||
|
||||
function buildResult () {
|
||||
function buildResult (val: any | undefined) {
|
||||
if (val === undefined || val === '') {
|
||||
dispatch('change', null)
|
||||
return
|
||||
@@ -106,12 +144,21 @@
|
||||
result = { $all: val }
|
||||
} else if (mode === 'any') {
|
||||
result = { $in: val }
|
||||
} else {
|
||||
} else if (mode === 'notIncludes') {
|
||||
result = { $nin: val }
|
||||
} else if (mode === 'size') {
|
||||
result = { $size: val }
|
||||
} else if (mode.startsWith('size')) {
|
||||
const operator = mode === 'sizeGt' ? '$gt' : mode === 'sizeGte' ? '$gte' : mode === 'sizeLt' ? '$lt' : '$lte'
|
||||
result = { $size: { [operator]: val } }
|
||||
}
|
||||
|
||||
value = result
|
||||
dispatch('change', result)
|
||||
}
|
||||
|
||||
function isSize (mode: string): boolean {
|
||||
return mode.startsWith('size')
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex-row-center flex-gap-4">
|
||||
@@ -124,44 +171,78 @@
|
||||
width={'100%'}
|
||||
on:selected={(e) => {
|
||||
mode = e.detail
|
||||
buildResult()
|
||||
buildResult(val)
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="text-input" class:context={contextValue}>
|
||||
{#if contextValue}
|
||||
{#if !isSize(mode)}
|
||||
{#if contextValue}
|
||||
<ContextValue
|
||||
{process}
|
||||
masterTag={process.masterTag}
|
||||
{contextValue}
|
||||
{context}
|
||||
{attribute}
|
||||
category={'attribute'}
|
||||
attrClass={core.class.ArrOf}
|
||||
on:update={(e) => {
|
||||
onSelect(e.detail)
|
||||
}}
|
||||
/>
|
||||
{:else}
|
||||
<div class="w-full">
|
||||
{#if baseEditor}
|
||||
<Component
|
||||
is={baseEditor}
|
||||
props={{
|
||||
label: attribute?.label,
|
||||
placeholder: attribute?.label,
|
||||
kind: 'ghost',
|
||||
size: 'large',
|
||||
width: '100%',
|
||||
justify: 'left',
|
||||
readonly,
|
||||
type: attribute?.type,
|
||||
value: val,
|
||||
onChange,
|
||||
focus
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{:else if contextValue}
|
||||
<ContextValue
|
||||
{process}
|
||||
masterTag={process.masterTag}
|
||||
{contextValue}
|
||||
{context}
|
||||
context={numberContext}
|
||||
{attribute}
|
||||
category={'attribute'}
|
||||
attrClass={core.class.ArrOf}
|
||||
attrClass={core.class.TypeNumber}
|
||||
on:update={(e) => {
|
||||
onSelect(e.detail)
|
||||
}}
|
||||
/>
|
||||
{:else}
|
||||
{:else if !Number.isNaN(val)}
|
||||
<div class="w-full">
|
||||
{#if baseEditor}
|
||||
<Component
|
||||
is={baseEditor}
|
||||
props={{
|
||||
label: attribute?.label,
|
||||
placeholder: attribute?.label,
|
||||
kind: 'ghost',
|
||||
size: 'large',
|
||||
width: '100%',
|
||||
justify: 'left',
|
||||
readonly,
|
||||
type: attribute?.type,
|
||||
value: val,
|
||||
onChange,
|
||||
focus
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
<Component
|
||||
is={view.component.NumberEditor}
|
||||
props={{
|
||||
label: attribute?.label,
|
||||
placeholder: attribute?.label,
|
||||
kind: 'ghost',
|
||||
size: 'large',
|
||||
width: '100%',
|
||||
justify: 'left',
|
||||
readonly,
|
||||
type: core.class.TypeNumber,
|
||||
value: val,
|
||||
onChange,
|
||||
focus
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="button flex-row-center">
|
||||
|
||||
Reference in New Issue
Block a user