import BsPrompt from "../Bootstrap/Prompt.js"; import DashboardAdminEdit from "./Admin/Edit.js"; import DashboardAdminWidgets from "./Admin/Widgets.js"; import DashboardAdminPresets from "./Admin/Presets.js"; import ApiDashboardBoard from "../../api/factory/dashboard/board.js"; export default { name: 'DashboardAdmin', components: { DashboardAdminEdit, DashboardAdminWidgets, DashboardAdminPresets, }, provide() { return { adminMode: true, widgetsSetup: Vue.computed(() => this.dashboard ? this.dashboard.widgetSetup : null) }; }, data() { return { dashboards: [], current: -1, widgets: [] }; }, computed: { dashboard() { return this.dashboards.find(el => el.dashboard_id == this.current); } }, methods: { dashboardAdd() { let _name = ''; BsPrompt .popup('New Dashboard name') .then(dashboard_kurzbz => { const params = { dashboard_kurzbz }; return this.$api .call(ApiDashboardBoard.add(params)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); let newDashboard = { dashboard_id: response.data, dashboard_kurzbz, beschreibung: '' }; this.dashboards.push(newDashboard); this.current = newDashboard.dashboard_id; }) .catch(this.$fhcAlert.handleSystemError); }); }, dashboardUpdate(dashboard) { this.$api .call(ApiDashboardBoard.update(dashboard)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); let old = this.dashboards.find(el => el.dashboard_id == dashboard.dashboard_id); old.dashboard_kurzbz = dashboard.dashboard_kurzbz; old.beschreibung = dashboard.beschreibung; }) .catch(this.$fhcAlert.handleSystemError); }, dashboardDelete(dashboard_id) { this.$api .call(ApiDashboardBoard.delete(dashboard_id)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); this.current = -1; this.dashboards = this.dashboards.filter(el => el.dashboard_id != dashboard_id); }) .catch(this.$fhcAlert.handleSystemError); }, assignWidgets(widgets) { this.widgets = widgets; } }, created() { this.$api .call(ApiDashboardBoard.list()) .then(result => { this.dashboards = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, template: /* html */`
` }