@infineon/infineon-vue-datatable 0.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +44 -0
  3. package/src/datatable/InfineonDatatable.vue +278 -0
  4. package/src/datatable/InfineonDatatablePager.vue +146 -0
  5. package/src/datatable/InfineonDatatableRow.vue +229 -0
  6. package/src/datatable/InfineonDatatableRowColumn.vue +88 -0
  7. package/src/datatable/InfineonDatatableShowColumnsPicker.vue +45 -0
  8. package/src/datatable/InfineonDatatableSortIcon.vue +49 -0
  9. package/src/index.js +4 -0
  10. package/src/plugins/axiosErrorHandler.js +11 -0
  11. package/src/plugins/axiosLoadingOverlay.js +42 -0
  12. package/src/plugins/fontawesome.js +70 -0
  13. package/src/plugins/treeView/index.js +12 -0
  14. package/src/plugins/treeView/src/components/Control.vue +152 -0
  15. package/src/plugins/treeView/src/components/HiddenFields.vue +40 -0
  16. package/src/plugins/treeView/src/components/Input.vue +298 -0
  17. package/src/plugins/treeView/src/components/Menu.vue +314 -0
  18. package/src/plugins/treeView/src/components/MenuPortal.vue +195 -0
  19. package/src/plugins/treeView/src/components/MultiValue.vue +60 -0
  20. package/src/plugins/treeView/src/components/MultiValueItem.vue +49 -0
  21. package/src/plugins/treeView/src/components/Option.vue +302 -0
  22. package/src/plugins/treeView/src/components/Placeholder.vue +20 -0
  23. package/src/plugins/treeView/src/components/SingleValue.vue +32 -0
  24. package/src/plugins/treeView/src/components/Tip.vue +40 -0
  25. package/src/plugins/treeView/src/components/Treeselect.vue +63 -0
  26. package/src/plugins/treeView/src/components/icons/Arrow.vue +14 -0
  27. package/src/plugins/treeView/src/components/icons/Delete.vue +17 -0
  28. package/src/plugins/treeView/src/constants.js +50 -0
  29. package/src/plugins/treeView/src/mixins/treeselectMixin.js +2083 -0
  30. package/src/plugins/treeView/src/utils/.eslintrc.js +6 -0
  31. package/src/plugins/treeView/src/utils/constant.js +1 -0
  32. package/src/plugins/treeView/src/utils/createMap.js +1 -0
  33. package/src/plugins/treeView/src/utils/debounce.js +1 -0
  34. package/src/plugins/treeView/src/utils/deepExtend.js +29 -0
  35. package/src/plugins/treeView/src/utils/find.js +6 -0
  36. package/src/plugins/treeView/src/utils/identity.js +1 -0
  37. package/src/plugins/treeView/src/utils/includes.js +3 -0
  38. package/src/plugins/treeView/src/utils/index.js +38 -0
  39. package/src/plugins/treeView/src/utils/isNaN.js +3 -0
  40. package/src/plugins/treeView/src/utils/isPromise.js +1 -0
  41. package/src/plugins/treeView/src/utils/last.js +1 -0
  42. package/src/plugins/treeView/src/utils/noop.js +1 -0
  43. package/src/plugins/treeView/src/utils/onLeftClick.js +7 -0
  44. package/src/plugins/treeView/src/utils/once.js +1 -0
  45. package/src/plugins/treeView/src/utils/quickDiff.js +9 -0
  46. package/src/plugins/treeView/src/utils/removeFromArray.js +4 -0
  47. package/src/plugins/treeView/src/utils/scrollIntoView.js +15 -0
  48. package/src/plugins/treeView/src/utils/setupResizeAndScrollEventListeners.js +34 -0
  49. package/src/plugins/treeView/src/utils/warning.js +11 -0
  50. package/src/plugins/treeView/src/utils/watchSize.js +67 -0
  51. package/src/plugins/treeView/styles/assets/checkbox-checked-disabled.png +0 -0
  52. package/src/plugins/treeView/styles/assets/checkbox-checked-disabled@2x.png +0 -0
  53. package/src/plugins/treeView/styles/assets/checkbox-checked-disabled@3x.png +0 -0
  54. package/src/plugins/treeView/styles/assets/checkbox-checked.png +0 -0
  55. package/src/plugins/treeView/styles/assets/checkbox-checked@2x.png +0 -0
  56. package/src/plugins/treeView/styles/assets/checkbox-checked@3x.png +0 -0
  57. package/src/plugins/treeView/styles/assets/checkbox-indeterminate-disabled.png +0 -0
  58. package/src/plugins/treeView/styles/assets/checkbox-indeterminate-disabled@2x.png +0 -0
  59. package/src/plugins/treeView/styles/assets/checkbox-indeterminate-disabled@3x.png +0 -0
  60. package/src/plugins/treeView/styles/assets/checkbox-indeterminate.png +0 -0
  61. package/src/plugins/treeView/styles/assets/checkbox-indeterminate@2x.png +0 -0
  62. package/src/plugins/treeView/styles/assets/checkbox-indeterminate@3x.png +0 -0
  63. package/src/plugins/treeView/styles/style.less +1150 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Infineon Technologies AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@infineon/infineon-vue-datatable",
3
+ "version": "0.0.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org/ "
7
+ },
8
+ "repository": "git://github.com/infineon/infineon-vue-datable",
9
+ "description": "",
10
+ "main": "src/index.js",
11
+ "files": [
12
+ "/src/**/*"
13
+ ],
14
+ "scripts": {
15
+ },
16
+ "keywords": [
17
+ "vue3"
18
+ ],
19
+ "author": "Verena Lechner, Kai Werther",
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ },
23
+ "devDependencies": {
24
+ "auto": "^10.37.4",
25
+ "vue": ">= 3.0.2",
26
+ "eslint": "^7.28.0",
27
+ "eslint-config-airbnb-base": "^14.2.1",
28
+ "eslint-import-resolver-alias": "^1.1.2",
29
+ "eslint-plugin-import": "^2.23.4",
30
+ "eslint-plugin-vue": "^9.1.1"
31
+ },
32
+ "peerDependencies": {
33
+ "vue": ">= 3.0.2",
34
+ "bootstrap": "^5.1.3",
35
+ "json2csv": "^5.0.6"
36
+ },
37
+ "auto": {
38
+ "plugins": [
39
+ "npm",
40
+ "released"
41
+ ],
42
+ "onlyPublishWithReleaseLabel": true
43
+ }
44
+ }
@@ -0,0 +1,278 @@
1
+ <template>
2
+ <div
3
+ class="d-flex flex-column justify-content-center flex-grow-1 pt-3"
4
+ style="overflow:auto"
5
+ >
6
+ <div
7
+ class="flex-grow-1 table-responsive"
8
+ style="overflow:auto"
9
+ >
10
+ <table
11
+ class="table table-sm table-hover"
12
+ style="border-collapse: separate;border-spacing: 0;"
13
+ >
14
+ <thead>
15
+ <tr>
16
+ <th
17
+ v-if="canEdit"
18
+ class="stickyHeader"
19
+ >
20
+ Actions
21
+ </th>
22
+ <th
23
+ v-for="(column, index) in shownColumns"
24
+ :key="index"
25
+ class="stickyHeader text-nowrap"
26
+ scope="col"
27
+ >
28
+ {{ column.title }}
29
+ <DatatableSortIcon
30
+ v-model:sort-column="sortColumn"
31
+ :column="column"
32
+ />
33
+ <a
34
+ v-if="column.hidable"
35
+ href="#"
36
+ @click="changeColumnVisibility(column.key)"
37
+ >
38
+ <font-awesome-icon
39
+ class="fa-sm ms-2"
40
+ :icon="['fas', 'times']"
41
+ />
42
+ </a>
43
+ </th>
44
+ </tr>
45
+ </thead>
46
+
47
+ <tbody>
48
+ <DatatableRow
49
+
50
+ v-for="(row,idx) in processedData"
51
+ :key="row.id"
52
+ :row-index="idx"
53
+
54
+ :row="row"
55
+ :columns="realColumns"
56
+ :hidden-column-keys="hiddenColumnKeys"
57
+ :row-is-in-edit-mode="(row.id) === (rowInEditMode?.id)"
58
+ :can-edit="canEdit"
59
+ :additional-actions="additionalActions"
60
+ @startEditRow="startEditRow"
61
+ @saveRow="saveRow"
62
+ @cancelRow="cancelRow"
63
+ >
64
+ <template
65
+ v-for="(_, name) in $slots"
66
+ #[name]="slotData"
67
+ >
68
+ <slot
69
+ :name="name"
70
+ v-bind="slotData || {}"
71
+ />
72
+ </template>
73
+ </DatatableRow>
74
+ </tbody>
75
+ </table>
76
+ </div>
77
+ <div class="mt-1 d-flex flex-row">
78
+ <DatatablePager
79
+ v-model:currentPage="currentPage"
80
+ class="flex-grow-1"
81
+ :page-size="pageSize"
82
+ :count="count"
83
+ @updatePageSize="updatePageSize"
84
+ />
85
+ <DatatableShowColumnsPicker
86
+ style="max-width:15em"
87
+ :columns="realColumns"
88
+ :hidden-column-keys="hiddenColumnKeys"
89
+ @changeColumnVisibility="changeColumnVisibility"
90
+ />
91
+ <div
92
+ v-if="exportable"
93
+ class="mt-1 ms-1"
94
+ >
95
+ <button
96
+ class="btn btn-sm btn-primary"
97
+ title="Download CSV File"
98
+ @click="exportCSV"
99
+ >
100
+ <font-awesome-icon :icon="['fas', 'file-download']" />
101
+ Download
102
+ </button>
103
+ </div>
104
+ </div>
105
+ </div>
106
+ </template>
107
+
108
+ <script setup>
109
+ // style="max-width: 13em"
110
+ import {
111
+ toRefs, computed, ref, onMounted, watch,
112
+ } from 'vue';
113
+ import json2Csv from 'json2csv/dist/json2csv.umd';
114
+ import DatatableRow from './InfineonDatatableRow.vue';
115
+ import DatatablePager from './InfineonDatatablePager.vue';
116
+ import DatatableSortIcon from './InfineonDatatableSortIcon.vue';
117
+ import DatatableShowColumnsPicker from './InfineonDatatableShowColumnsPicker.vue';
118
+
119
+ const props = defineProps({
120
+ canEdit: Boolean,
121
+ data: { type: Array, default: () => [] },
122
+ columns: { type: Array, default: () => [] },
123
+ exportable: Boolean,
124
+ defaultSort: { type: Object, default: () => {} }, // {key: '', type: 'A/D'}
125
+ additionalActions: { type: Object, default: () => {} },
126
+ // [ { label: '', action: (row) => {}, icon: ['fas', 'list-ol'] } ]
127
+ });
128
+ const emit = defineEmits(['saveRow']);
129
+
130
+ const { data, columns } = toRefs(props);
131
+
132
+ const sortColumn = ref(props.defaultSort);
133
+ const currentPage = ref(0);
134
+ const pageSize = ref(10);
135
+ const rowInEditMode = ref(undefined);
136
+ const count = ref(0);
137
+
138
+ const hiddenColumnKeys = ref([]);
139
+
140
+ const realColumns = computed(() => columns.value
141
+ .filter((c) => c.visible === undefined || c.visible === false));
142
+
143
+ const shownColumns = computed(() => realColumns.value
144
+ .filter((c) => !c.hidable || !hiddenColumnKeys.value.includes(c.key)));
145
+
146
+ // reset page & item count when data changes
147
+ watch(
148
+ data,
149
+ (newData) => {
150
+ count.value = newData ? newData.length : 0;
151
+ if (count.value / pageSize.value < currentPage.value) {
152
+ currentPage.value = parseInt(count.value / pageSize.value, 10);
153
+ }
154
+ },
155
+ { immediate: true },
156
+ );
157
+
158
+ const processedData = computed(() => {
159
+ const sortedData = data.value.slice(0);
160
+ if (sortColumn.value && sortColumn.value.key) {
161
+ const { key, type } = sortColumn.value;
162
+ const {
163
+ sortType,
164
+ valueResolver,
165
+ filterResolverKey,
166
+ } = realColumns.value.find((c) => c.key === key);
167
+
168
+ if (filterResolverKey || !valueResolver) {
169
+ const vKey = filterResolverKey || key;
170
+
171
+ if (sortType === 'NUMBER' && type === 'D') {
172
+ sortedData.sort((a, b) => b[vKey] - a[vKey]);
173
+ } else if (sortType === 'NUMBER' && type === 'A') {
174
+ sortedData.sort((a, b) => a[vKey] - b[vKey]);
175
+ } else if (sortType === 'STRING' && type === 'D') {
176
+ sortedData.sort((a, b) => b[vKey]?.localeCompare(a[vKey]));
177
+ } else if (sortType === 'STRING' && type === 'A') {
178
+ sortedData.sort((a, b) => a[vKey]?.localeCompare(b[vKey]));
179
+ }
180
+ } else if (valueResolver) {
181
+ if (sortType === 'NUMBER' && type === 'D') {
182
+ sortedData.sort((a, b) => valueResolver(b) - valueResolver(a));
183
+ } else if (sortType === 'NUMBER' && type === 'A') {
184
+ sortedData.sort((a, b) => valueResolver(a) - valueResolver(b));
185
+ } else if (sortType === 'STRING' && type === 'D') {
186
+ sortedData.sort((a, b) => valueResolver(b)?.localeCompare(valueResolver(a)));
187
+ } else if (sortType === 'STRING' && type === 'A') {
188
+ sortedData.sort((a, b) => valueResolver(a)?.localeCompare(valueResolver(b)));
189
+ }
190
+ }
191
+ }
192
+
193
+ const sliced = sortedData.slice(
194
+ currentPage.value * pageSize.value,
195
+ (currentPage.value + 1) * pageSize.value,
196
+ );
197
+
198
+ return sliced;
199
+ });
200
+
201
+ // we listen to column changes. so each table will have it's own storage key
202
+ const hiddenColumnsLocalStorageKey = computed(() => realColumns
203
+ .value.map((c) => c.key).sort().join());
204
+ onMounted(() => {
205
+ if (localStorage.getItem(hiddenColumnsLocalStorageKey.value)) {
206
+ try {
207
+ hiddenColumnKeys.value = JSON
208
+ .parse(localStorage.getItem(hiddenColumnsLocalStorageKey.value));
209
+ } catch (e) {
210
+ localStorage.removeItem(hiddenColumnsLocalStorageKey.value);
211
+ }
212
+ } else {
213
+ hiddenColumnKeys.value = realColumns.value.filter((c) => c.defaultHidden).map((c) => c.key);
214
+ }
215
+ });
216
+
217
+ function changeColumnVisibility(columnKey) {
218
+ if (hiddenColumnKeys.value.includes(columnKey)) {
219
+ const index = hiddenColumnKeys.value.indexOf(columnKey);
220
+ hiddenColumnKeys.value.splice(index, 1);
221
+ } else {
222
+ hiddenColumnKeys.value.push(columnKey);
223
+ }
224
+ localStorage.setItem(hiddenColumnsLocalStorageKey.value, JSON.stringify(hiddenColumnKeys.value));
225
+ }
226
+
227
+ function startEditRow(row) {
228
+ rowInEditMode.value = row ? { ...row } : undefined;
229
+ }
230
+ async function saveRow(row) {
231
+ emit('saveRow', row);
232
+ rowInEditMode.value = undefined;
233
+ }
234
+ function cancelRow() {
235
+ rowInEditMode.value = undefined;
236
+ }
237
+ function updatePageSize(size) {
238
+ pageSize.value = size;
239
+ }
240
+
241
+ async function exportCSV() {
242
+ const fields = shownColumns.value.map((col) => ({ label: col.title, value: col.key }));
243
+ const transforms = (row) => Object.fromEntries(
244
+ shownColumns.value.map((col) => [
245
+ col.key,
246
+ col.valueResolver ? col.valueResolver(row) : row[col.key],
247
+ ]),
248
+ );
249
+
250
+ const opts = { fields, transforms };
251
+
252
+ json2Csv.parseAsync(data.value, opts)
253
+ .then((csv) => {
254
+ const sep = 'sep=,\r\n';
255
+ const BOM = new Uint8Array([0xEF, 0xBB, 0xBF]);
256
+ const blob = new Blob([BOM, csv], { type: 'text/csv;charset=utf-8' });
257
+ const link = document.createElement('a');
258
+ link.href = URL.createObjectURL(blob);
259
+ link.download = 'download.csv';
260
+ link.click();
261
+ URL.revokeObjectURL(link.href);
262
+ }).catch((err) => console.log('Error downloading file!'));
263
+ }
264
+ </script>
265
+
266
+ <style scoped>
267
+ .oddRow {
268
+ --bs-table-accent-bg: var(--bs-table-striped-bg);
269
+ color: var(--bs-table-striped-color);
270
+ }
271
+
272
+ .stickyHeader {
273
+ position:sticky;
274
+ top:0;
275
+ border-bottom: 2px solid black;
276
+ background-color: white
277
+ }
278
+ </style>
@@ -0,0 +1,146 @@
1
+ <template>
2
+ <div class="text-center">
3
+ <nav
4
+ aria-label="Page navigation example"
5
+ class="d-inline-block"
6
+ >
7
+ <ul class="pagination justify-content-center mb-0">
8
+ <li
9
+ :class="{'invisible': currentPage <= 0}"
10
+ class="page-item"
11
+ >
12
+ <a
13
+ class="page-link"
14
+ href="#"
15
+ @click="changePage(0)"
16
+ ><font-awesome-icon
17
+ :icon="['fas', 'angle-double-left']"
18
+ /></a>
19
+ </li>
20
+ <li
21
+ :class="{'invisible': currentPage <= 0}"
22
+ class="page-item"
23
+ >
24
+ <a
25
+ class="page-link"
26
+ href="#"
27
+ @click="changePage(currentPage+-1)"
28
+ ><font-awesome-icon
29
+ :icon="['fas', 'angle-left']"
30
+ /></a>
31
+ </li>
32
+ <li
33
+ :class="{'invisible': currentPage - 2 <= 0}"
34
+ class="page-item disabled"
35
+ >
36
+ <a
37
+ class="page-link"
38
+ href="#"
39
+ >...</a>
40
+ </li>
41
+ <template
42
+ v-for="index in 5"
43
+ :key="index"
44
+ >
45
+ <li
46
+ class="page-item"
47
+ :class="{active: currentPage+index-3 === currentPage,
48
+ 'invisible': currentPage+index - 2 <= 0 || currentPage+index-4 >= pageCount}"
49
+ >
50
+ <a
51
+ class="page-link"
52
+ href="#"
53
+ @click="changePage(currentPage+index-3)"
54
+ >{{ currentPage+index - 2 }}</a>
55
+ </li>
56
+ </template>
57
+ <li
58
+ :class="{'invisible': currentPage + 2 >= pageCount}"
59
+ class="page-item disabled"
60
+ >
61
+ <a
62
+ class="page-link"
63
+ href="#"
64
+ >...</a>
65
+ </li>
66
+ <li
67
+ :class="{'invisible': currentPage >= pageCount}"
68
+ class="page-item"
69
+ >
70
+ <a
71
+ class="page-link"
72
+ href="#"
73
+ @click="changePage(currentPage+1)"
74
+ ><font-awesome-icon
75
+ :icon="['fas', 'angle-right']"
76
+ /></a>
77
+ </li>
78
+ <li
79
+ :class="{'invisible': currentPage >= pageCount}"
80
+ class="page-item"
81
+ >
82
+ <a
83
+ class="page-link"
84
+ href="#"
85
+ @click="changePage(pageCount)"
86
+ >
87
+ <font-awesome-icon
88
+ :icon="['fas', 'angle-double-right']"
89
+ />
90
+ </a>
91
+ </li>
92
+ <li class="page-item">
93
+ <select
94
+ id="pageSizeSelect"
95
+ :value="pageSize"
96
+ class="form-select mx-2"
97
+ style="width:75px;"
98
+ @change="updateSize($event)"
99
+ >
100
+ <option
101
+ v-for="size in sizeList"
102
+ :key="size"
103
+ >
104
+ {{ size }}
105
+ </option>
106
+ </select>
107
+ </li>
108
+ </ul>
109
+ </nav>
110
+ <div>
111
+ <span class="small text-muted">
112
+ displaying page {{ currentPage+1 }} of {{ pageCount+1 }}. Total messages: {{ count }}
113
+ </span>
114
+ </div>
115
+ </div>
116
+ </template>
117
+
118
+ <script setup>
119
+ import {
120
+ defineProps, toRefs, ref, computed, defineEmits,
121
+ } from 'vue';
122
+
123
+ const props = defineProps({
124
+ currentPage: { type: Number, default: 0 },
125
+ count: { type: Number, default: 0 },
126
+ pageSize: { type: Number, default: 5 },
127
+ });
128
+
129
+ const {
130
+ pageSize, count, currentPage,
131
+ } = toRefs(props);
132
+
133
+ const sizeList = ref([5, 10, 25, 50, 100]);
134
+ const pageCount = computed(() => parseInt((count.value - 1) / pageSize.value, 10));
135
+
136
+ const emit = defineEmits(['update:currentPage', 'updatePageSize']);
137
+
138
+ function changePage(newPage) {
139
+ emit('update:currentPage', newPage);
140
+ }
141
+
142
+ function updateSize(event) {
143
+ emit('updatePageSize', parseInt(event.target.value, 10));
144
+ }
145
+
146
+ </script>