Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame^] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | <b-row> |
| 5 | <b-col class="text-right"> |
| 6 | <table-filter :filters="tableFilters" @filterChange="onFilterChange" /> |
| 7 | </b-col> |
| 8 | </b-row> |
| 9 | <b-row> |
| 10 | <b-col> |
| 11 | <b-table |
| 12 | :fields="fields" |
| 13 | :items="filteredLogs" |
| 14 | sort-icon-left |
| 15 | no-sort-reset |
| 16 | sort-desc |
| 17 | show-empty |
| 18 | sort-by="date" |
| 19 | :sort-compare="onSortCompare" |
| 20 | :empty-text="$t('pageEventLogs.table.emptyMessage')" |
| 21 | > |
| 22 | <template v-slot:cell(severity)="{ value }"> |
| 23 | <status-icon :status="getStatus(value)" /> |
| 24 | {{ value }} |
| 25 | </template> |
| 26 | <template v-slot:cell(date)="{ value }"> |
| 27 | {{ value | formatDate }} {{ value | formatTime }} |
| 28 | </template> |
| 29 | </b-table> |
| 30 | </b-col> |
| 31 | </b-row> |
| 32 | </b-container> |
| 33 | </template> |
| 34 | |
| 35 | <script> |
| 36 | import PageTitle from '@/components/Global/PageTitle'; |
| 37 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 38 | import TableFilter from '@/components/Global/TableFilter'; |
| 39 | |
| 40 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 41 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
| 42 | |
| 43 | const SEVERITY = ['OK', 'Warning', 'Critical']; |
| 44 | |
| 45 | export default { |
| 46 | components: { PageTitle, StatusIcon, TableFilter }, |
| 47 | mixins: [LoadingBarMixin, TableFilterMixin], |
| 48 | data() { |
| 49 | return { |
| 50 | fields: [ |
| 51 | { |
| 52 | key: 'id', |
| 53 | label: this.$t('pageEventLogs.table.id'), |
| 54 | sortable: true |
| 55 | }, |
| 56 | { |
| 57 | key: 'severity', |
| 58 | label: this.$t('pageEventLogs.table.severity'), |
| 59 | sortable: true |
| 60 | }, |
| 61 | { |
| 62 | key: 'type', |
| 63 | label: this.$t('pageEventLogs.table.type'), |
| 64 | sortable: true |
| 65 | }, |
| 66 | { |
| 67 | key: 'date', |
| 68 | label: this.$t('pageEventLogs.table.date'), |
| 69 | sortable: true |
| 70 | }, |
| 71 | { |
| 72 | key: 'description', |
| 73 | label: this.$t('pageEventLogs.table.description') |
| 74 | } |
| 75 | ], |
| 76 | tableFilters: [ |
| 77 | { |
| 78 | label: this.$t('pageEventLogs.table.severity'), |
| 79 | values: SEVERITY |
| 80 | } |
| 81 | ], |
| 82 | activeFilters: [] |
| 83 | }; |
| 84 | }, |
| 85 | computed: { |
| 86 | allLogs() { |
| 87 | return this.$store.getters['eventLog/allEvents']; |
| 88 | }, |
| 89 | filteredLogs: { |
| 90 | get: function() { |
| 91 | return this.getFilteredTableData(this.allLogs, this.activeFilters); |
| 92 | }, |
| 93 | set: function(newVal) { |
| 94 | return newVal; |
| 95 | } |
| 96 | } |
| 97 | }, |
| 98 | created() { |
| 99 | this.startLoader(); |
| 100 | this.$store |
| 101 | .dispatch('eventLog/getEventLogData') |
| 102 | .finally(() => this.endLoader()); |
| 103 | }, |
| 104 | methods: { |
| 105 | getStatus(serverity) { |
| 106 | switch (serverity) { |
| 107 | case SEVERITY[2]: |
| 108 | return 'danger'; |
| 109 | case SEVERITY[1]: |
| 110 | return 'warning'; |
| 111 | case SEVERITY[0]: |
| 112 | return 'success'; |
| 113 | default: |
| 114 | return ''; |
| 115 | } |
| 116 | }, |
| 117 | onFilterChange({ activeFilters }) { |
| 118 | this.activeFilters = activeFilters; |
| 119 | this.filteredLogs = this.getFilteredTableData( |
| 120 | this.allLogs, |
| 121 | activeFilters |
| 122 | ); |
| 123 | }, |
| 124 | onSortCompare(a, b, key) { |
| 125 | if (key === 'severity') { |
| 126 | return SEVERITY.indexOf(a.status) - SEVERITY.indexOf(b.status); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | }; |
| 131 | </script> |