|
16 | 16 |
|
17 | 17 | <template> |
18 | 18 | <section class="wallboard section"> |
| 19 | + <div class="flex gap-2 justify-end absolute w-full md:w-[28rem] top-14 right-0 bg-black/20 py-3 px-4 rounded-bl"> |
| 20 | + <sba-input |
| 21 | + class="flex-1" |
| 22 | + v-model="termFilter" |
| 23 | + :placeholder="$t('term.filter')" |
| 24 | + name="filter" |
| 25 | + type="search" |
| 26 | + > |
| 27 | + <template #prepend> |
| 28 | + <font-awesome-icon icon="filter"/> |
| 29 | + </template> |
| 30 | + </sba-input> |
| 31 | + |
| 32 | + <select |
| 33 | + v-if="healthStatus.length > 1" |
| 34 | + v-model="statusFilter" |
| 35 | + class="relative focus:z-10 focus:ring-indigo-500 focus:border-indigo-500 block sm:text-sm border-gray-300 rounded" |
| 36 | + > |
| 37 | + <option selected value="none" v-text="$t('term.all')"/> |
| 38 | + <optgroup :label="t('health.label')"> |
| 39 | + <option |
| 40 | + v-for="status in healthStatus" |
| 41 | + :key="status" |
| 42 | + :value="status" |
| 43 | + v-text="t('health.status.' + status)" |
| 44 | + /> |
| 45 | + </optgroup> |
| 46 | + </select> |
| 47 | + </div> |
| 48 | + |
19 | 49 | <sba-alert |
20 | 50 | v-if="error" |
21 | 51 | :error="error" |
|
24 | 54 | severity="WARN" |
25 | 55 | /> |
26 | 56 |
|
27 | | - <p |
| 57 | + <sba-loading-spinner |
28 | 58 | v-if="!applicationsInitialized" |
29 | | - class="is-muted is-loading" |
30 | | - v-text="t('applications.loading_applications')" |
31 | 59 | /> |
32 | | - <hex-mesh |
33 | | - v-if="applicationsInitialized" |
34 | | - :class-for-item="classForApplication" |
35 | | - :items="applications" |
36 | | - @click="select" |
37 | | - > |
38 | | - <template #item="{ item: application }"> |
39 | | - <div :key="application.name" class="hex__body application"> |
40 | | - <div class="application__status-indicator" /> |
41 | | - <div class="application__header application__time-ago is-muted"> |
42 | | - <sba-time-ago :date="application.statusTimestamp" /> |
43 | | - </div> |
44 | | - <div class="application__body"> |
45 | | - <h1 class="application__name" v-text="application.name" /> |
46 | | - <p |
47 | | - class="application__instances is-muted" |
48 | | - v-text=" |
49 | | - t('wallboard.instances_count', application.instances.length) |
50 | | - " |
| 60 | + |
| 61 | + <template v-if="applicationsInitialized"> |
| 62 | + <div class="flex w-full h-full items-center text-center text-white text-xl" |
| 63 | + v-if="termFilter.length > 0 && applications.length === 0" |
| 64 | + v-text="t('term.no_results_for_term', { |
| 65 | + term: termFilter |
| 66 | + })"/> |
| 67 | + <hex-mesh |
| 68 | + v-if="applicationsInitialized" |
| 69 | + :class-for-item="classForApplication" |
| 70 | + :items="applications" |
| 71 | + @click="select" |
| 72 | + > |
| 73 | + <template #item="{ item: application }"> |
| 74 | + <div :key="application.name" class="hex__body application"> |
| 75 | + <div class="application__status-indicator"/> |
| 76 | + <div class="application__header application__time-ago is-muted"> |
| 77 | + <sba-time-ago :date="application.statusTimestamp"/> |
| 78 | + </div> |
| 79 | + <div class="application__body"> |
| 80 | + <h1 class="application__name" v-text="application.name"/> |
| 81 | + <p |
| 82 | + class="application__instances is-muted" |
| 83 | + v-text=" |
| 84 | + t('wallboard.instances_count', application.instances.length) |
| 85 | + " |
| 86 | + /> |
| 87 | + </div> |
| 88 | + <h2 |
| 89 | + class="application__footer application__version" |
| 90 | + v-text="application.buildVersion" |
51 | 91 | /> |
52 | 92 | </div> |
53 | | - <h2 |
54 | | - class="application__footer application__version" |
55 | | - v-text="application.buildVersion" |
56 | | - /> |
57 | | - </div> |
58 | | - </template> |
59 | | - </hex-mesh> |
| 93 | + </template> |
| 94 | + </hex-mesh> |
| 95 | + </template> |
60 | 96 | </section> |
61 | 97 | </template> |
62 | 98 |
|
63 | 99 | <script> |
64 | | -import { useI18n } from 'vue-i18n'; |
| 100 | +import Fuse from 'fuse.js'; |
| 101 | +import {computed, ref} from 'vue'; |
| 102 | +import {useI18n} from 'vue-i18n'; |
65 | 103 |
|
66 | | -import { HealthStatus } from '@/HealthStatus'; |
67 | | -import { useApplicationStore } from '@/composables/useApplicationStore'; |
| 104 | +import {HealthStatus} from '@/HealthStatus'; |
| 105 | +import {useApplicationStore} from '@/composables/useApplicationStore'; |
68 | 106 | import hexMesh from '@/views/wallboard/hex-mesh'; |
69 | 107 |
|
70 | 108 | export default { |
71 | | - components: { hexMesh }, |
| 109 | + components: {hexMesh}, |
72 | 110 | setup() { |
73 | | - const { t } = useI18n(); |
| 111 | + const {t} = useI18n(); |
| 112 | + const termFilter = ref(''); |
| 113 | + const statusFilter = ref('none'); |
74 | 114 |
|
75 | | - const { applications, applicationsInitialized, error } = |
| 115 | + const {applications, applicationsInitialized, error} = |
76 | 116 | useApplicationStore(); |
77 | | - return { applications, applicationsInitialized, error, t }; |
| 117 | +
|
| 118 | + const fuse = computed( |
| 119 | + () => |
| 120 | + new Fuse(applications.value, { |
| 121 | + includeScore: true, |
| 122 | + useExtendedSearch: true, |
| 123 | + threshold: 0.25, |
| 124 | + keys: ['name', 'buildVersion', 'instances.name', 'instances.id'], |
| 125 | + }) |
| 126 | + ); |
| 127 | +
|
| 128 | + const filteredApplications = computed(() => { |
| 129 | + function filterByTerm() { |
| 130 | + if (termFilter.value.length > 0) { |
| 131 | + return fuse.value.search(termFilter.value).map((sr) => sr.item); |
| 132 | + } else { |
| 133 | + return applications.value; |
| 134 | + } |
| 135 | + } |
| 136 | +
|
| 137 | + function filterByStatus(result) { |
| 138 | + if (statusFilter.value !== 'none') { |
| 139 | + return result.filter( |
| 140 | + (application) => application.status === statusFilter.value |
| 141 | + ); |
| 142 | + } |
| 143 | +
|
| 144 | + return result; |
| 145 | + } |
| 146 | +
|
| 147 | + let result = filterByTerm(); |
| 148 | + result = filterByStatus(result); |
| 149 | +
|
| 150 | + return result; |
| 151 | + }); |
| 152 | +
|
| 153 | + const healthStatus = computed(() => { |
| 154 | + return applications.value.map((application) => application.status); |
| 155 | + }); |
| 156 | +
|
| 157 | + return { |
| 158 | + applications: filteredApplications, |
| 159 | + applicationsInitialized, |
| 160 | + error, |
| 161 | + t, |
| 162 | + termFilter, |
| 163 | + statusFilter, |
| 164 | + healthStatus, |
| 165 | + }; |
78 | 166 | }, |
79 | 167 | methods: { |
80 | 168 | classForApplication(application) { |
@@ -105,17 +193,17 @@ export default { |
105 | 193 | if (application.instances.length === 1) { |
106 | 194 | this.$router.push({ |
107 | 195 | name: 'instances/details', |
108 | | - params: { instanceId: application.instances[0].id }, |
| 196 | + params: {instanceId: application.instances[0].id}, |
109 | 197 | }); |
110 | 198 | } else { |
111 | 199 | this.$router.push({ |
112 | 200 | name: 'applications', |
113 | | - params: { selected: application.name }, |
| 201 | + params: {selected: application.name}, |
114 | 202 | }); |
115 | 203 | } |
116 | 204 | }, |
117 | 205 | }, |
118 | | - install({ viewRegistry }) { |
| 206 | + install({viewRegistry}) { |
119 | 207 | viewRegistry.addView({ |
120 | 208 | path: '/wallboard', |
121 | 209 | name: 'wallboard', |
|
0 commit comments