@operato/app 8.0.0-beta.0 → 8.0.0-beta.10
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 +52 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -17
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/server.mjs +0 -8
- package/demo/data-grist-test.html +0 -473
- package/demo/index.html +0 -35
- package/src/filter-renderer/filter-resource-select.ts +0 -133
- package/src/filter-renderer/index.ts +0 -6
- package/src/filters-form/filter-resource-code.ts +0 -11
- package/src/filters-form/filter-resource-object.ts +0 -11
- package/src/filters-form/filter-resource-select.ts +0 -130
- package/src/filters-form/index.ts +0 -14
- package/src/filters-form/ox-filter-resource-code.ts +0 -154
- package/src/filters-form/ox-filter-resource-object.ts +0 -224
- package/src/grist-editor/index.ts +0 -26
- package/src/grist-editor/ox-grist-editor-code.ts +0 -64
- package/src/grist-editor/ox-grist-editor-json.ts +0 -64
- package/src/grist-editor/ox-grist-editor-privilege.ts +0 -58
- package/src/grist-editor/ox-grist-editor-resource-code.ts +0 -30
- package/src/grist-editor/ox-grist-editor-resource-id.ts +0 -88
- package/src/grist-editor/ox-grist-editor-resource-object-legacy.ts +0 -131
- package/src/grist-editor/ox-grist-editor-resource-object.ts +0 -156
- package/src/grist-editor/ox-grist-renderer-crontab.ts +0 -18
- package/src/grist-editor/ox-grist-renderer-resource-code.ts +0 -85
- package/src/grist-editor/ox-grist-renderer-resource-id.ts +0 -17
- package/src/grist-editor/ox-grist-renderer-resource-object.ts +0 -26
- package/src/grist-editor/ox-popup-code-input.ts +0 -69
- package/src/grist-editor/ox-popup-privilege-input.ts +0 -93
- package/src/index.ts +0 -4
- package/src/input/index.ts +0 -3
- package/src/input/ox-input-background-pattern.ts +0 -196
- package/src/input/ox-input-fill-style.ts +0 -377
- package/src/input/ox-input-graphql.ts +0 -153
- package/src/property-editor/index.ts +0 -83
- package/src/property-editor/ox-property-editor-graphql.ts +0 -22
- package/src/property-editor/ox-property-editor-resource-object.ts +0 -148
- package/src/selector/ox-selector-resource-id.ts +0 -201
- package/src/selector/ox-selector-resource-object-legacy.ts +0 -367
- package/src/selector/ox-selector-resource-object.ts +0 -300
- package/stories/graphql-client.stories.ts +0 -73
- package/stories/ox-input-graphql.stories.ts +0 -70
- package/stories/ox-selector-resource-object.stories.ts +0 -98
- package/tsconfig.json +0 -24
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import '@operato/input/ox-checkbox.js'
|
|
2
|
-
import '../selector/ox-selector-resource-id'
|
|
3
|
-
|
|
4
|
-
import { html } from 'lit-html'
|
|
5
|
-
|
|
6
|
-
import { ColumnConfig, FilterConfigObject, FilterSelectRenderer } from '@operato/data-grist'
|
|
7
|
-
import { i18next } from '@operato/i18n'
|
|
8
|
-
import { openPopup } from '@operato/layout'
|
|
9
|
-
|
|
10
|
-
type SelectedCallback = (value: { id: string; name: string; description: string }) => void
|
|
11
|
-
|
|
12
|
-
function openResourceSelector(column: ColumnConfig, value: any, confirmCallback: SelectedCallback) {
|
|
13
|
-
const { queryName, select, list, basicArgs, valueField = 'id', title } = column.record.options
|
|
14
|
-
|
|
15
|
-
var actualValue
|
|
16
|
-
if (typeof valueField === 'function') {
|
|
17
|
-
actualValue = valueField(value)
|
|
18
|
-
} else {
|
|
19
|
-
actualValue = value?.[valueField]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var template = html`
|
|
23
|
-
<ox-selector-resource-object
|
|
24
|
-
.value=${actualValue}
|
|
25
|
-
.confirmCallback=${confirmCallback}
|
|
26
|
-
.queryName=${queryName}
|
|
27
|
-
.columns=${select}
|
|
28
|
-
.list=${list}
|
|
29
|
-
.basicArgs=${basicArgs}
|
|
30
|
-
.valueField=${valueField}
|
|
31
|
-
></ox-selector-resource-object>
|
|
32
|
-
`
|
|
33
|
-
|
|
34
|
-
const popup = openPopup(template, {
|
|
35
|
-
backdrop: true,
|
|
36
|
-
size: 'large',
|
|
37
|
-
search: {
|
|
38
|
-
autofocus: true,
|
|
39
|
-
placeholder: title || i18next.t('title.select_item'),
|
|
40
|
-
handler: (instance: any, value: any) => {
|
|
41
|
-
/* instance: template instance */
|
|
42
|
-
instance.searchText(value)
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
filter: {
|
|
46
|
-
handler: (instance: any) => {
|
|
47
|
-
/* instance: template instance */
|
|
48
|
-
instance.toggleFilter()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const FilterResourceSelect: FilterSelectRenderer = (column, value, owner: any) => {
|
|
55
|
-
const filter = column.filter as FilterConfigObject
|
|
56
|
-
const { operator = 'like' } = filter
|
|
57
|
-
var { idField = 'id', nameField = 'name', descriptionField = 'description' } = column.record.options || {}
|
|
58
|
-
const hideValue = value ? value[idField] : ''
|
|
59
|
-
const text = value ? value[nameField] : ''
|
|
60
|
-
|
|
61
|
-
return operator === 'like'
|
|
62
|
-
? html` <input
|
|
63
|
-
type="text"
|
|
64
|
-
name=${column.name}
|
|
65
|
-
.value=${text}
|
|
66
|
-
@change=${(e: CustomEvent) => {
|
|
67
|
-
const input = e.target as HTMLInputElement
|
|
68
|
-
input.dispatchEvent(
|
|
69
|
-
new CustomEvent('filter-change', {
|
|
70
|
-
bubbles: true,
|
|
71
|
-
composed: true,
|
|
72
|
-
detail: {
|
|
73
|
-
name: column.name,
|
|
74
|
-
operator,
|
|
75
|
-
value: input.value
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
)
|
|
79
|
-
}}
|
|
80
|
-
/>`
|
|
81
|
-
: operator == 'in'
|
|
82
|
-
? html``
|
|
83
|
-
: operator === 'eq'
|
|
84
|
-
? html`
|
|
85
|
-
<input name="${column.name}" .value=${hideValue} type="text" hidden />
|
|
86
|
-
<input
|
|
87
|
-
type="text"
|
|
88
|
-
name="${column.name}_disp"
|
|
89
|
-
.value=${text}
|
|
90
|
-
readonly
|
|
91
|
-
@click=${(e: Event) => {
|
|
92
|
-
e.stopPropagation()
|
|
93
|
-
|
|
94
|
-
const input = e.target as HTMLInputElement
|
|
95
|
-
|
|
96
|
-
const confirmCallback = (selected?: { [field: string]: any }) => {
|
|
97
|
-
let disp = selected ? selected[idField] : ''
|
|
98
|
-
|
|
99
|
-
if (selected && nameField) {
|
|
100
|
-
disp = selected[nameField]
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
input.value = disp
|
|
104
|
-
|
|
105
|
-
let codeInput =
|
|
106
|
-
owner.tagName.toLowerCase() == 'ox-grid-header'
|
|
107
|
-
? owner.renderRoot.querySelector(`[name="${column.name}"]`)
|
|
108
|
-
: owner.renderRoot.querySelector(`form [name="${column.name}"]`)
|
|
109
|
-
|
|
110
|
-
const objectValue = selected ? selected[idField] : ''
|
|
111
|
-
codeInput.value = objectValue
|
|
112
|
-
|
|
113
|
-
input.dispatchEvent(new Event('change', { bubbles: true }))
|
|
114
|
-
|
|
115
|
-
owner.dispatchEvent(
|
|
116
|
-
new CustomEvent('filter-change', {
|
|
117
|
-
bubbles: true,
|
|
118
|
-
composed: true,
|
|
119
|
-
detail: {
|
|
120
|
-
name: column.name,
|
|
121
|
-
operator,
|
|
122
|
-
value: objectValue
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
openResourceSelector(column, value, confirmCallback)
|
|
129
|
-
}}
|
|
130
|
-
/>
|
|
131
|
-
`
|
|
132
|
-
: html``
|
|
133
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import './ox-filter-resource-code.js'
|
|
2
|
-
|
|
3
|
-
import { html } from 'lit-html'
|
|
4
|
-
|
|
5
|
-
import { FilterSelectRenderer } from '@operato/data-grist'
|
|
6
|
-
|
|
7
|
-
export const FilterResourceCode: FilterSelectRenderer = (column, value, owner) => {
|
|
8
|
-
return html`
|
|
9
|
-
<ox-filter-resource-code name=${column?.name} .column=${column} .value=${value}></ox-filter-resource-code>
|
|
10
|
-
`
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import './ox-filter-resource-object.js'
|
|
2
|
-
|
|
3
|
-
import { html } from 'lit-html'
|
|
4
|
-
|
|
5
|
-
import { FilterSelectRenderer } from '@operato/data-grist'
|
|
6
|
-
|
|
7
|
-
export const FilterResourceObject: FilterSelectRenderer = (column, value, owner) => {
|
|
8
|
-
return html`
|
|
9
|
-
<ox-filter-resource-object name=${column?.name} .column=${column} .value=${value}></ox-filter-resource-object>
|
|
10
|
-
`
|
|
11
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import '@operato/input/ox-checkbox.js'
|
|
2
|
-
import '../selector/ox-selector-resource-object'
|
|
3
|
-
|
|
4
|
-
import { html } from 'lit-html'
|
|
5
|
-
|
|
6
|
-
import { FilterConfig, FilterSelectRenderer } from '@operato/form'
|
|
7
|
-
import { i18next } from '@operato/i18n'
|
|
8
|
-
import { openPopup } from '@operato/layout'
|
|
9
|
-
import { GristRecord } from '@operato/data-grist'
|
|
10
|
-
|
|
11
|
-
type SelectedCallback = (value?: Partial<GristRecord>) => void
|
|
12
|
-
|
|
13
|
-
function openResourceSelector(filter: FilterConfig, value: any, confirmCallback: SelectedCallback) {
|
|
14
|
-
const { queryName, select, list, basicArgs, valueField = 'id', title } = filter.options || ({} as any)
|
|
15
|
-
|
|
16
|
-
var template = html`
|
|
17
|
-
<ox-selector-resource-object
|
|
18
|
-
.value=${value}
|
|
19
|
-
.confirmCallback=${confirmCallback}
|
|
20
|
-
.queryName=${queryName}
|
|
21
|
-
.columns=${select}
|
|
22
|
-
.list=${list}
|
|
23
|
-
.basicArgs=${basicArgs}
|
|
24
|
-
.valueField=${valueField}
|
|
25
|
-
></ox-selector-resource-object>
|
|
26
|
-
`
|
|
27
|
-
|
|
28
|
-
const popup = openPopup(template, {
|
|
29
|
-
backdrop: true,
|
|
30
|
-
size: 'large',
|
|
31
|
-
search: {
|
|
32
|
-
autofocus: true,
|
|
33
|
-
placeholder: title || i18next.t('title.select_item'),
|
|
34
|
-
handler: (instance: any, value: any) => {
|
|
35
|
-
/* instance: template instance */
|
|
36
|
-
instance.searchText(value)
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
filter: {
|
|
40
|
-
handler: (instance: any) => {
|
|
41
|
-
/* instance: template instance */
|
|
42
|
-
instance.toggleFilter()
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const FilterResourceSelect: FilterSelectRenderer = (filter, value, owner: any) => {
|
|
49
|
-
const { name, operator = 'like' } = filter
|
|
50
|
-
var { idField = 'id', nameField = 'name', descriptionField = 'description' } = filter.options || ({} as any)
|
|
51
|
-
const hideValue = value ? value[idField] : ''
|
|
52
|
-
const text = value ? value[nameField] : ''
|
|
53
|
-
|
|
54
|
-
return operator === 'like'
|
|
55
|
-
? html` <input
|
|
56
|
-
type="text"
|
|
57
|
-
name=${name}
|
|
58
|
-
.value=${text}
|
|
59
|
-
@change=${(e: CustomEvent) => {
|
|
60
|
-
const input = e.target as HTMLInputElement
|
|
61
|
-
input.dispatchEvent(
|
|
62
|
-
new CustomEvent('filter-change', {
|
|
63
|
-
bubbles: true,
|
|
64
|
-
composed: true,
|
|
65
|
-
detail: {
|
|
66
|
-
name,
|
|
67
|
-
operator,
|
|
68
|
-
value: input.value
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
)
|
|
72
|
-
}}
|
|
73
|
-
/>`
|
|
74
|
-
: operator == 'in'
|
|
75
|
-
? html``
|
|
76
|
-
: operator === 'eq'
|
|
77
|
-
? html`
|
|
78
|
-
<input name="${name}" .value=${hideValue} type="text" hidden />
|
|
79
|
-
<input
|
|
80
|
-
type="text"
|
|
81
|
-
name="${name}_disp"
|
|
82
|
-
.value=${text}
|
|
83
|
-
readonly
|
|
84
|
-
@change=${() => false}
|
|
85
|
-
@click=${(e: Event) => {
|
|
86
|
-
e.stopPropagation()
|
|
87
|
-
|
|
88
|
-
const input = e.target as HTMLInputElement
|
|
89
|
-
const codeInput =
|
|
90
|
-
owner.tagName.toLowerCase() == 'ox-grid-header'
|
|
91
|
-
? owner.renderRoot.querySelector(`[name="${name}"]`)
|
|
92
|
-
: owner.renderRoot.querySelector(`form [name="${name}"]`)
|
|
93
|
-
|
|
94
|
-
const confirmCallback = (selected?: { [field: string]: any }) => {
|
|
95
|
-
let disp = selected ? selected[idField] : ''
|
|
96
|
-
|
|
97
|
-
if (selected && nameField) {
|
|
98
|
-
disp = selected[nameField]
|
|
99
|
-
}
|
|
100
|
-
input.value = disp
|
|
101
|
-
|
|
102
|
-
const value = selected ? selected[idField] : ''
|
|
103
|
-
codeInput.value = value
|
|
104
|
-
|
|
105
|
-
codeInput.dispatchEvent(
|
|
106
|
-
new Event('change', {
|
|
107
|
-
bubbles: true,
|
|
108
|
-
composed: true
|
|
109
|
-
})
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
owner.dispatchEvent(
|
|
113
|
-
new CustomEvent('filter-change', {
|
|
114
|
-
bubbles: true,
|
|
115
|
-
composed: true,
|
|
116
|
-
detail: {
|
|
117
|
-
name: name,
|
|
118
|
-
operator,
|
|
119
|
-
value
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
openResourceSelector(filter, codeInput.value, confirmCallback)
|
|
126
|
-
}}
|
|
127
|
-
/>
|
|
128
|
-
`
|
|
129
|
-
: html``
|
|
130
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { registerFilterRenderer } from '@operato/form'
|
|
2
|
-
import { registerFilterRenderer as dataGristFilterRenderer } from '@operato/data-grist'
|
|
3
|
-
|
|
4
|
-
import { FilterResourceSelect } from './filter-resource-select.js'
|
|
5
|
-
|
|
6
|
-
import { FilterResourceCode } from './filter-resource-code.js'
|
|
7
|
-
import { FilterResourceObject } from './filter-resource-object.js'
|
|
8
|
-
|
|
9
|
-
registerFilterRenderer('resource-object', [FilterResourceSelect])
|
|
10
|
-
registerFilterRenderer('resource-id', [FilterResourceSelect])
|
|
11
|
-
|
|
12
|
-
dataGristFilterRenderer('code', [FilterResourceCode])
|
|
13
|
-
dataGristFilterRenderer('object', [FilterResourceObject])
|
|
14
|
-
dataGristFilterRenderer('resource-object', [FilterResourceObject])
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import '@operato/input/ox-select.js'
|
|
2
|
-
|
|
3
|
-
import gql from 'graphql-tag'
|
|
4
|
-
import { css, html } from 'lit'
|
|
5
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
6
|
-
|
|
7
|
-
import { i18next } from '@operato/i18n'
|
|
8
|
-
import { FilterConfigObject } from '@operato/data-grist'
|
|
9
|
-
import { client, gqlContext } from '@operato/graphql'
|
|
10
|
-
import { OxFormField } from '@operato/input'
|
|
11
|
-
|
|
12
|
-
type CommonCodeDetail = {
|
|
13
|
-
name: string
|
|
14
|
-
description: string
|
|
15
|
-
rank: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const FETCH_COMMON_CODE_GQL = (codeName: string) => gql`
|
|
19
|
-
{
|
|
20
|
-
commonCode(name: "${codeName}") {
|
|
21
|
-
details {
|
|
22
|
-
name
|
|
23
|
-
description
|
|
24
|
-
rank
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
`
|
|
29
|
-
|
|
30
|
-
@customElement('ox-filter-resource-code')
|
|
31
|
-
export class OxFilterResourceCode extends OxFormField {
|
|
32
|
-
static styles = css`
|
|
33
|
-
:host {
|
|
34
|
-
min-width: 100px;
|
|
35
|
-
}
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
@property({ type: Object }) column: any
|
|
39
|
-
@property({ type: String }) value?: string
|
|
40
|
-
|
|
41
|
-
@state() codes?: CommonCodeDetail[]
|
|
42
|
-
|
|
43
|
-
render() {
|
|
44
|
-
const { name, filter } = this.column
|
|
45
|
-
const operator = (filter as FilterConfigObject).operator
|
|
46
|
-
const { selectDispOpt = 'code-name' } = this.column.record || {}
|
|
47
|
-
|
|
48
|
-
if (!this.codes) {
|
|
49
|
-
return html`<p>Loading...</p>`
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return operator === 'in'
|
|
53
|
-
? html`
|
|
54
|
-
<ox-select
|
|
55
|
-
.value=${this.value}
|
|
56
|
-
@change=${(e: CustomEvent) => {
|
|
57
|
-
let val = e.detail
|
|
58
|
-
this.value = val?.length > 0 ? val : undefined
|
|
59
|
-
|
|
60
|
-
this?.dispatchEvent(
|
|
61
|
-
new CustomEvent('change', {
|
|
62
|
-
detail: {
|
|
63
|
-
name,
|
|
64
|
-
operator,
|
|
65
|
-
value: this.value
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
)
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
<ox-popup-list multiple attr-selected="checked" with-search align-left>
|
|
72
|
-
<ox-checkbox
|
|
73
|
-
checkAll
|
|
74
|
-
@click=${(e: any) => {
|
|
75
|
-
const checked = e.target.checked
|
|
76
|
-
const val = checked ? this.codes!.map((code: CommonCodeDetail) => code.name) : []
|
|
77
|
-
|
|
78
|
-
e.target?.dispatchEvent(new CustomEvent('select', { bubbles: true, detail: val }))
|
|
79
|
-
}}
|
|
80
|
-
>${i18next.t('label.all')}</ox-checkbox
|
|
81
|
-
>
|
|
82
|
-
${this.codes
|
|
83
|
-
?.filter((code: CommonCodeDetail) => !!code.name)
|
|
84
|
-
.map(
|
|
85
|
-
(code: CommonCodeDetail) => html`
|
|
86
|
-
<ox-checkbox
|
|
87
|
-
option
|
|
88
|
-
value=${code.name}
|
|
89
|
-
@change=${(e: any) => {
|
|
90
|
-
const parent = e.target.parentElement
|
|
91
|
-
const checkCnt = e.target.checked ? 1 : -1
|
|
92
|
-
const checkedLen = parent.querySelectorAll('ox-checkbox[option][checked]').length + checkCnt
|
|
93
|
-
|
|
94
|
-
parent.querySelector('ox-checkbox[checkAll]').checked =
|
|
95
|
-
this.codes!.filter((code: CommonCodeDetail) => !!code.name).length === checkedLen
|
|
96
|
-
}}
|
|
97
|
-
>${selectDispOpt.replace('name', code.description).replace('code', code.name)}</ox-checkbox
|
|
98
|
-
>
|
|
99
|
-
`
|
|
100
|
-
)}
|
|
101
|
-
</ox-popup-list>
|
|
102
|
-
</ox-select>
|
|
103
|
-
`
|
|
104
|
-
: html`
|
|
105
|
-
<ox-select
|
|
106
|
-
.value=${this.value}
|
|
107
|
-
@change=${(e: CustomEvent) => {
|
|
108
|
-
this.value = e.detail
|
|
109
|
-
this.dispatchEvent(
|
|
110
|
-
new CustomEvent('change', {
|
|
111
|
-
detail: {
|
|
112
|
-
name,
|
|
113
|
-
operator,
|
|
114
|
-
value: this.value
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
}}
|
|
119
|
-
>
|
|
120
|
-
<ox-popup-list with-search>
|
|
121
|
-
<div option value=""> </div>
|
|
122
|
-
${this.codes?.map(
|
|
123
|
-
(code: CommonCodeDetail) => html`
|
|
124
|
-
<div option value=${code.name}>
|
|
125
|
-
${selectDispOpt.replace('name', code.description).replace('code', code.name)}
|
|
126
|
-
</div>
|
|
127
|
-
`
|
|
128
|
-
)}
|
|
129
|
-
</ox-popup-list>
|
|
130
|
-
</ox-select>
|
|
131
|
-
`
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async fetchCodes() {
|
|
135
|
-
const { codeName } = this.column.record || {}
|
|
136
|
-
|
|
137
|
-
if (codeName) {
|
|
138
|
-
const response = await client.query({
|
|
139
|
-
query: FETCH_COMMON_CODE_GQL(codeName),
|
|
140
|
-
context: gqlContext()
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
this.codes = response?.data?.commonCode?.details || []
|
|
144
|
-
|
|
145
|
-
this.requestUpdate()
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
connectedCallback() {
|
|
150
|
-
super.connectedCallback()
|
|
151
|
-
|
|
152
|
-
this.fetchCodes()
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import '../selector/ox-selector-resource-object.js'
|
|
2
|
-
|
|
3
|
-
import { css, html } from 'lit'
|
|
4
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
5
|
-
|
|
6
|
-
import { i18next } from '@operato/i18n'
|
|
7
|
-
import { openPopup, PopupHandle } from '@operato/layout'
|
|
8
|
-
import { OxFormField } from '@operato/input'
|
|
9
|
-
|
|
10
|
-
@customElement('ox-filter-resource-object')
|
|
11
|
-
export class OxFilterResourceObject extends OxFormField {
|
|
12
|
-
static styles = [
|
|
13
|
-
css`
|
|
14
|
-
:host {
|
|
15
|
-
display: block;
|
|
16
|
-
position: relative;
|
|
17
|
-
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
|
18
|
-
min-width: 100px;
|
|
19
|
-
|
|
20
|
-
--ox-select-padding: var(--spacing-tiny);
|
|
21
|
-
--ox-select-font: var(--input-font);
|
|
22
|
-
--ox-select-color: var(--input-color, var(--md-sys-color-on-surface-variant));
|
|
23
|
-
--ox-select-icon-color: var(--theme-primary-text-color, var(--md-sys-color-on-surface-variant));
|
|
24
|
-
--ox-select-icon-hover-color: var(--md-sys-color-on-primary-container, #3c3938);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
div {
|
|
28
|
-
width: 100%;
|
|
29
|
-
box-sizing: border-box;
|
|
30
|
-
|
|
31
|
-
display: flex;
|
|
32
|
-
flex-direction: row;
|
|
33
|
-
align-items: center;
|
|
34
|
-
justify-content: center;
|
|
35
|
-
cursor: pointer;
|
|
36
|
-
padding: var(--ox-select-padding);
|
|
37
|
-
font: var(--ox-select-font);
|
|
38
|
-
color: var(--ox-select-color);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
span {
|
|
42
|
-
flex: 1;
|
|
43
|
-
overflow: hidden;
|
|
44
|
-
text-overflow: ellipsis;
|
|
45
|
-
white-space: nowrap;
|
|
46
|
-
gap: 4px;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
md-icon {
|
|
50
|
-
--md-icon-size: 16px;
|
|
51
|
-
display: block;
|
|
52
|
-
text-align: right;
|
|
53
|
-
color: var(--ox-select-icon-color);
|
|
54
|
-
opacity: 0.7;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
div:hover md-icon {
|
|
58
|
-
color: var(--md-sys-color-on-primary-container);
|
|
59
|
-
}
|
|
60
|
-
`
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
@property({ type: Object }) column: any
|
|
64
|
-
@property({ type: String }) value?: string
|
|
65
|
-
|
|
66
|
-
@state() resourceObject?: any
|
|
67
|
-
|
|
68
|
-
private popup?: PopupHandle
|
|
69
|
-
|
|
70
|
-
render() {
|
|
71
|
-
var { nameField = 'name', descriptionField = 'description' } = this.column.record.options || {}
|
|
72
|
-
|
|
73
|
-
var value = this.resourceObject || {}
|
|
74
|
-
var name, description
|
|
75
|
-
|
|
76
|
-
if (typeof nameField === 'function') {
|
|
77
|
-
name = nameField(value)
|
|
78
|
-
} else {
|
|
79
|
-
name = value[nameField]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeof descriptionField === 'function') {
|
|
83
|
-
description = descriptionField(value)
|
|
84
|
-
} else {
|
|
85
|
-
description = value[descriptionField] && `(${value[descriptionField]})`
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return html`
|
|
89
|
-
<div @click=${this._onclick} @keydown=${this._onkeydown}>
|
|
90
|
-
<span tabindex="0" style="flex:1">${name || ''}${(description && `(${description})`) || ''}</span>
|
|
91
|
-
<md-icon>search</md-icon>
|
|
92
|
-
</div>
|
|
93
|
-
`
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_onclick(e: Event): void {
|
|
97
|
-
e.stopPropagation()
|
|
98
|
-
this.openSelector()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
_onkeydown(e: KeyboardEvent): void {
|
|
102
|
-
const key = e.key
|
|
103
|
-
if (key == 'Enter') {
|
|
104
|
-
e.stopPropagation()
|
|
105
|
-
this.openSelector()
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
openSelector() {
|
|
110
|
-
if (this.popup) {
|
|
111
|
-
delete this.popup
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
var {
|
|
115
|
-
title = '',
|
|
116
|
-
idField = 'id',
|
|
117
|
-
nameField = 'name',
|
|
118
|
-
descriptionField = 'description',
|
|
119
|
-
valueField = 'id',
|
|
120
|
-
queryName,
|
|
121
|
-
basicArgs,
|
|
122
|
-
select,
|
|
123
|
-
columns,
|
|
124
|
-
pagination,
|
|
125
|
-
list
|
|
126
|
-
} = this.column.record.options || {}
|
|
127
|
-
|
|
128
|
-
if (!queryName) {
|
|
129
|
-
console.warn('queryName is empty')
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/* select options is only for compatability, it might be able to be deprecated. */
|
|
134
|
-
columns = columns || select
|
|
135
|
-
|
|
136
|
-
const confirmCallback = (selected?: { [field: string]: any }) => {
|
|
137
|
-
// this.department = selected
|
|
138
|
-
// ? {
|
|
139
|
-
// id: selected.id,
|
|
140
|
-
// controlNo: selected.controlNo,
|
|
141
|
-
// name: selected.name,
|
|
142
|
-
// description: selected.description
|
|
143
|
-
// }
|
|
144
|
-
// : null
|
|
145
|
-
|
|
146
|
-
// this.value = this.department?.name
|
|
147
|
-
|
|
148
|
-
// this.dispatchEvent(
|
|
149
|
-
// new CustomEvent('change', {
|
|
150
|
-
// bubbles: true,
|
|
151
|
-
// composed: true,
|
|
152
|
-
// detail: this.value
|
|
153
|
-
// })
|
|
154
|
-
// )
|
|
155
|
-
|
|
156
|
-
this.resourceObject = selected
|
|
157
|
-
? {
|
|
158
|
-
...(columns || [])
|
|
159
|
-
.map((field: any) => field.name)
|
|
160
|
-
.reduce(
|
|
161
|
-
(obj: { [field: string]: any }, fieldName: string) => {
|
|
162
|
-
return (obj = {
|
|
163
|
-
...obj,
|
|
164
|
-
[fieldName]: selected[fieldName]
|
|
165
|
-
})
|
|
166
|
-
},
|
|
167
|
-
{} as { [field: string]: any }
|
|
168
|
-
),
|
|
169
|
-
[idField]: selected[idField],
|
|
170
|
-
[nameField]: selected[nameField],
|
|
171
|
-
[descriptionField]: selected[descriptionField]
|
|
172
|
-
}
|
|
173
|
-
: null
|
|
174
|
-
|
|
175
|
-
this.value = this.resourceObject?.[nameField]
|
|
176
|
-
|
|
177
|
-
this.dispatchEvent(
|
|
178
|
-
new CustomEvent('change', {
|
|
179
|
-
detail: this.value
|
|
180
|
-
})
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
var value = this.resourceObject || {}
|
|
185
|
-
var actualValue
|
|
186
|
-
if (typeof valueField === 'function') {
|
|
187
|
-
actualValue = valueField(value)
|
|
188
|
-
} else {
|
|
189
|
-
actualValue = value[valueField]
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var template = html`
|
|
193
|
-
<ox-selector-resource-object
|
|
194
|
-
.value=${actualValue}
|
|
195
|
-
.confirmCallback=${confirmCallback.bind(this)}
|
|
196
|
-
.queryName=${queryName}
|
|
197
|
-
.columns=${columns}
|
|
198
|
-
.pagination=${pagination}
|
|
199
|
-
.list=${list}
|
|
200
|
-
.basicArgs=${basicArgs}
|
|
201
|
-
.valueField=${valueField}
|
|
202
|
-
></ox-selector-resource-object>
|
|
203
|
-
`
|
|
204
|
-
|
|
205
|
-
this.popup = openPopup(template, {
|
|
206
|
-
backdrop: true,
|
|
207
|
-
size: 'large',
|
|
208
|
-
search: {
|
|
209
|
-
autofocus: true,
|
|
210
|
-
placeholder: title || i18next.t('title.select_item'),
|
|
211
|
-
handler: (instance: any, value: any) => {
|
|
212
|
-
/* instance: template instance */
|
|
213
|
-
instance.searchText(value)
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
filter: {
|
|
217
|
-
handler: (instance: any) => {
|
|
218
|
-
/* instance: template instance */
|
|
219
|
-
instance.toggleFilter()
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
}
|
|
224
|
-
}
|