@operato/form 2.0.0-alpha.0 → 2.0.0-alpha.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -0
- package/demo/index.html +14 -3
- package/dist/src/components/ox-custom-input.d.ts +1 -1
- package/dist/src/components/ox-custom-select.d.ts +1 -1
- package/dist/src/components/ox-file-uploader.d.ts +1 -1
- package/dist/src/components/ox-file-uploader.js +7 -7
- package/dist/src/components/ox-file-uploader.js.map +1 -1
- package/dist/src/components/ox-form-paginator.d.ts +1 -1
- package/dist/src/components/ox-search-form.d.ts +10 -25
- package/dist/src/components/ox-search-form.js +163 -89
- package/dist/src/components/ox-search-form.js.map +1 -1
- package/dist/src/filters/filter-checkbox.d.ts +1 -1
- package/dist/src/filters/filter-checkbox.js +4 -2
- package/dist/src/filters/filter-checkbox.js.map +1 -1
- package/dist/src/filters/filter-input-barcode.d.ts +1 -1
- package/dist/src/filters/filter-input-barcode.js +2 -2
- package/dist/src/filters/filter-input-barcode.js.map +1 -1
- package/dist/src/filters/filter-input.d.ts +1 -1
- package/dist/src/filters/filter-input.js.map +1 -1
- package/dist/src/filters/filter-range-date.d.ts +1 -1
- package/dist/src/filters/filter-range-date.js +14 -3
- package/dist/src/filters/filter-range-date.js.map +1 -1
- package/dist/src/filters/filter-range-number.d.ts +1 -1
- package/dist/src/filters/filter-range-number.js.map +1 -1
- package/dist/src/filters/filter-select.d.ts +1 -1
- package/dist/src/filters/filter-select.js +23 -11
- package/dist/src/filters/filter-select.js.map +1 -1
- package/dist/src/filters/filter-styles.js +38 -28
- package/dist/src/filters/filter-styles.js.map +1 -1
- package/dist/src/filters/index.d.ts +1 -1
- package/dist/src/filters/index.js +1 -1
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/filters/ox-filters-form-base.d.ts +8 -9
- package/dist/src/filters/ox-filters-form-base.js +126 -72
- package/dist/src/filters/ox-filters-form-base.js.map +1 -1
- package/dist/src/filters/registry.d.ts +1 -1
- package/dist/src/filters/registry.js.map +1 -1
- package/dist/src/styles/search-form-styles.js +1 -1
- package/dist/src/styles/search-form-styles.js.map +1 -1
- package/dist/src/types.d.ts +59 -0
- package/dist/src/types.js.map +1 -0
- package/dist/stories/{ox-filter-form-barcode.stories.js → ox-filters-form-barcode.stories.js} +29 -12
- package/dist/stories/ox-filters-form-barcode.stories.js.map +1 -0
- package/dist/stories/{ox-filter-form-base.stories.d.ts → ox-filters-form-base-bounded.stories.d.ts} +3 -2
- package/dist/stories/ox-filters-form-base-bounded.stories.js +182 -0
- package/dist/stories/ox-filters-form-base-bounded.stories.js.map +1 -0
- package/dist/stories/ox-filters-form-base-change-handler.stories.d.ts +30 -0
- package/dist/stories/ox-filters-form-base-change-handler.stories.js +194 -0
- package/dist/stories/ox-filters-form-base-change-handler.stories.js.map +1 -0
- package/dist/stories/ox-filters-form-base-dependencies.stories.d.ts +30 -0
- package/dist/stories/ox-filters-form-base-dependencies.stories.js +182 -0
- package/dist/stories/ox-filters-form-base-dependencies.stories.js.map +1 -0
- package/dist/stories/ox-filters-form-base.stories.d.ts +30 -0
- package/dist/stories/ox-filters-form-base.stories.js +142 -0
- package/dist/stories/ox-filters-form-base.stories.js.map +1 -0
- package/dist/stories/ox-search-form.stories.d.ts +34 -0
- package/dist/stories/ox-search-form.stories.js +219 -0
- package/dist/stories/ox-search-form.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/components/ox-file-uploader.ts +7 -7
- package/src/components/ox-search-form.ts +195 -122
- package/src/filters/filter-checkbox.ts +5 -3
- package/src/filters/filter-input-barcode.ts +3 -3
- package/src/filters/filter-input.ts +1 -1
- package/src/filters/filter-range-date.ts +21 -6
- package/src/filters/filter-range-number.ts +1 -1
- package/src/filters/filter-select.ts +29 -20
- package/src/filters/filter-styles.ts +38 -28
- package/src/filters/index.ts +1 -1
- package/src/filters/ox-filters-form-base.ts +136 -72
- package/src/filters/registry.ts +1 -1
- package/src/styles/search-form-styles.ts +1 -1
- package/src/types.ts +96 -0
- package/stories/{ox-filter-form-barcode.stories.ts → ox-filters-form-barcode.stories.ts} +30 -13
- package/stories/ox-filters-form-base-bounded.stories.ts +206 -0
- package/stories/ox-filters-form-base-change-handler.stories.ts +218 -0
- package/stories/ox-filters-form-base.stories.ts +159 -0
- package/stories/ox-search-form.stories.ts +244 -0
- package/themes/app-theme.css +7 -7
- package/themes/form-theme.css +1 -1
- package/themes/input-theme.css +32 -0
- package/dist/src/filters/types.d.ts +0 -17
- package/dist/src/filters/types.js.map +0 -1
- package/dist/stories/ox-filter-form-barcode.stories.js.map +0 -1
- package/dist/stories/ox-filter-form-base.stories.js +0 -82
- package/dist/stories/ox-filter-form-base.stories.js.map +0 -1
- package/src/filters/types.ts +0 -47
- package/stories/ox-filter-form-base.stories.ts +0 -97
- /package/dist/src/{filters/types.js → types.js} +0 -0
- /package/dist/stories/{ox-filter-form-barcode.stories.d.ts → ox-filters-form-barcode.stories.d.ts} +0 -0
|
@@ -2,56 +2,68 @@ import { css } from 'lit'
|
|
|
2
2
|
|
|
3
3
|
export const FilterStyles = css`
|
|
4
4
|
:host {
|
|
5
|
-
--ox-input-placeholder-color: var(--primary-color);
|
|
6
|
-
|
|
7
|
-
--ox-input-
|
|
8
|
-
--ox-input-border: 1px solid
|
|
9
|
-
--ox-input-
|
|
10
|
-
--ox-input-
|
|
11
|
-
--ox-input-
|
|
12
|
-
--ox-
|
|
13
|
-
|
|
14
|
-
--ox-filters-
|
|
15
|
-
|
|
16
|
-
--ox-filters-form-
|
|
17
|
-
--ox-
|
|
5
|
+
--ox-filters-input-placeholder-color: var(--input-placeholder-color, var(--primary-color));
|
|
6
|
+
|
|
7
|
+
--ox-filters-input-border: var(--input-border, 1px solid rgba(0, 0, 0, 0.2));
|
|
8
|
+
--ox-filters-input-focus-border: var(--input-focus-border, 1px solid var(--primary-color));
|
|
9
|
+
--ox-filters-input-font: var(--input-font, normal 14px var(--theme-font));
|
|
10
|
+
--ox-filters-input-color: var(--input-color, var(--primary-text-color));
|
|
11
|
+
--ox-filters-input-focus-color: var(--input-focus-color, var(--primary-color));
|
|
12
|
+
--ox-filters-label-font: var(--label-font, normal 14px var(--theme-font));
|
|
13
|
+
--ox-filters-label-color: var(--label-color, var(--primary-text-color));
|
|
14
|
+
--ox-filters-input-background-color: transparent;
|
|
15
|
+
|
|
16
|
+
--ox-filters-form-gap: var(--input-gap-vertical, 8px) var(--input-gap-horizontal, 16px);
|
|
17
|
+
--ox-filters-input-padding: var(--input-padding, 6px 2px);
|
|
18
|
+
|
|
19
|
+
--ox-select-padding: var(--ox-filters-input-padding);
|
|
20
|
+
--ox-checkbox-background-color: var(--ox-filters-input-background-color, transparent);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
label {
|
|
21
|
-
font: var(--ox-filters-
|
|
22
|
-
color: var(--ox-filters-
|
|
24
|
+
font: var(--ox-filters-label-font);
|
|
25
|
+
color: var(--ox-filters-label-color);
|
|
23
26
|
}
|
|
27
|
+
|
|
24
28
|
span {
|
|
25
|
-
margin-right: var(--margin-narrow);
|
|
26
29
|
text-transform: capitalize;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
input::placeholder {
|
|
30
|
-
color: var(--ox-input-placeholder-color);
|
|
33
|
+
color: var(--ox-filters-input-placeholder-color);
|
|
31
34
|
opacity: 0.6;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
input {
|
|
38
|
+
padding: var(--ox-filters-input-padding);
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
ox-select,
|
|
35
42
|
input {
|
|
36
|
-
padding: var(--input-padding);
|
|
37
43
|
border: none;
|
|
38
|
-
border-bottom: var(--ox-input-border);
|
|
39
|
-
font: var(--ox-input-font);
|
|
40
|
-
color: var(--ox-input-color);
|
|
44
|
+
border-bottom: var(--ox-filters-input-border);
|
|
45
|
+
font: var(--ox-filters-input-font);
|
|
46
|
+
color: var(--ox-filters-input-color);
|
|
47
|
+
background-color: var(--ox-filters-input-background-color, transparent);
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
ox-select:focus,
|
|
44
51
|
input:focus {
|
|
45
52
|
outline: none;
|
|
46
|
-
border-bottom: var(--ox-input-focus-border);
|
|
47
|
-
color: var(--
|
|
53
|
+
border-bottom: var(--ox-filters-input-focus-border);
|
|
54
|
+
color: var(--ox-filters-input-focus-color);
|
|
48
55
|
}
|
|
56
|
+
|
|
49
57
|
ox-select {
|
|
50
|
-
|
|
58
|
+
min-width: 90px;
|
|
59
|
+
max-width: 170px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ox-input-search {
|
|
63
|
+
max-width: 150px;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
input[type='number'] {
|
|
54
|
-
padding-right: var(--padding-narrow);
|
|
55
67
|
max-width: 90px;
|
|
56
68
|
}
|
|
57
69
|
|
|
@@ -59,15 +71,13 @@ export const FilterStyles = css`
|
|
|
59
71
|
input[type*='time'],
|
|
60
72
|
input[type='week'],
|
|
61
73
|
input[type='month'] {
|
|
62
|
-
padding: 8px var(--padding-narrow) 8px var(--padding-default);
|
|
63
74
|
max-width: 170px;
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
@media only screen and (max-width: 460px) {
|
|
67
78
|
:host {
|
|
68
79
|
--ox-filters-form-label-font: bold 13px var(--theme-font);
|
|
69
|
-
--ox-input-font: normal 16px var(--theme-font);
|
|
70
|
-
--ox-filters-form-gap: var(--margin-narrow);
|
|
80
|
+
--ox-filters-input-font: normal 16px var(--theme-font);
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
input[from],
|
package/src/filters/index.ts
CHANGED
|
@@ -4,23 +4,19 @@ import '@operato/popup/ox-popup-list.js'
|
|
|
4
4
|
import '@operato/input/ox-input-search.js'
|
|
5
5
|
|
|
6
6
|
import json5 from 'json5'
|
|
7
|
-
import { css, html, LitElement, PropertyValues, TemplateResult } from 'lit'
|
|
7
|
+
import { css, html, LitElement, nothing, PropertyValueMap, PropertyValues, TemplateResult } from 'lit'
|
|
8
8
|
import { customElement, property, queryAsync } from 'lit/decorators.js'
|
|
9
9
|
|
|
10
|
+
import { getDefaultValue } from '@operato/time-calculator'
|
|
11
|
+
|
|
10
12
|
import { FilterStyles } from './filter-styles.js'
|
|
11
13
|
import { getFilterRenderer } from './registry.js'
|
|
12
|
-
import { FilterConfig, FilterOperator, FilterValue } from '
|
|
14
|
+
import { FilterConfig, FilterOperator, FilterSelectRenderer, FilterValue } from '../types.js'
|
|
13
15
|
|
|
14
16
|
export type QueryFilterRangeValue = [from: number, to: number]
|
|
15
17
|
|
|
16
|
-
export type QueryFilter = {
|
|
17
|
-
name: string
|
|
18
|
-
operator: FilterOperator
|
|
19
|
-
value: any
|
|
20
|
-
}
|
|
21
|
-
|
|
22
18
|
@customElement('ox-filters-form-base')
|
|
23
|
-
export class
|
|
19
|
+
export class OxFiltersFormBase extends LitElement {
|
|
24
20
|
static styles = [
|
|
25
21
|
FilterStyles,
|
|
26
22
|
css`
|
|
@@ -39,6 +35,7 @@ export class FiltersFormBase extends LitElement {
|
|
|
39
35
|
form > * {
|
|
40
36
|
display: flex;
|
|
41
37
|
align-items: center;
|
|
38
|
+
gap: var(--input-intra-gap, 7px);
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
label span {
|
|
@@ -53,8 +50,8 @@ export class FiltersFormBase extends LitElement {
|
|
|
53
50
|
`
|
|
54
51
|
]
|
|
55
52
|
|
|
56
|
-
@property({ type:
|
|
57
|
-
@property({ type:
|
|
53
|
+
@property({ type: Array }) value: FilterValue[] = []
|
|
54
|
+
@property({ type: Array }) filters: FilterConfig[] = []
|
|
58
55
|
@property({ type: Boolean, attribute: 'url-params-sensitive' }) urlParamsSensitive?: boolean
|
|
59
56
|
@property({ type: Boolean, attribute: 'autofocus' }) autofocus: boolean = true
|
|
60
57
|
|
|
@@ -62,24 +59,63 @@ export class FiltersFormBase extends LitElement {
|
|
|
62
59
|
|
|
63
60
|
private _popstateEventHandler?: EventListener
|
|
64
61
|
private _filtersChangeHandler?: EventListener
|
|
62
|
+
private autoUpdateTargetsOnChange: { [name: string]: string[] } = {}
|
|
65
63
|
|
|
66
64
|
connectedCallback(): void {
|
|
67
65
|
super.connectedCallback()
|
|
68
66
|
|
|
69
67
|
this.renderRoot.addEventListener('change', async (e: Event) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
const { target, detail: value } = e as CustomEvent
|
|
69
|
+
const name = (target as HTMLInputElement).name
|
|
70
|
+
const {
|
|
71
|
+
label,
|
|
72
|
+
type,
|
|
73
|
+
operator,
|
|
74
|
+
value: defaultValue,
|
|
75
|
+
onchange
|
|
76
|
+
} = this.filters.find(filter => filter.name == name) || {}
|
|
77
|
+
|
|
78
|
+
if (this.autoUpdateTargetsOnChange[name]) {
|
|
79
|
+
/*
|
|
80
|
+
일단은 심플하게, boundTo로 연결된 필터값이 바뀌면, 폼 전체를 update하도록 함.
|
|
81
|
+
*/
|
|
82
|
+
;(this.autoUpdateTargetsOnChange[name] || []).forEach(name => {
|
|
83
|
+
const target = this.renderRoot.querySelector(`[name='${name}']`)
|
|
84
|
+
if (target) {
|
|
85
|
+
;(target as HTMLInputElement).value = ''
|
|
77
86
|
}
|
|
78
87
|
})
|
|
79
|
-
|
|
88
|
+
|
|
89
|
+
this.requestUpdate()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const keepGoing = onchange ? await onchange.call(null, value ?? (target as HTMLInputElement).value, this) : true
|
|
93
|
+
|
|
94
|
+
keepGoing &&
|
|
95
|
+
this.dispatchEvent(
|
|
96
|
+
new CustomEvent('filters-change', {
|
|
97
|
+
bubbles: true,
|
|
98
|
+
composed: true,
|
|
99
|
+
detail: {
|
|
100
|
+
filters: this.value,
|
|
101
|
+
from: 'filters-form'
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
)
|
|
80
105
|
})
|
|
81
106
|
}
|
|
82
107
|
|
|
108
|
+
buildDefaultValue(operator: FilterOperator, defaultValue: any) {
|
|
109
|
+
if (defaultValue === undefined) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
if (operator == 'between') {
|
|
113
|
+
return (defaultValue as Array<any>).map(v => getDefaultValue(v, this))
|
|
114
|
+
} else {
|
|
115
|
+
return getDefaultValue(defaultValue, this)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
83
119
|
render(): TemplateResult {
|
|
84
120
|
return html`
|
|
85
121
|
<form
|
|
@@ -88,74 +124,88 @@ export class FiltersFormBase extends LitElement {
|
|
|
88
124
|
}}
|
|
89
125
|
>
|
|
90
126
|
${this.filters.map((filter: FilterConfig) => {
|
|
91
|
-
const { name, label, type, operator } = filter
|
|
127
|
+
const { name, label, type, operator, value: defaultValue } = filter
|
|
92
128
|
const idx = operator === 'between' ? 1 : 0
|
|
93
129
|
const renderer = getFilterRenderer(
|
|
94
130
|
operator === 'like' || operator === 'i_like' || operator === 'i_nlike' || operator === 'nlike'
|
|
95
131
|
? 'text'
|
|
96
132
|
: type
|
|
97
133
|
)[idx]
|
|
98
|
-
|
|
134
|
+
|
|
135
|
+
const value =
|
|
136
|
+
this.value?.find(filter => filter.name == name)?.value ?? this.buildDefaultValue(operator!, defaultValue)
|
|
99
137
|
|
|
100
138
|
if (!renderer) {
|
|
101
|
-
return
|
|
139
|
+
return nothing
|
|
102
140
|
}
|
|
103
141
|
|
|
104
142
|
return type === 'search'
|
|
105
143
|
? html`<ox-input-search name="search" .value=${value} ?autofocus=${this.autofocus}></ox-input-search>`
|
|
106
|
-
: type
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
name=${name}
|
|
116
|
-
placeholder=${label}
|
|
117
|
-
.value=${value}
|
|
118
|
-
@change=${(e: CustomEvent) =>
|
|
119
|
-
e.target?.dispatchEvent(
|
|
120
|
-
new CustomEvent('filter-change', {
|
|
121
|
-
detail: {
|
|
122
|
-
name,
|
|
123
|
-
operator,
|
|
124
|
-
value: e.detail
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
)}
|
|
128
|
-
>
|
|
129
|
-
<ox-popup-list multiple attr-selected="checked" with-search>
|
|
130
|
-
${renderer(filter, value, this)}
|
|
131
|
-
</ox-popup-list>
|
|
132
|
-
</ox-select>
|
|
133
|
-
`
|
|
134
|
-
: html`
|
|
135
|
-
<ox-select
|
|
136
|
-
name=${name}
|
|
137
|
-
placeholder=${label}
|
|
138
|
-
.value=${value}
|
|
139
|
-
@change=${(e: CustomEvent) =>
|
|
140
|
-
e.target?.dispatchEvent(
|
|
141
|
-
new CustomEvent('filter-change', {
|
|
142
|
-
detail: {
|
|
143
|
-
name,
|
|
144
|
-
operator,
|
|
145
|
-
value: e.detail
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
)}
|
|
149
|
-
>
|
|
150
|
-
<ox-popup-list with-search> ${renderer(filter, value, this)} </ox-popup-list>
|
|
151
|
-
</ox-select>
|
|
152
|
-
`
|
|
144
|
+
: type === 'boolean' || type === 'checkbox'
|
|
145
|
+
? renderer(filter, value, this)
|
|
146
|
+
: type !== 'select'
|
|
147
|
+
? html`
|
|
148
|
+
<label filter-title ?between=${operator == 'between'}
|
|
149
|
+
><span>${label}</span> ${renderer(filter, value, this)}
|
|
150
|
+
</label>
|
|
151
|
+
`
|
|
152
|
+
: this.renderSelect(filter, value, renderer)
|
|
153
153
|
})}
|
|
154
154
|
</form>
|
|
155
155
|
`
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
renderSelect(filter: FilterConfig, value: any, renderer: FilterSelectRenderer) {
|
|
159
|
+
const { name, label, operator, value: defaultValue } = filter
|
|
160
|
+
|
|
161
|
+
return operator === 'in'
|
|
162
|
+
? html`
|
|
163
|
+
<ox-select
|
|
164
|
+
name=${name}
|
|
165
|
+
placeholder=${label}
|
|
166
|
+
.value=${value ?? defaultValue}
|
|
167
|
+
@change=${(e: CustomEvent) =>
|
|
168
|
+
e.target?.dispatchEvent(
|
|
169
|
+
new CustomEvent('filter-change', {
|
|
170
|
+
detail: {
|
|
171
|
+
name,
|
|
172
|
+
operator,
|
|
173
|
+
value: e.detail
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
)}
|
|
177
|
+
>
|
|
178
|
+
<ox-popup-list multiple attr-selected="checked" with-search>
|
|
179
|
+
${renderer(filter, value, this)}
|
|
180
|
+
</ox-popup-list>
|
|
181
|
+
</ox-select>
|
|
182
|
+
`
|
|
183
|
+
: html`
|
|
184
|
+
<ox-select
|
|
185
|
+
name=${name}
|
|
186
|
+
placeholder=${label}
|
|
187
|
+
.value=${value ?? defaultValue}
|
|
188
|
+
@change=${(e: CustomEvent) =>
|
|
189
|
+
e.target?.dispatchEvent(
|
|
190
|
+
new CustomEvent('filter-change', {
|
|
191
|
+
detail: {
|
|
192
|
+
name,
|
|
193
|
+
operator,
|
|
194
|
+
value: e.detail
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
)}
|
|
198
|
+
>
|
|
199
|
+
<ox-popup-list with-search> ${renderer(filter, value, this)} </ox-popup-list>
|
|
200
|
+
</ox-select>
|
|
201
|
+
`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
getFieldByName(name: string) {
|
|
205
|
+
return this.renderRoot.querySelector(`[name=${name}]`)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
updated(changes: PropertyValues<this>) {
|
|
159
209
|
if (changes.has('urlParamsSensitive')) {
|
|
160
210
|
if (this.urlParamsSensitive) {
|
|
161
211
|
this._popstateEventHandler = () => {
|
|
@@ -216,9 +266,23 @@ export class FiltersFormBase extends LitElement {
|
|
|
216
266
|
}
|
|
217
267
|
}
|
|
218
268
|
}
|
|
269
|
+
|
|
270
|
+
if (changes.has('filters')) {
|
|
271
|
+
this.autoUpdateTargetsOnChange = {}
|
|
272
|
+
this.filters
|
|
273
|
+
?.filter(filter => filter.boundTo && filter.boundTo.length > 0)
|
|
274
|
+
.map(({ name, boundTo }) => {
|
|
275
|
+
boundTo!.forEach(to => {
|
|
276
|
+
const origin = this.autoUpdateTargetsOnChange[to] || []
|
|
277
|
+
if (name && !origin.includes(name)) {
|
|
278
|
+
this.autoUpdateTargetsOnChange[to] = [...origin, name]
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
}
|
|
219
283
|
}
|
|
220
284
|
|
|
221
|
-
async getQueryFilters(): Promise<
|
|
285
|
+
async getQueryFilters(): Promise<FilterValue[]> {
|
|
222
286
|
const formData = new FormData(await this.form)
|
|
223
287
|
|
|
224
288
|
var filters = this.filters
|
|
@@ -257,7 +321,7 @@ export class FiltersFormBase extends LitElement {
|
|
|
257
321
|
value: filterValue.length === 1 ? filterValue[0] : filterValue
|
|
258
322
|
}
|
|
259
323
|
})
|
|
260
|
-
.filter(result => result !== undefined) as
|
|
324
|
+
.filter(result => result !== undefined) as FilterValue[]
|
|
261
325
|
|
|
262
326
|
return filters
|
|
263
327
|
}
|
package/src/filters/registry.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FilterInput } from './filter-input.js'
|
|
|
4
4
|
import { FilterRangeDate } from './filter-range-date.js'
|
|
5
5
|
import { FilterRangeNumber } from './filter-range-number.js'
|
|
6
6
|
import { FilterSelect } from './filter-select.js'
|
|
7
|
-
import { FilterSelectRenderer } from '
|
|
7
|
+
import { FilterSelectRenderer } from '../types.js'
|
|
8
8
|
|
|
9
9
|
var RENDERERS: {
|
|
10
10
|
[name: string]: FilterSelectRenderer[]
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit-html'
|
|
2
|
+
import { OxFiltersFormBase } from './filters/ox-filters-form-base'
|
|
3
|
+
import { OxSearchForm } from './components/ox-search-form'
|
|
4
|
+
|
|
5
|
+
export type FilterOperator =
|
|
6
|
+
| 'search'
|
|
7
|
+
| 'eq'
|
|
8
|
+
| 'between'
|
|
9
|
+
| 'gte'
|
|
10
|
+
| 'lte'
|
|
11
|
+
| 'is_not_true'
|
|
12
|
+
| 'in'
|
|
13
|
+
| 'like'
|
|
14
|
+
| 'i_like'
|
|
15
|
+
| 'noteq'
|
|
16
|
+
| 'is_empty_num_id'
|
|
17
|
+
| 'is_blank'
|
|
18
|
+
| 'is_present'
|
|
19
|
+
| 'is_not_false'
|
|
20
|
+
| 'is_true'
|
|
21
|
+
| 'is_false'
|
|
22
|
+
| 'is_not_null'
|
|
23
|
+
| 'is_null'
|
|
24
|
+
| 'notin_with_null'
|
|
25
|
+
| 'notin'
|
|
26
|
+
| 'gt'
|
|
27
|
+
| 'lt'
|
|
28
|
+
| 'i_nlike'
|
|
29
|
+
| 'nlike'
|
|
30
|
+
|
|
31
|
+
export type SelectOptionObject =
|
|
32
|
+
| {
|
|
33
|
+
name: string
|
|
34
|
+
display?: never
|
|
35
|
+
value: string
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
display: string
|
|
39
|
+
name?: never
|
|
40
|
+
value: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type SelectOption = SelectOptionObject | string
|
|
44
|
+
|
|
45
|
+
export type FilterChangedCallback = (value: any, form: OxFiltersFormBase) => boolean | Promise<boolean>
|
|
46
|
+
|
|
47
|
+
export type FilterConfig = {
|
|
48
|
+
name: string
|
|
49
|
+
label: string
|
|
50
|
+
type: string
|
|
51
|
+
operator?: FilterOperator
|
|
52
|
+
options?:
|
|
53
|
+
| { [key: string]: any }
|
|
54
|
+
| SelectOption[]
|
|
55
|
+
| ((form: OxFiltersFormBase) => SelectOption[] | Promise<SelectOption[]>)
|
|
56
|
+
value?:
|
|
57
|
+
| string
|
|
58
|
+
| number
|
|
59
|
+
| boolean
|
|
60
|
+
| { name: string; [params: string]: any }
|
|
61
|
+
| string[]
|
|
62
|
+
| number[]
|
|
63
|
+
| { name: string; [params: string]: any }[]
|
|
64
|
+
| undefined
|
|
65
|
+
boundTo?: string[]
|
|
66
|
+
onchange?: FilterChangedCallback
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type FilterValue = {
|
|
70
|
+
name: string
|
|
71
|
+
operator: FilterOperator
|
|
72
|
+
value: string | number | boolean | string[] | number[] | undefined
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type FilterSelectRenderer = (
|
|
76
|
+
filter: FilterConfig,
|
|
77
|
+
value: string | number | boolean | string[] | number[] | any | undefined,
|
|
78
|
+
owner: Element
|
|
79
|
+
) => TemplateResult | string | void
|
|
80
|
+
|
|
81
|
+
export type SearchFormField = {
|
|
82
|
+
type: string
|
|
83
|
+
hidden?: boolean
|
|
84
|
+
name?: string
|
|
85
|
+
id?: string
|
|
86
|
+
label?: string
|
|
87
|
+
placeholder?: string
|
|
88
|
+
value?: any
|
|
89
|
+
field?: string
|
|
90
|
+
queryName?: string
|
|
91
|
+
props?: { [prop: string]: string }
|
|
92
|
+
attrs?: string[]
|
|
93
|
+
options?: SelectOption[] | ((form: OxSearchForm) => SelectOption[] | Promise<SelectOption[]>)
|
|
94
|
+
boundTo?: string[]
|
|
95
|
+
handlers?: { [event: string]: EventListener }
|
|
96
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { CommonHeaderStyles } from '@operato/styles'
|
|
1
2
|
import '../src/filters/ox-filters-form-base.js'
|
|
2
3
|
|
|
3
4
|
import { html, TemplateResult } from 'lit'
|
|
4
5
|
|
|
5
6
|
export default {
|
|
6
7
|
title: 'ox-filters-form-barcode',
|
|
7
|
-
component: 'ox-filters-form-
|
|
8
|
+
component: 'ox-filters-form-base',
|
|
8
9
|
argTypes: {
|
|
9
10
|
value: { control: 'object' },
|
|
10
11
|
filters: { control: 'object' },
|
|
@@ -27,21 +28,37 @@ interface ArgTypes {
|
|
|
27
28
|
const Template: Story<ArgTypes> = ({ value, filters, urlParamsSensitive }: ArgTypes) => html`
|
|
28
29
|
<link href="/themes/app-theme.css" rel="stylesheet" />
|
|
29
30
|
<link href="/themes/form-theme.css" rel="stylesheet" />
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
<link
|
|
33
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
|
34
|
+
rel="stylesheet"
|
|
35
|
+
/>
|
|
36
|
+
<link
|
|
37
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
|
38
|
+
rel="stylesheet"
|
|
39
|
+
/>
|
|
40
|
+
<link
|
|
41
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
|
42
|
+
rel="stylesheet"
|
|
43
|
+
/>
|
|
44
|
+
|
|
31
45
|
<style>
|
|
32
|
-
|
|
33
|
-
}
|
|
46
|
+
${CommonHeaderStyles.cssText}
|
|
34
47
|
</style>
|
|
35
48
|
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
<div class="header">
|
|
50
|
+
<div class="filters">
|
|
51
|
+
<ox-filters-form-base
|
|
52
|
+
.value=${value}
|
|
53
|
+
.filters=${filters}
|
|
54
|
+
?url-params-sensitive=${urlParamsSensitive}
|
|
55
|
+
@filters-change=${(e: CustomEvent) => {
|
|
56
|
+
console.log('filters changed', e.detail)
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
</ox-filters-form-base>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
45
62
|
`
|
|
46
63
|
|
|
47
64
|
export const Regular = Template.bind({})
|