@things-factory/integration-influxdb 8.0.0-beta.9 → 8.0.0

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.
@@ -0,0 +1,9 @@
1
+ import { OxPropertyEditor } from '@operato/property-editor'
2
+
3
+ import './editors/property-editor'
4
+
5
+ export default function bootstrap() {
6
+ OxPropertyEditor.register({
7
+ 'influxdb-point-scheme': 'property-editor-influxdb-point-scheme'
8
+ })
9
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import './things-editor-influxdb-point-scheme'
5
+
6
+ import { html } from 'lit'
7
+
8
+ import { OxPropertyEditor } from '@operato/property-editor'
9
+
10
+ export class PropertyEditorInfluxDBScheme extends OxPropertyEditor {
11
+ static get styles() {
12
+ return [...OxPropertyEditor.styles]
13
+ }
14
+
15
+ editorTemplate(value, spec) {
16
+ return html` <things-editor-influxdb-point-scheme id="editor" .value=${value}></things-editor-influxdb-point-scheme> `
17
+ }
18
+ }
19
+
20
+ customElements.define('property-editor-influxdb-point-scheme', PropertyEditorInfluxDBScheme)
@@ -0,0 +1,308 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/web/icon/icon.js'
6
+ import '@operato/i18n/ox-i18n.js'
7
+
8
+ import { css, html } from 'lit'
9
+ import { customElement, property, queryAll } from 'lit/decorators.js'
10
+
11
+ import { OxFormField } from '@operato/input'
12
+
13
+ type InfluxDBPointScheme = {
14
+ name: string
15
+ type: string
16
+ val?: any
17
+ accessor?: string
18
+ }
19
+
20
+ /**
21
+ input component for influxdb point scheme
22
+
23
+ Example:
24
+
25
+ <things-editor-influxdb-point-scheme
26
+ value=${map}
27
+ </things-editor-influxdb-point-scheme>
28
+ */
29
+ @customElement('things-editor-influxdb-point-scheme')
30
+ export class ThingsEditorInfluxPointScheme extends OxFormField {
31
+ static styles = [
32
+ css`
33
+ :host {
34
+ display: flex;
35
+ flex-direction: column;
36
+ overflow: hidden;
37
+ gap: var(--spacing-medium);
38
+ }
39
+
40
+ div {
41
+ display: flex;
42
+ flex-flow: row nowrap;
43
+ gap: var(--spacing-medium);
44
+ }
45
+
46
+ button {
47
+ border: var(--button-border);
48
+ border-radius: var(--border-radius);
49
+ background-color: var(--button-background-color);
50
+ padding: var(--spacing-small) var(--spacing-medium);
51
+ line-height: 0.8;
52
+ color: var(--button-color);
53
+ cursor: pointer;
54
+ }
55
+
56
+ button + button {
57
+ margin-left: -5px;
58
+ }
59
+
60
+ button md-icon {
61
+ font-size: var(--fontsize-default);
62
+ }
63
+
64
+ button:focus,
65
+ button:hover,
66
+ button:active {
67
+ border: var(--button-activ-border);
68
+ background-color: var(--button-background-focus-color);
69
+ color: var(--md-sys-color-on-primary);
70
+ }
71
+
72
+ input {
73
+ flex: 1;
74
+ border: 0;
75
+ border-bottom: var(--border-dim-color);
76
+ padding: var(--input-padding);
77
+ font: var(--input-font);
78
+ color: var(--primary-text-color);
79
+ min-width: 50px;
80
+ }
81
+
82
+ input:focus {
83
+ outline: none;
84
+ border-bottom: 1px solid var(--md-sys-color-primary);
85
+ }
86
+
87
+ button.hidden {
88
+ opacity: 0;
89
+ cursor: default;
90
+ }
91
+
92
+ select,
93
+ ox-select,
94
+ input:not([type='checkbox']) {
95
+ border: 1px solid rgba(0, 0, 0, 0.2);
96
+ border-radius: 4px;
97
+ }
98
+ `
99
+ ]
100
+
101
+ @property({ type: Array }) value: InfluxDBPointScheme[] = []
102
+
103
+ private _changingNow: boolean = false
104
+
105
+ @queryAll('[data-record]') records!: NodeListOf<HTMLElement>
106
+
107
+ firstUpdated() {
108
+ this.renderRoot.addEventListener('change', this._onChange.bind(this))
109
+ }
110
+
111
+ render() {
112
+ const parameters = this.value || []
113
+
114
+ return html`
115
+ ${parameters.map(
116
+ item => html`
117
+ <div data-record>
118
+ <input type="text" data-name placeholder="name" .value=${item.name} />
119
+ <select data-type placeholder="type" .value=${item.type}>
120
+ <option value="" ?selected=${item.type == ''}>&nbsp;</option>
121
+ <option value="Tag" ?selected=${item.type == 'Tag'}>Tag</option>
122
+ <option value="String" ?selected=${item.type == 'String'}>String</option>
123
+ <option value="Integer" ?selected=${item.type == 'Integer'}>Integer</option>
124
+ <option value="Unsigned" ?selected=${item.type == 'Unsigned'}>Unsigned</option>
125
+ <option value="Float" ?selected=${item.type == 'Float'}>Float</option>
126
+ <option value="Boolean" ?selected=${item.type == 'Boolean'}>Boolean</option>
127
+ </select>
128
+
129
+ <input type="text" data-accessor placeholder="accessor" .value=${item.accessor || ''} list="step-list" />
130
+ <input type="text" data-val placeholder="val" .value=${item.val || ''} />
131
+
132
+ <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">
133
+ <md-icon>remove</md-icon>
134
+ </button>
135
+ <button class="record-action" @click=${(e: MouseEvent) => this._up(e)} tabindex="-1">
136
+ <md-icon>arrow_upward</md-icon>
137
+ </button>
138
+ <button class="record-action" @click=${(e: MouseEvent) => this._down(e)} tabindex="-1">
139
+ <md-icon>arrow_downward</md-icon>
140
+ </button>
141
+ </div>
142
+ `
143
+ )}
144
+
145
+ <div data-record-new>
146
+ <input type="text" data-name placeholder="name" value="" />
147
+ <select data-type placeholder="type" value="">
148
+ <option value="" selected>&nbsp;</option>
149
+ <option value="Tag">Tag</option>
150
+ <option value="String">String</option>
151
+ <option value="Integer">Integer</option>
152
+ <option value="Unsigned">Unsigned</option>
153
+ <option value="Float">Float</option>
154
+ <option value="Boolean">Boolean</option>
155
+ </select>
156
+ <input type="text" data-accessor placeholder="accessor" value="" list="step-list" />
157
+ <input type="text" data-val placeholder="val" value="" />
158
+
159
+ <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
160
+ <md-icon>add</md-icon>
161
+ </button>
162
+ <button class="hidden"><md-icon>arrow_upward</md-icon></button>
163
+ <button class="hidden"><md-icon>arrow_downward</md-icon></button>
164
+ </div>
165
+ `
166
+ }
167
+
168
+ _onChange(e: Event) {
169
+ if (this._changingNow) {
170
+ return
171
+ }
172
+
173
+ this._changingNow = true
174
+
175
+ const input = e.target as HTMLInputElement
176
+
177
+ const record = (e.target as Element).closest('[data-record],[data-record-new]') as HTMLElement
178
+
179
+ if (record.hasAttribute('data-record')) {
180
+ this._build()
181
+ } else if (record.hasAttribute('data-record-new') && input.hasAttribute('data-type')) {
182
+ this._add()
183
+ }
184
+
185
+ this._changingNow = false
186
+ }
187
+
188
+ _adjust({ name, type, val, accessor }: InfluxDBPointScheme): InfluxDBPointScheme {
189
+ const entry = {
190
+ name: name && String(name).trim(),
191
+ type,
192
+ accessor: accessor && String(accessor).trim(),
193
+ val
194
+ } as InfluxDBPointScheme
195
+
196
+ return entry
197
+ }
198
+
199
+ _build(includeNewRecord?: boolean) {
200
+ if (includeNewRecord) {
201
+ var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
202
+ } else {
203
+ var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
204
+ }
205
+
206
+ var newmap: InfluxDBPointScheme[] = []
207
+
208
+ for (var i = 0; i < records.length; i++) {
209
+ var record = records[i]
210
+
211
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
212
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
213
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
214
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
215
+
216
+ const inputs = record.querySelectorAll(
217
+ '[data-type]:not([style*="display: none"])'
218
+ ) as NodeListOf<HTMLInputElement>
219
+
220
+ if (!inputs || inputs.length == 0) {
221
+ continue
222
+ }
223
+
224
+ if (name) {
225
+ newmap.push(this._adjust({ name, type, val, accessor }))
226
+ }
227
+ }
228
+
229
+ this.value = newmap
230
+ this._updateValue()
231
+ }
232
+
233
+ _updateValue() {
234
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
235
+ }
236
+
237
+ _add() {
238
+ this._build(true)
239
+
240
+ const inputs = this.renderRoot.querySelectorAll(
241
+ '[data-record-new] input:not([style*="display: none"])'
242
+ ) as NodeListOf<HTMLInputElement & { value: any }>
243
+
244
+ for (var i = 0; i < inputs.length; i++) {
245
+ let input = inputs[i]
246
+
247
+ input.value = ''
248
+ }
249
+
250
+ inputs[0].focus()
251
+ }
252
+
253
+ _delete(e: MouseEvent) {
254
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
255
+
256
+ ;(record!.querySelector('[data-name]') as HTMLInputElement)!.value = ''
257
+
258
+ this._build()
259
+ }
260
+
261
+ _up(e: MouseEvent) {
262
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
263
+ const array = Array.from(this.records)
264
+ const index = array.indexOf(record) - 1
265
+
266
+ if (index < 0) {
267
+ return
268
+ }
269
+
270
+ const deleted = array.splice(index, 1)
271
+ array.splice(index + 1, 0, ...deleted)
272
+
273
+ this.value = array.map(record => {
274
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
275
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
276
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
277
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
278
+
279
+ return this._adjust({ name, type, val, accessor })
280
+ })
281
+
282
+ this._updateValue()
283
+ }
284
+
285
+ _down(e: MouseEvent) {
286
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
287
+ const array = Array.from(this.records)
288
+ const index = array.indexOf(record)
289
+
290
+ if (index > array.length) {
291
+ return
292
+ }
293
+
294
+ array.splice(index, 1)
295
+ array.splice(index + 1, 0, record)
296
+
297
+ this.value = array.map(record => {
298
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
299
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
300
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
301
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
302
+
303
+ return this._adjust({ name, type, val, accessor })
304
+ })
305
+
306
+ this._updateValue()
307
+ }
308
+ }
File without changes