Remove widget in WidgetAdmin app

This commit is contained in:
chfhtw
2026-09-14 15:18:11 +02:00
parent 892fe4e6ea
commit 08cabe6e96
6 changed files with 111 additions and 1 deletions
@@ -38,6 +38,7 @@ class Widget extends FHCAPI_Controller
'setAllowed' => 'dashboard/admin:rw',
'create' => 'dashboard/admin:rw',
'update' => 'dashboard/admin:rw',
'remove' => 'dashboard/admin:rw',
'generators' => 'dashboard/admin:rw',
]);
@@ -257,6 +258,40 @@ class Widget extends FHCAPI_Controller
$this->terminateWithSuccess();
}
public function remove()
{
$this->loadPhrases([ 'dashboard' ]);
$this->load->library('form_validation');
$this->form_validation->set_rules(
'widget_id',
$this->p->t('dashboard', 'widget_id'),
'required'
);
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
$widget_id = $this->input->post('widget_id');
$result = $this->WidgetModel->load($widget_id);
$widget = $this->getDataOrTerminateWithError($result);
$widget = current($widget);
if (!$widget)
show_404();
$setup = json_decode($widget->setup);
if (!property_exists($setup, 'generator'))
$this->terminateWithError($this->p->t('dashboard', 'widget_error_delete_native'), null, REST_Controller::HTTP_METHOD_NOT_ALLOWED);
$result = $this->WidgetModel->delete($widget_id);
$this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess();
}
public function generators()
{
$result = $this->getGeneratorsRecursive();
@@ -69,6 +69,13 @@ export default {
params
};
},
remove(widget_id) {
return {
method: 'post',
url: '/api/frontend/v1/dashboard/widget/remove',
params: { widget_id }
};
},
generators() {
return {
method: 'get',
@@ -34,6 +34,10 @@ export default {
this.currentData = JSON.parse(JSON.stringify(data));
this.save();
},
remove(widget) {
this.$refs.list.$refs.table.tabulator.deleteRow(widget.widget_id);
this.originalData = this.currentData = null;
},
save() {
this.select(this.currentData);
this.$nextTick(() => {
@@ -65,6 +69,7 @@ export default {
v-model="currentData"
:original-data="originalData"
:unsaved-progress="unsavedProgress"
@remove="remove"
@saved="save"
/>
<div v-else class="h-100 d-flex justify-content-center align-items-center">
@@ -18,6 +18,7 @@ export default {
},
emits: [
"saved",
"remove",
"update:modelValue",
],
data() {
@@ -54,6 +55,22 @@ export default {
.catch(this.$fhcAlert.handleSystemError)
.finally(() => this.saving = false);
},
remove() {
this.$fhcAlert.confirmDelete()
.then(result => {
if (!result)
return Promise.reject({ handled: true });
this.saving = true;
return this.$api
.call(ApiWidget.remove(this.modelValue.widget_id));
})
.then(() => {
this.$emit('remove', this.modelValue);
})
.catch(this.$fhcAlert.handleSystemError)
.finally(() => this.saving = false);
},
},
template: /* html */`
<core-form
@@ -68,6 +85,13 @@ export default {
</template>
<edit-setup v-else v-model="modelValue.setup" />
<div class="position-absolute bottom-0 end-0 z-3">
<button
v-if="generator"
type="button"
:disabled="saving"
class="btn btn-danger me-2"
@click="remove"
>{{ $p.t('ui/loeschen') }}</button>
<button
type="submit"
:disabled="saving || !unsavedProgress"
+20 -1
View File
@@ -408,7 +408,7 @@ GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dashboard.tbl_dashboard_widget TO vil
--
GRANT SELECT ON TABLE dashboard.tbl_widget TO web;
GRANT SELECT,INSERT,UPDATE ON TABLE dashboard.tbl_widget TO vilesci;
GRANT SELECT,INSERT,UPDATE,DELETE ON TABLE dashboard.tbl_widget TO vilesci;
--
@@ -466,3 +466,22 @@ if($result = @$db->db_query("SELECT 1 FROM system.tbl_berechtigung WHERE berecht
}
}
// Add delete privilege for vilesci on tbl_widget
if ($result = @$db->db_query("
SELECT 1
FROM information_schema.role_table_grants
WHERE grantee = 'vilesci'
AND table_name = 'tbl_widget'
AND table_schema = 'dashboard'
AND privilege_type = 'DELETE'
LIMIT 1")) {
if ($db->db_num_rows($result) == 0) {
$qry = "GRANT SELECT,INSERT,UPDATE,DELETE ON TABLE dashboard.tbl_widget TO vilesci;";
if(!$db->db_query($qry)) {
echo '<strong>dashboard.tbl_widget '.$db->db_last_error().'</strong><br>';
} else {
echo 'dashboard.tbl_widget: Added delete privilege for vilesci<br>';
}
}
}
+20
View File
@@ -60890,6 +60890,26 @@ I have been informed that I am under no obligation to consent to the transmissio
)
)
),
array(
'app' => 'core',
'category' => 'dashboard',
'phrase' => 'widget_error_delete_native',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Native Widgets können nicht gelöscht werden!',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'Native widgets can not be deleted!',
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'dashboard',