add ActiveAdmin

This commit is contained in:
Lee Lawlor
2014-03-22 13:21:45 -04:00
parent f21dea069f
commit 156f4147ef
80 changed files with 912 additions and 241 deletions

View File

@ -0,0 +1,2 @@
#= require active_admin/base

View File

@ -208,7 +208,7 @@ o(b[3],a[3]);this.axisOffset=[0,0,0,0];this.clipOffset=[0,0,0,0]},drawChartBox:f
null,null,c-p,d-p));else{e={fill:j||Q};if(i)e.stroke=a.borderColor,e["stroke-width"]=i;this.chartBackground=b.rect(p/2,p/2,c-p,d-p,a.borderRadius,i).attr(e).add().shadow(a.shadow)}if(k)f?f.animate(s):this.plotBackground=b.rect(q,o,n,t,0).attr({fill:k}).add().shadow(a.plotShadow);if(l)h?h.animate(s):this.plotBGImage=b.image(l,q,o,n,t).add();r?r.animate({width:w.width,height:w.height}):this.clipRect=b.clipRect(w);if(m)g?g.animate(g.crisp(null,q,o,n,t)):this.plotBorder=b.rect(q,o,n,t,0,-m).attr({stroke:a.plotBorderColor,
"stroke-width":m,zIndex:1}).add();this.isDirtyBox=!1},propFromSeries:function(){var a=this,b=a.options.chart,c,d=a.options.series,e,f;n(["inverted","angular","polar"],function(g){c=L[b.type||b.defaultSeriesType];f=a[g]||b[g]||c&&c.prototype[g];for(e=d&&d.length;!f&&e--;)(c=L[d[e].type])&&c.prototype[g]&&(f=!0);a[g]=f})},linkSeries:function(){var a=this,b=a.series;n(b,function(a){a.linkedSeries.length=0});n(b,function(b){var d=b.options.linkedTo;if(da(d)&&(d=d===":previous"?a.series[b.index-1]:a.get(d)))d.linkedSeries.push(b),
b.linkedParent=d})},render:function(){var a=this,b=a.axes,c=a.renderer,d=a.options,e=d.labels,f=d.credits,g;a.setTitle();a.legend=new zb(a,d.legend);a.getStacks();n(b,function(a){a.setScale()});a.getMargins();a.maxTicks=null;n(b,function(a){a.setTickPositions(!0);a.setMaxTicks()});a.adjustTickAmounts();a.getMargins();a.drawChartBox();a.hasCartesianSeries&&n(b,function(a){a.render()});if(!a.seriesGroup)a.seriesGroup=c.g("series-group").attr({zIndex:3}).add();n(a.series,function(a){a.translate();a.setTooltipPoints();
a.render()});e.items&&n(e.items,function(b){var d=r(e.style,b.style),f=z(d.left)+a.plotLeft,g=z(d.top)+a.plotTop+12;delete d.left;delete d.top;c.text(b.html,f,g).attr({zIndex:2}).css(d).add()});if(f.enabled&&!a.credits)g=f.href,a.credits=c.text(f.text,0,0).on("click",function(){if(g)location.href=g}).attr({align:f.position.align,zIndex:8}).css(f.style).add().align(f.position);a.hasRendered=!0},destroy:function(){var a=this,b=a.axes,c=a.series,d=a.container,e,f=d&&d.parentNode;A(a,"destroy");Ja[a.index]=
a.render()});e.items&&n(e.items,function(b){var d=r(e.style,b.style),f=z(d.left)+a.plotLeft,g=z(d.top)+a.plotTop+12;delete d.left;delete d.top;c.text(b.html,f,g).attr({zIndex:2}).css(d).add()});if(f.enabled&&!a.credits)g=f.href,a.credits=c.text(f.text,0,0).on("click",function(){if(g)parent.location.href=g}).attr({align:f.position.align,zIndex:8}).css(f.style).add().align(f.position);a.hasRendered=!0},destroy:function(){var a=this,b=a.axes,c=a.series,d=a.container,e,f=d&&d.parentNode;A(a,"destroy");Ja[a.index]=
u;a.renderTo.removeAttribute("data-highcharts-chart");X(a);for(e=b.length;e--;)b[e]=b[e].destroy();for(e=c.length;e--;)c[e]=c[e].destroy();n("title,subtitle,chartBackground,plotBackground,plotBGImage,plotBorder,seriesGroup,clipRect,credits,pointer,scroller,rangeSelector,legend,resetZoomButton,tooltip,renderer".split(","),function(b){var c=a[b];c&&c.destroy&&(a[b]=c.destroy())});if(d)d.innerHTML="",X(d),f&&Oa(d);for(e in a)delete a[e]},isReadyToRender:function(){var a=this;return!V&&C==C.top&&v.readyState!==
"complete"||ba&&!C.canvg?(ba?Mb.push(function(){a.firstRender()},a.options.global.canvasToolsURL):v.attachEvent("onreadystatechange",function(){v.detachEvent("onreadystatechange",a.firstRender);v.readyState==="complete"&&a.firstRender()}),!1):!0},firstRender:function(){var a=this,b=a.options,c=a.callback;if(a.isReadyToRender())a.getContainer(),A(a,"init"),a.resetMargins(),a.setChartSize(),a.propFromSeries(),a.getAxes(),n(b.series||[],function(b){a.initSeries(b)}),a.linkSeries(),A(a,"beforeRender"),
a.pointer=new Za(a,b),a.render(),a.renderer.draw(),c&&c.apply(a,[a]),n(a.callbacks,function(b){b.apply(a,[a])}),a.cloneRenderTo(!0),A(a,"load")},splashArray:function(a,b){var c=b[a],c=S(c)?c:[c,c,c,c];return[o(b[a+"Top"],c[0]),o(b[a+"Right"],c[1]),o(b[a+"Bottom"],c[2]),o(b[a+"Left"],c[3])]}};eb.prototype.callbacks=[];var xb=Highcharts.CenteredSeriesMixin={getCenter:function(){var a=this.options,b=this.chart,c=2*(a.slicedOffset||0),d,e=b.plotWidth-2*c,f=b.plotHeight-2*c,b=a.center,a=[o(b[0],"50%"),

View File

@ -1,5 +1,6 @@
// if on api subdomain, redirect
// if on api subdomain except for charts, redirect
var wloc = window.location.toString();
if (wloc.indexOf('api') != -1 && wloc.indexOf('api') < 10) {
if (wloc.indexOf('api') !== -1 && wloc.indexOf('api') < 10 && wloc.indexOf('charts') === -1) {
window.location = wloc.replace('api', 'www');
}
}

View File

@ -13,11 +13,11 @@ function getDimensions(element) {
}
function updateChart(index,
postUpdate,
width,
height,
channelId,
newOptionsSave) {
postUpdate,
width,
height,
channelId,
newOptionsSave) {
// default width and height
var width = width;
var height = height;
@ -26,52 +26,52 @@ function updateChart(index,
var iframe = $('#iframe' + index).attr("default_src");
if (!iframe) {
iframe = $('#iframe' + index).attr('src');
iframe = $('#iframe' + index).attr('src');
}
src = iframe.split('?')[0];
// if not a line chart, a timeslice should be present or set timescale=30
if ($('#type_' + index).val() != 'line') {
if ($('#timescale_' + index).val().length == 0 && $('#average_' + index).val().length == 0 && $('#median_' + index).val().length == 0 && $('#sum_' + index).val().length == 0) {
$('#timescale_' + index).val(30);
}
if ($('#timescale_' + index).val().length == 0 && $('#average_' + index).val().length == 0 && $('#median_' + index).val().length == 0 && $('#sum_' + index).val().length == 0) {
$('#timescale_' + index).val(30);
}
}
// add inputs to array
var inputs = [];
$('.chart_options' + index).each(function() {
var v = $(this).val();
var id = $(this).attr('id');
var tag = id.split("_")[0];
var v = $(this).val();
var id = $(this).attr('id');
var tag = id.split("_")[0];
if (v.length > 0) { inputs.push([tag, v]); }
});
if (v.length > 0) { inputs.push([tag, v]); }
});
// create querystring
var qs = '';
while (inputs.length > 0) {
var p = inputs.pop();
if (p[0] == 'width') { width = parseInt(p[1]); }
if (p[0] == 'height') { height = parseInt(p[1]); }
var p = inputs.pop();
if (p[0] == 'width') { width = parseInt(p[1]); }
if (p[0] == 'height') { height = parseInt(p[1]); }
// don't add type=line to querystring, it's the default value
if (!(p[0] == 'type' && p[1] == 'line')) {
qs += '&' + p[0] + '=' + encodeURIComponent(p[1]);
}
// don't add type=line to querystring, it's the default value
if (!(p[0] == 'type' && p[1] == 'line')) {
qs += '&' + p[0] + '=' + encodeURIComponent(p[1]);
}
}
// if querystring exists, add it to src
if (qs.length > 0) { src += '?' + qs.substring(1); }
// save chart options to database
if (postUpdate && index > 0 && newOptionsSave) {
$.update("/channels/" + channelId + "/charts/" + index,
{
newOptions : { options: qs }
} );
$.update("/channels/" + channelId + "/charts/" + index,
{
newOptions : { options: qs }
} );
}
else if (postUpdate && index > 0) {
$.update("/channels/" + channelId + "/charts/" + index,
{ options: qs } );
$.update("/channels/" + channelId + "/charts/" + index,
{ options: qs } );
}
// set embed code
@ -90,9 +90,9 @@ function updateSelectValues() {
function setupChartForm(channelIndex) {
return function(index, value) {
if (value.length > 0) {
$('#' + value.split('=')[0] + "_" + channelIndex).val(decodeURIComponent(value.split('=')[1]));
}
if (value.length > 0) {
$('#' + value.split('=')[0] + "_" + channelIndex).val(decodeURIComponent(value.split('=')[1]));
}
};
}
@ -107,52 +107,52 @@ function setupColumns(current_user, channel_id)
function createWindowsWithData (data, current_user, channel_id, colName) {
for (var i in data) {
//each array element has a single chart object as an associative array with the type as the key
// so I need to iterate over a array with size=1 to get a string with the window type
for (var type in data[i]) {
var wtype = type;
}
if (data[i].chart_window) window = data[i].chart_window;
if (data[i].plugin_window) window = data[i].plugin_window;
if (data[i].portlet_window) window = data[i].portlet_window;
for (var i in data) {
//each array element has a single chart object as an associative array with the type as the key
// so I need to iterate over a array with size=1 to get a string with the window type
for (var type in data[i]) {
var wtype = type;
}
if (data[i].chart_window) window = data[i].chart_window;
if (data[i].plugin_window) window = data[i].plugin_window;
if (data[i].portlet_window) window = data[i].portlet_window;
if (window == "undefined")
if (window == "undefined")
var window = (data[i].portlet_window) ? data[i].portlet_window : data[i].chart_window;
colId = window.col;
title = window.title;
colId = window.col;
title = window.title;
var content = window.html;
if (data[i].chart_window) {
var windowId = window.id;
$("body").append("<div id='chartConfig"+windowId+"'></div>");
var content = window.html;
if (data[i].chart_window) {
var windowId = window.id;
$("body").append("<div id='chartConfig"+windowId+"'></div>");
}
var portlet = addWindow(colName, colId, window.id, wtype, title, content);
portlet.each ( decoratePortlet(current_user) ) ;
var portlet = addWindow(colName, colId, window.id, wtype, title, content);
portlet.each ( decoratePortlet(current_user) ) ;
portlet.find( ".ui-toggle" ).click( uiToggleClick );
portlet.find( ".ui-view" ).click( uiViewClick (channel_id) );
portlet.find( ".ui-edit" ).click( uiEditClick (channel_id) );
portlet.find( ".ui-close" ).click( uiCloseClick (channel_id) );
}
portlet.find( ".ui-toggle" ).click( uiToggleClick );
portlet.find( ".ui-view" ).click( uiViewClick (channel_id) );
portlet.find( ".ui-edit" ).click( uiEditClick (channel_id) );
portlet.find( ".ui-close" ).click( uiCloseClick (channel_id) );
}
}
var createWindows = function (current_user, channel_id, colName) {
return function(data) {
createWindowsWithData(data, current_user, channel_id, colName);
createWindowsWithData(data, current_user, channel_id, colName);
};
}
function addWindow(colName, colId, windowId, wtype, title, content) {
$("#"+colName+"_dialog"+colId).append('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ' +
'id="portlet_' + windowId +
'"><div class="portlet-header wtype wtype-'+ wtype
+ ' ui-widget-header ui-corner-all">' + title +
'</div><div class="portlet-content">'+content+'</div>') ;
'id="portlet_' + windowId +
'"><div class="portlet-header wtype wtype-'+ wtype
+ ' ui-widget-header ui-corner-all">' + title +
'</div><div class="portlet-content">'+content+'</div>') ;
if ($("#portlet_"+windowId).length > 1) {
throw "Portlet count doesn't match what's expected";
throw "Portlet count doesn't match what's expected";
} else {
return $("#portlet_"+windowId);
return $("#portlet_"+windowId);
}
}
@ -161,22 +161,22 @@ function addWindow(colName, colId, windowId, wtype, title, content) {
var updatePortletPositions = function( current_user, channel_id) {
return function() {
if (current_user) {
var result = $(this).sortable('serialize');
colId = $(this).attr('id').charAt($(this).attr('id').length - 1);
portletArray = getPortletArray(result);
jsonResult = {
"col" : colId,
"positions" : portletArray
} ;
var result = $(this).sortable('serialize');
colId = $(this).attr('id').charAt($(this).attr('id').length - 1);
portletArray = getPortletArray(result);
jsonResult = {
"col" : colId,
"positions" : portletArray
} ;
if (portletArray.length > 0) {
$.ajax({
type: 'PUT',
url: '../channels/' + channel_id + '/windows',
data: {_method:'PUT', page : JSON.stringify(jsonResult ) },
dataType: 'json'
});
}
if (portletArray.length > 0) {
$.ajax({
type: 'PUT',
url: '../channels/' + channel_id + '/windows',
data: {_method:'PUT', page : JSON.stringify(jsonResult ) },
dataType: 'json'
});
}
}
}
}
@ -184,31 +184,31 @@ var updatePortletPositions = function( current_user, channel_id) {
function sortColumnSetup(current_user, channel_id) {
$( ".column" ).sortable({
opacity: 0.6,
helper: function( event ) {
return $("<div class='ui-widget-header'>Drop to re-position</div>");
},
connectWith: ".column",
update: updatePortletPositions(current_user, channel_id)
});
opacity: 0.6,
helper: function( event ) {
return $("<div class='ui-widget-header'>Drop to re-position</div>");
},
connectWith: ".column",
update: updatePortletPositions(current_user, channel_id)
});
}
var decoratePortlet = function (current_user) {
return function() {
var portletHeader = $(this).find( ".portlet-header") ;
portletHeader.append( "<span id='commentBtn' class='ui-view ui-icon ui-icon-comment'></span>");
var portletHeader = $(this).find( ".portlet-header") ;
portletHeader.append( "<span id='commentBtn' class='ui-view ui-icon ui-icon-comment'></span>");
thisObject = $(this);
if (current_user == "true") {
// Use feature Rollout here - needs to be implemented for this user, and this channel needs to belong to this user.
thisObject.find('.wtype').prepend( "<span id='minusBtn' class='ui-toggle ui-icon ui-icon-minusthick'></span>");
thisObject.find(".wtype-chart_window").append("<span id='pencilBtn' class='ui-edit ui-icon ui-icon-pencil'></span>");
thisObject.find(".wtype").append("<span id='closeBtn' class='ui-close ui-icon ui-icon-close'></span>");
thisObject.find(".portlet-header").css("cursor","move");
}
else {
$(".column").sortable({ disabled:true });
}
return $(this).attr("id");
thisObject = $(this);
if (current_user == "true") {
// Use feature Rollout here - needs to be implemented for this user, and this channel needs to belong to this user.
thisObject.find('.wtype').prepend( "<span id='minusBtn' class='ui-toggle ui-icon ui-icon-minusthick'></span>");
thisObject.find(".wtype-chart_window").append("<span id='pencilBtn' class='ui-edit ui-icon ui-icon-pencil'></span>");
thisObject.find(".wtype").append("<span id='closeBtn' class='ui-close ui-icon ui-icon-close'></span>");
thisObject.find(".portlet-header").css("cursor","move");
}
else {
$(".column").sortable({ disabled:true });
}
return $(this).attr("id");
}
}
function getPortletArray(data) {
@ -218,8 +218,8 @@ function getPortletArray(data) {
for (i in inputArray) {
val = inputArray[i].split("=")[1] ;
resultArray.push(val);
val = inputArray[i].split("=")[1] ;
resultArray.push(val);
}
return resultArray;
@ -228,63 +228,63 @@ function getPortletArray(data) {
var uiEditClick = function (channel_id) {
return function() {
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
var options = "";
$("#chartConfig"+id).load("/channels/"+channel_id+"/charts/"+id+"/edit",
function() {
options = $("#chartOptions"+id).html();
var options = "";
$("#chartConfig"+id).load("/channels/"+channel_id+"/charts/"+id+"/edit",
function() {
options = $("#chartOptions"+id).html();
if (options != "undefined" && options.length >2) {
$.each((options.split('&amp;')), setupChartForm( id ));
}
$("#button"+id).click( function() {
updateChart(id, true, 450, 250, channel_id, true);
$("#chartConfig"+id).dialog("close");
if (options != "undefined" && options.length >2) {
$.each((options.split('&amp;')), setupChartForm( id ));
}
$("#button"+id).click( function() {
updateChart(id, true, 450, 250, channel_id, true);
$("#chartConfig"+id).dialog("close");
});
})
.dialog({ title:"Chart Options", modal: true, resizable: false, width: 500, dialogClass: "dev-info-dialog" });
});
})
.dialog({ title:"Chart Options", modal: true, resizable: false, width: 500, dialogClass: "dev-info-dialog" });
};
}
var uiViewClick = function (channel_id) {
return function() {
var x = $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).offset().left;
var y = $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).offset().top;
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
var x = $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).offset().left;
var y = $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).offset().top;
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
$("body").append('<div id="iframepopup'+id+'" style="display:none">' +
'<div id="iframeinner'+id+'"style="font-size:1.2em;overflow:auto;height:115px;background-color:white">' +
'</div></div>');
$("body").append('<div id="iframepopup'+id+'" style="display:none">' +
'<div id="iframeinner'+id+'"style="font-size:1.2em;overflow:auto;height:115px;background-color:white">' +
'</div></div>');
$.get("/channels/"+channel_id+"/windows/"+id+"/iframe",
function(response) {
var display = response.replace(/id=\"iframe[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?\"/, "" );
$("#iframeinner"+id).text(display);
}
);
$.get("/channels/"+channel_id+"/windows/"+id+"/iframe",
function(response) {
var display = response.replace(/id=\"iframe[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?\"/, "" );
$("#iframeinner"+id).text(display);
}
);
$("#iframepopup"+id).dialog({
resizable:false,
width: "300px",
position:[x+200,y-200],
title: "Chart Iframe",
dialogClass: "dev-info-dialog"
});
$("#iframepopup"+id).dialog({
resizable:false,
width: "300px",
position:[x+200,y-200],
title: "Chart Iframe",
dialogClass: "dev-info-dialog"
});
};
}
var uiCloseClick = function (channel_id) {
return function() {
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
var portlet = $( this ).parents( ".portlet:first" ) ;
$.update("/channels/"+channel_id+"/windows/"+id+"/hide" ,
function(response) {
portlet.hide("drop", function(){
portlet.remove();});
}) ;
var id = $( this ).parents( ".portlet:first" ).attr("id").substring(8);
var portlet = $( this ).parents( ".portlet:first" ) ;
$.update("/channels/"+channel_id+"/windows/"+id+"/hide" ,
function(response) {
portlet.hide("drop", function(){
portlet.remove();});
}) ;
}
}