From 049f46a4cfe6ac68ae4d2fabd8257938f1cd3493 Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Tue, 22 Mar 2022 20:14:16 +0800 Subject: [PATCH] feat: update dashboard list and reload templates (#33) --- src/locales/lang/en.ts | 2 + src/locales/lang/zh.ts | 2 + src/router/database.ts | 3 +- src/store/modules/dashboard.ts | 26 ++++-- src/views/dashboard/Edit.vue | 2 +- src/views/dashboard/List.vue | 92 ++++++++++++++----- src/views/dashboard/New.vue | 2 +- src/views/dashboard/configuration/Widget.vue | 9 +- src/views/dashboard/controls/Widget.vue | 11 ++- src/views/dashboard/data.ts | 9 +- src/views/dashboard/graphs/EndpointList.vue | 19 +++- src/views/dashboard/graphs/InstanceList.vue | 20 +++- src/views/dashboard/graphs/ServiceList.vue | 13 ++- src/views/dashboard/panel/Tool.vue | 24 +++-- .../related/topology/components/Graph.vue | 26 +++--- .../topology/components/PodTopology.vue | 23 +++-- 16 files changed, 202 insertions(+), 81 deletions(-) diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index a1a87f5f..26dc9d19 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -121,6 +121,8 @@ const msg = { linux: "Linux", editWarning: "You are entering edit mode", viewWarning: "You are entering view mode", + virtualDatabase: "Virtual Database", + reloadDashboards: "Reload dashboards", hourTip: "Select Hour", minuteTip: "Select Minute", secondTip: "Select Second", diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index a4acc1f2..f8702996 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -121,6 +121,8 @@ const msg = { browser: "浏览器", editWarning: "你正在进入编辑模式", viewWarning: "你正在进入预览模式", + virtualDatabase: "虚拟数据库", + reloadDashboards: "重新加载仪表盘", hourTip: "选择小时", minuteTip: "选择分钟", secondTip: "选择秒数", diff --git a/src/router/database.ts b/src/router/database.ts index ce566976..4d285f43 100644 --- a/src/router/database.ts +++ b/src/router/database.ts @@ -24,6 +24,7 @@ export const routesDatabase: Array = [ meta: { title: "database", icon: "bar_chart", + hasGroup: true, }, redirect: "/database", component: Layout, @@ -32,7 +33,7 @@ export const routesDatabase: Array = [ path: "/database", name: "Database", meta: { - title: "database", + title: "virtualDatabase", headPath: "/database", exact: true, }, diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 6e7d33a0..0f485c1f 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -296,7 +296,7 @@ export const dashboardStore = defineStore({ const list = []; for (const t of data) { const c = JSON.parse(t.configuration); - const key = [c.layer, c.entity, c.name.split(" ").join("-")].join("_"); + const key = [c.layer, c.entity, c.name].join("_"); list.push({ id: t.id, @@ -326,6 +326,17 @@ export const dashboardStore = defineStore({ sessionStorage.getItem("dashboards") || "[]" ); }, + async resetTemplates() { + const res = await this.fetchTemplates(); + if (res.errors) { + this.dashboards = []; + ElMessage.error(res.errors); + return; + } + this.dashboards = JSON.parse( + sessionStorage.getItem("dashboards") || "[]" + ); + }, async updateDashboard(setting: { id: string; configuration: string }) { const res: AxiosResponse = await graphql.query("updateTemplate").params({ setting, @@ -385,7 +396,7 @@ export const dashboardStore = defineStore({ } if (!json.status) { ElMessage.error(json.message); - return; + return json; } if (!this.currentDashboard.id) { ElMessage.success("Saved successfully"); @@ -393,22 +404,21 @@ export const dashboardStore = defineStore({ const key = [ this.currentDashboard.layer, this.currentDashboard.entity, - this.currentDashboard.name.split(" ").join("-"), + this.currentDashboard.name, ].join("_"); + this.currentDashboard.id = json.id; if (this.currentDashboard.id) { sessionStorage.removeItem(key); this.dashboards = this.dashboards.filter( (d: DashboardItem) => d.id !== this.currentDashboard.id ); } - this.dashboards.push({ - ...this.currentDashboard, - id: json.id, - }); + this.dashboards.push(this.currentDashboard); const l = { id: json.id, configuration: c }; sessionStorage.setItem(key, JSON.stringify(l)); sessionStorage.setItem("dashboards", JSON.stringify(this.dashboards)); + return json; }, async deleteDashboard() { const res: AxiosResponse = await graphql @@ -430,7 +440,7 @@ export const dashboardStore = defineStore({ const key = [ this.currentDashboard.layer, this.currentDashboard.entity, - this.currentDashboard.name.split(" ").join("-"), + this.currentDashboard.name, ].join("_"); sessionStorage.removeItem(key); }, diff --git a/src/views/dashboard/Edit.vue b/src/views/dashboard/Edit.vue index 67d850c1..eb62f74c 100644 --- a/src/views/dashboard/Edit.vue +++ b/src/views/dashboard/Edit.vue @@ -55,7 +55,7 @@ async function setTemplate() { if (!p.entity) { const { layer, entity, name } = dashboardStore.currentDashboard; - layoutKey.value = `${layer}_${entity}_${name.split(" ").join("-")}`; + layoutKey.value = `${layer}_${entity}_${name}`; } const c: { configuration: string; id: string } = JSON.parse( sessionStorage.getItem(layoutKey.value) || "{}" diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 9211c0cd..822f9430 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -18,7 +18,7 @@ limitations under the License. --> @@ -28,6 +28,10 @@ limitations under the License. --> + + + {{ t("reloadDashboards") }} + + {{ t("newDashboard") }} @@ -37,7 +41,7 @@ limitations under the License. -->
- + - +