mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Hopefully last changes
This commit is contained in:
@@ -1703,7 +1703,7 @@ tr.search:nth-child(odd) {
|
||||
background: red!important;
|
||||
}
|
||||
|
||||
.tile_header {
|
||||
.widget_header {
|
||||
padding: 0.8em;
|
||||
background-color: #000000;
|
||||
color: #ffffff;
|
||||
@@ -1713,6 +1713,6 @@ tr.search:nth-child(odd) {
|
||||
border-top-right-radius: 4px;
|
||||
}
|
||||
|
||||
.tile_body {
|
||||
.widget_body {
|
||||
padding: 0.8em;
|
||||
}
|
||||
|
||||
@@ -5,23 +5,31 @@ $message = 'Error updating user dashboard config';
|
||||
|
||||
$data = json_decode($_POST['data'],true);
|
||||
$sub_type = mres($_POST['sub_type']);
|
||||
$tile_id = mres($_POST['tile_id']);
|
||||
$widget_id = mres($_POST['widget_id']);
|
||||
|
||||
if ($sub_type == 'remove' && is_numeric($tile_id)) {
|
||||
if ($tile_id == 0 || dbDelete('dashboard_items','`user_id`=? AND `dashboard_item_id`=?', array($_SESSION['user_id'],$tile_id))) {
|
||||
if ($sub_type == 'remove' && is_numeric($widget_id)) {
|
||||
if ($widget_id == 0 || dbDelete('users_widgets','`user_id`=? AND `user_widget_id`=?', array($_SESSION['user_id'],$widget_id))) {
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
}
|
||||
elseif ($sub_type == 'add' && is_numeric($tile_id)) {
|
||||
$tile = dbFetchRow('SELECT * FROM `tiles` WHERE `tile_id`=?', array($tile_id));
|
||||
if (is_array($tile)) {
|
||||
list($x,$y) = explode(',',$tile['base_dimensions']);
|
||||
$item_id = dbInsert(array('user_id'=>$_SESSION['user_id'],'widget_id'=>$tile_id,'title'=>$tile['tile_title'],'content'=>$tile['tile'],'size_x'=>$x,'size_y'=>$y),'dashboard_items');
|
||||
if (is_numeric($item_id)) {
|
||||
$extra = array('item_id'=>$item_id,'title'=>$tile['tile_title'],'content'=>$tile['tile'],'size_x'=>$x,'size_y'=>$y);
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
elseif ($sub_type == 'add' && is_numeric($widget_id)) {
|
||||
$dupe_check = dbFetchCEll('SELECT `user_widget_id` FROM `users_widgets` WHERE `user_id`=? AND `widget_id`=?',array($_SESSION['user_id'],$widget_id));
|
||||
|
||||
if (is_numeric($dupe_check)) {
|
||||
$message = 'This widget has already been added';
|
||||
}
|
||||
else {
|
||||
|
||||
$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', array($widget_id));
|
||||
if (is_array($widget)) {
|
||||
list($x,$y) = explode(',',$widget['base_dimensions']);
|
||||
$item_id = dbInsert(array('user_id'=>$_SESSION['user_id'],'widget_id'=>$widget_id,'title'=>$widget['widget_title'],'size_x'=>$x,'size_y'=>$y),'users_widgets');
|
||||
if (is_numeric($item_id)) {
|
||||
$extra = array('item_id'=>$widget_id,'title'=>$widget['widget_title'],'widget'=>$widget['widget'],'size_x'=>$x,'size_y'=>$y);
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +40,7 @@ else {
|
||||
foreach ($data as $line) {
|
||||
if (is_array($line)) {
|
||||
$update = array('col'=>$line['col'],'row'=>$line['row'],'size_x'=>$line['size_x'],'size_y'=>$line['size_y']);
|
||||
dbUpdate($update, 'dashboard_items', '`dashboard_item_id`=?', array($line['id']));
|
||||
dbUpdate($update, 'users_widgets', '`user_widget_id`=?', array($line['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,41 +14,31 @@
|
||||
|
||||
$no_refresh = true;
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `dashboard_items` WHERE `user_id`=?',array($_SESSION['user_id'])) as $items) {
|
||||
foreach (dbFetchRows('SELECT * FROM `users_widgets` LEFT JOIN `widgets` ON `widgets`.`widget_id`=`users_widgets`.`widget_id` WHERE `user_id`=?',array($_SESSION['user_id'])) as $items) {
|
||||
$data[] = $items;
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data[] = array('dashboard_item_id'=>'0','widget_id'=>1,'title'=>'Add a widget','content'=>'placeholder','col'=>1,'row'=>1,'size_x'=>2,'size_y'=>2,'refresh'=>60);
|
||||
$data[] = array('user_widget_id'=>'0','widget_id'=>1,'title'=>'Add a widget','widget'=>'placeholder','col'=>1,'row'=>1,'size_x'=>2,'size_y'=>2,'refresh'=>60);
|
||||
}
|
||||
|
||||
$data = serialize(json_encode($data));
|
||||
$dash_config = unserialize(stripslashes($data));
|
||||
|
||||
$new_tile = '
|
||||
<select id="tile_id" name="tile_id" class="form-control">
|
||||
<option value="" disabled selected></option>
|
||||
';
|
||||
?>
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `tiles` ORDER BY `tile_title`") as $tiles) {
|
||||
$new_tile .= '<option value="'. $tiles['tile_id'] .'">'. $tiles['tile_title'] .'</option>';
|
||||
<a class="btn btn-primary" role="button" data-toggle="collapse" href="#add_widget" aria-expanded="false" aria-controls="add_widget"">Add Widget</a>
|
||||
<div class="collapse" id="add_widget">
|
||||
<div class="well">
|
||||
<?php
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widgets) {
|
||||
echo '<a class="btn btn-success" role="button" id="place_widget" name="place_widget" data-widget_id="'.$widgets['widget_id'] .'">'. $widgets['widget_title'] .'</a> ';
|
||||
}
|
||||
|
||||
$new_title .= '
|
||||
</select>
|
||||
';
|
||||
|
||||
?>
|
||||
|
||||
<button type='button' id='new-tile' class='btn btn-success btn-sm' name='new-dashboard-tile' data-html='true' data-container='body' data-toggle='popover' data-placement='right' data-content='<a href="#">
|
||||
<?php
|
||||
echo $new_tile;
|
||||
?>
|
||||
</a>'><span class='glyphicon glyphicon-plus' aria-hidden='true'></span> Add tile</button>
|
||||
<script>
|
||||
$('#new-tile').popover();
|
||||
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src='https://www.google.com/jsapi'></script>
|
||||
<script src="js/jquery.gridster.min.js"></script>
|
||||
@@ -65,6 +55,7 @@ $('#new-tile').popover();
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var gridster;
|
||||
|
||||
var serialization = <?php echo $dash_config; ?>;
|
||||
@@ -95,9 +86,6 @@ $('#new-tile').popover();
|
||||
gridster = $(".gridster ul").gridster({
|
||||
widget_base_dimensions: [100, 100],
|
||||
widget_margins: [5, 5],
|
||||
autogrow_cols: true,
|
||||
min_cols: 1,
|
||||
min_rows: 2,
|
||||
avoid_overlapped_widgets: true,
|
||||
draggable: {
|
||||
handle: 'header',
|
||||
@@ -125,25 +113,38 @@ $('#new-tile').popover();
|
||||
gridster.remove_all_widgets();
|
||||
$.each(serialization, function() {
|
||||
gridster.add_widget(
|
||||
'<li id="'+this.dashboard_item_id+'">'+
|
||||
'\<script\>var timeout'+this.dashboard_item_id+' = grab_data('+this.dashboard_item_id+','+this.refresh+',\''+this.content+'\');\<\/script\>'+
|
||||
'<header class="tile_header">'+this.title+'<button style="color: #ffffff" type="button" class="close close-tile" data-tile-id="'+this.dashboard_item_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="tile_body" id="tile_body_'+this.dashboard_item_id+'">'+this.content+'</div>'+
|
||||
'<li id="'+this.user_widget_id+'">'+
|
||||
'\<script\>var timeout'+this.user_widget_id+' = grab_data('+this.user_widget_id+','+this.refresh+',\''+this.widget+'\');\<\/script\>'+
|
||||
'<header class="widget_header">'+this.title+'<button style="color: #ffffff" type="button" class="close close-widget" data-widget-id="'+this.user_widget_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="widget_body" id="widget_body_'+this.user_widget_id+'">'+this.widget+'</div>'+
|
||||
'</li>',
|
||||
this.size_x, this.size_y, this.col, this.row
|
||||
parseInt(this.size_x), parseInt(this.size_y), parseInt(this.col), parseInt(this.row)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on( "click", ".close-tile", function() {
|
||||
var tile_id = $(this).data('tile-id');
|
||||
$('a[name="place_widget"]').on('click', function(event, state) {
|
||||
var widget_id = $(this).data('widget_id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", sub_type: 'remove', tile_id: tile_id},
|
||||
data: {type: "update-dashboard-config", sub_type: 'add', widget_id: widget_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
gridster.remove_widget($('#'+tile_id));
|
||||
var widget_id = data.extra.widget_id;
|
||||
var title = data.extra.title;
|
||||
var widget = data.extra.widget;
|
||||
var size_x = data.extra.size_x;
|
||||
var size_y = data.extra.size_y;
|
||||
gridster.add_widget(
|
||||
'<li id="'+widget_id+'">'+
|
||||
'\<script\>var timeout'+widget_id+' = grab_data('+widget_id+',60,\''+widget+'\');\<\/script\>'+
|
||||
'<header class="widget_header">'+title+'<button type="button" class="close close-widget" data-widget-id="'+widget_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="wiwdget_body" id="widget_body_'+widget_id+'">'+widget+'</div>'+
|
||||
'</li>',
|
||||
parseInt(size_x), parseInt(size_y)
|
||||
);
|
||||
$('#new-widget').popover('hide')
|
||||
updatePos(gridster);
|
||||
}
|
||||
else {
|
||||
@@ -156,40 +157,28 @@ $('#new-tile').popover();
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('change','#tile_id',function(){
|
||||
var tile_id = $(this).val();
|
||||
$(document).on( "click", ".close-widget", function() {
|
||||
var widget_id = $(this).data('widget-id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", sub_type: 'add', tile_id: tile_id},
|
||||
data: {type: "update-dashboard-config", sub_type: 'remove', widget_id: widget_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
var item_id = data.extra.item_id;
|
||||
var title = data.extra.title;
|
||||
var content = data.extra.content;
|
||||
var size_x = data.extra.size_x;
|
||||
var size_y = data.extra.size_y;
|
||||
gridster.add_widget(
|
||||
'<li id="'+item_id+'">'+
|
||||
'\<script\>var timeout'+item_id+' = grab_data('+item_id+',60,\''+content+'\');\<\/script\>'+
|
||||
'<header class="tile_header">'+title+'<button type="button" class="close" data-tile-id="'+item_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="tile_body" id="tile_body_'+item_id+'">'+content+'</div>'+
|
||||
'</li>',
|
||||
size_x, size_y
|
||||
);
|
||||
$('#new-tile').popover('hide')
|
||||
updatePos(gridster);
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
if (data.status == 'ok') {
|
||||
gridster.remove_widget($('#'+widget_id));
|
||||
updatePos(gridster);
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function grab_data(id,refresh,data_type) {
|
||||
@@ -201,14 +190,14 @@ $('#new-tile').popover();
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
$("#tile_body_"+id).html(data.html);
|
||||
$("#widget_body_"+id).html(data.html);
|
||||
}
|
||||
else {
|
||||
$("#tile_body_"+id).html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#tile_body_"+id).html('<div class="alert alert-info">Problem with backend</div>');
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">Problem with backend</div>');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -217,4 +206,6 @@ $('#new-tile').popover();
|
||||
},
|
||||
new_refresh);
|
||||
}
|
||||
$('#new-widget').popover();
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
CREATE TABLE `dashboard_items` ( `dashboard_item_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `widget_id` int(11) NOT NULL, `col` tinyint(4) NOT NULL, `row` tinyint(4) NOT NULL, `size_x` tinyint(4) NOT NULL, `size_y` tinyint(4) NOT NULL, `title` varchar(255) NOT NULL, `content` text NOT NULL, `refresh` tinyint(4) NOT NULL DEFAULT '60', PRIMARY KEY (`dashboard_item_id`), KEY `user_id` (`user_id`,`widget_id`) ) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `tiles` ( `tile_id` int(11) NOT NULL AUTO_INCREMENT, `tile_title` varchar(255) NOT NULL, `tile` varchar(255) NOT NULL, `base_dimensions` varchar(10) NOT NULL, PRIMARY KEY (`tile_id`), UNIQUE KEY `tile` (`tile`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `tiles` (`tile_id`, `tile_title`, `tile`, `base_dimensions`) VALUES (1, 'Availability map', 'availability-map', '4,3'), (2, 'Device summary horizontal', 'device-summary-horiz', '4,2'), (3, 'Alerts', 'alerts', '6,4'), (4, 'Device summary vertical', 'device-summary-vert', '4,3'), (5, 'World map', 'globe', '3,3');
|
||||
CREATE TABLE `users_widgets` ( `user_widget_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `widget_id` int(11) NOT NULL, `col` tinyint(4) NOT NULL, `row` tinyint(4) NOT NULL, `size_x` tinyint(4) NOT NULL, `size_y` tinyint(4) NOT NULL, `title` varchar(255) NOT NULL, `refresh` tinyint(4) NOT NULL DEFAULT '60', PRIMARY KEY (`user_widget_id`), KEY `user_id` (`user_id`,`widget_id`) ) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `widgets` ( `widget_id` int(11) NOT NULL AUTO_INCREMENT, `widget_title` varchar(255) NOT NULL, `widget` varchar(255) NOT NULL, `base_dimensions` varchar(10) NOT NULL, PRIMARY KEY (`widget_id`), UNIQUE KEY `widget` (`widget`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
|
||||
INSERT INTO `widgets` (`widget_id`, `widget_title`, `widget`, `base_dimensions`) VALUES (1, 'Availability map', 'availability-map', '4,3'), (2, 'Device summary horizontal', 'device-summary-horiz', '4,2'), (3, 'Alerts', 'alerts', '8,4'), (4, 'Device summary vertical', 'device-summary-vert', '4,3'), (5, 'World map', 'globe', '3,3');
|
||||
|
||||
Reference in New Issue
Block a user