@mixd-id/web-scaffold 0.2.240701 → 0.2.240703

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.
Files changed (92) hide show
  1. package/docs/schema/user-action.json +266 -0
  2. package/package.json +6 -2
  3. package/public/assets/dashboard/bar.png +0 -0
  4. package/public/assets/dashboard/doughnut.png +0 -0
  5. package/public/assets/dashboard/metric.png +0 -0
  6. package/public/assets/dashboard/pie.png +0 -0
  7. package/public/assets/dashboard/polar-area.png +0 -0
  8. package/public/assets/dashboard/virtual-table.png +0 -0
  9. package/public/static/dashboard/bar.png +0 -0
  10. package/public/static/dashboard/doughnut.png +0 -0
  11. package/public/static/dashboard/metric.png +0 -0
  12. package/public/static/dashboard/pie.png +0 -0
  13. package/public/static/dashboard/polar-area.png +0 -0
  14. package/public/static/dashboard/virtual-table.png +0 -0
  15. package/src/components/Button.vue +179 -160
  16. package/src/components/Checkbox.vue +0 -1
  17. package/src/components/Datepicker.vue +8 -6
  18. package/src/components/GHeatMaps.vue +317 -0
  19. package/src/components/GmapsDirection.vue +191 -0
  20. package/src/components/Grid.vue +2 -0
  21. package/src/components/HTMLEditor.vue +2 -2
  22. package/src/components/List.vue +384 -308
  23. package/src/components/Modal.vue +2 -3
  24. package/src/components/PresetSelectorFilterItem.vue +15 -2
  25. package/src/components/Switch.vue +3 -0
  26. package/src/components/Tabs.vue +1 -1
  27. package/src/components/TextWithTag.vue +67 -25
  28. package/src/components/Textbox.vue +5 -0
  29. package/src/components/VirtualGrid.vue +224 -228
  30. package/src/components/VirtualTable.vue +46 -28
  31. package/src/configs/dashboard/bar.js +10 -0
  32. package/src/configs/dashboard/collection-1.js +5 -0
  33. package/src/configs/dashboard/doughnut.js +7 -0
  34. package/src/configs/dashboard/gheatmaps.js +9 -0
  35. package/src/configs/dashboard/grid-2.js +34 -0
  36. package/src/configs/dashboard/grid-3.js +34 -0
  37. package/src/configs/dashboard/grid-4.js +34 -0
  38. package/src/configs/dashboard/grid.js +15 -0
  39. package/src/configs/dashboard/metric.js +10 -0
  40. package/src/configs/dashboard/pie.js +7 -0
  41. package/src/configs/dashboard/polar-area.js +7 -0
  42. package/src/configs/dashboard/virtual-table.js +9 -0
  43. package/src/defs/dashboard-preset.js +22 -0
  44. package/src/index.js +35 -23
  45. package/src/mixin/ready-state.js +37 -0
  46. package/src/stores/datasource.js +11 -0
  47. package/src/themes/default/index.js +1 -1
  48. package/src/utils/dashboard.js +1080 -0
  49. package/src/utils/event-bus.js +8 -0
  50. package/src/utils/helpers.js +56 -10
  51. package/src/utils/helpers.mjs +35 -1
  52. package/src/utils/preset-selector.js +5 -2
  53. package/src/utils/preset-selector.mjs +23 -13
  54. package/src/widgets/Dashboard/BarChart.vue +330 -0
  55. package/src/widgets/Dashboard/BarChartSetting.vue +317 -0
  56. package/src/widgets/Dashboard/DatasourceFilterSharing.vue +93 -0
  57. package/src/widgets/Dashboard/DatasourcePreview.vue +93 -0
  58. package/src/widgets/Dashboard/DatasourceSelector.vue +122 -0
  59. package/src/widgets/Dashboard/Doughnut.vue +157 -0
  60. package/src/widgets/Dashboard/DoughnutSetting.vue +196 -0
  61. package/src/widgets/Dashboard/GHeatMapsSetting.vue +108 -0
  62. package/src/widgets/Dashboard/InteractionEdit.vue +228 -0
  63. package/src/widgets/Dashboard/Metric.vue +76 -0
  64. package/src/widgets/Dashboard/MetricSetting.vue +174 -0
  65. package/src/widgets/Dashboard/Pie.vue +139 -0
  66. package/src/widgets/Dashboard/PieSetting.vue +247 -0
  67. package/src/widgets/Dashboard/PolarArea.vue +159 -0
  68. package/src/widgets/Dashboard/PolarAreaSetting.vue +195 -0
  69. package/src/widgets/Dashboard/SharingModal.vue +116 -0
  70. package/src/widgets/Dashboard/ViewSelector.vue +183 -0
  71. package/src/widgets/Dashboard/VirtualColumnEdit.vue +97 -0
  72. package/src/widgets/Dashboard/VirtualTableSetting.vue +234 -0
  73. package/src/widgets/Dashboard.vue +1773 -0
  74. package/src/widgets/PresetBar.vue +136 -175
  75. package/src/widgets/PresetBarPivot.vue +186 -0
  76. package/src/widgets/UserActionBuilder/UserActionCondition.vue +97 -0
  77. package/src/widgets/UserActionBuilder/UserActionConsole.vue +77 -0
  78. package/src/widgets/UserActionBuilder/UserActionItem.vue +163 -58
  79. package/src/widgets/UserActionBuilder/UserActionOutput.vue +35 -9
  80. package/src/widgets/UserActionBuilder/UserActionOutputDelay.vue +27 -0
  81. package/src/widgets/UserActionBuilder/UserActionOutputLog.vue +28 -0
  82. package/src/widgets/UserActionBuilder/UserActionOutputReply.vue +135 -0
  83. package/src/widgets/UserActionBuilder/UserActionProps.vue +211 -0
  84. package/src/widgets/UserActionBuilder.vue +68 -199
  85. package/src/widgets/WebPageBuilder4/GridSetting.vue +123 -73
  86. package/src/widgets/WebPageBuilder4/HeightSetting.vue +14 -11
  87. package/src/widgets/WebPageBuilder4/MarginSetting.vue +4 -1
  88. package/src/widgets/WebPageBuilder4/MultiValueSetting.vue +12 -4
  89. package/src/widgets/WebPageBuilder4/PaddingSetting.vue +4 -0
  90. package/src/widgets/WebPageBuilder4/TreeView.vue +6 -3
  91. package/src/widgets/WebPageBuilder4/TreeViewItem.vue +32 -58
  92. package/tailwind.config.js +2 -2
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <div :class="$style.comp">
3
+ <label class="text-text-400 text-ellipsis overflow-hidden whitespace-nowrap">{{ label }}</label>
4
+ <div class="flex flex-row gap-2">
5
+ <h1 v-if="readyState === 1" class="text-ellipsis overflow-hidden whitespace-nowrap" :class="column2Enabled ? '' : 'text-green-600'">
6
+ {{ cValue }}
7
+ </h1>
8
+ <h1 v-else class="text-ellipsis overflow-hidden whitespace-nowrap text-text-300">
9
+ Loading...
10
+ </h1>
11
+
12
+ <div class="flex flex-col" v-if="column2Enabled && readyState === 1">
13
+ <div class="text-sm text-ellipsis whitespace-nowrap overflow-hidden" :class="value?.comparedPercent <= 50 ? 'text-red-600' : 'text-green-600'">{{ value?.comparedPercent }}%</div>
14
+ <div class="text-sm text-ellipsis whitespace-nowrap overflow-hidden">{{ ccValue }}</div>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+
22
+ import {readyStateMixin} from "../../mixin/ready-state";
23
+
24
+ export default{
25
+
26
+ computed: {
27
+
28
+ cValue(){
29
+ let value = parseFloat(this.value?.value)
30
+ if(isNaN(value)) return 'N/A'
31
+ return value.toLocaleString()
32
+ },
33
+
34
+ ccValue(){
35
+ if(!this.column2Enabled) return
36
+
37
+ let value = parseFloat(this.value?.comparedValue)
38
+ if(isNaN(value)) return 'N/A'
39
+ return value.toLocaleString()
40
+ }
41
+
42
+ },
43
+
44
+ mixins: [ readyStateMixin ],
45
+
46
+ props: {
47
+
48
+ column: String,
49
+ columnModifier: String,
50
+
51
+ column2: String,
52
+ column2Enabled: [ Boolean, Number ],
53
+ column2Modifier: String,
54
+
55
+ datasourceUid: String,
56
+
57
+ label: String,
58
+
59
+ value: Object,
60
+
61
+ uid: String,
62
+
63
+ }
64
+
65
+ }
66
+
67
+ </script>
68
+
69
+ <style module>
70
+
71
+ .comp{
72
+ @apply border-[1px] border-text-50 bg-base-500 rounded-xl overflow-hidden;
73
+ @apply p-3 flex flex-col gap-1;
74
+ }
75
+
76
+ </style>
@@ -0,0 +1,174 @@
1
+ <template>
2
+ <div class="flex flex-col gap-5 p-6">
3
+
4
+ <div class="flex flex-row items-center">
5
+ <label class="flex-1">Active</label>
6
+ <Switch v-model="value.props.enabled" :readonly="readonly" @change="$emit('change')" />
7
+ </div>
8
+
9
+ <div class="flex flex-col gap-1">
10
+ <div class="flex flex-row gap-2">
11
+ <label class="flex-1">Datasource</label>
12
+ <button type="button" class="text-primary"
13
+ @click="previewDatasource(selectedDatasource)">Preview</button>
14
+ </div>
15
+ <Dropdown class="min-w-[150px]"
16
+ :readonly="readonly"
17
+ v-model="value.props.datasourceUid"
18
+ @change="delete value.props.columns">
19
+ <option v-for="obj in datasource"
20
+ :value="obj.uid">
21
+ {{ obj.name }}
22
+ </option>
23
+ </Dropdown>
24
+ </div>
25
+
26
+ <div class="flex flex-col gap-1">
27
+ <label class="flex-1">Label</label>
28
+ <Textbox v-model="value.props.label"
29
+ maxlength="30"
30
+ placeholder="Label"
31
+ :readonly="readonly"
32
+ @keyup.enter="$emit('change')"
33
+ @blur="$emit('change')" />
34
+ </div>
35
+
36
+ <div v-if="value.props.datasourceUid" class="flex flex-col gap-5">
37
+ <div class="flex flex-col gap-1">
38
+ <label class="flex-1">Column</label>
39
+ <div class="flex flex-row gap-2">
40
+ <Dropdown class="min-w-[150px] flex-1"
41
+ :readonly="readonly"
42
+ v-model="value.props.column"
43
+ @change="$emit('change')">
44
+ <option v-for="column in selectedDatasourceColumns"
45
+ :value="column.key">
46
+ {{ selectedDatasource.pivot?.enabled ? column.key : column.label }}
47
+ </option>
48
+ </Dropdown>
49
+
50
+ <Dropdown class="w-[125px]"
51
+ :readonly="readonly"
52
+ v-model="value.props.columnModifier"
53
+ @change="$emit('change')">
54
+ <option value="count">Count</option>
55
+ <option value="countDistinct">Unique Count</option>
56
+ <option value="sum">Sum</option>
57
+ <option value="avg">Avg</option>
58
+ <option value="min">Min</option>
59
+ <option value="max">Max</option>
60
+ <option value="first">First</option>
61
+ <option value="last">Last</option>
62
+ </Dropdown>
63
+ </div>
64
+ </div>
65
+
66
+ <div class="flex flex-col gap-2">
67
+ <div>
68
+ <Checkbox v-model="value.props.column2Enabled" :disabled="readonly">
69
+ Compare to
70
+ </Checkbox>
71
+ </div>
72
+ <div class="flex flex-row gap-2">
73
+ <Dropdown class="min-w-[150px] flex-1"
74
+ :readonly="readonly || !value.props.column2Enabled"
75
+ v-model="value.props.column2"
76
+ @change="$emit('change')">
77
+ <option v-for="column in selectedDatasourceColumns"
78
+ :value="column.key">
79
+ {{ selectedDatasource.pivot?.enabled ? column.key : column.label }}
80
+ </option>
81
+ </Dropdown>
82
+
83
+ <Dropdown class="w-[125px]"
84
+ :readonly="readonly || !value.props.column2Enabled"
85
+ v-model="value.props.column2Modifier"
86
+ @change="$emit('change')">
87
+ <option value="count">Count</option>
88
+ <option value="countDistinct">Unique Count</option>
89
+ <option value="sum">Sum</option>
90
+ <option value="avg">Avg</option>
91
+ <option value="min">Min</option>
92
+ <option value="max">Max</option>
93
+ <option value="first">First</option>
94
+ <option value="last">Last</option>
95
+ </Dropdown>
96
+ </div>
97
+ </div>
98
+
99
+ <div v-if="value.props.column2Enabled && !readonly" class="flex justify-center p-3">
100
+ <button type="button" class="text-primary" @click="swap">
101
+ <svg width="14" height="14" class="fill-primary inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M449.9 39.96l-48.5 48.53C362.5 53.19 311.4 32 256 32C161.5 32 78.59 92.34 49.58 182.2c-5.438 16.81 3.797 34.88 20.61 40.28c16.97 5.5 34.86-3.812 40.3-20.59C130.9 138.5 189.4 96 256 96c37.96 0 73 14.18 100.2 37.8L311.1 178C295.1 194.8 306.8 223.4 330.4 224h146.9C487.7 223.7 496 215.3 496 204.9V59.04C496 34.99 466.9 22.95 449.9 39.96zM441.8 289.6c-16.94-5.438-34.88 3.812-40.3 20.59C381.1 373.5 322.6 416 256 416c-37.96 0-73-14.18-100.2-37.8L200 334C216.9 317.2 205.2 288.6 181.6 288H34.66C24.32 288.3 16 296.7 16 307.1v145.9c0 24.04 29.07 36.08 46.07 19.07l48.5-48.53C149.5 458.8 200.6 480 255.1 480c94.45 0 177.4-60.34 206.4-150.2C467.9 313 458.6 294.1 441.8 289.6z"/></svg>
102
+ Swap
103
+ </button>
104
+ </div>
105
+ </div>
106
+
107
+ </div>
108
+ </template>
109
+
110
+ <script>
111
+
112
+ export default{
113
+
114
+ computed: {
115
+
116
+ selectedDatasource(){
117
+ return this.datasource.find(d => d.uid === this.value.props.datasourceUid)
118
+ },
119
+
120
+ selectedDatasourceColumns(){
121
+ if(!this.selectedDatasource) return []
122
+
123
+ return this.selectedDatasource.pivot?.enabled ?
124
+ this.selectedDatasource.pivot.columns :
125
+ [
126
+ ...(this.selectedDatasource.computedColumns ?? []),
127
+ ...this.selectedDatasource.columns
128
+ ]
129
+ },
130
+
131
+ },
132
+
133
+ emits: [ 'change' ],
134
+
135
+ inject: [ 'previewDatasource' ],
136
+
137
+ methods: {
138
+
139
+ swap(){
140
+ const props = {
141
+ column: this.value.props.column2,
142
+ columnModifier: this.value.props.column2Modifier,
143
+ column2: this.value.props.column,
144
+ column2Modifier: this.value.props.columnModifier,
145
+ }
146
+
147
+ Object.assign(this.value.props, props)
148
+
149
+ this.$emit('change')
150
+ }
151
+
152
+ },
153
+
154
+ props: {
155
+
156
+ datasource: Object,
157
+
158
+ readonly: [ Boolean, Number ],
159
+
160
+ value: Object
161
+
162
+ }
163
+
164
+ }
165
+
166
+ </script>
167
+
168
+ <style module>
169
+
170
+ .comp{
171
+
172
+ }
173
+
174
+ </style>
@@ -0,0 +1,139 @@
1
+ <template>
2
+ <div v-if="readyState === 1" class="flex flex-col gap-2">
3
+
4
+ <Pie class="aspect-square"
5
+ :options="chartOptions"
6
+ :data="chartData" />
7
+
8
+ <div class="px-3 text-center text-ellipsis overflow-hidden whitespace-nowrap capitalize">
9
+ {{ label }}
10
+ </div>
11
+
12
+ </div>
13
+
14
+ <div v-else-if="readyState === 2" class="aspect-square flex items-center justify-center">
15
+ <label class="text-text-300">Loading...</label>
16
+ </div>
17
+ </template>
18
+
19
+ <script>
20
+
21
+ import {Pie} from 'vue-chartjs'
22
+ import {color} from 'chart.js/helpers'
23
+ import {strVars} from "../../utils/helpers.mjs";
24
+ import {readyStateMixin} from "../../mixin/ready-state";
25
+
26
+ export default{
27
+
28
+ components: {
29
+ Pie
30
+ },
31
+
32
+ computed: {
33
+
34
+ chartData(){
35
+ if(!this.value?.datasets)
36
+ return { labels:[], datasets:[] }
37
+
38
+ return {
39
+ labels: this.value?.labels ?? [],
40
+ datasets: this.value.datasets.map(_ => {
41
+ return {
42
+ ..._,
43
+ borderWidth: 1,
44
+ borderColor: function(context, options) {
45
+ const hex = options.color;
46
+ return color(hex).darken(0.5).rgbString()
47
+ }
48
+ }
49
+ })
50
+ }
51
+ },
52
+
53
+ chartOptions(){
54
+ return {
55
+ responsive: true,
56
+ maintainAspectRatio: true,
57
+ plugins: {
58
+ legend: {
59
+ display: false
60
+ },
61
+ tooltip: {
62
+ callbacks: {
63
+ title: function(tooltipItems) {
64
+ return `${tooltipItems[0].label}`;
65
+ },
66
+ label: (tooltipItem) => {
67
+ const total = tooltipItem.dataset.data.reduce((a, b) => a + b, 0)
68
+ const percentage = ((tooltipItem.raw / total) * 100).toFixed(1)
69
+
70
+ return `${tooltipItem.dataset.label}: ${tooltipItem.raw} (${percentage}%)`;
71
+ }
72
+ },
73
+ },
74
+ },
75
+ onClick: this.onClick
76
+ }
77
+ },
78
+
79
+ },
80
+
81
+ inject: [ 'selectPreset' ],
82
+
83
+ methods: {
84
+
85
+ onClick(e, segments){
86
+
87
+ const clickInteractions = (this.interactions ?? []).filter(_ => _.event === 'click')
88
+ const segment = segments[0]
89
+ if(!segment) return
90
+
91
+ const dataset = this.value.datasets[segment.datasetIndex]
92
+ const obj = {
93
+ segment: this.value.labels[segment.index],
94
+ key: dataset.label,
95
+ value: dataset.data[segment.index]
96
+ }
97
+
98
+ for(let click of clickInteractions){
99
+ const { action, presetUid, filters } = click
100
+
101
+ const params = filters.reduce((res, cur) => {
102
+ res[cur.datasourceUid + '.filters.' + cur.key + '.' + cur.operator] = strVars(cur.value, obj)
103
+ return res
104
+ }, {})
105
+
106
+ switch(action){
107
+
108
+ case 'openDashboardPreset':
109
+ if(typeof this.selectPreset === 'function')
110
+ this.selectPreset(presetUid, params)
111
+ break
112
+ }
113
+ }
114
+
115
+ }
116
+
117
+ },
118
+
119
+ mixins: [ readyStateMixin ],
120
+
121
+ props: {
122
+
123
+ label: String,
124
+
125
+ value: Object,
126
+
127
+ column: Object,
128
+
129
+ datasourceUid: String,
130
+
131
+ interactions: Array,
132
+
133
+ uid: String
134
+
135
+ }
136
+
137
+ }
138
+
139
+ </script>
@@ -0,0 +1,247 @@
1
+ <template>
2
+ <div class="flex flex-col gap-6 p-6">
3
+
4
+ <div class="flex flex-row items-center">
5
+ <label class="flex-1">Active</label>
6
+ <Switch v-model="value.props.enabled" :readonly="readonly" @change="$emit('change')" />
7
+ </div>
8
+
9
+ <div>
10
+ <div class="flex flex-row gap-2">
11
+ <label class="flex-1">Datasource</label>
12
+ <button type="button" class="text-primary"
13
+ @click="previewDatasource(selectedDatasource)">Preview</button>
14
+ </div>
15
+ <Dropdown class="min-w-[150px]"
16
+ :readonly="readonly"
17
+ v-model="value.props.datasourceUid"
18
+ @change="delete value.props.columns">
19
+ <option v-for="obj in datasource"
20
+ :value="obj.uid">
21
+ {{ obj.name }}
22
+ </option>
23
+ </Dropdown>
24
+ </div>
25
+
26
+ <div class="flex flex-col gap-1">
27
+ <label class="text-text-400">Label</label>
28
+ <Textbox v-model="value.props.label" maxlength="50" placeholder="Label" :readonly="readonly" />
29
+ </div>
30
+
31
+ <div v-if="value.props.datasourceUid" class="flex flex-col gap-5">
32
+ <div>
33
+ <label class="text-text-400">Segment</label>
34
+ <div class="flex flex-row gap-2">
35
+ <Dropdown class="min-w-[150px]"
36
+ v-model="value.props.rows"
37
+ :readonly="readonly"
38
+ @change="$emit('change')">
39
+ <option v-for="column in selectedDatasourceColumns"
40
+ :value="column.key">
41
+ {{ column.label }}
42
+ </option>
43
+ </Dropdown>
44
+
45
+ <Dropdown v-model="value.props.rowsModifier"
46
+ :readonly="readonly"
47
+ class="w-[125px]"
48
+ @change="$emit('change')">
49
+ <option value="">-</option>
50
+ <option value="lowercase">Lower</option>
51
+ <option value="capitalize">Capitalize</option>
52
+ <option value="uppercase">Upper</option>
53
+ <option disabled>-----</option>
54
+ <option value="date">Date</option>
55
+ <option value="month">Month</option>
56
+ <option value="year">Year</option>
57
+ <option value="hour">Hour</option>
58
+ <option value="minute">Minute</option>
59
+ </Dropdown>
60
+ </div>
61
+ </div>
62
+
63
+ <div>
64
+ <div class="flex flex-row">
65
+ <label class="flex-1 text-primary cursor-pointer"
66
+ ref="yAxis"
67
+ @click="$refs.context2.open($refs.yAxis)">
68
+ {{ value.props.multipleValues ? 'Multiple Values' : 'Value' }}
69
+ <svg class="fill-primary inline relative top-[-1px]" width="12" height="12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M310.6 246.6l-127.1 128C176.4 380.9 168.2 384 160 384s-16.38-3.125-22.63-9.375l-127.1-128C.2244 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75S319.8 237.5 310.6 246.6z"/></svg>
70
+ </label>
71
+ <ContextMenu ref="context2">
72
+ <div class="flex flex-col min-w-[100px]">
73
+
74
+ <button class="w-full p-3 text-left flex flex-row" :class="appStyle.menuItem"
75
+ @click="value.props.multipleValues = false;$emit('change')">
76
+ Single
77
+ </button>
78
+ <button class="w-full p-3 text-left flex flex-row" :class="appStyle.menuItem"
79
+ @click="value.props.multipleValues = true;$emit('change')">
80
+ Multiple
81
+ </button>
82
+ </div>
83
+ </ContextMenu>
84
+ <button v-if="value.props.multipleValues && !readonly" type="button" class="text-primary" @click="column.push({})">
85
+ <svg width="14" height="14" class="fill-primary" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"/></svg>
86
+ </button>
87
+ </div>
88
+ <ListItem :items="column"
89
+ class="mt-2 bg-transparent"
90
+ container-class="flex flex-col gap-2"
91
+ @reorder="(from, to) => { column.splice(to, 0, column.splice(from, 1)[0]); $emit('change') }">
92
+ <template v-slot="{ item, index }">
93
+ <div class="flex flex-row items-center gap-2">
94
+ <div data-reorder v-if="column.length > 1">
95
+ <svg width="14" height="14" class="fill-text-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M496 288H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-128H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16z"/></svg>
96
+ </div>
97
+ <div class="flex-1 flex flex-row gap-2">
98
+ <Dropdown class="flex-1"
99
+ v-model="item.key"
100
+ :readonly="readonly"
101
+ @change="$emit('change')">
102
+ <option v-for="column in selectedDatasourceColumns"
103
+ :value="column.key">
104
+ {{ column.label }}
105
+ </option>
106
+ </Dropdown>
107
+
108
+ <Dropdown v-model="item.modifier"
109
+ :readonly="readonly"
110
+ class="w-[125px]"
111
+ @change="$emit('change')">
112
+ <option value="">-</option>
113
+ <option value="count">Count</option>
114
+ <option value="countDistinct">Unique Count</option>
115
+ <option value="sum">Sum</option>
116
+ <option value="avg">Avg</option>
117
+ <option value="min">Min</option>
118
+ <option value="max">Max</option>
119
+ </Dropdown>
120
+ </div>
121
+ <button v-if="column.length > 1 && !readonly" type="button" @click="column.splice(index, 1);$emit('change')">
122
+ <svg width="16" height="16" class="fill-text-300 hover:fill-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"/></svg>
123
+ </button>
124
+ </div>
125
+ </template>
126
+ </ListItem>
127
+ </div>
128
+
129
+ <div>
130
+ <div class="flex flex-row gap-2">
131
+ <label class="text-text-400 flex-1">Interactions</label>
132
+ <button type="button" class="text-primary" @click="$refs.interactionEdit.create()">
133
+ <svg width="14" height="14" class="fill-primary" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"/></svg>
134
+ </button>
135
+ </div>
136
+ <div class="mt-1">
137
+ <ListItem :items="interactions"
138
+ class="rounded-xl"
139
+ container-class="flex flex-col divide-y divide-text-50"
140
+ @reorder="(from, to) => { interactions.splice(to, 0, interactions.splice(from, 1)[0]); }">
141
+ <template v-slot="{ item, index }">
142
+ <div class="flex flex-row items-center gap-3 px-3">
143
+ <div data-reorder v-if="interactions.length > 1">
144
+ <svg width="14" height="14" class="fill-text-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M496 288H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-128H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16z"/></svg>
145
+ </div>
146
+ <div class="flex-1 p-3 cursor-pointer" @click="$refs.interactionEdit.open(item)">
147
+ {{ item.event }}
148
+ {{ item.eventModifier ? item.eventModifier : '' }}
149
+ </div>
150
+ <button type="button" @click="interactions.splice(index, 1)">
151
+ <svg width="16" height="16" class="fill-text-300 hover:fill-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"/></svg>
152
+ </button>
153
+ </div>
154
+ </template>
155
+ </ListItem>
156
+
157
+ <InteractionEdit ref="interactionEdit" @save="addInteraction" />
158
+ </div>
159
+ </div>
160
+ </div>
161
+
162
+ </div>
163
+ </template>
164
+
165
+ <script>
166
+
167
+ import InteractionEdit from "./InteractionEdit.vue";
168
+
169
+ export default{
170
+ components: {InteractionEdit},
171
+
172
+ computed: {
173
+
174
+ column(){
175
+ if(!Array.isArray(this.value.props.column))
176
+ this.value.props.column = [ { key:'' } ]
177
+
178
+ if(this.value.props.multipleValues)
179
+ return this.value.props.column
180
+ return [ this.value.props.column[0] ]
181
+ },
182
+
183
+ interactions(){
184
+ if(!Array.isArray(this.value.props.interactions))
185
+ this.value.props.interactions = []
186
+ return this.value.props.interactions
187
+ },
188
+
189
+ selectedDatasource(){
190
+ return this.datasource.find(d => d.uid === this.value.props.datasourceUid)
191
+ },
192
+
193
+ selectedDatasourceColumns(){
194
+ if(!this.selectedDatasource) return []
195
+
196
+ return this.selectedDatasource.pivot?.enabled ?
197
+ this.selectedDatasource.pivot.columns :
198
+ [
199
+ ...(this.selectedDatasource.computedColumns ?? []),
200
+ ...this.selectedDatasource.columns
201
+ ]
202
+ },
203
+
204
+ },
205
+
206
+ emits: [ 'change' ],
207
+
208
+ inject: [ 'appStyle', 'previewDatasource' ],
209
+
210
+ methods: {
211
+
212
+ addInteraction(obj){
213
+ this.$util.push(this.interactions, obj)
214
+ },
215
+
216
+ applyDefault(){
217
+ if(!this.value.props.datasourceUid && this.datasource?.length === 1){
218
+ this.value.props.datasourceUid = this.datasource[0].uid
219
+ }
220
+ },
221
+
222
+ onColumnChanged(){
223
+ if(!this.value.props.label)
224
+ this.value.props.label = this.column[0]
225
+
226
+ this.$emit('change')
227
+ }
228
+
229
+ },
230
+
231
+ mounted() {
232
+ this.applyDefault()
233
+ },
234
+
235
+ props: {
236
+
237
+ datasource: Object,
238
+
239
+ readonly: [ Boolean, Number ],
240
+
241
+ value: Object
242
+
243
+ }
244
+
245
+ }
246
+
247
+ </script>