blob: 1921c86a5872272b982d35532238d4d1a6bdcaf1 [file] [log] [blame]
Sukanya Pandey34efde22020-12-02 19:04:09 +05301<template>
2 <b-container fluid="xl">
3 <page-title />
4 <b-row class="align-items-end">
5 <b-col sm="6" md="5" xl="4">
6 <search
7 :placeholder="$t('pageClientSessions.table.searchSessions')"
8 @change-search="onChangeSearchInput"
9 @clear-search="onClearSearchInput"
10 />
11 </b-col>
12 <b-col sm="3" md="3" xl="2">
13 <table-cell-count
14 :filtered-items-count="filteredRows"
15 :total-number-of-cells="allConnections.length"
16 ></table-cell-count>
17 </b-col>
18 </b-row>
19 <b-row>
20 <b-col>
21 <table-toolbar
22 ref="toolbar"
23 :selected-items-count="selectedRows.length"
24 :actions="batchActions"
25 @clear-selected="clearSelectedRows($refs.table)"
26 @batch-action="onBatchAction"
27 >
28 </table-toolbar>
29 <b-table
30 id="table-session-logs"
31 ref="table"
32 responsive="md"
33 selectable
34 no-select-on-click
35 hover
36 show-empty
37 sort-by="clientID"
38 :fields="fields"
39 :items="allConnections"
40 :filter="searchFilter"
41 :empty-text="$t('global.table.emptyMessage')"
42 :per-page="perPage"
43 :current-page="currentPage"
44 @filtered="onFiltered"
45 @row-selected="onRowSelected($event, allConnections.length)"
46 >
47 <!-- Checkbox column -->
48 <template #head(checkbox)>
49 <b-form-checkbox
50 v-model="tableHeaderCheckboxModel"
51 data-test-id="sessionLogs-checkbox-selectAll"
52 :indeterminate="tableHeaderCheckboxIndeterminate"
53 @change="onChangeHeaderCheckbox($refs.table)"
54 >
55 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
56 </b-form-checkbox>
57 </template>
58 <template #cell(checkbox)="row">
59 <b-form-checkbox
60 v-model="row.rowSelected"
61 :data-test-id="`sessionLogs-checkbox-selectRow-${row.index}`"
62 @change="toggleSelectRow($refs.table, row.index)"
63 >
64 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
65 </b-form-checkbox>
66 </template>
67
68 <!-- Actions column -->
69 <template #cell(actions)="row" class="ml-3">
70 <table-row-action
71 v-for="(action, index) in row.item.actions"
72 :key="index"
73 :value="action.value"
74 :title="action.title"
75 :row-data="row.item"
SurenNeware6e2cb972020-12-24 20:58:16 +053076 :btn-icon-only="false"
Sukanya Pandey34efde22020-12-02 19:04:09 +053077 :data-test-id="`sessionLogs-button-deleteRow-${row.index}`"
78 @click-table-action="onTableRowAction($event, row.item)"
79 ></table-row-action>
80 </template>
81 </b-table>
82 </b-col>
83 </b-row>
84
85 <!-- Table pagination -->
86 <b-row>
87 <b-col sm="6">
88 <b-form-group
89 class="table-pagination-select"
90 :label="$t('global.table.itemsPerPage')"
91 label-for="pagination-items-per-page"
92 >
93 <b-form-select
94 id="pagination-items-per-page"
95 v-model="perPage"
96 :options="itemsPerPageOptions"
97 />
98 </b-form-group>
99 </b-col>
100 <b-col sm="6">
101 <b-pagination
102 v-model="currentPage"
103 first-number
104 last-number
105 :per-page="perPage"
106 :total-rows="getTotalRowCount(allConnections.length)"
107 aria-controls="table-session-logs"
108 />
109 </b-col>
110 </b-row>
111 </b-container>
112</template>
113
114<script>
115import PageTitle from '@/components/Global/PageTitle';
116import Search from '@/components/Global/Search';
117import TableCellCount from '@/components/Global/TableCellCount';
118import TableRowAction from '@/components/Global/TableRowAction';
119import TableToolbar from '@/components/Global/TableToolbar';
120
121import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
122import BVPaginationMixin, {
123 currentPage,
124 perPage,
125 itemsPerPageOptions,
126} from '@/components/Mixins/BVPaginationMixin';
127import BVTableSelectableMixin, {
128 selectedRows,
129 tableHeaderCheckboxModel,
130 tableHeaderCheckboxIndeterminate,
131} from '@/components/Mixins/BVTableSelectableMixin';
132import BVToastMixin from '@/components/Mixins/BVToastMixin';
133import SearchFilterMixin, {
134 searchFilter,
135} from '@/components/Mixins/SearchFilterMixin';
136
137export default {
138 components: {
139 PageTitle,
140 Search,
141 TableCellCount,
142 TableRowAction,
143 TableToolbar,
144 },
145 mixins: [
146 BVPaginationMixin,
147 BVTableSelectableMixin,
148 BVToastMixin,
149 LoadingBarMixin,
150 SearchFilterMixin,
151 ],
152 beforeRouteLeave(to, from, next) {
153 // Hide loader if the user navigates to another page
154 // before request is fulfilled.
155 this.hideLoader();
156 next();
157 },
158 data() {
159 return {
160 fields: [
161 {
162 key: 'checkbox',
163 },
164 {
165 key: 'clientID',
166 label: this.$t('pageClientSessions.table.clientID'),
167 },
168 {
169 key: 'username',
170 label: this.$t('pageClientSessions.table.username'),
171 },
172 {
173 key: 'ipAddress',
174 label: this.$t('pageClientSessions.table.ipAddress'),
175 },
176 {
177 key: 'actions',
178 label: '',
179 },
180 ],
181 batchActions: [
182 {
183 value: 'disconnect',
184 label: this.$t('pageClientSessions.action.disconnect'),
185 },
186 ],
187 currentPage: currentPage,
188 itemsPerPageOptions: itemsPerPageOptions,
189 perPage: perPage,
190 selectedRows: selectedRows,
191 searchTotalFilteredRows: 0,
192 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
193 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
194 searchFilter: searchFilter,
195 };
196 },
197 computed: {
198 filteredRows() {
199 return this.searchFilter
200 ? this.searchTotalFilteredRows
201 : this.allConnections.length;
202 },
203 allConnections() {
204 return this.$store.getters['clientSessions/allConnections'].map(
205 (session) => {
206 return {
207 ...session,
208 actions: [
209 {
210 value: 'disconnect',
211 title: this.$t('pageClientSessions.action.disconnect'),
212 },
213 ],
214 };
215 }
216 );
217 },
218 },
219 created() {
220 this.startLoader();
221 this.$store
222 .dispatch('clientSessions/getClientSessionsData')
223 .finally(() => this.endLoader());
224 },
225 methods: {
226 onFiltered(filteredItems) {
227 this.searchTotalFilteredRows = filteredItems.length;
228 },
229 onChangeSearchInput(event) {
230 this.searchFilter = event;
231 },
232 disconnectSessions(uris) {
233 this.$store
234 .dispatch('clientSessions/disconnectSessions', uris)
235 .then((messages) => {
236 messages.forEach(({ type, message }) => {
237 if (type === 'success') {
238 this.successToast(message);
239 } else if (type === 'error') {
240 this.errorToast(message);
241 }
242 });
243 });
244 },
245 onTableRowAction(action, { uri }) {
246 if (action === 'disconnect') {
247 this.$bvModal
248 .msgBoxConfirm(
249 this.$tc('pageClientSessions.modal.disconnectMessage'),
250 {
251 title: this.$tc('pageClientSessions.modal.disconnectTitle'),
252 okTitle: this.$t('pageClientSessions.action.disconnect'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530253 cancelTitle: this.$t('global.action.cancel'),
Sukanya Pandey34efde22020-12-02 19:04:09 +0530254 }
255 )
256 .then((deleteConfirmed) => {
257 if (deleteConfirmed) this.disconnectSessions([uri]);
258 });
259 }
260 },
261 onBatchAction(action) {
262 if (action === 'disconnect') {
263 const uris = this.selectedRows.map((row) => row.uri);
264 this.$bvModal
265 .msgBoxConfirm(
266 this.$tc(
267 'pageClientSessions.modal.disconnectMessage',
268 this.selectedRows.length
269 ),
270 {
271 title: this.$tc(
272 'pageClientSessions.modal.disconnectTitle',
273 this.selectedRows.length
274 ),
275 okTitle: this.$t('pageClientSessions.action.disconnect'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530276 cancelTitle: this.$t('global.action.cancel'),
Sukanya Pandey34efde22020-12-02 19:04:09 +0530277 }
278 )
279 .then((deleteConfirmed) => {
280 if (deleteConfirmed) {
281 this.disconnectSessions(uris);
282 }
283 });
284 }
285 },
286 },
287};
288</script>
289<style lang="scss">
290#table-session-logs {
291 td .btn-link {
292 width: auto !important;
293 }
294}
295</style>