uptime-kuma/src/components/PublicGroupList.vue

258 lines
8.8 KiB
Vue
Raw Normal View History

2021-09-13 07:21:39 -04:00
<template>
<!-- Group List -->
<Draggable
v-model="$root.publicGroupList"
:disabled="!editMode"
item-key="id"
:animation="100"
>
2021-09-15 02:34:30 -04:00
<template #item="group">
2021-09-17 02:42:19 -04:00
<div class="mb-5 ">
2021-09-14 11:27:11 -04:00
<!-- Group Title -->
2021-09-17 02:42:19 -04:00
<h2 class="group-title">
2021-09-15 02:34:30 -04:00
<font-awesome-icon v-if="editMode && showGroupDrag" icon="arrows-alt-v" class="action drag me-3" />
<font-awesome-icon v-if="editMode" icon="times" class="action remove me-3" @click="removeGroup(group.index)" />
<Editable v-model="group.element.name" :contenteditable="editMode" tag="span" />
2021-09-14 11:27:11 -04:00
</h2>
2021-09-13 07:21:39 -04:00
<div class="shadow-box monitor-list mt-4 position-relative">
2021-09-15 02:34:30 -04:00
<div v-if="group.element.monitorList.length === 0" class="text-center no-monitor-msg">
2021-09-13 07:21:39 -04:00
{{ $t("No Monitors") }}
</div>
<!-- Monitor List -->
2021-09-15 02:34:30 -04:00
<!-- animation is not working, no idea why -->
2021-09-13 07:21:39 -04:00
<Draggable
2021-09-15 02:34:30 -04:00
v-model="group.element.monitorList"
2021-09-13 07:21:39 -04:00
class="monitor-list"
group="same-group"
:disabled="!editMode"
:animation="100"
2021-09-14 02:12:27 -04:00
item-key="id"
2021-09-13 07:21:39 -04:00
>
2021-09-15 02:34:30 -04:00
<template #item="monitor">
2021-09-13 07:21:39 -04:00
<div class="item">
<div class="row">
<div class="col-9 col-md-8 small-padding">
<div class="info">
2021-09-15 08:40:26 -04:00
<font-awesome-icon v-if="editMode" icon="arrows-alt-v" class="action drag me-3" />
2021-09-15 02:34:30 -04:00
<font-awesome-icon v-if="editMode" icon="times" class="action remove me-3" @click="removeMonitor(group.index, monitor.index)" />
<Uptime :monitor="monitor.element" type="24" :pill="true" />
<a
v-if="showLink(monitor)"
:href="monitor.element.url"
class="item-name"
target="_blank"
rel="noopener noreferrer"
>
{{ monitor.element.name }}
</a>
<p v-else class="item-name"> {{ monitor.element.name }} </p>
2023-03-10 07:25:04 -05:00
<span
2023-05-29 09:11:06 -04:00
title="Setting"
2023-03-10 07:25:04 -05:00
>
<font-awesome-icon
2023-03-10 10:04:47 -05:00
v-if="editMode"
2023-03-10 07:25:04 -05:00
:class="{'link-active': true, 'btn-link': true}"
2023-05-29 09:11:06 -04:00
icon="cog" class="action me-3"
@click="$refs.monitorSettingDialog.show(group, monitor)"
2023-03-10 07:25:04 -05:00
/>
</span>
2023-07-13 20:50:17 -04:00
<span v-if="showCertificateExpiry" class="badge rounded-pill" :class=" 'bg-' + certExpiryColor(monitor)"> {{ $t("Expiry") }}: {{ formattedCertExpiryMessage(monitor) }} </span>
2021-10-27 21:53:27 -04:00
</div>
<div v-if="showTags" class="tags">
2021-10-27 06:06:06 -04:00
<Tag v-for="tag in monitor.element.tags" :key="tag" :item="tag" :size="'sm'" />
2021-09-13 07:21:39 -04:00
</div>
</div>
<div :key="$root.userHeartbeatBar" class="col-3 col-md-4">
2021-09-15 02:34:30 -04:00
<HeartbeatBar size="small" :monitor-id="monitor.element.id" />
2021-09-13 07:21:39 -04:00
</div>
</div>
</div>
</template>
</Draggable>
</div>
</div>
</template>
</Draggable>
2023-05-30 09:06:53 -04:00
<MonitorSettingDialog ref="monitorSettingDialog" />
2021-09-13 07:21:39 -04:00
</template>
<script>
2023-05-29 09:11:06 -04:00
import MonitorSettingDialog from "./MonitorSettingDialog.vue";
2021-09-13 07:21:39 -04:00
import Draggable from "vuedraggable";
import HeartbeatBar from "./HeartbeatBar.vue";
import Uptime from "./Uptime.vue";
2021-10-27 06:06:06 -04:00
import Tag from "./Tag.vue";
2021-09-13 07:21:39 -04:00
export default {
components: {
2023-05-29 09:11:06 -04:00
MonitorSettingDialog,
2021-09-13 07:21:39 -04:00
Draggable,
HeartbeatBar,
Uptime,
2021-10-27 06:06:06 -04:00
Tag,
2021-09-13 07:21:39 -04:00
},
props: {
/** Are we in edit mode? */
2021-09-13 07:21:39 -04:00
editMode: {
type: Boolean,
required: true,
},
/** Should tags be shown? */
2022-03-18 05:56:46 -04:00
showTags: {
type: Boolean,
2023-07-04 19:37:45 -04:00
},
/** Should expiry be shown? */
showCertificateExpiry: {
type: Boolean,
2022-03-18 05:56:46 -04:00
}
2021-09-13 07:21:39 -04:00
},
data() {
return {
2021-09-17 02:42:19 -04:00
};
2021-09-13 07:21:39 -04:00
},
2021-09-15 02:34:30 -04:00
computed: {
showGroupDrag() {
return (this.$root.publicGroupList.length >= 2);
}
},
2021-09-13 07:21:39 -04:00
created() {
2021-09-15 02:34:30 -04:00
},
methods: {
/**
* Remove the specified group
* @param {number} index Index of group to remove
*/
2021-09-15 02:34:30 -04:00
removeGroup(index) {
this.$root.publicGroupList.splice(index, 1);
},
/**
* Remove a monitor from a group
* @param {number} groupIndex Index of group to remove monitor
* from
* @param {number} index Index of monitor to remove
*/
2021-09-15 02:34:30 -04:00
removeMonitor(groupIndex, index) {
this.$root.publicGroupList[groupIndex].monitorList.splice(index, 1);
},
/**
* Should a link to the monitor be shown?
* Attempts to guess if a link should be shown based upon if
* sendUrl is set and if the URL is default or not.
* @param {Object} monitor Monitor to check
* @param {boolean} [ignoreSendUrl=false] Should the presence of the sendUrl
* property be ignored. This will only work in edit mode.
* @returns {boolean}
*/
showLink(monitor, ignoreSendUrl = false) {
// We must check if there are any elements in monitorList to
// prevent undefined errors if it hasn't been loaded yet
if (this.$parent.editMode && ignoreSendUrl && Object.keys(this.$root.monitorList).length) {
✨ feat: json-query monitor added (#3253) * ✨ feat: json-query monitor added Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: import warning error Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: br tag and remove comment Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: supporting compare string with other types Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: switch to a better lib for json query Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: better description on json query and using `v-html` in jsonQueryDescription element to fix `a` tags Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: result variable in error message Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: typos in json query description Co-authored-by: Frank Elsinga <frank@elsinga.de> * 📝 docs: `HTTP(s) Json Query` added to monitor list in `README.md` Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> * 🐛 fix: needed white space in `README.md` Co-authored-by: Frank Elsinga <frank@elsinga.de> * Nostr dm notifications (#3051) * Add nostr DM notification provider * require crypto for node 18 compatibility * remove whitespace Co-authored-by: Frank Elsinga <frank@elsinga.de> * move closer to where it is used * simplify success or failure logic * don't clobber the non-alert msg * Update server/notification-providers/nostr.js Co-authored-by: Frank Elsinga <frank@elsinga.de> * polyfills required for node <= 18 * resolve linter warnings * missing comma --------- Co-authored-by: Frank Elsinga <frank@elsinga.de> * Drop nostr * Rebuild package-lock.json * Lint --------- Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev> Co-authored-by: Frank Elsinga <frank@elsinga.de> Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
2023-07-13 11:37:26 -04:00
return this.$root.monitorList[monitor.element.id].type === "http" || this.$root.monitorList[monitor.element.id].type === "keyword" || this.$root.monitorList[monitor.element.id].type === "json-query";
}
return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://" && !this.editMode;
},
2023-07-04 19:37:45 -04:00
/**
* Returns formatted certificate expiry or Bad cert message
* @param {Object} monitor Monitor to show expiry for
* @returns {string}
*/
formattedCertExpiryMessage(monitor) {
if (monitor?.element?.validCert && monitor?.element?.certExpiryDaysRemaining) {
return monitor.element.certExpiryDaysRemaining + " " + this.$tc("day", monitor.element.certExpiryDaysRemaining);
} else if (monitor?.element?.validCert === false) {
return this.$t("noOrBadCertificate");
2023-07-04 19:37:45 -04:00
} else {
2023-07-13 20:50:17 -04:00
return this.$t("Unknown") + " " + this.$tc("day", 2);
}
},
/**
* Returns certificate expiry based on days remaining
* @param {Object} monitor Monitor to show expiry for
* @returns {string}
*/
certExpiryColor(monitor) {
2023-07-13 20:37:21 -04:00
if (monitor?.element?.validCert && monitor.element.certExpiryDaysRemaining > 7) {
return "primary";
2023-07-04 19:37:45 -04:00
}
return "danger";
2023-07-04 19:37:45 -04:00
},
2021-09-13 07:21:39 -04:00
}
2021-09-17 02:42:19 -04:00
};
2021-09-13 07:21:39 -04:00
</script>
<style lang="scss" scoped>
2021-09-15 02:34:30 -04:00
@import "../assets/vars";
2021-09-13 07:21:39 -04:00
2021-09-15 02:34:30 -04:00
.no-monitor-msg {
position: absolute;
width: 100%;
top: 20px;
left: 0;
}
2021-09-13 07:21:39 -04:00
2021-09-15 02:34:30 -04:00
.monitor-list {
min-height: 46px;
}
2021-09-13 07:21:39 -04:00
.item-name {
padding-left: 5px;
padding-right: 5px;
margin: 0;
display: inline-block;
}
2022-07-04 06:33:38 -04:00
.btn-link {
color: #bbbbbb;
margin-left: 5px;
}
.link-active {
2022-07-04 06:33:38 -04:00
color: $primary;
}
2021-09-15 02:34:30 -04:00
.flip-list-move {
transition: transform 0.5s;
}
.no-move {
transition: transform 0s;
}
.drag {
color: #bbb;
cursor: grab;
}
.remove {
color: $danger;
}
2021-09-16 10:48:28 -04:00
.group-title {
span {
display: inline-block;
min-width: 15px;
}
}
2021-09-23 04:31:45 -04:00
.mobile {
.item {
padding: 13px 0 10px;
2021-09-23 04:31:45 -04:00
}
}
.bg-maintenance {
background-color: $maintenance;
}
2021-09-13 07:21:39 -04:00
</style>