Feat: Add monitorList search box

This commit is contained in:
Nelson Chan 2021-09-09 02:10:32 +08:00
parent c2148fc0f1
commit e66a2d362d
2 changed files with 87 additions and 23 deletions

View File

@ -1,31 +1,45 @@
<template> <template>
<div class="shadow-box list mb-3" :class="{ scrollbar: scrollbar }"> <div class="shadow-box mb-3">
<div v-if="Object.keys($root.monitorList).length === 0" class="text-center mt-3"> <div class="list-header">
{{ $t("No Monitors, please") }} <router-link to="/add">{{ $t("add one") }}</router-link> <div class="placeholder"></div>
<div class="search-wrapper">
<a v-if="searchText == ''" class="search-icon">
<font-awesome-icon icon="search" />
</a>
<a v-if="searchText != ''" class="search-icon" @click="clearSearchText">
<font-awesome-icon icon="times" />
</a>
<input v-model="searchText" class="form-control search-input" :placeholder="$t('Search...')" />
</div>
</div> </div>
<div class="list" :class="{ scrollbar: scrollbar }">
<router-link v-for="(item, index) in sortedMonitorList" :key="index" :to="monitorURL(item.id)" class="item" :class="{ 'disabled': ! item.active }"> <div v-if="Object.keys($root.monitorList).length === 0" class="text-center mt-3">
<div class="row"> {{ $t("No Monitors, please") }} <router-link to="/add">{{ $t("add one") }}</router-link>
<div class="col-6 col-md-8 small-padding" :class="{ 'monitorItem': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
<div class="info">
<Uptime :monitor="item" type="24" :pill="true" />
{{ item.name }}
</div>
<div class="tags">
<Tag v-for="tag in item.tags" :key="tag" :item="tag" :size="'sm'" />
</div>
</div>
<div v-show="$root.userHeartbeatBar == 'normal'" :key="$root.userHeartbeatBar" class="col-6 col-md-4">
<HeartbeatBar size="small" :monitor-id="item.id" />
</div>
</div> </div>
<div v-if="$root.userHeartbeatBar == 'bottom'" class="row"> <router-link v-for="(item, index) in sortedMonitorList" :key="index" :to="monitorURL(item.id)" class="item" :class="{ 'disabled': ! item.active }">
<div class="col-12"> <div class="row">
<HeartbeatBar size="small" :monitor-id="item.id" /> <div class="col-6 col-md-8 small-padding" :class="{ 'monitorItem': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
<div class="info">
<Uptime :monitor="item" type="24" :pill="true" />
{{ item.name }}
</div>
<div class="tags">
<Tag v-for="tag in item.tags" :key="tag" :item="tag" :size="'sm'" />
</div>
</div>
<div v-show="$root.userHeartbeatBar == 'normal'" :key="$root.userHeartbeatBar" class="col-6 col-md-4">
<HeartbeatBar size="small" :monitor-id="item.id" />
</div>
</div> </div>
</div>
</router-link> <div v-if="$root.userHeartbeatBar == 'bottom'" class="row">
<div class="col-12">
<HeartbeatBar size="small" :monitor-id="item.id" />
</div>
</div>
</router-link>
</div>
</div> </div>
</template> </template>
@ -45,6 +59,11 @@ export default {
type: Boolean, type: Boolean,
}, },
}, },
data() {
return {
searchText: "",
}
},
computed: { computed: {
sortedMonitorList() { sortedMonitorList() {
let result = Object.values(this.$root.monitorList); let result = Object.values(this.$root.monitorList);
@ -74,6 +93,17 @@ export default {
return m1.name.localeCompare(m2.name); return m1.name.localeCompare(m2.name);
}) })
// Simple filter by search text
// finds monitor name, tag name or tag value
if (this.searchText != "") {
const loweredSearchText = this.searchText.toLowerCase();
result = result.filter(monitor => {
return monitor.name.toLowerCase().includes(loweredSearchText)
|| monitor.tags.find(tag => tag.name.toLowerCase().includes(loweredSearchText)
|| tag.value?.toLowerCase().includes(loweredSearchText))
})
}
return result; return result;
}, },
}, },
@ -81,6 +111,9 @@ export default {
monitorURL(id) { monitorURL(id) {
return "/dashboard/" + id; return "/dashboard/" + id;
}, },
clearSearchText() {
this.searchText = "";
}
}, },
} }
</script> </script>
@ -93,6 +126,35 @@ export default {
padding-right: 5px !important; padding-right: 5px !important;
} }
.list-header {
border-bottom: 1px solid #dee2e6;
border-radius: 10px 10px 0 0;
margin: -10px;
margin-bottom: 10px;
padding: 15px;
display: flex;
justify-content: space-between;
.dark & {
background-color: #161b22;
border-bottom: 0;
}
}
.search-wrapper {
display: flex;
align-items: center;
}
.search-icon {
padding: 10px;
color: #c0c0c0;
}
.search-input {
max-width: 15em;
}
.list { .list {
&.scrollbar { &.scrollbar {
min-height: calc(100vh - 240px); min-height: calc(100vh - 240px);

View File

@ -9,6 +9,7 @@ import {
faPause, faPause,
faPlay, faPlay,
faPlus, faPlus,
faSearch,
faTachometerAlt, faTachometerAlt,
faTimes, faTimes,
faTrash faTrash
@ -28,6 +29,7 @@ library.add(
faPause, faPause,
faPlay, faPlay,
faPlus, faPlus,
faSearch,
faTachometerAlt, faTachometerAlt,
faTimes, faTimes,
faTrash, faTrash,