in src/store/modules/dashboard.ts [372:431]
async saveDashboard() {
if (!this.currentDashboard?.name) {
ElMessage.error("The dashboard name is needed.");
return;
}
const c = {
children: this.layout,
...this.currentDashboard,
};
let res: Recordable;
let json;
if (this.currentDashboard.id) {
res = await this.updateDashboard({
id: this.currentDashboard.id,
configuration: JSON.stringify(c),
});
json = res.data.changeTemplate;
} else {
c.isRoot = false;
const index = this.dashboards.findIndex(
(d: DashboardItem) =>
d.name === this.currentDashboard?.name &&
d.entity === this.currentDashboard.entity &&
d.layer === this.currentDashboard?.layer,
);
if (index > -1) {
ElMessage.error("The dashboard name cannot be duplicate");
return;
}
res = await graphql.query("addNewTemplate").params({ setting: { configuration: JSON.stringify(c) } });
json = res.data.addTemplate;
if (!json.status) {
ElMessage.error(json.message);
}
}
if (res.errors) {
ElMessage.error(res.errors);
return res;
}
if (!json.status) {
return json;
}
if (!this.currentDashboard.id) {
ElMessage.success("Saved successfully");
}
const key = [this.currentDashboard.layer, this.currentDashboard.entity, 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);
const l = { id: json.id, configuration: c };
sessionStorage.setItem(key, JSON.stringify(l));
sessionStorage.setItem("dashboards", JSON.stringify(this.dashboards));
return json;
},