verificate dashboard names

This commit is contained in:
Qiuxia Fan 2022-03-22 16:47:57 +08:00
parent ecd046c663
commit 83496dc4b5
8 changed files with 24 additions and 38 deletions

View File

@ -296,7 +296,7 @@ export const dashboardStore = defineStore({
const list = []; const list = [];
for (const t of data) { for (const t of data) {
const c = JSON.parse(t.configuration); 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({ list.push({
id: t.id, id: t.id,
@ -404,7 +404,7 @@ export const dashboardStore = defineStore({
const key = [ const key = [
this.currentDashboard.layer, this.currentDashboard.layer,
this.currentDashboard.entity, this.currentDashboard.entity,
this.currentDashboard.name.split(" ").join("-"), this.currentDashboard.name,
].join("_"); ].join("_");
if (this.currentDashboard.id) { if (this.currentDashboard.id) {
sessionStorage.removeItem(key); sessionStorage.removeItem(key);
@ -441,7 +441,7 @@ export const dashboardStore = defineStore({
const key = [ const key = [
this.currentDashboard.layer, this.currentDashboard.layer,
this.currentDashboard.entity, this.currentDashboard.entity,
this.currentDashboard.name.split(" ").join("-"), this.currentDashboard.name,
].join("_"); ].join("_");
sessionStorage.removeItem(key); sessionStorage.removeItem(key);
}, },

View File

@ -55,7 +55,7 @@ async function setTemplate() {
if (!p.entity) { if (!p.entity) {
const { layer, entity, name } = dashboardStore.currentDashboard; 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( const c: { configuration: string; id: string } = JSON.parse(
sessionStorage.getItem(layoutKey.value) || "{}" sessionStorage.getItem(layoutKey.value) || "{}"

View File

@ -172,7 +172,7 @@ async function importTemplates(event: any) {
(d: DashboardItem) => d.id === item.id (d: DashboardItem) => d.id === item.id
); );
const p: DashboardItem = { const p: DashboardItem = {
name: name, name: name.split(" ").join("-"),
layer: layer, layer: layer,
entity: entity, entity: entity,
isRoot: false, isRoot: false,
@ -196,7 +196,7 @@ function exportTemplates() {
} }
); );
const templates = arr.map((d: DashboardItem) => { const templates = arr.map((d: DashboardItem) => {
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_"); const key = [d.layer, d.entity, d.name].join("_");
const layout = JSON.parse(sessionStorage.getItem(key) || "{}"); const layout = JSON.parse(sessionStorage.getItem(key) || "{}");
return layout; return layout;
}); });
@ -211,9 +211,7 @@ function handleEdit(row: DashboardItem) {
dashboardStore.setEntity(row.entity); dashboardStore.setEntity(row.entity);
dashboardStore.setLayer(row.layer); dashboardStore.setLayer(row.layer);
dashboardStore.setCurrentDashboard(row); dashboardStore.setCurrentDashboard(row);
router.push( router.push(`/dashboard/${row.layer}/${row.entity}/${row.name}`);
`/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}`
);
} }
function handleView(row: DashboardItem) { function handleView(row: DashboardItem) {
@ -221,9 +219,7 @@ function handleView(row: DashboardItem) {
dashboardStore.setEntity(row.entity); dashboardStore.setEntity(row.entity);
dashboardStore.setLayer(row.layer); dashboardStore.setLayer(row.layer);
dashboardStore.setCurrentDashboard(row); dashboardStore.setCurrentDashboard(row);
router.push( router.push(`/dashboard/${row.layer}/${row.entity}/${row.name}`);
`/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}`
);
} }
async function setRoot(row: DashboardItem) { async function setRoot(row: DashboardItem) {
@ -232,7 +228,7 @@ async function setRoot(row: DashboardItem) {
for (const d of dashboardStore.dashboards) { for (const d of dashboardStore.dashboards) {
if (d.id === row.id) { if (d.id === row.id) {
d.isRoot = !row.isRoot; d.isRoot = !row.isRoot;
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_"); const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}"; const layout = sessionStorage.getItem(key) || "{}";
const c = { const c = {
...JSON.parse(layout).configuration, ...JSON.parse(layout).configuration,
@ -262,7 +258,7 @@ async function setRoot(row: DashboardItem) {
d.isRoot === true d.isRoot === true
) { ) {
d.isRoot = false; d.isRoot = false;
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_"); const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}"; const layout = sessionStorage.getItem(key) || "{}";
const c = { const c = {
...JSON.parse(layout).configuration, ...JSON.parse(layout).configuration,
@ -307,7 +303,11 @@ function handleRename(row: DashboardItem) {
}); });
} }
async function updateName(d: DashboardItem, value: string) { async function updateName(d: DashboardItem, value: string) {
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_"); if (new RegExp(/\s/).test(value)) {
ElMessage.error("The name cannot contain spaces, carriage returns, etc");
return;
}
const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}"; const layout = sessionStorage.getItem(key) || "{}";
const c = { const c = {
...JSON.parse(layout).configuration, ...JSON.parse(layout).configuration,
@ -341,7 +341,7 @@ async function updateName(d: DashboardItem, value: string) {
const str = [ const str = [
dashboardStore.currentDashboard.layer, dashboardStore.currentDashboard.layer,
dashboardStore.currentDashboard.entity, dashboardStore.currentDashboard.entity,
dashboardStore.currentDashboard.name.split(" ").join("-"), dashboardStore.currentDashboard.name,
].join("_"); ].join("_");
sessionStorage.setItem( sessionStorage.setItem(
str, str,
@ -359,9 +359,7 @@ async function handleDelete(row: DashboardItem) {
dashboards.value = dashboardStore.dashboards; dashboards.value = dashboardStore.dashboards;
loading.value = false; loading.value = false;
sessionStorage.setItem("dashboards", JSON.stringify(dashboards.value)); sessionStorage.setItem("dashboards", JSON.stringify(dashboards.value));
sessionStorage.removeItem( sessionStorage.removeItem(`${row.layer}_${row.entity}_${row.name}`);
`${row.layer}_${row.entity}_${row.name.split(" ").join("-")}`
);
} }
function searchDashboards() { function searchDashboards() {
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]"); const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");

View File

@ -90,7 +90,7 @@ const onCreate = () => {
entity: states.entity, entity: states.entity,
layer: states.selectedLayer, layer: states.selectedLayer,
}); });
const name = states.name.split(" ").join("-"); const name = states.name;
const path = `/dashboard/${states.selectedLayer}/${states.entity}/${name}`; const path = `/dashboard/${states.selectedLayer}/${states.entity}/${name}`;
router.push(path); router.push(path);
}; };

View File

@ -170,9 +170,7 @@ function clickEndpoint(scope: any) {
dashboardStore.setEntity(EntityType[2].value); dashboardStore.setEntity(EntityType[2].value);
dashboardStore.setCurrentDashboard(d); dashboardStore.setCurrentDashboard(d);
router.push( router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${ `/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}`
scope.row.id
}/${d.name.split(" ").join("-")}`
); );
} }
function changePage(pageIndex: number) { function changePage(pageIndex: number) {

View File

@ -175,9 +175,7 @@ function clickInstance(scope: any) {
dashboardStore.setCurrentDashboard(d); dashboardStore.setCurrentDashboard(d);
dashboardStore.setEntity(d.entity); dashboardStore.setEntity(d.entity);
router.push( router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${ `/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}`
scope.row.id
}/${d.name.split(" ").join("-")}`
); );
} }

View File

@ -254,9 +254,7 @@ function handleLinkClick(event: any, d: Call) {
entity: `${e}Relation`, entity: `${e}Relation`,
}); });
dashboardStore.setEntity(p.entity); dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/${e}Relation/${d.source.id}/${ const path = `/dashboard/${p.layer}/${e}Relation/${d.source.id}/${d.target.id}/${p.name}`;
d.target.id
}/${p.name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
dashboardStore.setEntity(origin); dashboardStore.setEntity(origin);
@ -412,9 +410,7 @@ function handleGoInstance(name: string) {
entity: EntityType[3].value, entity: EntityType[3].value,
}); });
dashboardStore.setEntity(p.entity); dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/ServiceInstance/${ const path = `/dashboard/${p.layer}/ServiceInstance/${topologyStore.node.id}/${name}`;
topologyStore.node.id
}/${name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");

View File

@ -176,9 +176,7 @@ function goDashboard() {
}); });
dashboardStore.setEntity(entity); dashboardStore.setEntity(entity);
dashboardStore.setCurrentDashboard(d); dashboardStore.setCurrentDashboard(d);
const path = `/dashboard/${d.layer}/${entity}/${ const path = `/dashboard/${d.layer}/${entity}/${topologyStore.node.serviceId}/${topologyStore.node.id}/${d.name}`;
topologyStore.node.serviceId
}/${topologyStore.node.id}/${d.name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
topologyStore.setNode(null); topologyStore.setNode(null);
@ -217,9 +215,7 @@ function selectNodeLink(d: any) {
entity, entity,
}); });
dashboardStore.setEntity(entity); dashboardStore.setEntity(entity);
const path = `/dashboard/${p.layer}/${entity}/${sourceObj.serviceId}/${ const path = `/dashboard/${p.layer}/${entity}/${sourceObj.serviceId}/${sourceObj.id}/${targetObj.serviceId}/${targetObj.id}/${p.name}`;
sourceObj.id
}/${targetObj.serviceId}/${targetObj.id}/${p.name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
return; return;