Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Monitor Tags on Status Page #815

Merged
merged 11 commits into from
Nov 7, 2021
25 changes: 22 additions & 3 deletions server/routers/api-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ router.get("/api/status-page/config", async (_request, response) => {
config.statusPagePublished = true;
}

if (! config.statusPageTags) {
config.statusPageTags = false;
}

if (! config.title) {
config.title = "Uptime Kuma";
}
Expand Down Expand Up @@ -140,10 +144,25 @@ router.get("/api/status-page/monitor-list", cache("5 minutes"), async (_request,
try {
await checkPublished();
const publicGroupList = [];
let list = await R.find("group", " public = 1 ORDER BY weight ");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops accidental change, just didn't notice I delated it in the diff.

const tagsVisible = (await getSettings("statusPage")).statusPageTags;
const list = await R.find("group", " public = 1 ORDER BY weight ");
for (let groupBean of list) {
publicGroupList.push(await groupBean.toPublicJSON());
let monitorGroup = await groupBean.toPublicJSON();
if (tagsVisible) {
monitorGroup.monitorList = await Promise.all(monitorGroup.monitorList.map(async (monitor) => {
// Includes tags as an array in response, allows for tags to be displayed on public status page
const tags = await R.getAll(
`SELECT monitor_tag.monitor_id, monitor_tag.value, tag.name, tag.color
FROM monitor_tag
JOIN tag
ON monitor_tag.tag_id = tag.id
WHERE monitor_tag.monitor_id = ?`, [monitor.id]
);
return {...monitor, tags: tags}
}));
}

publicGroupList.push(monitorGroup);
}

response.json(publicGroupList);
Expand Down
4 changes: 4 additions & 0 deletions src/assets/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ textarea.form-control {
&.active {
background-color: #cdf8f4;
}
.tags {
// Removes margin to line up tags list with uptime percentage
margin-left: -0.25rem;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/PublicGroupList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<Uptime :monitor="monitor.element" type="24" :pill="true" />
{{ monitor.element.name }}
</div>
<div class="tags">
<Tag v-for="tag in monitor.element.tags" :key="tag" :item="tag" :size="'sm'" />
</div>
</div>
<div :key="$root.userHeartbeatBar" class="col-3 col-md-4">
<HeartbeatBar size="small" :monitor-id="monitor.element.id" />
Expand All @@ -59,12 +62,14 @@
import Draggable from "vuedraggable";
import HeartbeatBar from "./HeartbeatBar.vue";
import Uptime from "./Uptime.vue";
import Tag from "./Tag.vue";

export default {
components: {
Draggable,
HeartbeatBar,
Uptime,
Tag,
},
props: {
editMode: {
Expand Down
34 changes: 34 additions & 0 deletions src/pages/StatusPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
<font-awesome-icon icon="save" />
{{ $t("Switch to Dark Theme") }}
</button>

<button class="btn btn-secondary me-2" @click="changeTagsVisibilty(!tagsVisible)">
<template v-if="tagsVisible">
<font-awesome-icon icon="eye-slash" />
{{ $t("Hide Tags") }}
</template>
<template v-else>
<font-awesome-icon icon="eye" />
{{ $t("Show Tags") }}
</template>
</button>
</div>
</div>

Expand Down Expand Up @@ -292,6 +303,10 @@ export default {
return this.config.statusPageTheme;
},

tagsVisible() {
return this.config.statusPageTags
},

logoClass() {
if (this.editMode) {
return {
Expand Down Expand Up @@ -472,6 +487,25 @@ export default {
changeTheme(name) {
this.config.statusPageTheme = name;
},
changeTagsVisibilty(newState) {
this.config.statusPageTags = newState;

// On load, the status page will not include tags if it's not enabled for security reasons
// Which means if we enable tags, it won't show in the UI until saved
// So we have this to enhance UX and load in the tags from the authenticated source instantly
this.$root.publicGroupList = this.$root.publicGroupList.map((group) => {
return {
...group,
monitorList: group.monitorList.map((monitor) => {
// We only include the tags if visible so we can reuse the logic to hide the tags on disable
return {
...monitor,
tags: newState ? this.$root.monitorList[monitor.id].tags : []
}
})
}
});
},

/**
* Crop Success
Expand Down