Skip to content

Commit 5bc8ccc

Browse files
yoshiemuranakarfrandse
authored andcommitted
Add export functionality to Sensors page
- Create TableToolbarExport component to be used as a slot in TableToolbar - Allows selected table items to be exported Signed-off-by: Yoshie Muranaka <[email protected]> Change-Id: I929347e046af8a5d5188e4c4fd9fc874e067cce5
1 parent dd3a1db commit 5bc8ccc

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

src/components/Global/TableToolbar.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
>
1616
{{ action.label }}
1717
</b-button>
18+
<slot name="export"></slot>
1819
<b-button
1920
variant="primary"
2021
class="d-block"
@@ -38,7 +39,7 @@ export default {
3839
},
3940
actions: {
4041
type: Array,
41-
required: true,
42+
default: () => [],
4243
validator: prop => {
4344
return prop.every(action => {
4445
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<b-link
3+
class="btn btn-primary d-block align-self-center"
4+
:download="download"
5+
:href="href"
6+
>
7+
{{ $t('global.action.export') }}
8+
</b-link>
9+
</template>
10+
11+
<script>
12+
export default {
13+
props: {
14+
data: {
15+
type: Array,
16+
default: () => []
17+
},
18+
fileName: {
19+
type: String,
20+
default: 'data'
21+
}
22+
},
23+
computed: {
24+
dataForExport() {
25+
return JSON.stringify(this.data);
26+
},
27+
download() {
28+
return `${this.fileName}.json`;
29+
},
30+
href() {
31+
return `data:text/json;charset=utf-8,${this.dataForExport}`;
32+
}
33+
}
34+
};
35+
</script>

src/locales/en-US.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"download": "Download",
1212
"edit": "Edit",
1313
"enable": "Enable",
14+
"export": "Export",
1415
"filter": "Filter",
1516
"replace": "Replace",
1617
"save": "Save",

src/views/Health/Sensors/Sensors.vue

+48-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88
</b-row>
99
<b-row>
1010
<b-col xl="12">
11+
<table-toolbar
12+
ref="toolbar"
13+
:selected-items-count="selectedRows.length"
14+
@clearSelected="clearSelectedRows($refs.table)"
15+
>
16+
<template v-slot:export>
17+
<table-toolbar-export
18+
:data="selectedRows"
19+
:file-name="$t('appPageTitle.sensors')"
20+
/>
21+
</template>
22+
</table-toolbar>
1123
<b-table
24+
ref="table"
25+
selectable
26+
no-select-on-click
1227
sort-icon-left
1328
no-sort-reset
1429
sticky-header="75vh"
@@ -17,7 +32,23 @@
1732
:fields="fields"
1833
:sort-desc="true"
1934
:sort-compare="sortCompare"
35+
@row-selected="onRowSelected($event, filteredSensors.length)"
2036
>
37+
<!-- Checkbox column -->
38+
<template v-slot:head(checkbox)>
39+
<b-form-checkbox
40+
v-model="tableHeaderCheckboxModel"
41+
:indeterminate="tableHeaderCheckboxIndeterminate"
42+
@change="onChangeHeaderCheckbox($refs.table)"
43+
/>
44+
</template>
45+
<template v-slot:cell(checkbox)="row">
46+
<b-form-checkbox
47+
v-model="row.rowSelected"
48+
@change="toggleSelectRow($refs.table, row.index)"
49+
/>
50+
</template>
51+
2152
<template v-slot:cell(status)="{ value }">
2253
<status-icon :status="statusIcon(value)" />
2354
{{ value }}
@@ -47,7 +78,11 @@
4778
import PageTitle from '../../../components/Global/PageTitle';
4879
import StatusIcon from '../../../components/Global/StatusIcon';
4980
import TableFilter from '../../../components/Global/TableFilter';
81+
import TableToolbar from '@/components/Global/TableToolbar';
82+
import TableToolbarExport from '@/components/Global/TableToolbarExport';
83+
5084
import TableFilterMixin from '../../../components/Mixins/TableFilterMixin';
85+
import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
5186
5287
const SENSOR_STATUS = ['OK', 'Warning', 'Critical'];
5388
@@ -60,11 +95,22 @@ const valueFormatter = value => {
6095
6196
export default {
6297
name: 'Sensors',
63-
components: { PageTitle, StatusIcon, TableFilter },
64-
mixins: [TableFilterMixin],
98+
components: {
99+
PageTitle,
100+
StatusIcon,
101+
TableFilter,
102+
TableToolbar,
103+
TableToolbarExport
104+
},
105+
mixins: [TableFilterMixin, BVTableSelectableMixin],
65106
data() {
66107
return {
67108
fields: [
109+
{
110+
key: 'checkbox',
111+
sortable: false,
112+
label: ''
113+
},
68114
{
69115
key: 'name',
70116
sortable: true,

0 commit comments

Comments
 (0)