mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-20 03:06:48 +02:00
Fix the warning and error
This commit is contained in:
parent
f9bef48658
commit
d6bfd9b952
2 changed files with 170 additions and 116 deletions
|
@ -1,11 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-if="group && group.monitorList && group.monitorList.length > 1" class="sort-dropdown">
|
<div v-if="group && group.monitorList && group.monitorList.length > 1" class="sort-dropdown">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button :id="'sortDropdown' + groupIndex" type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle sort-button"
|
<button
|
||||||
|
:id="'sortDropdown' + groupIndex"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-outline-secondary dropdown-toggle sort-button"
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
:aria-label="$t('Sort options')"
|
:aria-label="$t('Sort options')"
|
||||||
:title="$t('Sort options')">
|
:title="$t('Sort options')"
|
||||||
|
>
|
||||||
<div class="sort-arrows">
|
<div class="sort-arrows">
|
||||||
<font-awesome-icon
|
<font-awesome-icon
|
||||||
icon="arrow-down"
|
icon="arrow-down"
|
||||||
|
@ -25,9 +29,13 @@
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end sort-menu" :aria-labelledby="'sortDropdown' + groupIndex">
|
<ul class="dropdown-menu dropdown-menu-end sort-menu" :aria-labelledby="'sortDropdown' + groupIndex">
|
||||||
<li>
|
<li>
|
||||||
<button class="dropdown-item sort-item" type="button" @click="setSort('status')"
|
<button
|
||||||
|
class="dropdown-item sort-item"
|
||||||
|
type="button"
|
||||||
:aria-label="$t('Sort by status')"
|
:aria-label="$t('Sort by status')"
|
||||||
:title="$t('Sort by status')">
|
:title="$t('Sort by status')"
|
||||||
|
@click="setSort('status')"
|
||||||
|
>
|
||||||
<div class="sort-item-content">
|
<div class="sort-item-content">
|
||||||
<span>{{ $t("Status") }}</span>
|
<span>{{ $t("Status") }}</span>
|
||||||
<span v-if="getSortKey() === 'status'" class="sort-indicators">
|
<span v-if="getSortKey() === 'status'" class="sort-indicators">
|
||||||
|
@ -40,9 +48,13 @@
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button class="dropdown-item sort-item" type="button" @click="setSort('name')"
|
<button
|
||||||
|
class="dropdown-item sort-item"
|
||||||
|
type="button"
|
||||||
:aria-label="$t('Sort by name')"
|
:aria-label="$t('Sort by name')"
|
||||||
:title="$t('Sort by name')">
|
:title="$t('Sort by name')"
|
||||||
|
@click="setSort('name')"
|
||||||
|
>
|
||||||
<div class="sort-item-content">
|
<div class="sort-item-content">
|
||||||
<span>{{ $t("Name") }}</span>
|
<span>{{ $t("Name") }}</span>
|
||||||
<span v-if="getSortKey() === 'name'" class="sort-indicators">
|
<span v-if="getSortKey() === 'name'" class="sort-indicators">
|
||||||
|
@ -55,9 +67,13 @@
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button class="dropdown-item sort-item" type="button" @click="setSort('uptime')"
|
<button
|
||||||
|
class="dropdown-item sort-item"
|
||||||
|
type="button"
|
||||||
:aria-label="$t('Sort by uptime')"
|
:aria-label="$t('Sort by uptime')"
|
||||||
:title="$t('Sort by uptime')">
|
:title="$t('Sort by uptime')"
|
||||||
|
@click="setSort('uptime')"
|
||||||
|
>
|
||||||
<div class="sort-item-content">
|
<div class="sort-item-content">
|
||||||
<span>{{ $t("Uptime") }}</span>
|
<span>{{ $t("Uptime") }}</span>
|
||||||
<span v-if="getSortKey() === 'uptime'" class="sort-indicators">
|
<span v-if="getSortKey() === 'uptime'" class="sort-indicators">
|
||||||
|
@ -70,9 +86,13 @@
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="showCertificateExpiry">
|
<li v-if="showCertificateExpiry">
|
||||||
<button class="dropdown-item sort-item" type="button" @click="setSort('cert')"
|
<button
|
||||||
|
class="dropdown-item sort-item"
|
||||||
|
type="button"
|
||||||
:aria-label="$t('Sort by certificate expiry')"
|
:aria-label="$t('Sort by certificate expiry')"
|
||||||
:title="$t('Sort by certificate expiry')">
|
:title="$t('Sort by certificate expiry')"
|
||||||
|
@click="setSort('cert')"
|
||||||
|
>
|
||||||
<div class="sort-item-content">
|
<div class="sort-item-content">
|
||||||
<span>{{ $t("Cert Exp.") }}</span>
|
<span>{{ $t("Cert Exp.") }}</span>
|
||||||
<span v-if="getSortKey() === 'cert'" class="sort-indicators">
|
<span v-if="getSortKey() === 'cert'" class="sort-indicators">
|
||||||
|
@ -109,6 +129,7 @@ export default {
|
||||||
default: false,
|
default: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
emits: [ "update-group" ],
|
||||||
computed: {
|
computed: {
|
||||||
/**
|
/**
|
||||||
* Parse sort settings from URL query parameters
|
* Parse sort settings from URL query parameters
|
||||||
|
@ -118,12 +139,15 @@ export default {
|
||||||
const sortSettings = {};
|
const sortSettings = {};
|
||||||
if (this.$route && this.$route.query) {
|
if (this.$route && this.$route.query) {
|
||||||
for (const [ key, value ] of Object.entries(this.$route.query)) {
|
for (const [ key, value ] of Object.entries(this.$route.query)) {
|
||||||
if (key.startsWith('sort_') && typeof value === 'string') {
|
if (key.startsWith("sort_") && typeof value === "string") {
|
||||||
const groupId = key.replace('sort_', '');
|
const groupId = key.replace("sort_", "");
|
||||||
const [sortKey, direction] = value.split('_');
|
const [ sortKey, direction ] = value.split("_");
|
||||||
if (sortKey && ['status', 'name', 'uptime', 'cert'].includes(sortKey) &&
|
if (sortKey && [ "status", "name", "uptime", "cert" ].includes(sortKey) &&
|
||||||
direction && ['asc', 'desc'].includes(direction)) {
|
direction && [ "asc", "desc" ].includes(direction)) {
|
||||||
sortSettings[groupId] = { sortKey, direction };
|
sortSettings[ groupId ] = {
|
||||||
|
sortKey,
|
||||||
|
direction
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,15 +180,17 @@ export default {
|
||||||
const urlSetting = newSortSettings[ groupId ];
|
const urlSetting = newSortSettings[ groupId ];
|
||||||
|
|
||||||
if (urlSetting) {
|
if (urlSetting) {
|
||||||
this.group.sortKey = urlSetting.sortKey;
|
this.updateGroup({
|
||||||
this.group.sortDirection = urlSetting.direction;
|
sortKey: urlSetting.sortKey,
|
||||||
|
sortDirection: urlSetting.direction
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Set defaults if not in URL
|
// Set defaults if not in URL
|
||||||
if (this.group.sortKey === undefined) {
|
if (this.group.sortKey === undefined) {
|
||||||
this.group.sortKey = "status";
|
this.updateGroup({ sortKey: "status" });
|
||||||
}
|
}
|
||||||
if (this.group.sortDirection === undefined) {
|
if (this.group.sortDirection === undefined) {
|
||||||
this.group.sortDirection = "asc";
|
this.updateGroup({ sortDirection: "asc" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +210,15 @@ export default {
|
||||||
return this.group.sortKey || "status";
|
return this.group.sortKey || "status";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update group properties by emitting to parent
|
||||||
|
* @param {object} updates - object with properties to update
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
updateGroup(updates) {
|
||||||
|
this.$emit("update-group", this.groupIndex, updates);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set group sort key and direction, then apply sorting
|
* Set group sort key and direction, then apply sorting
|
||||||
* @param {string} key - sort key ('status', 'name', 'uptime', 'cert')
|
* @param {string} key - sort key ('status', 'name', 'uptime', 'cert')
|
||||||
|
@ -191,10 +226,14 @@ export default {
|
||||||
*/
|
*/
|
||||||
setSort(key) {
|
setSort(key) {
|
||||||
if (this.group.sortKey === key) {
|
if (this.group.sortKey === key) {
|
||||||
this.group.sortDirection = this.group.sortDirection === "asc" ? "desc" : "asc";
|
this.updateGroup({
|
||||||
|
sortDirection: this.group.sortDirection === "asc" ? "desc" : "asc"
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.group.sortKey = key;
|
this.updateGroup({
|
||||||
this.group.sortDirection = "asc";
|
sortKey: key,
|
||||||
|
sortDirection: "asc"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.applySort();
|
this.applySort();
|
||||||
|
@ -206,7 +245,9 @@ export default {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
updateRouterQuery() {
|
updateRouterQuery() {
|
||||||
if (!this.$router) return;
|
if (!this.$router) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const query = { ...this.$route.query };
|
const query = { ...this.$route.query };
|
||||||
const groupId = this.getGroupIdentifier();
|
const groupId = this.getGroupIdentifier();
|
||||||
|
@ -232,7 +273,8 @@ export default {
|
||||||
const sortKey = this.group.sortKey || "status";
|
const sortKey = this.group.sortKey || "status";
|
||||||
const sortDirection = this.group.sortDirection || "desc";
|
const sortDirection = this.group.sortDirection || "desc";
|
||||||
|
|
||||||
this.group.monitorList.sort((a, b) => {
|
this.updateGroup({
|
||||||
|
monitorList: [ ...this.group.monitorList ].sort((a, b) => {
|
||||||
if (!a || !b) {
|
if (!a || !b) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -298,6 +340,7 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
return sortDirection === "asc" ? comparison : (comparison * -1);
|
return sortDirection === "asc" ? comparison : (comparison * -1);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
:group="group.element"
|
:group="group.element"
|
||||||
:group-index="group.index"
|
:group-index="group.index"
|
||||||
:show-certificate-expiry="showCertificateExpiry"
|
:show-certificate-expiry="showCertificateExpiry"
|
||||||
|
@update-group="updateGroup"
|
||||||
/>
|
/>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
@ -206,6 +207,16 @@ export default {
|
||||||
return "#DC2626";
|
return "#DC2626";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update group properties
|
||||||
|
* @param {number} groupIndex Index of group to update
|
||||||
|
* @param {object} updates Object with properties to update
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
updateGroup(groupIndex, updates) {
|
||||||
|
Object.assign(this.$root.publicGroupList[groupIndex], updates);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get unique identifier for a group
|
* Get unique identifier for a group
|
||||||
* @param {object} group object
|
* @param {object} group object
|
||||||
|
|
Loading…
Add table
Reference in a new issue