Skip to content

Commit

Permalink
A whole load of commits to the dashboard module to make public dashbo…
Browse files Browse the repository at this point in the history
…ards work again, changes to site top nav menu and other polishing and hacks to get the whole application to work as expected and be backwards compatible
  • Loading branch information
trystan committed Mar 13, 2013
1 parent f761677 commit 37565a2
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Modules/raspberrypi
Modules/site
Modules/command
Modules/sap
Modules/time
Modules/rss
Modules/adminusers
2 changes: 2 additions & 0 deletions Modules/dashboard/Views/dashboard_edit_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
if (!$dashboard['height']) $dashboard['height'] = 400;
?>

<link href="<?php echo $path; ?>Modules/dashboard/Views/js/widget.css" rel="stylesheet">

<script type="text/javascript" src="<?php echo $path; ?>Lib/flot/jquery.flot.min.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/dashboard/Views/js/widgetlist.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/dashboard/Views/js/render.js"></script>
Expand Down
31 changes: 30 additions & 1 deletion Modules/dashboard/Views/dashboard_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@

</div>

<div id="myModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="false">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">WARNING deleting a dashboard is permanent</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this dashboard?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="confirmdelete" class="btn btn-primary">Delete permanently</button>
</div>
</div>

<script>

var path = "<?php echo $path; ?>";
Expand All @@ -46,10 +60,13 @@

'edit-action':{'title':'', 'type':"edit"},
'delete-action':{'title':'', 'type':"delete"},
'draw-action':{'title':'', 'type':"iconlink", 'icon':"icon-edit", 'link':path+"dashboard/edit?id="},
'view-action':{'title':'', 'type':"iconlink", 'link':path+"dashboard/view?id="}

}

table.deletedata = false;

update();

function update() {
Expand All @@ -64,8 +81,20 @@ function update() {
dashboard.set(id,fields_to_update);
});

$("#table").bind("onDelete", function(e,id){
$("#table").bind("onDelete", function(e,id,row){
$('#myModal').modal('show');
$('#myModal').attr('feedid',id);
$('#myModal').attr('feedrow',row);
});

$("#confirmdelete").click(function()
{
var id = $('#myModal').attr('feedid');
var row = $('#myModal').attr('feedrow');
dashboard.delete(id);
table.delete(row);

$('#myModal').modal('hide');
});

</script>
29 changes: 15 additions & 14 deletions Modules/dashboard/Views/dashboard_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
http://openenergymonitor.org
*/

global $path, $useckeditor;
global $path, $session, $useckeditor;
?>

<style>
Expand Down Expand Up @@ -47,20 +47,21 @@
<?php echo $menu; ?>
</ul>

<div align="right" style="padding:4px;">
<?php if ($type=="view" && isset($id)) { ?>
<a href="<?php echo $path; ?>dashboard/edit?id=<?php echo $id; ?>" title="<?php echo _("Draw Editor"); ?>" ><i class="icon-edit"></i></a>
<?php } ?>
<?php if ($session['write']) { ?>

<?php if ($type=="edit" && isset($id)) { ?>
<a href="<?php echo $path; ?>dashboard/view?id=<?php echo $id; ?>" title="<?php echo _("View mode"); ?>"><i class="icon-eye-open"></i></a>
<?php } ?>
<div align="right" style="padding:4px;">
<?php if ($type=="view" && isset($id)) { ?>
<a href="<?php echo $path; ?>dashboard/edit?id=<?php echo $id; ?>" title="<?php echo _("Draw Editor"); ?>" ><i class="icon-edit"></i></a>
<?php } ?>

<?php if (isset($id)) { ?>
<a href="#myModal" role="button" data-toggle="modal"><i class="icon-wrench"></i></a>
<?php } ?>
<?php if ($type=="edit" && isset($id)) { ?>
<a href="<?php echo $path; ?>dashboard/view?id=<?php echo $id; ?>" title="<?php echo _("View mode"); ?>"><i class="icon-eye-open"></i></a>
<a href="#myModal" role="button" data-toggle="modal"><i class="icon-wrench"></i></a>
<?php } ?>

<a href="#" onclick="$.ajax({type : 'POST',url : path + 'dashboard/create.json ',data : '',dataType : 'json',success : location.reload()});" title="<?php echo _("New"); ?>"><i class="icon-plus-sign"></i></a>
<a href="#" onclick="$.ajax({type : 'POST',url : path + 'dashboard/create.json ',data : '',dataType : 'json',success : location.reload()});" title="<?php echo _("New"); ?>"><i class="icon-plus-sign"></i></a>

<a href="<?php echo $path; ?>dashboard/list"><i class="icon-th-list" title="<?php echo _('List view'); ?>"></i></a>
</div>
<a href="<?php echo $path; ?>dashboard/list"><i class="icon-th-list" title="<?php echo _('List view'); ?>"></i></a>
</div>

<?php } ?>
2 changes: 2 additions & 0 deletions Modules/dashboard/Views/dashboard_view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php global $session, $path; ?>

<link href="<?php echo $path; ?>Modules/dashboard/Views/js/widget.css" rel="stylesheet">

<script type="text/javascript" src="<?php echo $path; ?>Lib/flot/jquery.flot.min.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/dashboard/Views/js/widgetlist.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/dashboard/Views/js/render.js"></script>
Expand Down
47 changes: 31 additions & 16 deletions Modules/dashboard/Views/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,44 @@ function show_dashboard()
browserVersion = Browser.Version();
if (browserVersion < 9) dialrate = 0.2;

for (z in widget)
{
var fname = widget[z]+"_init";
var fn = window[fname];
fn();
}

update();
}

// update function
function update()
{
var data = feed.list();

for (z in data)
{
var newstr = data[z]['name'].replace(/\s/g, '-');
var value = parseFloat(data[z]['value']);
$("." + newstr).html(value);
assoc[newstr] = value * 1;
feedids[newstr] = data[z]['id'];
}

for (z in widget)
var query = path + "feed/list.json?userid="+userid;
$.ajax(
{
var fname = widget[z]+"_slowupdate";
var fn = window[fname];
fn();
}
url : query,
dataType : 'json',
success : function(data)
{

for (z in data)
{
var newstr = data[z]['name'].replace(/\s/g, '-');
var value = parseFloat(data[z]['value']);
$("." + newstr).html(value);
assoc[newstr] = value * 1;
feedids[newstr] = data[z]['id'];
}

for (z in widget)
{
var fname = widget[z]+"_slowupdate";
var fn = window[fname];
fn();
}
}
});
}

function fast_update()
Expand Down
52 changes: 52 additions & 0 deletions Modules/dashboard/Views/js/widget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.Container-White {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #E5E5E5;
box-shadow: 0 4px 10px -1px rgba(200, 200, 200, 0.7);
margin: 0px;
padding: 0px;
}

.Container-Grey {
background: none repeat scroll 0 0 #ddd;
border: 1px solid #ccc;
box-shadow: 0 4px 10px -1px rgba(200, 200, 200, 0.7);
margin: 0px;
padding: 0px;
}

.Container-Black {
background: none repeat scroll 0 0 #000;
border: 1px solid #888;
box-shadow: 0 4px 10px -1px rgba(200, 200, 200, 0.7);
margin: 0px;
padding: 0px;
}

.Container-BlueLine {

border: 3px solid #0d97f3;
box-shadow: 0px 0px 2px 2px rgba(200, 200, 200, 0.7);
margin: 0px;
padding: 0px;
}

.heading-center {
font-weight:bold;
font-size:24px;
padding-top:20px;
text-align:center;
}

.feedvalue {
font-weight:bold;
font-size:24px;
padding-top:20px;
text-align:center;
color:#4444CC;
}

.heading {
font-weight:bold;
font-size:24px;
padding-top:20px;
}
14 changes: 14 additions & 0 deletions Modules/dashboard/Views/js/widgetlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
},

"Container-Grey":
{
"offsetx":-100,"offsety":-180,"width":200,"height":360,
"menu":"Containers",
"html":""
},

"Container-Black":
{
"offsetx":-100,"offsety":-180,"width":200,"height":360,
"menu":"Containers",
"html":""
},

"Container-BlueLine":
{
"offsetx":-100,"offsety":-180,"width":200,"height":360,
"menu":"Containers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ function cylinder_fastupdate()

function draw_cylinder(ctx,cyl_bot,cyl_top,width,height)
{
if (!ctx) return;

console.log("Draw cylinder");
if (!ctx) console.log("No CTX");
if (!ctx) return;

//var width = 168;
var midx = width / 2;
var cyl_width = width - 8;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions Modules/dashboard/Views/js/widgets/jgauge/jgauge_render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Global variables
var img = null,
needle = null;

function jgauge_widgetlist()
{
var widgets = {
"jgauge":
{
"offsetx":-80,"offsety":-80,"width":160,"height":160,
"menu":"Widgets",
"options":["feed", "max", "units"],
"optionstype":["feed","value","value"]
}
}
return widgets;
}

function jgauge_init()
{
setup_widget_canvas('jgauge');

// Load the needle image
needle = new Image();
needle.src = path+'Modules/dashboard/Views/js/widgets/jgauge/needle2.png';

// Load the jgauge image
img = new Image();
img.src = path+'Modules/dashboard/Views/js/widgets/jgauge/jgauge.png';
}

function jgauge_draw()
{
$('.jgauge').each(function(index)
{
var feed = $(this).attr("feed");
var val = curve_value(feed,dialrate);
// ONLY UPDATE ON CHANGE
if ((val * 1).toFixed(2) != (assoc[feed] * 1).toFixed(2) || redraw == 1)
{
var id = "can-"+$(this).attr("id");
var scale = 1*$(this).attr("scale") || 1;
draw_jgauge(widgetcanvas[id],0,0,$(this).width(),$(this).height(),val*scale,$(this).attr("max"),$(this).attr("units"));
}
});
}

function jgauge_slowupdate()
{

}

function jgauge_fastupdate()
{
jgauge_draw();
}

function draw_jgauge(ctx,x,y,width,height,value,max,units)
{
if (!max) max = 1000;
if (!value) value = 0;
if (!units) units = " ";
var offset = 45;
var position = ((value*270)/max);
if (position > 270) {
position = 270;
}
var size = 0;
if (width>height) {
size = height;
} else {
size = width;
}
if (size>170) size=170;
if (size<120) size=120;

ctx.clearRect(0,0,width,height);

// Draw the jgauge onto the canvas
ctx.drawImage(img, 0, 0, size, size);

//ticks labels
ctx.font = "8pt Arial";
ctx.fillStyle = "rgb(34,198,252)";
ctx.fillText(0, 28*(size/100), 70*(size/100)); // first tick
ctx.fillText(Math.floor(max/6)*1, 20*(size/100), 52*(size/100)); // second tick
ctx.fillText(Math.floor(max/6)*2, 25*(size/100), 33*(size/100)); // third tick
ctx.fillText(Math.floor(max/6)*3, 45*(size/100), 22*(size/100)); // 4th tick
ctx.fillText(Math.floor(max/6)*4, 65*(size/100), 33*(size/100)); // 5th tick
ctx.fillStyle = "rgb(245,144,0)";
ctx.fillText(Math.floor(max/6)*5, 75*(size/100), 52*(size/100)); // 6th tick
ctx.fillStyle = "rgb(255,0,0)";
ctx.fillText(Math.floor(max), 65*(size/100), 70*(size/100)); // 7th tick

// main label
ctx.font = "15pt Calibri,Geneva,Arial";
ctx.strokeStyle = "rgb(255,255,255)";
ctx.fillStyle = "rgb(255,255,255)";
if (value<10) {
ctx.fillText(Math.floor(value)+units, 43*(size/100), 85*(size/100));
}
else if ((value<100) && (value>10)) {
ctx.fillText(Math.floor(value)+units, 40*(size/100), 85*(size/100));
}
else {
ctx.fillText(Math.floor(value)+units, 37*(size/100), 85*(size/100));
}

// Save the current drawing state
ctx.save();

// move to the middle of the image
ctx.translate((size/2), (size/2));

// Rotate around this point
ctx.rotate((position + offset) * (Math.PI / 180));

// Draw the image back and up
ctx.drawImage(needle, -(size/2), -(size/2), size, size);

// Restore the previous drawing state
ctx.restore();
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 37565a2

Please sign in to comment.