mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Merge branch 'ent-5811-CSV-export-on-graphs-agent-view-not-adding-all-modules' into 'develop'
CSV flot export fixes See merge request artica/pandorafms!3209
This commit is contained in:
commit
fc420cf9e9
@ -1,227 +1,19 @@
|
|||||||
(function ($) {
|
(function ($) {
|
||||||
var options = {
|
var options = {
|
||||||
export: {
|
export: {
|
||||||
export_data: false, // or true
|
export_data: false, // or true
|
||||||
labels_long: null,
|
labels_long: null,
|
||||||
homeurl: ''
|
homeurl: "",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function init(plot) {
|
function init(plot) {
|
||||||
plot.exportDataCSV = function (args) {
|
plot.exportDataCSV = function (args) {
|
||||||
//amount = plot.getOptions().export.type,
|
//amount = plot.getOptions().export.type,
|
||||||
//options = options || {};
|
//options = options || {};
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
var type = 'csv';
|
var type = "csv";
|
||||||
type = type.toLowerCase().trim();
|
|
||||||
|
|
||||||
var graphData,
|
|
||||||
dataObject,
|
|
||||||
dataObjects = plot.getData(),
|
|
||||||
result = [];
|
|
||||||
|
|
||||||
// Throw errors
|
|
||||||
var retrieveDataOject = function (dataObjects, custom) {
|
|
||||||
var result;
|
|
||||||
if (typeof dataObjects === 'undefined')
|
|
||||||
throw new Error('Empty parameter');
|
|
||||||
|
|
||||||
// Try to retrieve the avg set (not 100% reliable, I know)
|
|
||||||
if (dataObjects.length == 1) {
|
|
||||||
result = dataObjects.shift();
|
|
||||||
}
|
|
||||||
if (dataObjects.length > 1) {
|
|
||||||
dataObjects.forEach(function (element) {
|
|
||||||
if(custom){
|
|
||||||
if (/^Avg.:/i.test(element.label)){
|
|
||||||
result = element;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = element;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// If the avg set is missing, retrieve the first set
|
|
||||||
if (typeof result === 'undefined')
|
|
||||||
result = dataObjects.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof result === 'undefined')
|
|
||||||
throw new Error('Empty result');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Throw errors
|
|
||||||
var processDataObject = function (dataObject) {
|
|
||||||
var result;
|
|
||||||
|
|
||||||
if (typeof dataObject === 'undefined')
|
|
||||||
throw new Error('Empty parameter');
|
|
||||||
|
|
||||||
if (typeof dataObject.data === 'undefined'
|
|
||||||
|| !(dataObject.data instanceof Array))
|
|
||||||
throw new Error('Object malformed');
|
|
||||||
|
|
||||||
/* {
|
|
||||||
* head: [<column>,<column>,...,<column>],
|
|
||||||
* data: [
|
|
||||||
* [<data>,<data>,...,<data>],
|
|
||||||
* [<data>,<data>,...,<data>],
|
|
||||||
* ...,
|
|
||||||
* [<data>,<data>,...,<data>],
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
if (type === 'csv') {
|
|
||||||
result = {
|
|
||||||
head: ['timestap', 'date', 'value', 'label'],
|
|
||||||
data: []
|
|
||||||
};
|
|
||||||
|
|
||||||
dataObject.data.forEach(function (item, index) {
|
|
||||||
var timestap = item[0];
|
|
||||||
|
|
||||||
var d = new Date(item[0]);
|
|
||||||
var monthNames = [
|
|
||||||
"Jan", "Feb", "Mar",
|
|
||||||
"Apr", "May", "Jun",
|
|
||||||
"Jul", "Aug", "Sep",
|
|
||||||
"Oct", "Nov", "Dec"
|
|
||||||
];
|
|
||||||
|
|
||||||
date_format = (d.getDate() <10?'0':'') + d.getDate() + " " +
|
|
||||||
monthNames[d.getMonth()] + " " +
|
|
||||||
d.getFullYear() + " " +
|
|
||||||
(d.getHours()<10?'0':'') + d.getHours() + ":" +
|
|
||||||
(d.getMinutes()<10?'0':'') + d.getMinutes() + ":" +
|
|
||||||
(d.getSeconds()<10?'0':'') + d.getSeconds();
|
|
||||||
|
|
||||||
var date = date_format;
|
|
||||||
|
|
||||||
var value = item[1];
|
|
||||||
|
|
||||||
var clean_label = plot.getOptions().export.labels_long[dataObject.label];
|
|
||||||
clean_label = clean_label.replace( new RegExp(" ", "g"), " ");
|
|
||||||
result.data.push([timestap, date, value, clean_label]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/* [
|
|
||||||
* {
|
|
||||||
* 'date': <date>,
|
|
||||||
* 'value': <value>
|
|
||||||
* }
|
|
||||||
* ],
|
|
||||||
* [
|
|
||||||
* {
|
|
||||||
* 'date': <date>,
|
|
||||||
* 'value': <value>
|
|
||||||
* }
|
|
||||||
* ],
|
|
||||||
* ...,
|
|
||||||
* [
|
|
||||||
* {
|
|
||||||
* 'date': <date>,
|
|
||||||
* 'value': <value>
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
*/
|
|
||||||
else if (type === 'json') {
|
|
||||||
result = [];
|
|
||||||
|
|
||||||
dataObject.data.forEach(function (item, index) {
|
|
||||||
var date = '', value = item[1];
|
|
||||||
|
|
||||||
// Long labels are preferred
|
|
||||||
if (typeof labels_long[index] !== 'undefined')
|
|
||||||
date = labels_long[index];
|
|
||||||
else if (typeof labels[index] !== 'undefined')
|
|
||||||
date = labels[index];
|
|
||||||
|
|
||||||
result.push({
|
|
||||||
'date': date,
|
|
||||||
'value': value,
|
|
||||||
'label': dataObject.label
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof result === 'undefined')
|
|
||||||
throw new Error('Empty result');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
var elements = [];
|
|
||||||
var custom_graph = $('#hidden-custom_graph').val();
|
|
||||||
|
|
||||||
if (custom_graph) {
|
|
||||||
dataObject = retrieveDataOject(dataObjects,0);
|
|
||||||
dataObjects.forEach(function (element) {
|
|
||||||
elements.push(processDataObject(element));
|
|
||||||
});
|
|
||||||
graphData = elements;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dataObject = retrieveDataOject(dataObjects,1);
|
|
||||||
elements.push(processDataObject(dataObject));
|
|
||||||
graphData = elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transform the object data into a string
|
|
||||||
// cause PHP has limitations in the number
|
|
||||||
// of POST params received.
|
|
||||||
var graphDataStr = JSON.stringify(graphData);
|
|
||||||
|
|
||||||
// Build form
|
|
||||||
var $form = $('<form></form>'),
|
|
||||||
$dataInput = $('<input>'),
|
|
||||||
$typeInput = $('<input>'),
|
|
||||||
$separatorInput = $('<input>'),
|
|
||||||
$excelInput = $('<input>');
|
|
||||||
|
|
||||||
$dataInput
|
|
||||||
.prop('name', 'data')
|
|
||||||
.prop('type', 'text')
|
|
||||||
.prop('value', graphDataStr);
|
|
||||||
|
|
||||||
$typeInput
|
|
||||||
.prop('name', 'type')
|
|
||||||
.prop('type', 'text')
|
|
||||||
.prop('value', type);
|
|
||||||
|
|
||||||
$separatorInput
|
|
||||||
.prop('name', 'separator')
|
|
||||||
.prop('type', 'text')
|
|
||||||
.prop('value', ';');
|
|
||||||
|
|
||||||
$excelInput
|
|
||||||
.prop('name', 'excel_encoding')
|
|
||||||
.prop('type', 'text')
|
|
||||||
.prop('value', 0);
|
|
||||||
|
|
||||||
$form
|
|
||||||
.prop('method', 'POST')
|
|
||||||
.prop('action', plot.getOptions().export.homeurl + 'include/graphs/export_data.php')
|
|
||||||
.append($dataInput, $typeInput, $separatorInput, $excelInput)
|
|
||||||
.hide()
|
|
||||||
// Firefox made me write into the DOM for this :(
|
|
||||||
.appendTo('body')
|
|
||||||
.submit();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
alert('There was an error exporting the data');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plot.exportDataJSON = function (args) {
|
|
||||||
//amount = plot.getOptions().export.type,
|
|
||||||
//options = options || {};
|
|
||||||
|
|
||||||
// Options
|
|
||||||
var type = 'json';
|
|
||||||
type = type.toLowerCase().trim();
|
type = type.toLowerCase().trim();
|
||||||
|
|
||||||
var graphData,
|
var graphData,
|
||||||
@ -233,8 +25,8 @@
|
|||||||
var retrieveDataOject = function (dataObjects) {
|
var retrieveDataOject = function (dataObjects) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (typeof dataObjects === 'undefined')
|
if (typeof dataObjects === "undefined")
|
||||||
throw new Error('Empty parameter');
|
throw new Error("Empty parameter");
|
||||||
|
|
||||||
// Try to retrieve the avg set (not 100% reliable, I know)
|
// Try to retrieve the avg set (not 100% reliable, I know)
|
||||||
if (dataObjects.length == 1) {
|
if (dataObjects.length == 1) {
|
||||||
@ -242,31 +34,30 @@
|
|||||||
}
|
}
|
||||||
if (dataObjects.length > 1) {
|
if (dataObjects.length > 1) {
|
||||||
dataObjects.forEach(function (element) {
|
dataObjects.forEach(function (element) {
|
||||||
if (/^Avg.:/i.test(element.label))
|
if (/^Avg.:/i.test(element.label)) result = element;
|
||||||
result = element;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the avg set is missing, retrieve the first set
|
// If the avg set is missing, retrieve the first set
|
||||||
if (typeof result === 'undefined')
|
if (typeof result === "undefined") result = dataObjects.shift();
|
||||||
result = dataObjects.shift();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof result === 'undefined')
|
if (typeof result === "undefined") throw new Error("Empty result");
|
||||||
throw new Error('Empty result');
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Throw errors
|
// Throw errors
|
||||||
var processDataObject = function (dataObject) {
|
var processDataObject = function (dataObject) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (typeof dataObject === 'undefined')
|
if (typeof dataObject === "undefined")
|
||||||
throw new Error('Empty parameter');
|
throw new Error("Empty parameter");
|
||||||
|
|
||||||
if (typeof dataObject.data === 'undefined'
|
if (
|
||||||
|| !(dataObject.data instanceof Array))
|
typeof dataObject.data === "undefined" ||
|
||||||
throw new Error('Object malformed');
|
!(dataObject.data instanceof Array)
|
||||||
|
)
|
||||||
|
throw new Error("Object malformed");
|
||||||
|
|
||||||
/* {
|
/* {
|
||||||
* head: [<column>,<column>,...,<column>],
|
* head: [<column>,<column>,...,<column>],
|
||||||
@ -278,74 +69,291 @@
|
|||||||
* ]
|
* ]
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
if (type === 'csv') {
|
if (type === "csv") {
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
head: ['date', 'value','label'],
|
head: ["timestap", "date", "value", "label"],
|
||||||
data: []
|
data: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
dataObject.data.forEach(function (item, index) {
|
dataObject.data.forEach(function (item, index) {
|
||||||
var date = '', value = item[1];
|
var timestap = item[0];
|
||||||
|
|
||||||
// Long labels are preferred
|
var d = new Date(item[0]);
|
||||||
if (typeof plot.getOptions().export.labels_long[index] !== 'undefined')
|
var monthNames = [
|
||||||
date = plot.getOptions().export.labels_long[index];
|
"Jan",
|
||||||
else if (typeof labels[index] !== 'undefined')
|
"Feb",
|
||||||
date = labels[index];
|
"Mar",
|
||||||
|
"Apr",
|
||||||
|
"May",
|
||||||
|
"Jun",
|
||||||
|
"Jul",
|
||||||
|
"Aug",
|
||||||
|
"Sep",
|
||||||
|
"Oct",
|
||||||
|
"Nov",
|
||||||
|
"Dec",
|
||||||
|
];
|
||||||
|
|
||||||
result.data.push([date, value,dataObject.label]);
|
date_format =
|
||||||
|
(d.getDate() < 10 ? "0" : "") +
|
||||||
|
d.getDate() +
|
||||||
|
" " +
|
||||||
|
monthNames[d.getMonth()] +
|
||||||
|
" " +
|
||||||
|
d.getFullYear() +
|
||||||
|
" " +
|
||||||
|
(d.getHours() < 10 ? "0" : "") +
|
||||||
|
d.getHours() +
|
||||||
|
":" +
|
||||||
|
(d.getMinutes() < 10 ? "0" : "") +
|
||||||
|
d.getMinutes() +
|
||||||
|
":" +
|
||||||
|
(d.getSeconds() < 10 ? "0" : "") +
|
||||||
|
d.getSeconds();
|
||||||
|
|
||||||
|
var date = date_format;
|
||||||
|
|
||||||
|
var value = item[1];
|
||||||
|
|
||||||
|
var clean_label = plot.getOptions().export.labels_long[
|
||||||
|
dataObject.label
|
||||||
|
];
|
||||||
|
clean_label = clean_label.replace(new RegExp(" ", "g"), " ");
|
||||||
|
result.data.push([timestap, date, value, clean_label]);
|
||||||
});
|
});
|
||||||
}
|
} else if (type === "json") {
|
||||||
/* [
|
/* [
|
||||||
* {
|
* {
|
||||||
* 'date': <date>,
|
* 'date': <date>,
|
||||||
* 'value': <value>
|
* 'value': <value>
|
||||||
* }
|
* }
|
||||||
* ],
|
* ],
|
||||||
* [
|
* [
|
||||||
* {
|
* {
|
||||||
* 'date': <date>,
|
* 'date': <date>,
|
||||||
* 'value': <value>
|
* 'value': <value>
|
||||||
* }
|
* }
|
||||||
* ],
|
* ],
|
||||||
* ...,
|
* ...,
|
||||||
* [
|
* [
|
||||||
* {
|
* {
|
||||||
* 'date': <date>,
|
* 'date': <date>,
|
||||||
* 'value': <value>
|
* 'value': <value>
|
||||||
* }
|
* }
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
else if (type === 'json') {
|
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
dataObject.data.forEach(function (item, index) {
|
dataObject.data.forEach(function (item, index) {
|
||||||
var date = '', value = item[1];
|
var date = "",
|
||||||
|
value = item[1];
|
||||||
|
|
||||||
// Long labels are preferred
|
// Long labels are preferred
|
||||||
if (typeof labels_long[index] !== 'undefined')
|
if (typeof labels_long[index] !== "undefined")
|
||||||
date = labels_long[index];
|
date = labels_long[index];
|
||||||
else if (typeof labels[index] !== 'undefined')
|
else if (typeof labels[index] !== "undefined") date = labels[index];
|
||||||
date = labels[index];
|
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
'date': date,
|
date: date,
|
||||||
'value': value,
|
value: value,
|
||||||
'label': dataObject.label
|
label: dataObject.label,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof result === 'undefined')
|
if (typeof result === "undefined") throw new Error("Empty result");
|
||||||
throw new Error('Empty result');
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var elements = [];
|
var elements = [];
|
||||||
var custom_graph = $('input:hidden[name=custom_graph]').value;
|
dataObject = retrieveDataOject(dataObjects);
|
||||||
|
if (dataObject) {
|
||||||
|
elements.push(processDataObject(dataObject));
|
||||||
|
}
|
||||||
|
dataObjects.forEach(function (element) {
|
||||||
|
elements.push(processDataObject(element));
|
||||||
|
});
|
||||||
|
graphData = elements;
|
||||||
|
|
||||||
|
|
||||||
|
// Transform the object data into a string
|
||||||
|
// cause PHP has limitations in the number
|
||||||
|
// of POST params received.
|
||||||
|
var graphDataStr = JSON.stringify(graphData);
|
||||||
|
|
||||||
|
// Build form
|
||||||
|
var $form = $("<form></form>"),
|
||||||
|
$dataInput = $("<input>"),
|
||||||
|
$typeInput = $("<input>"),
|
||||||
|
$separatorInput = $("<input>"),
|
||||||
|
$excelInput = $("<input>");
|
||||||
|
|
||||||
|
$dataInput
|
||||||
|
.prop("name", "data")
|
||||||
|
.prop("type", "text")
|
||||||
|
.prop("value", graphDataStr);
|
||||||
|
|
||||||
|
$typeInput
|
||||||
|
.prop("name", "type")
|
||||||
|
.prop("type", "text")
|
||||||
|
.prop("value", type);
|
||||||
|
|
||||||
|
$separatorInput
|
||||||
|
.prop("name", "separator")
|
||||||
|
.prop("type", "text")
|
||||||
|
.prop("value", ";");
|
||||||
|
|
||||||
|
$excelInput
|
||||||
|
.prop("name", "excel_encoding")
|
||||||
|
.prop("type", "text")
|
||||||
|
.prop("value", 0);
|
||||||
|
|
||||||
|
$form
|
||||||
|
.prop("method", "POST")
|
||||||
|
.prop(
|
||||||
|
"action",
|
||||||
|
plot.getOptions().export.homeurl + "include/graphs/export_data.php"
|
||||||
|
)
|
||||||
|
.append($dataInput, $typeInput, $separatorInput, $excelInput)
|
||||||
|
.hide()
|
||||||
|
// Firefox made me write into the DOM for this :(
|
||||||
|
.appendTo("body")
|
||||||
|
.submit();
|
||||||
|
} catch (e) {
|
||||||
|
alert("There was an error exporting the data");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
plot.exportDataJSON = function (args) {
|
||||||
|
//amount = plot.getOptions().export.type,
|
||||||
|
//options = options || {};
|
||||||
|
|
||||||
|
// Options
|
||||||
|
var type = "json";
|
||||||
|
type = type.toLowerCase().trim();
|
||||||
|
|
||||||
|
var graphData,
|
||||||
|
dataObject,
|
||||||
|
dataObjects = plot.getData(),
|
||||||
|
result = [];
|
||||||
|
|
||||||
|
// Throw errors
|
||||||
|
var retrieveDataOject = function (dataObjects) {
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (typeof dataObjects === "undefined")
|
||||||
|
throw new Error("Empty parameter");
|
||||||
|
|
||||||
|
// Try to retrieve the avg set (not 100% reliable, I know)
|
||||||
|
if (dataObjects.length == 1) {
|
||||||
|
result = dataObjects.shift();
|
||||||
|
}
|
||||||
|
if (dataObjects.length > 1) {
|
||||||
|
dataObjects.forEach(function (element) {
|
||||||
|
if (/^Avg.:/i.test(element.label)) result = element;
|
||||||
|
});
|
||||||
|
|
||||||
|
// If the avg set is missing, retrieve the first set
|
||||||
|
if (typeof result === "undefined") result = dataObjects.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof result === "undefined") throw new Error("Empty result");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Throw errors
|
||||||
|
var processDataObject = function (dataObject) {
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (typeof dataObject === "undefined")
|
||||||
|
throw new Error("Empty parameter");
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof dataObject.data === "undefined" ||
|
||||||
|
!(dataObject.data instanceof Array)
|
||||||
|
)
|
||||||
|
throw new Error("Object malformed");
|
||||||
|
|
||||||
|
/* {
|
||||||
|
* head: [<column>,<column>,...,<column>],
|
||||||
|
* data: [
|
||||||
|
* [<data>,<data>,...,<data>],
|
||||||
|
* [<data>,<data>,...,<data>],
|
||||||
|
* ...,
|
||||||
|
* [<data>,<data>,...,<data>],
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
if (type === "csv") {
|
||||||
|
result = {
|
||||||
|
head: ["date", "value", "label"],
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
dataObject.data.forEach(function (item, index) {
|
||||||
|
var date = "",
|
||||||
|
value = item[1];
|
||||||
|
|
||||||
|
// Long labels are preferred
|
||||||
|
if (
|
||||||
|
typeof plot.getOptions().export.labels_long[index] !== "undefined"
|
||||||
|
)
|
||||||
|
date = plot.getOptions().export.labels_long[index];
|
||||||
|
else if (typeof labels[index] !== "undefined") date = labels[index];
|
||||||
|
|
||||||
|
result.data.push([date, value, dataObject.label]);
|
||||||
|
});
|
||||||
|
} else if (type === "json") {
|
||||||
|
/* [
|
||||||
|
* {
|
||||||
|
* 'date': <date>,
|
||||||
|
* 'value': <value>
|
||||||
|
* }
|
||||||
|
* ],
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* 'date': <date>,
|
||||||
|
* 'value': <value>
|
||||||
|
* }
|
||||||
|
* ],
|
||||||
|
* ...,
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* 'date': <date>,
|
||||||
|
* 'value': <value>
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
result = [];
|
||||||
|
|
||||||
|
dataObject.data.forEach(function (item, index) {
|
||||||
|
var date = "",
|
||||||
|
value = item[1];
|
||||||
|
|
||||||
|
// Long labels are preferred
|
||||||
|
if (typeof labels_long[index] !== "undefined")
|
||||||
|
date = labels_long[index];
|
||||||
|
else if (typeof labels[index] !== "undefined") date = labels[index];
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
date: date,
|
||||||
|
value: value,
|
||||||
|
label: dataObject.label,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof result === "undefined") throw new Error("Empty result");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
var elements = [];
|
||||||
|
var custom_graph = $("input:hidden[name=custom_graph]").value;
|
||||||
|
|
||||||
if (custom_graph) {
|
if (custom_graph) {
|
||||||
dataObject = retrieveDataOject(dataObjects);
|
dataObject = retrieveDataOject(dataObjects);
|
||||||
@ -353,8 +361,7 @@
|
|||||||
elements.push(processDataObject(element));
|
elements.push(processDataObject(element));
|
||||||
});
|
});
|
||||||
graphData = elements;
|
graphData = elements;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataObject = retrieveDataOject(dataObjects);
|
dataObject = retrieveDataOject(dataObjects);
|
||||||
elements.push(processDataObject(dataObject));
|
elements.push(processDataObject(dataObject));
|
||||||
graphData = elements;
|
graphData = elements;
|
||||||
@ -366,51 +373,53 @@
|
|||||||
var graphDataStr = JSON.stringify(graphData);
|
var graphDataStr = JSON.stringify(graphData);
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var $form = $('<form></form>'),
|
var $form = $("<form></form>"),
|
||||||
$dataInput = $('<input>'),
|
$dataInput = $("<input>"),
|
||||||
$typeInput = $('<input>'),
|
$typeInput = $("<input>"),
|
||||||
$separatorInput = $('<input>'),
|
$separatorInput = $("<input>"),
|
||||||
$excelInput = $('<input>');
|
$excelInput = $("<input>");
|
||||||
|
|
||||||
$dataInput
|
$dataInput
|
||||||
.prop('name', 'data')
|
.prop("name", "data")
|
||||||
.prop('type', 'text')
|
.prop("type", "text")
|
||||||
.prop('value', graphDataStr);
|
.prop("value", graphDataStr);
|
||||||
|
|
||||||
$typeInput
|
$typeInput
|
||||||
.prop('name', 'type')
|
.prop("name", "type")
|
||||||
.prop('type', 'text')
|
.prop("type", "text")
|
||||||
.prop('value', type);
|
.prop("value", type);
|
||||||
|
|
||||||
$separatorInput
|
$separatorInput
|
||||||
.prop('name', 'separator')
|
.prop("name", "separator")
|
||||||
.prop('type', 'text')
|
.prop("type", "text")
|
||||||
.prop('value', ';');
|
.prop("value", ";");
|
||||||
|
|
||||||
$excelInput
|
$excelInput
|
||||||
.prop('name', 'excel_encoding')
|
.prop("name", "excel_encoding")
|
||||||
.prop('type', 'text')
|
.prop("type", "text")
|
||||||
.prop('value', 0);
|
.prop("value", 0);
|
||||||
|
|
||||||
$form
|
$form
|
||||||
.prop('method', 'POST')
|
.prop("method", "POST")
|
||||||
.prop('action', plot.getOptions().export.homeurl + 'include/graphs/export_data.php')
|
.prop(
|
||||||
|
"action",
|
||||||
|
plot.getOptions().export.homeurl + "include/graphs/export_data.php"
|
||||||
|
)
|
||||||
.append($dataInput, $typeInput, $separatorInput, $excelInput)
|
.append($dataInput, $typeInput, $separatorInput, $excelInput)
|
||||||
.hide()
|
.hide()
|
||||||
// Firefox made me write into the DOM for this :(
|
// Firefox made me write into the DOM for this :(
|
||||||
.appendTo('body')
|
.appendTo("body")
|
||||||
.submit();
|
.submit();
|
||||||
|
} catch (e) {
|
||||||
|
alert("There was an error exporting the data");
|
||||||
}
|
}
|
||||||
catch (e) {
|
};
|
||||||
alert('There was an error exporting the data');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$.plot.plugins.push({
|
$.plot.plugins.push({
|
||||||
init: init,
|
init: init,
|
||||||
options: options,
|
options: options,
|
||||||
name: 'exportdata',
|
name: "exportdata",
|
||||||
version: '0.1'
|
version: "0.1",
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user