@things-factory/resource-ui 5.0.0-alpha.2 → 5.0.0-alpha.20

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.
@@ -1,17 +1,26 @@
1
- import { store } from '@things-factory/shell'
2
- import { addRoutingType } from '@things-factory/menu-base'
3
-
4
- import { registerEditor, registerRenderer, TextRenderer } from '@things-factory/grist-ui'
1
+ /* should use @things-factory/grist-ui to register both grist (things-factory grist and operato grist) */
2
+ import {
3
+ registerEditor as registerGristEditor,
4
+ registerRenderer as registerGristRenderer
5
+ } from '@things-factory/grist-ui'
5
6
 
6
- import { ObjectRenderer } from './data-grist/renderers/object-renderer'
7
- import { ObjectEditor } from './data-grist/editors/object-editor'
8
- import { CodeEditor } from './data-grist/editors/code-editor'
7
+ import { OxGristEditorResourceCode } from '@operato/app/grist-editor/ox-grist-editor-resource-code.js'
8
+ import { OxGristEditorResourceObject } from '@operato/app/grist-editor/ox-grist-editor-resource-object.js'
9
+ import { OxGristRendererResourceObject } from '@operato/app/grist-editor/ox-grist-renderer-resource-object.js'
10
+ import { OxGristRendererText } from '@operato/data-grist'
11
+ import { addRoutingType } from '@things-factory/menu-base'
12
+ import { store } from '@things-factory/shell'
9
13
 
10
14
  export default function bootstrap() {
11
- registerRenderer('object', ObjectRenderer)
12
- registerEditor('object', ObjectEditor)
13
- registerRenderer('code', TextRenderer)
14
- registerEditor('code', CodeEditor)
15
+ registerGristRenderer('object', OxGristRendererResourceObject)
16
+ registerGristEditor('object', OxGristEditorResourceObject)
17
+ registerGristRenderer('resource-object', OxGristRendererResourceObject)
18
+ registerGristEditor('resource-object', OxGristEditorResourceObject)
19
+
20
+ registerGristRenderer('code', OxGristRendererText)
21
+ registerGristEditor('code', OxGristEditorResourceCode)
22
+ registerGristRenderer('resource-code', OxGristRendererText)
23
+ registerGristEditor('resource-code', OxGristEditorResourceCode)
15
24
 
16
25
  store.dispatch(addRoutingType('RESOURCE', 'resource'))
17
26
  }
@@ -1,7 +1,7 @@
1
- import { LitElement, html, css } from 'lit'
2
-
3
1
  import '@things-factory/grist-ui'
4
2
 
3
+ import { LitElement, css, html } from 'lit'
4
+
5
5
  const GUTTERS = [
6
6
  {
7
7
  type: 'gutter',
@@ -117,7 +117,7 @@ export class DataListWrapper extends LitElement {
117
117
  .map(column => {
118
118
  return {
119
119
  name: column.name,
120
- descending: !!column.reverseSort
120
+ desc: !!column.reverseSort
121
121
  }
122
122
  })
123
123
 
package/client/index.js CHANGED
@@ -1,3 +1 @@
1
- export * from './elements/code-select'
2
- export * from './elements/object-input'
3
1
  export * from './elements/object-selector'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/resource-ui",
3
- "version": "5.0.0-alpha.2",
3
+ "version": "5.0.0-alpha.20",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,15 +24,16 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/auth-ui": "^5.0.0-alpha.2",
28
- "@things-factory/context-ui": "^5.0.0-alpha.2",
29
- "@things-factory/form-ui": "^5.0.0-alpha.2",
30
- "@things-factory/grist-ui": "^5.0.0-alpha.2",
31
- "@things-factory/i18n-base": "^5.0.0-alpha.2",
32
- "@things-factory/import-ui-csv": "^5.0.0-alpha.2",
33
- "@things-factory/layout-base": "^5.0.0-alpha.2",
34
- "@things-factory/menu-base": "^5.0.0-alpha.2",
35
- "@things-factory/resource-base": "^5.0.0-alpha.2"
27
+ "@operato/app": "^1.0.0-alpha.41",
28
+ "@things-factory/auth-ui": "^5.0.0-alpha.20",
29
+ "@things-factory/context-ui": "^5.0.0-alpha.20",
30
+ "@things-factory/form-ui": "^5.0.0-alpha.20",
31
+ "@things-factory/grist-ui": "^5.0.0-alpha.20",
32
+ "@things-factory/i18n-base": "^5.0.0-alpha.20",
33
+ "@things-factory/import-ui-csv": "^5.0.0-alpha.20",
34
+ "@things-factory/layout-base": "^5.0.0-alpha.20",
35
+ "@things-factory/menu-base": "^5.0.0-alpha.20",
36
+ "@things-factory/resource-base": "^5.0.0-alpha.20"
36
37
  },
37
- "gitHead": "055536f981d229d51ae63f46585036b35fa86602"
38
+ "gitHead": "47487b293458170f7eeb97612dfa8bbb750f092f"
38
39
  }
@@ -1,65 +0,0 @@
1
- import { html } from 'lit'
2
- import gql from 'graphql-tag'
3
- import '@material/mwc-icon'
4
-
5
- import { client } from '@things-factory/shell'
6
- import { InputEditor } from '@things-factory/grist-ui'
7
- import { gqlContext } from '@things-factory/shell'
8
-
9
- const FETCH_COMMON_CODE_GQL = codeName => gql`
10
- {
11
- commonCode(name: "${codeName}") {
12
- details {
13
- name
14
- description
15
- rank
16
- }
17
- }
18
- }
19
- `
20
-
21
- export class CodeEditor extends InputEditor {
22
- async firstUpdated() {
23
- super.firstUpdated()
24
-
25
- var { codeName, codes } = this.column.record || {}
26
-
27
- if (!codes && codeName) {
28
- /* codeName으로 fetch 해와서, this.column.record.codes에 보관한다. */
29
- var response = await client.query({
30
- query: FETCH_COMMON_CODE_GQL(codeName),
31
- context: gqlContext()
32
- })
33
-
34
- var commonCode = response && response.data && response.data.commonCode
35
-
36
- if (commonCode) {
37
- this.column.record.codes = [{ name: '', description: '' }].concat(
38
- commonCode.details.sort(function (a, b) {
39
- return a.rank - b.rank
40
- })
41
- )
42
-
43
- this.requestUpdate()
44
- }
45
- }
46
- }
47
-
48
- get editorTemplate() {
49
- var { codes } = this.column.record || {}
50
-
51
- return html`
52
- <select>
53
- ${(codes || ['']).map(
54
- code => html`
55
- <option ?selected=${code.name == this.value} value=${code.name}>
56
- ${code.name}${code.description ? ` - ${code.description}` : ''}
57
- </option>
58
- `
59
- )}
60
- </select>
61
- `
62
- }
63
- }
64
-
65
- customElements.define('code-editor', CodeEditor)
@@ -1,156 +0,0 @@
1
- import '@material/mwc-icon'
2
- import { i18next } from '@things-factory/i18n-base'
3
- import { openPopup } from '@things-factory/layout-base'
4
- import { css, html, LitElement } from 'lit'
5
- import '../../elements/object-selector'
6
-
7
- export class ObjectEditor extends LitElement {
8
- static get properties() {
9
- return {
10
- value: Object,
11
- column: Object,
12
- record: Object,
13
- row: Number
14
- }
15
- }
16
-
17
- static get styles() {
18
- return css`
19
- :host {
20
- display: flex;
21
- flex-flow: row nowrap;
22
-
23
- padding: 7px 0px;
24
- box-sizing: border-box;
25
-
26
- width: 100%;
27
- height: 100%;
28
-
29
- border: 0;
30
- background-color: transparent;
31
-
32
- font: var(--grist-object-editor-font);
33
- color: var(--grist-object-editor-color);
34
- justify-content: inherit;
35
- }
36
-
37
- span {
38
- display: flex;
39
- flex: auto;
40
-
41
- justify-content: inherit;
42
- }
43
-
44
- mwc-icon {
45
- width: 20px;
46
- font-size: 1.5em;
47
- margin-left: auto;
48
- }
49
- `
50
- }
51
-
52
- render() {
53
- var value = this.value || {}
54
-
55
- var { nameField = 'name', descriptionField = 'description' } = this.column.record.options || {}
56
- var name, description
57
- if (typeof nameField === 'function') {
58
- name = nameField(value)
59
- } else {
60
- name = value[nameField]
61
- }
62
-
63
- if (typeof descriptionField === 'function') {
64
- description = descriptionField(value)
65
- } else {
66
- description = value[descriptionField] && `(${value[descriptionField]})`
67
- }
68
-
69
- return html`
70
- ${!value ? html`` : html` <span>${name || ''}${description || ''}</span> `}
71
- <mwc-icon>arrow_drop_down</mwc-icon>
72
- `
73
- }
74
-
75
- async firstUpdated() {
76
- this.value = this.record[this.column.name]
77
- this.template = ((this.column.record || {}).options || {}).template
78
-
79
- await this.updateComplete
80
-
81
- this.shadowRoot.addEventListener('click', e => {
82
- e.stopPropagation()
83
-
84
- this.openSelector()
85
- })
86
- }
87
-
88
- openSelector() {
89
- if (this.popup) {
90
- delete this.popup
91
- }
92
-
93
- const confirmCallback = selected => {
94
- var { idField = 'id', nameField = 'name', descriptionField = 'description' } = this.column.record.options || {}
95
-
96
- this.dispatchEvent(
97
- new CustomEvent('field-change', {
98
- bubbles: true,
99
- composed: true,
100
- detail: {
101
- before: this.value,
102
- after: {
103
- ...(this.column.record.options.select || [])
104
- .map(field => field.name)
105
- .reduce((obj, fieldName) => {
106
- return (obj = {
107
- ...obj,
108
- [fieldName]: selected[fieldName]
109
- })
110
- }, {}),
111
- [idField]: selected[idField],
112
- [nameField]: selected[nameField],
113
- [descriptionField]: selected[descriptionField]
114
- },
115
- record: this.record,
116
- column: this.column,
117
- row: this.row
118
- }
119
- })
120
- )
121
- }
122
-
123
- var value = this.value || {}
124
- var valueField = this.column.record.options.valueField
125
- var actualValue
126
- if (typeof valueField === 'function') {
127
- actualValue = valueField(value)
128
- } else if (valueField) {
129
- actualValue = value[valueField]
130
- } else {
131
- actualValue = value.id
132
- }
133
-
134
- var template =
135
- this.template ||
136
- html`
137
- <object-selector
138
- .value=${actualValue}
139
- .confirmCallback=${confirmCallback.bind(this)}
140
- .queryName=${this.column.record.options.queryName}
141
- .select=${this.column.record.options.select}
142
- .list=${this.column.record.options.list}
143
- .basicArgs=${this.column.record.options.basicArgs}
144
- .valueField=${this.column.record.options.valueField}
145
- ></object-selector>
146
- `
147
-
148
- this.popup = openPopup(template, {
149
- backdrop: true,
150
- size: 'large',
151
- title: i18next.t('title.select_item')
152
- })
153
- }
154
- }
155
-
156
- customElements.define('object-editor', ObjectEditor)
@@ -1,26 +0,0 @@
1
- import { html } from 'lit-html'
2
-
3
- export const ObjectRenderer = (value, column, record, rowIndex, field) => {
4
- if (!value) {
5
- return ''
6
- }
7
-
8
- var { nameField = 'name', descriptionField = 'description' } = column.record.options || {}
9
- var name, description
10
-
11
- if (typeof nameField === 'function') {
12
- name = nameField(value)
13
- } else {
14
- name = value[nameField]
15
- }
16
-
17
- if (typeof descriptionField === 'function') {
18
- description = descriptionField(value)
19
- } else {
20
- description = value[descriptionField] && `(${value[descriptionField]})`
21
- }
22
-
23
- return html`
24
- ${name || ''}${description || ''}
25
- `
26
- }
@@ -1,61 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { client } from '@things-factory/shell'
3
-
4
- const FETCH_COMMON_CODE_GQL = codeName => gql`
5
- {
6
- commonCode(name: "${codeName}") {
7
- details {
8
- name
9
- description
10
- rank
11
- }
12
- }
13
- }
14
- `
15
-
16
- /*
17
- * USAGE
18
- *
19
- * <select codename="USER_TYPES" is="code-select"></select>
20
- *
21
- */
22
- export class CodeSelect extends HTMLSelectElement {
23
- static get observedAttributes() {
24
- return ['codename']
25
- }
26
-
27
- connectedCallback() {}
28
-
29
- async attributeChangedCallback(name, oldValue, newValue) {
30
- if (oldValue !== newValue) {
31
- this._fecthCodes(newValue)
32
- }
33
- }
34
-
35
- async _fecthCodes(codeName) {
36
- this.innerHTML = ''
37
-
38
- var response = await client.query({
39
- query: FETCH_COMMON_CODE_GQL(codeName)
40
- })
41
-
42
- var commonCode = response && response.data && response.data.commonCode
43
-
44
- if (commonCode) {
45
- var codes = [{ name: '', description: '' }]
46
- .concat(
47
- commonCode.details.sort(function(a, b) {
48
- return a.rank - b.rank
49
- })
50
- )
51
- .forEach(code => {
52
- let option = document.createElement('option')
53
- option.value = code.name
54
- option.text = `${code.name}${code.description ? ` - ${code.description}` : ''}`
55
- this.add(option, null)
56
- })
57
- }
58
- }
59
- }
60
-
61
- customElements.define('code-select', CodeSelect, { extends: 'select' })
@@ -1,159 +0,0 @@
1
- import { LitElement, html, css, customElement } from 'lit'
2
- import gql from 'graphql-tag'
3
- import { client } from '@things-factory/shell'
4
- import { gqlBuilder } from '@things-factory/utils'
5
- import { openPopup } from '@things-factory/layout-base'
6
- import { i18next } from '@things-factory/i18n-base'
7
-
8
- import './object-selector'
9
-
10
- /*
11
- * USAGE
12
- *
13
- * <input type="text" query-name="boards" value="9432279e-28ea-4c60-bb92-6211439ec390" is="object-input" />
14
- *
15
- */
16
- class ObjectInputContainer extends LitElement {
17
- static get styles() {
18
- return css`
19
- :host {
20
- display: inline;
21
- position: relative;
22
- }
23
-
24
- div {
25
- position: absolute;
26
- height: 100%;
27
- width: 100%;
28
- left: 0;
29
- top: 0;
30
- }
31
-
32
- ::slotted(input) {
33
- opacity: 0;
34
- }
35
- `
36
- }
37
-
38
- static get properties() {
39
- return {
40
- queryName: String,
41
- value: String,
42
- _object: Object
43
- }
44
- }
45
-
46
- render() {
47
- var object = this._object || {}
48
- return html`
49
- <slot> </slot>
50
- <div>${object.name}</div>
51
- `
52
- }
53
-
54
- get input() {
55
- return this.querySelector('input')
56
- }
57
-
58
- async firstUpdated() {
59
- await this.updateComplete
60
-
61
- this.shadowRoot.addEventListener('click', () => {
62
- this.queryName && this.openSelector(this.queryName)
63
- })
64
- }
65
-
66
- async updated(changes) {
67
- if (changes.has('queryName') || changes.has('value')) {
68
- if (this.queryName && this.value) {
69
- this._object = await this._fetchObject(this.queryName, this.value)
70
- } else {
71
- this._object = {}
72
- }
73
- }
74
- }
75
-
76
- async _fetchObject(queryName, id) {
77
- const response = await client.query({
78
- query: gql`
79
- query {
80
- ${queryName} (${gqlBuilder.buildArgs({
81
- filters: [
82
- {
83
- name: 'id',
84
- operator: 'eq',
85
- value: id
86
- }
87
- ]
88
- })}) {
89
- items {
90
- id
91
- name
92
- description
93
- }
94
- total
95
- }
96
- }
97
- `
98
- })
99
-
100
- return response.data[queryName].items[0]
101
- }
102
-
103
- openSelector(queryName) {
104
- if (this.popup) {
105
- delete this.popup
106
- }
107
-
108
- const confirmCallback = selected => {
109
- this._object = selected
110
-
111
- this.input.setAttribute('value', this._object.id)
112
- }
113
-
114
- var value = this._object || {}
115
- var basicArgs = {}
116
-
117
- var template =
118
- this.template ||
119
- html`
120
- <object-selector
121
- .value=${value.id}
122
- .confirmCallback=${confirmCallback.bind(this)}
123
- .queryName=${queryName}
124
- .basicArgs=${basicArgs}
125
- ></object-selector>
126
- `
127
-
128
- this.popup = openPopup(template, {
129
- backdrop: true,
130
- size: 'large',
131
- title: i18next.t('title.select_item')
132
- })
133
- }
134
- }
135
-
136
- customElements.define('object-input-container', ObjectInputContainer)
137
-
138
- export class ObjectInput extends HTMLInputElement {
139
- static get observedAttributes() {
140
- return ['query-name', 'value']
141
- }
142
-
143
- connectedCallback() {
144
- if (this.__container) {
145
- this.__container.value = this.value
146
- this.__container.queryName = this.getAttribute('query-name')
147
-
148
- return
149
- }
150
-
151
- this.__container = document.createElement('object-input-container')
152
- this.parentNode.insertBefore(this.__container, this)
153
- this.__container.appendChild(this)
154
- }
155
-
156
- async attributeChangedCallback(name, oldValue, newValue) {}
157
- }
158
-
159
- customElements.define('object-input', ObjectInput, { extends: 'input' })
File without changes