Dashboard Edit: Add widget group assign/unassign feature (#7489)

* Dashboard Edit: Add widget group assign/unassign feature

* Update dashboard.php

* Update app_languages.php

* Update index.php

* Update dashboard_widget_edit.php

* Update dashboard_widget_list.php

* Update dashboard.php
This commit is contained in:
Alex
2025-09-10 13:55:59 -07:00
committed by GitHub
parent eb0b92823a
commit abf431ea3b
5 changed files with 273 additions and 16 deletions

View File

@@ -270,7 +270,7 @@
}
}
public function delete_items($records) {
public function delete_widgets($records) {
//assign the variables
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
@@ -321,7 +321,7 @@
}
}
public function toggle_items($records) {
public function toggle_widgets($records) {
//assign the variables
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
@@ -390,4 +390,176 @@
}
}
public function assign_widgets($records, $dashboard_uuid, $group_uuid) {
//assign the variables
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
if (permission_exists($this->name.'_add')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$database = new database;
$group = $database->select($sql, $parameters, 'row');
}
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//assign dashboard widget groups
$array[$this->name.'_groups'][$x][$this->name.'_group_uuid'] = uuid();
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
unset($records);
//exlude exist rows
if (!empty($array) && @sizeof($array) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid, ";
$sql .= "group_uuid from v_".$this->name."_groups ";
$database = new database;
$dashboard_widget_groups = $database->select($sql, null, 'all');
$array[$this->name.'_groups'] = array_filter($array[$this->name.'_groups'], function($ar) use ($dashboard_widget_groups) {
foreach ($dashboard_widget_groups as $existing_array_item) {
if ($ar['dashboard_uuid'] == $existing_array_item['dashboard_uuid'] && $ar[$this->name.'_uuid'] == $existing_array_item[$this->name.'_uuid'] && $ar['group_uuid'] == $existing_array_item['group_uuid']) {
return false;
}
}
return true;
});
unset($dashboard_widget_groups);
}
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//execute save
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-add']);
}
}
}
}
public function unassign_widgets($records, $dashboard_uuid, $group_uuid) {
//assign the variables
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
if (permission_exists($this->name.'_add')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$database = new database;
$group = $database->select($sql, $parameters, 'row');
}
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//assign dashboard widget groups
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
unset($records);
//include child dashboard widgets and their dasboard_uuid too
if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid from v_".$this->table." ";
$sql .= "where ".$this->name."_parent_uuid in (".implode(', ', $uuids).") ";
$database = new database;
$rows = $database->select($sql, null, 'all');
if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
//assign dashboard widget groups
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $row['dashboard_uuid'];
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $row['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
}
unset($uuids);
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('dashboard_widget_group_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('dashboard_widget_group_delete', 'temp');
//set message
message::add($text['message-delete']);
}
}
}
}
}