[Status Page] Delete status page

This commit is contained in:
Louis Lam 2022-03-18 15:19:52 +08:00
parent 243fab5f26
commit 37be7df9b0
4 changed files with 95 additions and 15 deletions

View file

@ -6,6 +6,7 @@ const ImageDataURI = require("../image-data-uri");
const Database = require("../database"); const Database = require("../database");
const apicache = require("../modules/apicache"); const apicache = require("../modules/apicache");
const StatusPage = require("../model/status_page"); const StatusPage = require("../model/status_page");
const server = require("../server");
module.exports.statusPageSocketHandler = (socket) => { module.exports.statusPageSocketHandler = (socket) => {
@ -242,4 +243,51 @@ module.exports.statusPageSocketHandler = (socket) => {
} }
}); });
// Delete a status page
socket.on("deleteStatusPage", async (slug, callback) => {
try {
checkLogin(socket);
let statusPageID = await StatusPage.slugToID(slug);
if (statusPageID) {
// Reset entry page if it is the default one.
if (server.entryPage === "statusPage-" + slug) {
server.entryPage = "dashboard";
await setSettings("entryPage", server.entryPage, "general");
}
// No need to delete records from `status_page_cname`, because it has cascade foreign key.
// But for incident & group, it is hard to add cascade foreign key during migration, so they have to be deleted manually.
// Delete incident
await R.exec("DELETE FROM incident WHERE status_page_id = ? ", [
statusPageID
]);
// Delete group
await R.exec("DELETE FROM `group` WHERE status_page_id = ? ", [
statusPageID
]);
// Delete status_page
await R.exec("DELETE FROM status_page WHERE id = ? ", [
statusPageID
]);
} else {
throw new Error("Status Page is not found");
}
callback({
ok: true,
});
} catch (error) {
callback({
ok: false,
msg: error.message,
});
}
});
}; };

View file

@ -331,21 +331,21 @@ export default {
dark: "dark", dark: "dark",
Post: "Post", Post: "Post",
"Please input title and content": "Please input title and content", "Please input title and content": "Please input title and content",
Created: "Created", "Created": "Created",
"Last Updated": "Last Updated", "Last Updated": "Last Updated",
Unpin: "Unpin", "Unpin": "Unpin",
"Switch to Light Theme": "Switch to Light Theme", "Switch to Light Theme": "Switch to Light Theme",
"Switch to Dark Theme": "Switch to Dark Theme", "Switch to Dark Theme": "Switch to Dark Theme",
"Show Tags": "Show Tags", "Show Tags": "Show Tags",
"Hide Tags": "Hide Tags", "Hide Tags": "Hide Tags",
Description: "Description", "Description": "Description",
"No monitors available.": "No monitors available.", "No monitors available.": "No monitors available.",
"Add one": "Add one", "Add one": "Add one",
"No Monitors": "No Monitors", "No Monitors": "No Monitors",
"Untitled Group": "Untitled Group", "Untitled Group": "Untitled Group",
Services: "Services", "Services": "Services",
Discard: "Discard", "Discard": "Discard",
Cancel: "Cancel", "Cancel": "Cancel",
"Powered by": "Powered by", "Powered by": "Powered by",
shrinkDatabaseDescription: "Trigger database VACUUM for SQLite. If your database is created after 1.10.0, AUTO_VACUUM is already enabled and this action is not needed.", shrinkDatabaseDescription: "Trigger database VACUUM for SQLite. If your database is created after 1.10.0, AUTO_VACUUM is already enabled and this action is not needed.",
serwersms: "SerwerSMS.pl", serwersms: "SerwerSMS.pl",
@ -353,7 +353,7 @@ export default {
serwersmsAPIPassword: "API Password", serwersmsAPIPassword: "API Password",
serwersmsPhoneNumber: "Phone number", serwersmsPhoneNumber: "Phone number",
serwersmsSenderName: "SMS Sender Name (registered via customer portal)", serwersmsSenderName: "SMS Sender Name (registered via customer portal)",
"stackfield": "Stackfield", stackfield: "Stackfield",
smtpDkimSettings: "DKIM Settings", smtpDkimSettings: "DKIM Settings",
smtpDkimDesc: "Please refer to the Nodemailer DKIM {0} for usage.", smtpDkimDesc: "Please refer to the Nodemailer DKIM {0} for usage.",
documentation: "documentation", documentation: "documentation",
@ -370,4 +370,5 @@ export default {
alertaApiKey: "API Key", alertaApiKey: "API Key",
alertaAlertState: "Alert State", alertaAlertState: "Alert State",
alertaRecoverState: "Recover State", alertaRecoverState: "Recover State",
deleteStatusPageMsg: "Are you sure want to delete this status page?",
}; };

View file

@ -96,7 +96,7 @@ export default {
Test: "測試", Test: "測試",
keywordDescription: "搜索 HTML 或 JSON 裡是否有出現關鍵字(注意英文大細階)", keywordDescription: "搜索 HTML 或 JSON 裡是否有出現關鍵字(注意英文大細階)",
"Certificate Info": "憑證詳細資料", "Certificate Info": "憑證詳細資料",
deleteMonitorMsg: "是否確定刪除這個監測器", deleteMonitorMsg: "是否確定刪除這個監測器",
deleteNotificationMsg: "是否確定刪除這個通知設定?如監測器啟用了這個通知,將會收不到通知。", deleteNotificationMsg: "是否確定刪除這個通知設定?如監測器啟用了這個通知,將會收不到通知。",
"Resolver Server": "DNS 伺服器", "Resolver Server": "DNS 伺服器",
"Resource Record Type": "DNS 記錄類型", "Resource Record Type": "DNS 記錄類型",
@ -199,4 +199,5 @@ export default {
pushbullet: "Pushbullet", pushbullet: "Pushbullet",
line: "Line Messenger", line: "Line Messenger",
mattermost: "Mattermost", mattermost: "Mattermost",
deleteStatusPageMsg: "是否確定刪除這個 Status Page",
}; };

View file

@ -40,10 +40,12 @@
<textarea id="cname" v-model="config.domanNames" rows="3" disabled class="form-control" :placeholder="domainNamesPlaceholder"></textarea> <textarea id="cname" v-model="config.domanNames" rows="3" disabled class="form-control" :placeholder="domainNamesPlaceholder"></textarea>
</div> </div>
<button class="btn btn-danger me-2" @click="discard"> <div class="danger-zone">
<button class="btn btn-danger me-2" @click="deleteDialog">
<font-awesome-icon icon="trash" /> <font-awesome-icon icon="trash" />
{{ $t("Delete") }} {{ $t("Delete") }}
</button> </button>
</div>
<!-- Sidebar Footer --> <!-- Sidebar Footer -->
<div class="sidebar-footer"> <div class="sidebar-footer">
@ -228,6 +230,10 @@
{{ $t("Powered by") }} <a target="_blank" href="https://github.com/louislam/uptime-kuma">{{ $t("Uptime Kuma" ) }}</a> {{ $t("Powered by") }} <a target="_blank" href="https://github.com/louislam/uptime-kuma">{{ $t("Uptime Kuma" ) }}</a>
</footer> </footer>
</div> </div>
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="deleteStatusPage">
{{ $t("deleteStatusPageMsg") }}
</Confirm>
</div> </div>
</template> </template>
@ -240,6 +246,7 @@ import { useToast } from "vue-toastification";
import dayjs from "dayjs"; import dayjs from "dayjs";
import Favico from "favico.js"; import Favico from "favico.js";
import { getResBaseURL } from "../util-frontend"; import { getResBaseURL } from "../util-frontend";
import Confirm from "../components/Confirm.vue";
const toast = useToast(); const toast = useToast();
@ -254,7 +261,8 @@ const favicon = new Favico({
export default { export default {
components: { components: {
PublicGroupList, PublicGroupList,
ImageCropUpload ImageCropUpload,
Confirm,
}, },
// Leave Page for vue route change // Leave Page for vue route change
@ -533,6 +541,21 @@ export default {
}); });
}, },
deleteDialog() {
this.$refs.confirmDelete.show();
},
deleteStatusPage() {
this.$root.getSocket().emit("deleteStatusPage", this.slug, (res) => {
if (res.ok) {
this.enableEditMode = false;
location.href = "/manage-status-page";
} else {
toast.error(res.msg);
}
});
},
monitorSelectorLabel(monitor) { monitorSelectorLabel(monitor) {
return `${monitor.name}`; return `${monitor.name}`;
}, },
@ -573,8 +596,6 @@ export default {
}) })
}; };
}); });
} else {
} }
}, },
@ -705,6 +726,11 @@ h1 {
overflow-y: auto; overflow-y: auto;
border-right: 1px solid #ededed; border-right: 1px solid #ededed;
.danger-zone {
border-top: 1px solid #ededed;
padding-top: 15px;
}
.sidebar-footer { .sidebar-footer {
width: 100%; width: 100%;
bottom: 0; bottom: 0;
@ -793,6 +819,10 @@ footer {
background-color: $dark-header-bg; background-color: $dark-header-bg;
border-right-color: $dark-border-color; border-right-color: $dark-border-color;
.danger-zone {
border-top-color: $dark-border-color;
}
.sidebar-footer { .sidebar-footer {
border-top-color: $dark-border-color; border-top-color: $dark-border-color;
} }