simplify widgetAdd, widgetUpdate and widgetRemove

This commit is contained in:
chfhtw
2026-04-20 14:30:31 +02:00
parent cf14501311
commit cdf63840b0
3 changed files with 11 additions and 16 deletions
@@ -23,7 +23,7 @@ export default {
}
},
methods: {
widgetAdd(section_name, widget) {
widgetAdd(widget, section_name) {
this.$refs.widgetpicker.getWidget().then(widget_id => {
widget.widget = widget_id;
widget.id = 'loading_' + String((new Date()).valueOf());
@@ -64,8 +64,7 @@ export default {
})
.catch(() => {});
},
widgetUpdate(section_name, payload) {
payload = payload[section_name];
widgetUpdate(payload, section_name) {
for (var k in payload) {
const section = this.sections.find(section => section.name == section_name);
for (var wid in section.widgets) {
@@ -105,7 +104,7 @@ export default {
})
.catch(this.$fhcAlert.handleSystemError);
},
widgetRemove(section_name, id) {
widgetRemove(id, section_name) {
const params = {
db: this.dashboard,
funktion_kurzbz: section_name,
+5 -7
View File
@@ -40,8 +40,7 @@ export default {
}
},
methods: {
widgetAdd(section_name, widget) {
// TODO(chris): remove section_name? (change order of params => get rid of it)
widgetAdd(widget) {
this.$refs.widgetpicker
.getWidget()
.then(widget_id => {
@@ -63,8 +62,7 @@ export default {
})
.catch(() => {});
},
widgetUpdate(section_name, payload) {
payload = payload[section_name];
widgetUpdate(payload) {
for (var k in payload) {
for (var wid in this.widgets) {
if (this.widgets[wid].id == k) {
@@ -112,7 +110,7 @@ export default {
})
.catch(this.$fhcAlert.handleSystemError);
},
widgetRemove(section_name, id) {
widgetRemove(id) {
this.$api
.call(ApiDashboardUser.removeWidget(this.dashboard, id))
.then(() => {
@@ -148,7 +146,7 @@ export default {
}
}
remove.forEach(wid => this.widgetRemove('general', wid));
remove.forEach(wid => this.widgetRemove(wid));
this.widgets = widgets;
})
@@ -160,7 +158,7 @@ export default {
{{ $p.t('global/personalGreeting', [ viewData?.name ]) }}
<button style="margin-left: 8px;" class="btn" @click="editMode = !editMode" aria-label="edit dashboard" v-tooltip="{showDelay:1000,value:'edit dashboard'}"><i class="fa-solid fa-gear" aria-hidden="true"></i></button>
</h3>
<dashboard-section :seperator="0" name="general" :widgets="widgets" @widgetAdd="widgetAdd" @widgetUpdate="widgetUpdate" @widgetRemove="widgetRemove"></dashboard-section>
<dashboard-section :seperator="0" name="general" :widgets="widgets" @widget-add="widgetAdd" @widget-update="widgetUpdate" @widget-remove="widgetRemove"></dashboard-section>
<dashboard-widget-picker ref="widgetpicker" :widgets="widgetsSetup"></dashboard-widget-picker>
</div>`
}
+3 -5
View File
@@ -133,7 +133,7 @@ export default {
},
removeWidget(item, revert) {
if (item.custom) {
BsConfirm.popup(this.$p.t('dashboard', 'alert_deleteWidget')).then(() => this.$emit('widgetRemove', this.name, item.id));
BsConfirm.popup(this.$p.t('dashboard', 'alert_deleteWidget')).then(() => this.$emit('widgetRemove', item.id, this.name));
} else {
let update = {};
update[item.id] = { hidden: !revert };
@@ -187,9 +187,7 @@ export default {
this.updatePreset(result);
},
updatePreset(update) {
let payload = {};
payload[this.name] = update;
this.$emit('widgetUpdate', this.name, payload);
this.$emit('widgetUpdate', update, this.name);
}
},
mounted() {
@@ -230,7 +228,7 @@ export default {
<div
v-if="item.placeholder"
class="empty-tile-hover"
@click="$emit('widgetAdd', name, { widget: 1, config: {}, place: {[gridWidth]: {x:item.x,y:item.y,w:1,h:1}}, custom: 1 })"
@click="$emit('widgetAdd', { widget: 1, config: {}, place: {[gridWidth]: {x:item.x,y:item.y,w:1,h:1}}, custom: 1 }, name)"
></div>
<dashboard-item
v-else