diff --git a/server/model/group.js b/server/model/group.js
index 567f3865..3e1f2d44 100644
--- a/server/model/group.js
+++ b/server/model/group.js
@@ -3,12 +3,12 @@ const { R } = require("redbean-node");
class Group extends BeanModel {
- async toPublicJSON() {
+ async toPublicJSON(showTags = false) {
let monitorBeanList = await this.getMonitorList();
let monitorList = [];
for (let bean of monitorBeanList) {
- monitorList.push(await bean.toPublicJSON());
+ monitorList.push(await bean.toPublicJSON(showTags));
}
return {
diff --git a/server/model/monitor.js b/server/model/monitor.js
index b4a80598..bafc0d2d 100644
--- a/server/model/monitor.js
+++ b/server/model/monitor.js
@@ -24,18 +24,22 @@ const apicache = require("../modules/apicache");
class Monitor extends BeanModel {
/**
- * Return a object that ready to parse to JSON for public
+ * Return an object that ready to parse to JSON for public
* Only show necessary data to public
*/
- async toPublicJSON() {
- return {
+ async toPublicJSON(showTags = false) {
+ let obj = {
id: this.id,
name: this.name,
};
+ if (showTags) {
+ obj.tags = await this.getTags();
+ }
+ return obj;
}
/**
- * Return a object that ready to parse to JSON
+ * Return an object that ready to parse to JSON
*/
async toJSON() {
@@ -49,7 +53,7 @@ class Monitor extends BeanModel {
notificationIDList[bean.notification_id] = true;
}
- const tags = await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [this.id]);
+ const tags = await this.getTags();
return {
id: this.id,
@@ -82,6 +86,10 @@ class Monitor extends BeanModel {
};
}
+ async getTags() {
+ return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [this.id]);
+ }
+
/**
* Encode user and password to Base64 encoding
* for HTTP "basic" auth, as per RFC-7617
diff --git a/server/routers/api-router.js b/server/routers/api-router.js
index e9076e99..ad887084 100644
--- a/server/routers/api-router.js
+++ b/server/routers/api-router.js
@@ -113,30 +113,14 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
// Public Group List
const publicGroupList = [];
- const tagsVisible = !!statusPage.show_tags;
+ const showTags = !!statusPage.show_tags;
+ debug("Show Tags???" + showTags);
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
statusPage.id
]);
for (let groupBean of list) {
- 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
- };
- }));
- }
-
+ let monitorGroup = await groupBean.toPublicJSON(showTags);
publicGroupList.push(monitorGroup);
}
diff --git a/src/components/PublicGroupList.vue b/src/components/PublicGroupList.vue
index f30edcef..37440e31 100644
--- a/src/components/PublicGroupList.vue
+++ b/src/components/PublicGroupList.vue
@@ -41,7 +41,7 @@