Saving status layout mode
parent
d7f36da391
commit
19ae7db77a
|
@ -38,7 +38,7 @@ class StatusController extends AbstractServerController {
|
|||
function __construct(Database $db, Template $tpl) {
|
||||
parent::__construct($db, $tpl);
|
||||
|
||||
$this->setActions(array('index'), 'index');
|
||||
$this->setActions(array('index', 'saveLayout'), 'index');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,13 +50,21 @@ class StatusController extends AbstractServerController {
|
|||
$this->black_background = true;
|
||||
|
||||
// add header accessories
|
||||
$layout = $this->user->getUserPref('status_layout', 0);
|
||||
$layout_data = array(
|
||||
'block_layout_active' => ($layout == 0) ? 'active' : '',
|
||||
'list_layout_active' => ($layout != 0) ? 'active' : '',
|
||||
);
|
||||
$this->tpl->newTemplate('status_layout_selector', 'server/status.tpl.html');
|
||||
$this->tpl->addTemplateData('status_layout_selector', $layout_data);
|
||||
$html_accessories = $this->tpl->getTemplate('status_layout_selector');
|
||||
$this->setHeaderAccessories($html_accessories);
|
||||
|
||||
$this->setTemplateId('server_status', 'server/status.tpl.html');
|
||||
$this->addFooter(false);
|
||||
|
||||
$this->tpl->addTemplateData($this->getTemplateId(), $layout_data);
|
||||
|
||||
// get the active servers from database
|
||||
$servers = $this->getServers();
|
||||
|
||||
|
@ -97,6 +105,19 @@ class StatusController extends AbstractServerController {
|
|||
}
|
||||
}
|
||||
|
||||
protected function executeSaveLayout() {
|
||||
if($this->isXHR()) {
|
||||
$layout = psm_POST('layout', 0);
|
||||
$this->user->setUserPref('status_layout', $layout);
|
||||
|
||||
$response = new \Symfony\Component\HttpFoundation\JsonResponse();
|
||||
$response->setData(array(
|
||||
'layout' => $layout,
|
||||
));
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
protected function createHTMLLabels() {
|
||||
$this->tpl->addTemplateData(
|
||||
$this->getTemplateId(),
|
||||
|
|
|
@ -68,7 +68,13 @@ class User {
|
|||
*/
|
||||
protected $user_id;
|
||||
|
||||
/**
|
||||
/**
|
||||
*Current user preferences
|
||||
* @var array $user_preferences
|
||||
*/
|
||||
protected $user_preferences;
|
||||
|
||||
/**
|
||||
* The user's login status
|
||||
* @var boolean $user_is_logged_in
|
||||
*/
|
||||
|
@ -435,6 +441,61 @@ class User {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read current user preferences from the database
|
||||
* @return boolean return false is user not connected
|
||||
*/
|
||||
private function getPreferences() {
|
||||
if($this->user_preferences === null) {
|
||||
if(!$this->getUser()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->user_preferences = array();
|
||||
foreach($this->db_connection->query('SELECT * FROM ' . PSM_DB_PREFIX . 'users_preferences WHERE user_id = ' . $this->user_id) as $row) {
|
||||
$this->user_preferences[$row['key']] = $row['value'];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user preference value
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserPref($key, $default = '') {
|
||||
if(!$this->getPreferences() || !isset($this->user_preferences[$key])) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = $this->user_preferences[$key];
|
||||
settype($value, gettype($default));
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user preference value
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setUserPref($key, $value) {
|
||||
if($this->getPreferences()) {
|
||||
if(isset($this->user_preferences[$key])) {
|
||||
if($this->user_preferences[$key] == $value) {
|
||||
return; // no change
|
||||
}
|
||||
$sql = 'UPDATE ' . PSM_DB_PREFIX . 'users_preferences SET `key` = ?, `value` = ? WHERE `user_id` = ?';
|
||||
} else{
|
||||
$sql = 'INSERT INTO ' . PSM_DB_PREFIX . 'users_preferences SET `key` = ?, `value` = ?, `user_id` = ?';
|
||||
}
|
||||
$sth = $this->db_connection->prepare($sql);
|
||||
$sth->execute(array($key, $value, $this->user_id));
|
||||
$this->user_preferences[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session object
|
||||
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
|
|
|
@ -264,6 +264,10 @@ class Installer {
|
|||
// upgrade to 3.0.0
|
||||
$this->upgrade300();
|
||||
}
|
||||
if(version_compare($version_from, '3.1.0', '<')) {
|
||||
// upgrade to 3.1.0
|
||||
$this->upgrade310();
|
||||
}
|
||||
psm_update_conf('version', $version_to);
|
||||
}
|
||||
|
||||
|
@ -378,4 +382,15 @@ class Installer {
|
|||
}
|
||||
$this->execSQL("ALTER TABLE `".PSM_DB_PREFIX."users` DROP `server_id`;");
|
||||
}
|
||||
|
||||
protected function upgrade310() {
|
||||
$queries = array();
|
||||
$queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` (
|
||||
`user_id` int(11) unsigned NOT NULL,
|
||||
`key` varchar(255) NOT NULL,
|
||||
`value` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`user_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
|
||||
$this->execSQL($queries);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<!--%tpl_server_status-->
|
||||
<div class="tab-content">
|
||||
<div id="flow-layout" class="tab-pane active">
|
||||
<div id="flow-layout" class="tab-pane {block_layout_active}">
|
||||
<div class="entity-container">
|
||||
<!--%tpl_repeat_servers_offline-->
|
||||
<div class="offline">
|
||||
|
@ -24,7 +24,7 @@
|
|||
{servers_online}
|
||||
</div>
|
||||
</div>
|
||||
<div id="list-layout" class="tab-pane">
|
||||
<div id="list-layout" class="tab-pane {list_layout_active}">
|
||||
<div class="entity-container">
|
||||
<table class="table table-bordered">
|
||||
<tbody>
|
||||
|
@ -67,7 +67,7 @@
|
|||
|
||||
<!--%tpl_status_layout_selector-->
|
||||
<div class="btn-group" data-toggle="buttons-radio">
|
||||
<button class="btn active" data-toggle="tab" data-target="#flow-layout"><i class="icon-th-large"></i></button>
|
||||
<button class="btn" data-toggle="tab" data-target="#list-layout"><i class="icon-th-list"></i></button>
|
||||
<button class="btn {block_layout_active}" data-toggle="tab" data-target="#flow-layout" onclick="psm_saveLayout(0)"><i class="icon-th-large"></i></button>
|
||||
<button class="btn {list_layout_active}" data-toggle="tab" data-target="#list-layout" onclick="psm_saveLayout(1)"><i class="icon-th-list"></i></button>
|
||||
</div>
|
||||
<!--%%tpl_status_layout_selector-->
|
||||
|
|
|
@ -63,6 +63,14 @@ function psm_xhr(mod, params, method, on_complete, options) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function psm_saveLayout(layout) {
|
||||
var params = {
|
||||
action: 'saveLayout',
|
||||
layout: layout
|
||||
};
|
||||
psm_xhr('server_status', params, 'POST');
|
||||
}
|
||||
|
||||
function psm_tooltips() {
|
||||
$('input[data-toggle="tooltip"]').tooltip({
|
||||
'trigger':'hover',
|
||||
|
|
Loading…
Reference in New Issue