xref: /openbmc/webui-vue/src/views/SecurityAndAccess/Sessions/Sessions.vue (revision de23ea23d88451a2fa2774ec72053772603c23ae)
1b440616cSSandeepa Singh<template>
2b440616cSSandeepa Singh  <b-container fluid="xl">
3b440616cSSandeepa Singh    <page-title />
4b440616cSSandeepa Singh    <b-row class="align-items-end">
5b440616cSSandeepa Singh      <b-col sm="6" md="5" xl="4">
6b440616cSSandeepa Singh        <search
7b440616cSSandeepa Singh          :placeholder="$t('pageSessions.table.searchSessions')"
8b440616cSSandeepa Singh          data-test-id="sessions-input-searchSessions"
9b440616cSSandeepa Singh          @change-search="onChangeSearchInput"
10b440616cSSandeepa Singh          @clear-search="onClearSearchInput"
11b440616cSSandeepa Singh        />
12b440616cSSandeepa Singh      </b-col>
13b440616cSSandeepa Singh      <b-col sm="3" md="3" xl="2">
14b440616cSSandeepa Singh        <table-cell-count
15b440616cSSandeepa Singh          :filtered-items-count="filteredRows"
16b440616cSSandeepa Singh          :total-number-of-cells="allConnections.length"
17b440616cSSandeepa Singh        ></table-cell-count>
18b440616cSSandeepa Singh      </b-col>
19b440616cSSandeepa Singh    </b-row>
20b440616cSSandeepa Singh    <b-row>
21b440616cSSandeepa Singh      <b-col>
22b440616cSSandeepa Singh        <table-toolbar
23b440616cSSandeepa Singh          ref="toolbar"
24b440616cSSandeepa Singh          :selected-items-count="selectedRows.length"
25b440616cSSandeepa Singh          :actions="batchActions"
26b440616cSSandeepa Singh          @clear-selected="clearSelectedRows($refs.table)"
27b440616cSSandeepa Singh          @batch-action="onBatchAction"
28b440616cSSandeepa Singh        >
29b440616cSSandeepa Singh        </table-toolbar>
30b440616cSSandeepa Singh        <b-table
31b440616cSSandeepa Singh          id="table-session-logs"
32b440616cSSandeepa Singh          ref="table"
33b440616cSSandeepa Singh          responsive="md"
34b440616cSSandeepa Singh          selectable
35b440616cSSandeepa Singh          no-select-on-click
36b440616cSSandeepa Singh          hover
37b440616cSSandeepa Singh          show-empty
38568b8a93Skirankumarb07          sort-by="sessionID"
3941057853SKenneth Fullbright          :busy="isBusy"
40b440616cSSandeepa Singh          :fields="fields"
41b440616cSSandeepa Singh          :items="allConnections"
42b440616cSSandeepa Singh          :filter="searchFilter"
43b440616cSSandeepa Singh          :empty-text="$t('global.table.emptyMessage')"
44b440616cSSandeepa Singh          :per-page="perPage"
45b440616cSSandeepa Singh          :current-page="currentPage"
46b440616cSSandeepa Singh          @filtered="onFiltered"
47b440616cSSandeepa Singh          @row-selected="onRowSelected($event, allConnections.length)"
48b440616cSSandeepa Singh        >
49b440616cSSandeepa Singh          <!-- Checkbox column -->
50b440616cSSandeepa Singh          <template #head(checkbox)>
51b440616cSSandeepa Singh            <b-form-checkbox
52b440616cSSandeepa Singh              v-model="tableHeaderCheckboxModel"
53b440616cSSandeepa Singh              data-test-id="sessions-checkbox-selectAll"
54b440616cSSandeepa Singh              :indeterminate="tableHeaderCheckboxIndeterminate"
55b440616cSSandeepa Singh              @change="onChangeHeaderCheckbox($refs.table)"
56b440616cSSandeepa Singh            >
57b440616cSSandeepa Singh              <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
58b440616cSSandeepa Singh            </b-form-checkbox>
59b440616cSSandeepa Singh          </template>
60b440616cSSandeepa Singh          <template #cell(checkbox)="row">
61b440616cSSandeepa Singh            <b-form-checkbox
62b440616cSSandeepa Singh              v-model="row.rowSelected"
63b440616cSSandeepa Singh              :data-test-id="`sessions-checkbox-selectRow-${row.index}`"
64b440616cSSandeepa Singh              @change="toggleSelectRow($refs.table, row.index)"
65b440616cSSandeepa Singh            >
66b440616cSSandeepa Singh              <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
67b440616cSSandeepa Singh            </b-form-checkbox>
68b440616cSSandeepa Singh          </template>
69b440616cSSandeepa Singh
70b440616cSSandeepa Singh          <!-- Actions column -->
7147009075SEd Tanous          <template #cell(actions)="row">
72b440616cSSandeepa Singh            <table-row-action
73b440616cSSandeepa Singh              v-for="(action, index) in row.item.actions"
74b440616cSSandeepa Singh              :key="index"
75b440616cSSandeepa Singh              :value="action.value"
76b440616cSSandeepa Singh              :title="action.title"
77b440616cSSandeepa Singh              :row-data="row.item"
78b440616cSSandeepa Singh              :btn-icon-only="false"
79b440616cSSandeepa Singh              :data-test-id="`sessions-button-disconnect-${row.index}`"
80b440616cSSandeepa Singh              @click-table-action="onTableRowAction($event, row.item)"
81b440616cSSandeepa Singh            ></table-row-action>
82b440616cSSandeepa Singh          </template>
83b440616cSSandeepa Singh        </b-table>
84b440616cSSandeepa Singh      </b-col>
85b440616cSSandeepa Singh    </b-row>
86b440616cSSandeepa Singh
87b440616cSSandeepa Singh    <!-- Table pagination -->
88b440616cSSandeepa Singh    <b-row>
89b440616cSSandeepa Singh      <b-col sm="6">
90b440616cSSandeepa Singh        <b-form-group
91b440616cSSandeepa Singh          class="table-pagination-select"
92b440616cSSandeepa Singh          :label="$t('global.table.itemsPerPage')"
93b440616cSSandeepa Singh          label-for="pagination-items-per-page"
94b440616cSSandeepa Singh        >
95b440616cSSandeepa Singh          <b-form-select
96b440616cSSandeepa Singh            id="pagination-items-per-page"
97b440616cSSandeepa Singh            v-model="perPage"
98b440616cSSandeepa Singh            :options="itemsPerPageOptions"
99b440616cSSandeepa Singh          />
100b440616cSSandeepa Singh        </b-form-group>
101b440616cSSandeepa Singh      </b-col>
102b440616cSSandeepa Singh      <b-col sm="6">
103b440616cSSandeepa Singh        <b-pagination
104b440616cSSandeepa Singh          v-model="currentPage"
105b440616cSSandeepa Singh          first-number
106b440616cSSandeepa Singh          last-number
107b440616cSSandeepa Singh          :per-page="perPage"
108f7000cd6SSukanya Pandey          :total-rows="getTotalRowCount(filteredRows)"
109b440616cSSandeepa Singh          aria-controls="table-session-logs"
110b440616cSSandeepa Singh        />
111b440616cSSandeepa Singh      </b-col>
112b440616cSSandeepa Singh    </b-row>
113b440616cSSandeepa Singh  </b-container>
114b440616cSSandeepa Singh</template>
115b440616cSSandeepa Singh
116b440616cSSandeepa Singh<script>
117b440616cSSandeepa Singhimport PageTitle from '@/components/Global/PageTitle';
118b440616cSSandeepa Singhimport Search from '@/components/Global/Search';
119b440616cSSandeepa Singhimport TableCellCount from '@/components/Global/TableCellCount';
120b440616cSSandeepa Singhimport TableRowAction from '@/components/Global/TableRowAction';
121b440616cSSandeepa Singhimport TableToolbar from '@/components/Global/TableToolbar';
122b440616cSSandeepa Singh
123b440616cSSandeepa Singhimport LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
124b440616cSSandeepa Singhimport BVPaginationMixin, {
125b440616cSSandeepa Singh  currentPage,
126b440616cSSandeepa Singh  perPage,
127b440616cSSandeepa Singh  itemsPerPageOptions,
128b440616cSSandeepa Singh} from '@/components/Mixins/BVPaginationMixin';
129b440616cSSandeepa Singhimport BVTableSelectableMixin, {
130b440616cSSandeepa Singh  selectedRows,
131b440616cSSandeepa Singh  tableHeaderCheckboxModel,
132b440616cSSandeepa Singh  tableHeaderCheckboxIndeterminate,
133b440616cSSandeepa Singh} from '@/components/Mixins/BVTableSelectableMixin';
134b440616cSSandeepa Singhimport BVToastMixin from '@/components/Mixins/BVToastMixin';
135b440616cSSandeepa Singhimport SearchFilterMixin, {
136b440616cSSandeepa Singh  searchFilter,
137b440616cSSandeepa Singh} from '@/components/Mixins/SearchFilterMixin';
138*de23ea23SSurya Vimport { useI18n } from 'vue-i18n';
139*de23ea23SSurya Vimport i18n from '@/i18n';
140b440616cSSandeepa Singh
141b440616cSSandeepa Singhexport default {
142b440616cSSandeepa Singh  components: {
143b440616cSSandeepa Singh    PageTitle,
144b440616cSSandeepa Singh    Search,
145b440616cSSandeepa Singh    TableCellCount,
146b440616cSSandeepa Singh    TableRowAction,
147b440616cSSandeepa Singh    TableToolbar,
148b440616cSSandeepa Singh  },
149b440616cSSandeepa Singh  mixins: [
150b440616cSSandeepa Singh    BVPaginationMixin,
151b440616cSSandeepa Singh    BVTableSelectableMixin,
152b440616cSSandeepa Singh    BVToastMixin,
153b440616cSSandeepa Singh    LoadingBarMixin,
154b440616cSSandeepa Singh    SearchFilterMixin,
155b440616cSSandeepa Singh  ],
156b440616cSSandeepa Singh  beforeRouteLeave(to, from, next) {
157b440616cSSandeepa Singh    // Hide loader if the user navigates to another page
158b440616cSSandeepa Singh    // before request is fulfilled.
159b440616cSSandeepa Singh    this.hideLoader();
160b440616cSSandeepa Singh    next();
161b440616cSSandeepa Singh  },
162b440616cSSandeepa Singh  data() {
163b440616cSSandeepa Singh    return {
164*de23ea23SSurya V      $t: useI18n().t,
16541057853SKenneth Fullbright      isBusy: true,
166b440616cSSandeepa Singh      fields: [
167b440616cSSandeepa Singh        {
168b440616cSSandeepa Singh          key: 'checkbox',
169568b8a93Skirankumarb07          class: 'text-center',
170b440616cSSandeepa Singh        },
171b440616cSSandeepa Singh        {
172568b8a93Skirankumarb07          key: 'sessionID',
173*de23ea23SSurya V          label: i18n.global.t('pageSessions.table.sessionID'),
174568b8a93Skirankumarb07          class: 'text-center',
175568b8a93Skirankumarb07        },
176568b8a93Skirankumarb07        {
177568b8a93Skirankumarb07          key: 'context',
178*de23ea23SSurya V          label: i18n.global.t('pageSessions.table.context'),
179568b8a93Skirankumarb07          class: 'text-center',
180b440616cSSandeepa Singh        },
181b440616cSSandeepa Singh        {
182b440616cSSandeepa Singh          key: 'username',
183*de23ea23SSurya V          label: i18n.global.t('pageSessions.table.username'),
184568b8a93Skirankumarb07          class: 'text-center',
185b440616cSSandeepa Singh        },
186b440616cSSandeepa Singh        {
187b440616cSSandeepa Singh          key: 'ipAddress',
188*de23ea23SSurya V          label: i18n.global.t('pageSessions.table.ipAddress'),
189568b8a93Skirankumarb07          class: 'text-center',
190b440616cSSandeepa Singh        },
191b440616cSSandeepa Singh        {
192b440616cSSandeepa Singh          key: 'actions',
193b440616cSSandeepa Singh          label: '',
194568b8a93Skirankumarb07          class: 'text-center',
195b440616cSSandeepa Singh        },
196b440616cSSandeepa Singh      ],
197b440616cSSandeepa Singh      batchActions: [
198b440616cSSandeepa Singh        {
199b440616cSSandeepa Singh          value: 'disconnect',
200*de23ea23SSurya V          label: i18n.global.t('pageSessions.action.disconnect'),
201b440616cSSandeepa Singh        },
202b440616cSSandeepa Singh      ],
203b440616cSSandeepa Singh      currentPage: currentPage,
204b440616cSSandeepa Singh      itemsPerPageOptions: itemsPerPageOptions,
205b440616cSSandeepa Singh      perPage: perPage,
206b440616cSSandeepa Singh      selectedRows: selectedRows,
207b440616cSSandeepa Singh      searchTotalFilteredRows: 0,
208b440616cSSandeepa Singh      tableHeaderCheckboxModel: tableHeaderCheckboxModel,
209b440616cSSandeepa Singh      tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
210b440616cSSandeepa Singh      searchFilter: searchFilter,
211b440616cSSandeepa Singh    };
212b440616cSSandeepa Singh  },
213b440616cSSandeepa Singh  computed: {
214b440616cSSandeepa Singh    filteredRows() {
215b440616cSSandeepa Singh      return this.searchFilter
216b440616cSSandeepa Singh        ? this.searchTotalFilteredRows
217b440616cSSandeepa Singh        : this.allConnections.length;
218b440616cSSandeepa Singh    },
219b440616cSSandeepa Singh    allConnections() {
220b440616cSSandeepa Singh      return this.$store.getters['sessions/allConnections'].map((session) => {
221b440616cSSandeepa Singh        return {
222b440616cSSandeepa Singh          ...session,
223b440616cSSandeepa Singh          actions: [
224b440616cSSandeepa Singh            {
225b440616cSSandeepa Singh              value: 'disconnect',
226*de23ea23SSurya V              title: i18n.global.t('pageSessions.action.disconnect'),
227b440616cSSandeepa Singh            },
228b440616cSSandeepa Singh          ],
229b440616cSSandeepa Singh        };
230b440616cSSandeepa Singh      });
231b440616cSSandeepa Singh    },
232b440616cSSandeepa Singh  },
233b440616cSSandeepa Singh  created() {
234b440616cSSandeepa Singh    this.startLoader();
23541057853SKenneth Fullbright    this.$store.dispatch('sessions/getSessionsData').finally(() => {
23641057853SKenneth Fullbright      this.endLoader();
23741057853SKenneth Fullbright      this.isBusy = false;
23841057853SKenneth Fullbright    });
239b440616cSSandeepa Singh  },
240b440616cSSandeepa Singh  methods: {
241b440616cSSandeepa Singh    onFiltered(filteredItems) {
242b440616cSSandeepa Singh      this.searchTotalFilteredRows = filteredItems.length;
243b440616cSSandeepa Singh    },
244b440616cSSandeepa Singh    onChangeSearchInput(event) {
245b440616cSSandeepa Singh      this.searchFilter = event;
246b440616cSSandeepa Singh    },
247b440616cSSandeepa Singh    disconnectSessions(uris) {
248b440616cSSandeepa Singh      this.$store
249b440616cSSandeepa Singh        .dispatch('sessions/disconnectSessions', uris)
250b440616cSSandeepa Singh        .then((messages) => {
251b440616cSSandeepa Singh          messages.forEach(({ type, message }) => {
252b440616cSSandeepa Singh            if (type === 'success') {
253b440616cSSandeepa Singh              this.successToast(message);
254b440616cSSandeepa Singh            } else if (type === 'error') {
255b440616cSSandeepa Singh              this.errorToast(message);
256b440616cSSandeepa Singh            }
257b440616cSSandeepa Singh          });
258b440616cSSandeepa Singh        });
259b440616cSSandeepa Singh    },
260b440616cSSandeepa Singh    onTableRowAction(action, { uri }) {
261b440616cSSandeepa Singh      if (action === 'disconnect') {
262b440616cSSandeepa Singh        this.$bvModal
263*de23ea23SSurya V          .msgBoxConfirm(
264*de23ea23SSurya V            i18n.global.t('pageSessions.modal.disconnectMessage'),
265*de23ea23SSurya V            {
266*de23ea23SSurya V              title: i18n.global.t('pageSessions.modal.disconnectTitle'),
267*de23ea23SSurya V              okTitle: i18n.global.t('pageSessions.action.disconnect'),
268*de23ea23SSurya V              cancelTitle: i18n.global.t('global.action.cancel'),
269d1ef18e6SPaul Fertser              autoFocusButton: 'ok',
270*de23ea23SSurya V            },
271*de23ea23SSurya V          )
272b440616cSSandeepa Singh          .then((deleteConfirmed) => {
273b440616cSSandeepa Singh            if (deleteConfirmed) this.disconnectSessions([uri]);
274b440616cSSandeepa Singh          });
275b440616cSSandeepa Singh      }
276b440616cSSandeepa Singh    },
277b440616cSSandeepa Singh    onBatchAction(action) {
278b440616cSSandeepa Singh      if (action === 'disconnect') {
279b440616cSSandeepa Singh        const uris = this.selectedRows.map((row) => row.uri);
280b440616cSSandeepa Singh        this.$bvModal
281b440616cSSandeepa Singh          .msgBoxConfirm(
282*de23ea23SSurya V            i18n.global.t(
283b440616cSSandeepa Singh              'pageSessions.modal.disconnectMessage',
2848132399cSEd Tanous              this.selectedRows.length,
285b440616cSSandeepa Singh            ),
286b440616cSSandeepa Singh            {
287*de23ea23SSurya V              title: i18n.global.t(
288b440616cSSandeepa Singh                'pageSessions.modal.disconnectTitle',
2898132399cSEd Tanous                this.selectedRows.length,
290b440616cSSandeepa Singh              ),
291*de23ea23SSurya V              okTitle: i18n.global.t('pageSessions.action.disconnect'),
292*de23ea23SSurya V              cancelTitle: i18n.global.t('global.action.cancel'),
293d1ef18e6SPaul Fertser              autoFocusButton: 'ok',
2948132399cSEd Tanous            },
295b440616cSSandeepa Singh          )
296b440616cSSandeepa Singh          .then((deleteConfirmed) => {
297b440616cSSandeepa Singh            if (deleteConfirmed) {
298b440616cSSandeepa Singh              this.disconnectSessions(uris);
299b440616cSSandeepa Singh            }
300b440616cSSandeepa Singh          });
301b440616cSSandeepa Singh      }
302b440616cSSandeepa Singh    },
303b440616cSSandeepa Singh  },
304b440616cSSandeepa Singh};
305b440616cSSandeepa Singh</script>
306b440616cSSandeepa Singh<style lang="scss">
307b440616cSSandeepa Singh#table-session-logs {
308b440616cSSandeepa Singh  td .btn-link {
309b440616cSSandeepa Singh    width: auto !important;
310b440616cSSandeepa Singh  }
311b440616cSSandeepa Singh}
312b440616cSSandeepa Singh</style>
313