First Draft in Per-User default dashboards

This commit is contained in:
Daniel Preussker
2015-12-13 19:39:12 +00:00
parent 40b2b7552c
commit a63ea78441
3 changed files with 30 additions and 3 deletions

View File

@@ -312,6 +312,10 @@ else {
} }
} }
if (!empty($vars['dashboard'])) {
dbUpdate(array('dashboard'=>$vars['dashboard']),'users','user_id = ?',array($vars['user_id']));
}
echo "<form class='form-horizontal' role='form' method='post' action=''> echo "<form class='form-horizontal' role='form' method='post' action=''>
<input type='hidden' name='user_id' value='".$vars['user_id']."'> <input type='hidden' name='user_id' value='".$vars['user_id']."'>
<input type='hidden' name='cur_username' value='" . $users_details['username'] . "'> <input type='hidden' name='cur_username' value='" . $users_details['username'] . "'>
@@ -374,6 +378,18 @@ if (passwordscanchange($users_details['username'])) {
</div> </div>
"; ";
} }
echo "
<div class='form-group'>
<label for='dashboard' class='col-sm-2 control-label'>Dashboard</label>
<div class='col-sm-4'><select class='form-control' name='dashboard'>";
$defdash = dbFetchCell("SELECT dashboard FROM users WHERE user_id = ?",array($vars['user_id']));
foreach(dbFetchRows("SELECT dashboards.*,users.username FROM `dashboards` INNER JOIN `users` ON users.user_id = dashboards.user_id WHERE (dashboards.access > 0 && dashboards.user_id != ?) || dashboards.user_id = ?",array($vars['user_id'],$vars['user_id'])) as $dash) {
echo "<option value='".$dash['dashboard_id']."'".($defdash == $dash['dashboard_id'] ? ' selected' : '').">".$dash['dashboard_name']."</option>";
}
echo "</select>
</div>
</div>
";
echo "<div class='form-group'> echo "<div class='form-group'>
<div class='col-sm-6'> <div class='col-sm-6'>

View File

@@ -16,8 +16,13 @@
* Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html * Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html
*/ */
$no_refresh = true; $no_refresh = true;
if (dbFetchCell('SELECT dashboard_id FROM dashboards WHERE user_id=?',array($_SESSION['user_id'])) == 0) { $default_dash = 0;
if (($tmp = dbFetchCell('SELECT dashboard FROM users WHERE user_id=?',array($_SESSION['user_id']))) != 0) {
$default_dash = $tmp;
}
else if (dbFetchCell('SELECT dashboard_id FROM dashboards WHERE user_id=?',array($_SESSION['user_id'])) == 0) {
$tmp = dbInsert(array('dashboard_name'=>'Default','user_id'=>$_SESSION['user_id']),'dashboards');
$vars['dashboard'] = dbInsert(array('dashboard_name'=>'Default','user_id'=>$_SESSION['user_id']),'dashboards'); $vars['dashboard'] = dbInsert(array('dashboard_name'=>'Default','user_id'=>$_SESSION['user_id']),'dashboards');
if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?',array($_SESSION['user_id'],0)) == 1) { if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?',array($_SESSION['user_id'],0)) == 1) {
dbUpdate(array('dashboard_id'=>$vars['dashboard']),'users_widgets','user_id = ? && dashboard_id = ?',array($_SESSION['user_id'],0)); dbUpdate(array('dashboard_id'=>$vars['dashboard']),'users_widgets','user_id = ? && dashboard_id = ?',array($_SESSION['user_id'],0));
@@ -31,7 +36,12 @@ if (!empty($vars['dashboard'])) {
} }
} }
if (empty($vars['dashboard'])) { if (empty($vars['dashboard'])) {
$vars['dashboard'] = dbFetchRow('select * from dashboards where user_id = ? order by dashboard_id limit 1',array($_SESSION['user_id'])); if ($default_dash != 0) {
$vars['dashboard'] = dbFetchRow('select * from dashboards where dashboard_id = ?',array($default_dash));
}
else {
$vars['dashboard'] = dbFetchRow('select * from dashboards where user_id = ? order by dashboard_id limit 1',array($_SESSION['user_id']));
}
if (isset($orig)) { if (isset($orig)) {
$msg_box[] = array('type' => 'error', 'message' => 'Dashboard <code>#'.$orig.'</code> does not exist! Loaded <code>'.$vars['dashboard']['dashboard_name'].'</code> instead.','title' => 'Requested Dashboard Not Found!'); $msg_box[] = array('type' => 'error', 'message' => 'Dashboard <code>#'.$orig.'</code> does not exist! Loaded <code>'.$vars['dashboard']['dashboard_name'].'</code> instead.','title' => 'Requested Dashboard Not Found!');
} }

1
sql-schema/084.sql Normal file
View File

@@ -0,0 +1 @@
ALTER TABLE `users` ADD `dashboard` INT( 11 ) DEFAULT 0 NOT NULL;