Modularize server related remaining files like replication, plugins, queries, processes.
Sever monitor is also modularised and is not working but jQplot is not imported as it is giving error with webpack. Another issue with these files is that table sorter is also not woking working properly as it is not available on npm as plugin. Signed-off-by: Piyush Vijay <piyushvijay.1997@gmail.com>
This commit is contained in:
parent
f92e1ebccd
commit
a99acfef71
678
js/src/classes/Chart.js
vendored
Normal file
678
js/src/classes/Chart.js
vendored
Normal file
@ -0,0 +1,678 @@
|
||||
/**
|
||||
* Chart type enumerations
|
||||
*/
|
||||
var ChartType = {
|
||||
LINE : 'line',
|
||||
SPLINE : 'spline',
|
||||
AREA : 'area',
|
||||
BAR : 'bar',
|
||||
COLUMN : 'column',
|
||||
PIE : 'pie',
|
||||
TIMELINE: 'timeline',
|
||||
SCATTER: 'scatter'
|
||||
};
|
||||
|
||||
/**
|
||||
* Column type enumeration
|
||||
*/
|
||||
var ColumnType = {
|
||||
STRING : 'string',
|
||||
NUMBER : 'number',
|
||||
BOOLEAN : 'boolean',
|
||||
DATE : 'date'
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract chart factory which defines the contract for chart factories
|
||||
*/
|
||||
var ChartFactory = function () {
|
||||
};
|
||||
ChartFactory.prototype = {
|
||||
createChart : function (type, options) {
|
||||
throw new Error('createChart must be implemented by a subclass');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract chart which defines the contract for charts
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var Chart = function (elementId) {
|
||||
this.elementId = elementId;
|
||||
};
|
||||
Chart.prototype = {
|
||||
draw : function (data, options) {
|
||||
throw new Error('draw must be implemented by a subclass');
|
||||
},
|
||||
redraw : function (options) {
|
||||
throw new Error('redraw must be implemented by a subclass');
|
||||
},
|
||||
destroy : function () {
|
||||
throw new Error('destroy must be implemented by a subclass');
|
||||
},
|
||||
toImageString : function () {
|
||||
throw new Error('toImageString must be implemented by a subclass');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract representation of charts that operates on DataTable where,<br />
|
||||
* <ul>
|
||||
* <li>First column provides index to the data.</li>
|
||||
* <li>Each subsequent columns are of type
|
||||
* <code>ColumnType.NUMBER<code> and represents a data series.</li>
|
||||
* </ul>
|
||||
* Line chart, area chart, bar chart, column chart are typical examples.
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var BaseChart = function (elementId) {
|
||||
Chart.call(this, elementId);
|
||||
};
|
||||
BaseChart.prototype = new Chart();
|
||||
BaseChart.prototype.constructor = BaseChart;
|
||||
BaseChart.prototype.validateColumns = function (dataTable) {
|
||||
var columns = dataTable.getColumns();
|
||||
if (columns.length < 2) {
|
||||
throw new Error('Minimum of two columns are required for this chart');
|
||||
}
|
||||
for (var i = 1; i < columns.length; i++) {
|
||||
if (columns[i].type !== ColumnType.NUMBER) {
|
||||
throw new Error('Column ' + (i + 1) + ' should be of type \'Number\'');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract pie chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var PieChart = function (elementId) {
|
||||
BaseChart.call(this, elementId);
|
||||
};
|
||||
PieChart.prototype = new BaseChart();
|
||||
PieChart.prototype.constructor = PieChart;
|
||||
PieChart.prototype.validateColumns = function (dataTable) {
|
||||
var columns = dataTable.getColumns();
|
||||
if (columns.length > 2) {
|
||||
throw new Error('Pie charts can draw only one series');
|
||||
}
|
||||
return BaseChart.prototype.validateColumns.call(this, dataTable);
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract timeline chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var TimelineChart = function (elementId) {
|
||||
BaseChart.call(this, elementId);
|
||||
};
|
||||
TimelineChart.prototype = new BaseChart();
|
||||
TimelineChart.prototype.constructor = TimelineChart;
|
||||
TimelineChart.prototype.validateColumns = function (dataTable) {
|
||||
var result = BaseChart.prototype.validateColumns.call(this, dataTable);
|
||||
if (result) {
|
||||
var columns = dataTable.getColumns();
|
||||
if (columns[0].type !== ColumnType.DATE) {
|
||||
throw new Error('First column of timeline chart need to be a date column');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract scatter chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var ScatterChart = function (elementId) {
|
||||
BaseChart.call(this, elementId);
|
||||
};
|
||||
ScatterChart.prototype = new BaseChart();
|
||||
ScatterChart.prototype.constructor = ScatterChart;
|
||||
ScatterChart.prototype.validateColumns = function (dataTable) {
|
||||
var result = BaseChart.prototype.validateColumns.call(this, dataTable);
|
||||
if (result) {
|
||||
var columns = dataTable.getColumns();
|
||||
if (columns[0].type !== ColumnType.NUMBER) {
|
||||
throw new Error('First column of scatter chart need to be a numeric column');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* The data table contains column information and data for the chart.
|
||||
*/
|
||||
var DataTable = function () {
|
||||
var columns = [];
|
||||
var data = null;
|
||||
|
||||
this.addColumn = function (type, name) {
|
||||
columns.push({
|
||||
'type' : type,
|
||||
'name' : name
|
||||
});
|
||||
};
|
||||
|
||||
this.getColumns = function () {
|
||||
return columns;
|
||||
};
|
||||
|
||||
this.setData = function (rows) {
|
||||
data = rows;
|
||||
fillMissingValues();
|
||||
};
|
||||
|
||||
this.getData = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
var fillMissingValues = function () {
|
||||
if (columns.length === 0) {
|
||||
throw new Error('Set columns first');
|
||||
}
|
||||
var row;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
row = data[i];
|
||||
if (row.length > columns.length) {
|
||||
row.splice(columns.length - 1, row.length - columns.length);
|
||||
} else if (row.length < columns.length) {
|
||||
for (var j = row.length; j < columns.length; j++) {
|
||||
row.push(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/** *****************************************************************************
|
||||
* JQPlot specific code
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Abstract JQplot chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotChart = function (elementId) {
|
||||
Chart.call(this, elementId);
|
||||
this.plot = null;
|
||||
this.validator = null;
|
||||
};
|
||||
JQPlotChart.prototype = new Chart();
|
||||
JQPlotChart.prototype.constructor = JQPlotChart;
|
||||
JQPlotChart.prototype.draw = function (data, options) {
|
||||
if (this.validator.validateColumns(data)) {
|
||||
this.plot = $.jqplot(this.elementId, this.prepareData(data), this
|
||||
.populateOptions(data, options));
|
||||
}
|
||||
};
|
||||
JQPlotChart.prototype.destroy = function () {
|
||||
if (this.plot !== null) {
|
||||
this.plot.destroy();
|
||||
}
|
||||
};
|
||||
JQPlotChart.prototype.redraw = function (options) {
|
||||
if (this.plot !== null) {
|
||||
this.plot.replot(options);
|
||||
}
|
||||
};
|
||||
JQPlotChart.prototype.toImageString = function (options) {
|
||||
if (this.plot !== null) {
|
||||
return $('#' + this.elementId).jqplotToImageStr({});
|
||||
}
|
||||
};
|
||||
JQPlotChart.prototype.populateOptions = function (dataTable, options) {
|
||||
throw new Error('populateOptions must be implemented by a subclass');
|
||||
};
|
||||
JQPlotChart.prototype.prepareData = function (dataTable) {
|
||||
throw new Error('prepareData must be implemented by a subclass');
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot line chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotLineChart = function (elementId) {
|
||||
JQPlotChart.call(this, elementId);
|
||||
this.validator = BaseChart.prototype;
|
||||
};
|
||||
JQPlotLineChart.prototype = new JQPlotChart();
|
||||
JQPlotLineChart.prototype.constructor = JQPlotLineChart;
|
||||
|
||||
JQPlotLineChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var columns = dataTable.getColumns();
|
||||
var optional = {
|
||||
axes : {
|
||||
xaxis : {
|
||||
label : columns[0].name,
|
||||
renderer : $.jqplot.CategoryAxisRenderer,
|
||||
ticks : []
|
||||
},
|
||||
yaxis : {
|
||||
label : (columns.length === 2 ? columns[1].name : 'Values'),
|
||||
labelRenderer : $.jqplot.CanvasAxisLabelRenderer
|
||||
}
|
||||
},
|
||||
highlighter: {
|
||||
show: true,
|
||||
tooltipAxes: 'y',
|
||||
formatString:'%d'
|
||||
},
|
||||
series : []
|
||||
};
|
||||
$.extend(true, optional, options);
|
||||
|
||||
if (optional.series.length === 0) {
|
||||
for (var i = 1; i < columns.length; i++) {
|
||||
optional.series.push({
|
||||
label : columns[i].name.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
if (optional.axes.xaxis.ticks.length === 0) {
|
||||
var data = dataTable.getData();
|
||||
for (var j = 0; j < data.length; j++) {
|
||||
optional.axes.xaxis.ticks.push(data[j][0].toString());
|
||||
}
|
||||
}
|
||||
return optional;
|
||||
};
|
||||
|
||||
JQPlotLineChart.prototype.prepareData = function (dataTable) {
|
||||
var data = dataTable.getData();
|
||||
var row;
|
||||
var retData = [];
|
||||
var retRow;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
row = data[i];
|
||||
for (var j = 1; j < row.length; j++) {
|
||||
retRow = retData[j - 1];
|
||||
if (retRow === undefined) {
|
||||
retRow = [];
|
||||
retData[j - 1] = retRow;
|
||||
}
|
||||
retRow.push(row[j]);
|
||||
}
|
||||
}
|
||||
return retData;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot spline chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotSplineChart = function (elementId) {
|
||||
JQPlotLineChart.call(this, elementId);
|
||||
};
|
||||
JQPlotSplineChart.prototype = new JQPlotLineChart();
|
||||
JQPlotSplineChart.prototype.constructor = JQPlotSplineChart;
|
||||
|
||||
JQPlotSplineChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var optional = {};
|
||||
var opt = JQPlotLineChart.prototype.populateOptions.call(this, dataTable,
|
||||
options);
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
rendererOptions : {
|
||||
smooth : true
|
||||
}
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, opt, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot scatter chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotScatterChart = function (elementId) {
|
||||
JQPlotChart.call(this, elementId);
|
||||
this.validator = ScatterChart.prototype;
|
||||
};
|
||||
JQPlotScatterChart.prototype = new JQPlotChart();
|
||||
JQPlotScatterChart.prototype.constructor = JQPlotScatterChart;
|
||||
|
||||
JQPlotScatterChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var columns = dataTable.getColumns();
|
||||
var optional = {
|
||||
axes : {
|
||||
xaxis : {
|
||||
label : columns[0].name
|
||||
},
|
||||
yaxis : {
|
||||
label : (columns.length === 2 ? columns[1].name : 'Values'),
|
||||
labelRenderer : $.jqplot.CanvasAxisLabelRenderer
|
||||
}
|
||||
},
|
||||
highlighter: {
|
||||
show: true,
|
||||
tooltipAxes: 'xy',
|
||||
formatString:'%d, %d'
|
||||
},
|
||||
series : []
|
||||
};
|
||||
for (var i = 1; i < columns.length; i++) {
|
||||
optional.series.push({
|
||||
label : columns[i].name.toString()
|
||||
});
|
||||
}
|
||||
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
showLine: false,
|
||||
markerOptions: {
|
||||
size: 7,
|
||||
style: 'x'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.extend(true, optional, options, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
JQPlotScatterChart.prototype.prepareData = function (dataTable) {
|
||||
var data = dataTable.getData();
|
||||
var row;
|
||||
var retData = [];
|
||||
var retRow;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
row = data[i];
|
||||
if (row[0]) {
|
||||
for (var j = 1; j < row.length; j++) {
|
||||
retRow = retData[j - 1];
|
||||
if (retRow === undefined) {
|
||||
retRow = [];
|
||||
retData[j - 1] = retRow;
|
||||
}
|
||||
retRow.push([row[0], row[j]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retData;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot timeline chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotTimelineChart = function (elementId) {
|
||||
JQPlotLineChart.call(this, elementId);
|
||||
this.validator = TimelineChart.prototype;
|
||||
};
|
||||
JQPlotTimelineChart.prototype = new JQPlotLineChart();
|
||||
JQPlotTimelineChart.prototype.constructor = JQPlotTimelineChart;
|
||||
|
||||
JQPlotTimelineChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var optional = {
|
||||
axes : {
|
||||
xaxis : {
|
||||
tickOptions : {
|
||||
formatString: '%b %#d, %y'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var opt = JQPlotLineChart.prototype.populateOptions.call(this, dataTable, options);
|
||||
var compulsory = {
|
||||
axes : {
|
||||
xaxis : {
|
||||
renderer : $.jqplot.DateAxisRenderer
|
||||
}
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, opt, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
JQPlotTimelineChart.prototype.prepareData = function (dataTable) {
|
||||
var data = dataTable.getData();
|
||||
var row;
|
||||
var d;
|
||||
var retData = [];
|
||||
var retRow;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
row = data[i];
|
||||
d = row[0];
|
||||
for (var j = 1; j < row.length; j++) {
|
||||
retRow = retData[j - 1];
|
||||
if (retRow === undefined) {
|
||||
retRow = [];
|
||||
retData[j - 1] = retRow;
|
||||
}
|
||||
if (d !== null) {
|
||||
retRow.push([d.getTime(), row[j]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retData;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot area chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotAreaChart = function (elementId) {
|
||||
JQPlotLineChart.call(this, elementId);
|
||||
};
|
||||
JQPlotAreaChart.prototype = new JQPlotLineChart();
|
||||
JQPlotAreaChart.prototype.constructor = JQPlotAreaChart;
|
||||
|
||||
JQPlotAreaChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var optional = {
|
||||
seriesDefaults : {
|
||||
fillToZero : true
|
||||
}
|
||||
};
|
||||
var opt = JQPlotLineChart.prototype.populateOptions.call(this, dataTable,
|
||||
options);
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
fill : true
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, opt, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot column chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotColumnChart = function (elementId) {
|
||||
JQPlotLineChart.call(this, elementId);
|
||||
};
|
||||
JQPlotColumnChart.prototype = new JQPlotLineChart();
|
||||
JQPlotColumnChart.prototype.constructor = JQPlotColumnChart;
|
||||
|
||||
JQPlotColumnChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var optional = {
|
||||
seriesDefaults : {
|
||||
fillToZero : true
|
||||
}
|
||||
};
|
||||
var opt = JQPlotLineChart.prototype.populateOptions.call(this, dataTable,
|
||||
options);
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
renderer : $.jqplot.BarRenderer
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, opt, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot bar chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotBarChart = function (elementId) {
|
||||
JQPlotLineChart.call(this, elementId);
|
||||
};
|
||||
JQPlotBarChart.prototype = new JQPlotLineChart();
|
||||
JQPlotBarChart.prototype.constructor = JQPlotBarChart;
|
||||
|
||||
JQPlotBarChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var columns = dataTable.getColumns();
|
||||
var optional = {
|
||||
axes : {
|
||||
yaxis : {
|
||||
label : columns[0].name,
|
||||
labelRenderer : $.jqplot.CanvasAxisLabelRenderer,
|
||||
renderer : $.jqplot.CategoryAxisRenderer,
|
||||
ticks : []
|
||||
},
|
||||
xaxis : {
|
||||
label : (columns.length === 2 ? columns[1].name : 'Values'),
|
||||
labelRenderer : $.jqplot.CanvasAxisLabelRenderer
|
||||
}
|
||||
},
|
||||
highlighter: {
|
||||
show: true,
|
||||
tooltipAxes: 'x',
|
||||
formatString:'%d'
|
||||
},
|
||||
series : [],
|
||||
seriesDefaults : {
|
||||
fillToZero : true
|
||||
}
|
||||
};
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
renderer : $.jqplot.BarRenderer,
|
||||
rendererOptions : {
|
||||
barDirection : 'horizontal'
|
||||
}
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, options, compulsory);
|
||||
|
||||
if (optional.axes.yaxis.ticks.length === 0) {
|
||||
var data = dataTable.getData();
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
optional.axes.yaxis.ticks.push(data[i][0].toString());
|
||||
}
|
||||
}
|
||||
if (optional.series.length === 0) {
|
||||
for (var j = 1; j < columns.length; j++) {
|
||||
optional.series.push({
|
||||
label : columns[j].name.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
return optional;
|
||||
};
|
||||
|
||||
/**
|
||||
* JQPlot pie chart
|
||||
*
|
||||
* @param elementId
|
||||
* id of the div element the chart is drawn in
|
||||
*/
|
||||
var JQPlotPieChart = function (elementId) {
|
||||
JQPlotChart.call(this, elementId);
|
||||
this.validator = PieChart.prototype;
|
||||
};
|
||||
JQPlotPieChart.prototype = new JQPlotChart();
|
||||
JQPlotPieChart.prototype.constructor = JQPlotPieChart;
|
||||
|
||||
JQPlotPieChart.prototype.populateOptions = function (dataTable, options) {
|
||||
var optional = {
|
||||
highlighter: {
|
||||
show: true,
|
||||
tooltipAxes: 'xy',
|
||||
formatString:'%s, %d',
|
||||
useAxesFormatters: false
|
||||
},
|
||||
legend: {
|
||||
renderer: $.jqplot.EnhancedPieLegendRenderer,
|
||||
},
|
||||
};
|
||||
var compulsory = {
|
||||
seriesDefaults : {
|
||||
shadow: false,
|
||||
renderer : $.jqplot.PieRenderer,
|
||||
rendererOptions: { sliceMargin: 1, showDataLabels: true }
|
||||
}
|
||||
};
|
||||
$.extend(true, optional, options, compulsory);
|
||||
return optional;
|
||||
};
|
||||
|
||||
JQPlotPieChart.prototype.prepareData = function (dataTable) {
|
||||
var data = dataTable.getData();
|
||||
var row;
|
||||
var retData = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
row = data[i];
|
||||
retData.push([row[0], row[1]]);
|
||||
}
|
||||
return [retData];
|
||||
};
|
||||
|
||||
/**
|
||||
* Chart factory that returns JQPlotCharts
|
||||
*/
|
||||
var JQPlotChartFactory = function () {
|
||||
};
|
||||
JQPlotChartFactory.prototype = new ChartFactory();
|
||||
JQPlotChartFactory.prototype.createChart = function (type, elementId) {
|
||||
var chart = null;
|
||||
switch (type) {
|
||||
case ChartType.LINE:
|
||||
chart = new JQPlotLineChart(elementId);
|
||||
break;
|
||||
case ChartType.SPLINE:
|
||||
chart = new JQPlotSplineChart(elementId);
|
||||
break;
|
||||
case ChartType.TIMELINE:
|
||||
chart = new JQPlotTimelineChart(elementId);
|
||||
break;
|
||||
case ChartType.AREA:
|
||||
chart = new JQPlotAreaChart(elementId);
|
||||
break;
|
||||
case ChartType.BAR:
|
||||
chart = new JQPlotBarChart(elementId);
|
||||
break;
|
||||
case ChartType.COLUMN:
|
||||
chart = new JQPlotColumnChart(elementId);
|
||||
break;
|
||||
case ChartType.PIE:
|
||||
chart = new JQPlotPieChart(elementId);
|
||||
break;
|
||||
case ChartType.SCATTER:
|
||||
chart = new JQPlotScatterChart(elementId);
|
||||
break;
|
||||
}
|
||||
|
||||
return chart;
|
||||
};
|
||||
|
||||
export default JQPlotChartFactory;
|
||||
384
js/src/export.js
Normal file
384
js/src/export.js
Normal file
@ -0,0 +1,384 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
import { createTemplate, loadTemplate, updateTemplate,
|
||||
deleteTemplate, toggle_save_to_file, toggle_structure_data_opts,
|
||||
check_table_select_all, handleAddProcCheckbox, check_table_select_struture_or_data,
|
||||
check_table_selected, toggle_table_select, toggle_table_select_all_str,
|
||||
check_selected_tables, toggle_table_select_all_data, setup_table_structure_or_data,
|
||||
toggle_quick_or_custom, toggle_sql_include_comments, disable_dump_some_rows_sub_options,
|
||||
enable_dump_some_rows_sub_options, aliasToggleRow, addAlias, createAliasModal
|
||||
} from './functions/export';
|
||||
import { PMA_Messages as PMA_messages } from './variables/export_variables';
|
||||
import { PMA_commonParams } from './variables/common_params';
|
||||
import { PMA_ajaxShowMessage } from './utils/show_ajax_messages';
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
export function teardown1 () {
|
||||
$('#plugins').off('change');
|
||||
$('input[type=\'radio\'][name=\'sql_structure_or_data\']').off('change');
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').off('change');
|
||||
$('input[type=\'radio\'][name=\'output_format\']').off('change');
|
||||
$('#checkbox_sql_include_comments').off('change');
|
||||
$('input[type=\'radio\'][name=\'quick_or_custom\']').off('change');
|
||||
$('input[type=\'radio\'][name=\'allrows\']').off('change');
|
||||
$('#btn_alias_config').off('click');
|
||||
$('.alias_remove').off('click');
|
||||
$('#db_alias_button').off('click');
|
||||
$('#table_alias_button').off('click');
|
||||
$('#column_alias_button').off('click');
|
||||
$('input[name="table_select[]"]').off('change');
|
||||
$('input[name="table_structure[]"]').off('change');
|
||||
$('input[name="table_data[]"]').off('change');
|
||||
$('#table_structure_all').off('change');
|
||||
$('#table_data_all').off('change');
|
||||
$('input[name="createTemplate"]').off('click');
|
||||
$('select[name="template"]').off('change');
|
||||
$('input[name="updateTemplate"]').off('click');
|
||||
$('input[name="deleteTemplate"]').off('click');
|
||||
}
|
||||
|
||||
export function onload1 () {
|
||||
/**
|
||||
* Export template handling code
|
||||
*/
|
||||
// create a new template
|
||||
$('input[name="createTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var name = $('input[name="templateName"]').val();
|
||||
if (name.length) {
|
||||
createTemplate(name);
|
||||
}
|
||||
});
|
||||
|
||||
// load an existing template
|
||||
$('select[name="template"]').on('change', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).val();
|
||||
if (id.length) {
|
||||
loadTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
// udpate an existing template with new criteria
|
||||
$('input[name="updateTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $('select[name="template"]').val();
|
||||
if (id.length) {
|
||||
updateTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
// delete an existing template
|
||||
$('input[name="deleteTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $('select[name="template"]').val();
|
||||
if (id.length) {
|
||||
deleteTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options
|
||||
* according to the currently selected plugin from the dropdown list
|
||||
*/
|
||||
$('#plugins').on('change', function () {
|
||||
$('#format_specific_opts').find('div.format_specific_options').hide();
|
||||
var selected_plugin_name = $('#plugins').find('option:selected').val();
|
||||
$('#' + selected_plugin_name + '_options').show();
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
|
||||
*/
|
||||
$('input[type=\'radio\'][name=\'sql_structure_or_data\']').on('change', function () {
|
||||
var comments_are_present = $('#checkbox_sql_include_comments').prop('checked');
|
||||
var show = $('input[type=\'radio\'][name=\'sql_structure_or_data\']:checked').val();
|
||||
if (show === 'data') {
|
||||
// disable the SQL comment options
|
||||
if (comments_are_present) {
|
||||
$('#checkbox_sql_dates').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
}
|
||||
$('#checkbox_sql_relation').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
$('#checkbox_sql_mime').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
// enable the SQL comment options
|
||||
if (comments_are_present) {
|
||||
$('#checkbox_sql_dates').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
$('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
$('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
|
||||
if (show === 'structure') {
|
||||
$('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
});
|
||||
|
||||
// For separate-file exports only ZIP compression is allowed
|
||||
$('input[type="checkbox"][name="as_separate_files"]').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
$('#compression').val('zip');
|
||||
}
|
||||
});
|
||||
|
||||
$('#compression').on('change', function () {
|
||||
if ($('option:selected').val() !== 'zip') {
|
||||
$('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function onload2 () {
|
||||
toggle_save_to_file();
|
||||
$('input[type=\'radio\'][name=\'output_format\']').on('change', toggle_save_to_file);
|
||||
}
|
||||
|
||||
export function onload3 () {
|
||||
/**
|
||||
* For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
|
||||
*/
|
||||
var $create = $('#checkbox_sql_create_table_statements');
|
||||
var $create_options = $('#ul_create_table_statements').find('input');
|
||||
$create.on('change', function () {
|
||||
$create_options.prop('checked', $(this).prop('checked'));
|
||||
});
|
||||
$create_options.on('change', function () {
|
||||
if ($create_options.is(':checked')) {
|
||||
$create.prop('checked', true);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Disables the view output as text option if the output must be saved as a file
|
||||
*/
|
||||
$('#plugins').on('change', function () {
|
||||
var active_plugin = $('#plugins').find('option:selected').val();
|
||||
var force_file = $('#force_file_' + active_plugin).val();
|
||||
if (force_file === 'true') {
|
||||
if ($('#radio_dump_asfile').prop('checked') !== true) {
|
||||
$('#radio_dump_asfile').prop('checked', true);
|
||||
toggle_save_to_file();
|
||||
}
|
||||
$('#radio_view_as_text').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$('#radio_view_as_text').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
});
|
||||
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
|
||||
toggle_structure_data_opts();
|
||||
});
|
||||
|
||||
$('input[name="table_select[]"]').on('change', function () {
|
||||
toggle_table_select($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('input[name="table_structure[]"]').on('change', function () {
|
||||
check_table_selected($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('input[name="table_data[]"]').on('change', function () {
|
||||
check_table_selected($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('#table_structure_all').on('change', function () {
|
||||
toggle_table_select_all_str();
|
||||
check_selected_tables();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('#table_data_all').on('change', function () {
|
||||
toggle_table_select_all_data();
|
||||
check_selected_tables();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
if ($('input[name=\'export_type\']').val() === 'database') {
|
||||
// Hide structure or data radio buttons
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').each(function () {
|
||||
var $this = $(this);
|
||||
var name = $this.prop('name');
|
||||
var val = $('input[name="' + name + '"]:checked').val();
|
||||
var name_default = name + '_default';
|
||||
if (!$('input[name="' + name_default + '"]').length) {
|
||||
$this
|
||||
.after(
|
||||
$('<input type="hidden" name="' + name_default + '" value="' + val + '" disabled>')
|
||||
)
|
||||
.after(
|
||||
$('<input type="hidden" name="' + name + '" value="structure_and_data">')
|
||||
);
|
||||
$this.parent().find('label').remove();
|
||||
} else {
|
||||
$this.parent().remove();
|
||||
}
|
||||
});
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').remove();
|
||||
|
||||
// Disable CREATE table checkbox for sql
|
||||
var createTableCheckbox = $('#checkbox_sql_create_table');
|
||||
createTableCheckbox.prop('checked', true);
|
||||
var dummyCreateTable = $('#checkbox_sql_create_table')
|
||||
.clone()
|
||||
.removeAttr('id')
|
||||
.attr('type', 'hidden');
|
||||
createTableCheckbox
|
||||
.prop('disabled', true)
|
||||
.after(dummyCreateTable)
|
||||
.parent()
|
||||
.fadeTo('fast', 0.4);
|
||||
|
||||
setup_table_structure_or_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle force structure_or_data
|
||||
*/
|
||||
$('#plugins').on('change', setup_table_structure_or_data);
|
||||
}
|
||||
|
||||
export function onload4 () {
|
||||
$('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', toggle_quick_or_custom);
|
||||
|
||||
$('#scroll_to_options_msg').hide();
|
||||
$('#format_specific_opts').find('div.format_specific_options')
|
||||
.hide()
|
||||
.css({
|
||||
'border': 0,
|
||||
'margin': 0,
|
||||
'padding': 0
|
||||
})
|
||||
.find('h3')
|
||||
.remove();
|
||||
toggle_quick_or_custom();
|
||||
toggle_structure_data_opts();
|
||||
toggle_sql_include_comments();
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
|
||||
/**
|
||||
* Initially disables the "Dump some row(s)" sub-options
|
||||
*/
|
||||
disable_dump_some_rows_sub_options();
|
||||
|
||||
/**
|
||||
* Disables the "Dump some row(s)" sub-options when it is not selected
|
||||
*/
|
||||
$('input[type=\'radio\'][name=\'allrows\']').on('change', function () {
|
||||
if ($('input[type=\'radio\'][name=\'allrows\']').prop('checked')) {
|
||||
enable_dump_some_rows_sub_options();
|
||||
} else {
|
||||
disable_dump_some_rows_sub_options();
|
||||
}
|
||||
});
|
||||
|
||||
// Open Alias Modal Dialog on click
|
||||
$('#btn_alias_config').on('click', createAliasModal);
|
||||
$('.alias_remove').on('click', function () {
|
||||
$(this).parents('tr').remove();
|
||||
});
|
||||
$('#db_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
// var db = $(this).val();
|
||||
var table = PMA_commonParams.get('table');
|
||||
if (table) {
|
||||
var option = $('<option></option>');
|
||||
option.text(table);
|
||||
option.attr('value', table);
|
||||
$('#table_alias_select').append(option).val(table).trigger('change');
|
||||
} else {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : $(this).val(),
|
||||
type: 'list-tables'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.tables, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#table_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#table_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : $('#db_alias_select').val(),
|
||||
table: $(this).val(),
|
||||
type: 'list-columns'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.columns, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#column_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#column_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
});
|
||||
$('#db_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasDatabase,
|
||||
db,
|
||||
'aliases[' + db + '][alias]',
|
||||
$('#db_alias_name').val()
|
||||
);
|
||||
$('#db_alias_name').val('');
|
||||
});
|
||||
$('#table_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
var table = $('#table_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasTable,
|
||||
db + '.' + table,
|
||||
'aliases[' + db + '][tables][' + table + '][alias]',
|
||||
$('#table_alias_name').val()
|
||||
);
|
||||
$('#table_alias_name').val('');
|
||||
});
|
||||
$('#column_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
var table = $('#table_alias_select').val();
|
||||
var column = $('#column_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasColumn,
|
||||
db + '.' + table + '.' + column,
|
||||
'aliases[' + db + '][tables][' + table + '][colums][' + column + ']',
|
||||
$('#column_alias_name').val()
|
||||
);
|
||||
$('#column_alias_name').val('');
|
||||
});
|
||||
}
|
||||
66
js/src/functions/chart.js
Normal file
66
js/src/functions/chart.js
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Creates a Profiling Chart. Used in sql.js
|
||||
* and in server_status_monitor.js
|
||||
*/
|
||||
import JQPlotChartFactory from '../classes/Chart';
|
||||
|
||||
export function PMA_createProfilingChart (target, data) {
|
||||
// create the chart
|
||||
var factory = new JQPlotChartFactory();
|
||||
var chart = factory.createChart(ChartType.PIE, target);
|
||||
|
||||
// create the data table and add columns
|
||||
var dataTable = new DataTable();
|
||||
dataTable.addColumn(ColumnType.STRING, '');
|
||||
dataTable.addColumn(ColumnType.NUMBER, '');
|
||||
dataTable.setData(data);
|
||||
|
||||
var windowWidth = $(window).width();
|
||||
var location = 's';
|
||||
if (windowWidth > 768) {
|
||||
var location = 'se';
|
||||
}
|
||||
|
||||
// draw the chart and return the chart object
|
||||
chart.draw(dataTable, {
|
||||
seriesDefaults: {
|
||||
rendererOptions: {
|
||||
showDataLabels: true
|
||||
}
|
||||
},
|
||||
highlighter: {
|
||||
tooltipLocation: 'se',
|
||||
sizeAdjust: 0,
|
||||
tooltipAxes: 'pieref',
|
||||
formatString: '%s, %.9Ps'
|
||||
},
|
||||
legend: {
|
||||
show: true,
|
||||
location: location,
|
||||
rendererOptions: {
|
||||
numberColumns: 2
|
||||
}
|
||||
},
|
||||
// from http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette
|
||||
seriesColors: [
|
||||
'#fce94f',
|
||||
'#fcaf3e',
|
||||
'#e9b96e',
|
||||
'#8ae234',
|
||||
'#729fcf',
|
||||
'#ad7fa8',
|
||||
'#ef2929',
|
||||
'#888a85',
|
||||
'#c4a000',
|
||||
'#ce5c00',
|
||||
'#8f5902',
|
||||
'#4e9a06',
|
||||
'#204a87',
|
||||
'#5c3566',
|
||||
'#a40000',
|
||||
'#babdb6',
|
||||
'#2e3436'
|
||||
]
|
||||
});
|
||||
return chart;
|
||||
}
|
||||
621
js/src/functions/export.js
Normal file
621
js/src/functions/export.js
Normal file
@ -0,0 +1,621 @@
|
||||
/**
|
||||
* Functions used in the export tab
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Disables the "Dump some row(s)" sub-options
|
||||
*/
|
||||
export function disable_dump_some_rows_sub_options () {
|
||||
$('label[for=\'limit_to\']').fadeTo('fast', 0.4);
|
||||
$('label[for=\'limit_from\']').fadeTo('fast', 0.4);
|
||||
$('input[type=\'text\'][name=\'limit_to\']').prop('disabled', 'disabled');
|
||||
$('input[type=\'text\'][name=\'limit_from\']').prop('disabled', 'disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the "Dump some row(s)" sub-options
|
||||
*/
|
||||
export function enable_dump_some_rows_sub_options () {
|
||||
$('label[for=\'limit_to\']').fadeTo('fast', 1);
|
||||
$('label[for=\'limit_from\']').fadeTo('fast', 1);
|
||||
$('input[type=\'text\'][name=\'limit_to\']').prop('disabled', '');
|
||||
$('input[type=\'text\'][name=\'limit_from\']').prop('disabled', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return template data as a json object
|
||||
*
|
||||
* @returns template data
|
||||
*/
|
||||
export function getTemplateData () {
|
||||
var $form = $('form[name="dump"]');
|
||||
var blacklist = ['token', 'server', 'db', 'table', 'single_table',
|
||||
'export_type', 'export_method', 'sql_query', 'template_id'];
|
||||
var obj = {};
|
||||
var arr = $form.serializeArray();
|
||||
$.each(arr, function () {
|
||||
if ($.inArray(this.name, blacklist) < 0) {
|
||||
if (obj[this.name] !== undefined) {
|
||||
if (! obj[this.name].push) {
|
||||
obj[this.name] = [obj[this.name]];
|
||||
}
|
||||
obj[this.name].push(this.value || '');
|
||||
} else {
|
||||
obj[this.name] = this.value || '';
|
||||
}
|
||||
}
|
||||
});
|
||||
// include unchecked checboxes (which are ignored by serializeArray()) with null
|
||||
// to uncheck them when loading the template
|
||||
$form.find('input[type="checkbox"]:not(:checked)').each(function () {
|
||||
if (obj[this.name] === undefined) {
|
||||
obj[this.name] = null;
|
||||
}
|
||||
});
|
||||
// include empty multiselects
|
||||
$form.find('select').each(function () {
|
||||
if ($(this).find('option:selected').length === 0) {
|
||||
obj[this.name] = [];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a template with selected options
|
||||
*
|
||||
* @param name name of the template
|
||||
*/
|
||||
export function createTemplate (name) {
|
||||
var templateData = getTemplateData();
|
||||
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'create',
|
||||
templateName : name,
|
||||
templateData : JSON.stringify(templateData)
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$('#templateName').val('');
|
||||
$('#template').html(response.data);
|
||||
$('#template').find('option').each(function () {
|
||||
if ($(this).text() === name) {
|
||||
$(this).prop('selected', true);
|
||||
}
|
||||
});
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateCreated);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a template
|
||||
*
|
||||
* @param id ID of the template to load
|
||||
*/
|
||||
export function loadTemplate (id) {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'load',
|
||||
templateId : id,
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
var $form = $('form[name="dump"]');
|
||||
var options = JSON.parse(response.data);
|
||||
$.each(options, function (key, value) {
|
||||
var $element = $form.find('[name="' + key + '"]');
|
||||
if ($element.length) {
|
||||
if (($element.is('input') && $element.attr('type') === 'checkbox') && value === null) {
|
||||
$element.prop('checked', false);
|
||||
} else {
|
||||
if (($element.is('input') && $element.attr('type') === 'checkbox') ||
|
||||
($element.is('input') && $element.attr('type') === 'radio') ||
|
||||
($element.is('select') && $element.attr('multiple') === 'multiple')) {
|
||||
if (! value.push) {
|
||||
value = [value];
|
||||
}
|
||||
}
|
||||
$element.val(value);
|
||||
}
|
||||
$element.trigger('change');
|
||||
}
|
||||
});
|
||||
$('input[name="template_id"]').val(id);
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateLoaded);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing template with current options
|
||||
*
|
||||
* @param id ID of the template to update
|
||||
*/
|
||||
export function updateTemplate (id) {
|
||||
var templateData = getTemplateData();
|
||||
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'update',
|
||||
templateId : id,
|
||||
templateData : JSON.stringify(templateData)
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateUpdated);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a template
|
||||
*
|
||||
* @param id ID of the template to delete
|
||||
*/
|
||||
export function deleteTemplate (id) {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'delete',
|
||||
templateId : id,
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$('#template').find('option[value="' + id + '"]').remove();
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateDeleted);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function setup_table_structure_or_data () {
|
||||
if ($('input[name=\'export_type\']').val() !== 'database') {
|
||||
return;
|
||||
}
|
||||
var pluginName = $('#plugins').find('option:selected').val();
|
||||
var formElemName = pluginName + '_structure_or_data';
|
||||
var force_structure_or_data = !($('input[name=\'' + formElemName + '_default\']').length);
|
||||
|
||||
if (force_structure_or_data === true) {
|
||||
$('input[name="structure_or_data_forced"]').val(1);
|
||||
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
|
||||
.prop('disabled', true);
|
||||
$('.export_structure, .export_data').fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$('input[name="structure_or_data_forced"]').val(0);
|
||||
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
|
||||
.prop('disabled', false);
|
||||
$('.export_structure, .export_data').fadeTo('fast', 1);
|
||||
|
||||
var structure_or_data = $('input[name="' + formElemName + '_default"]').val();
|
||||
|
||||
if (structure_or_data === 'structure') {
|
||||
$('.export_data input[type="checkbox"]')
|
||||
.prop('checked', false);
|
||||
} else if (structure_or_data === 'data') {
|
||||
$('.export_structure input[type="checkbox"]')
|
||||
.prop('checked', false);
|
||||
}
|
||||
if (structure_or_data === 'structure' || structure_or_data === 'structure_and_data') {
|
||||
if (!$('.export_structure input[type="checkbox"]:checked').length) {
|
||||
$('input[name="table_select[]"]:checked')
|
||||
.closest('tr')
|
||||
.find('.export_structure input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
}
|
||||
}
|
||||
if (structure_or_data === 'data' || structure_or_data === 'structure_and_data') {
|
||||
if (!$('.export_data input[type="checkbox"]:checked').length) {
|
||||
$('input[name="table_select[]"]:checked')
|
||||
.closest('tr')
|
||||
.find('.export_data input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
}
|
||||
}
|
||||
|
||||
check_selected_tables();
|
||||
check_table_select_all();
|
||||
check_table_select_struture_or_data();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of plugin structure-specific and data-specific
|
||||
* options
|
||||
*/
|
||||
export function toggle_structure_data_opts () {
|
||||
var pluginName = $('select#plugins').val();
|
||||
var radioFormName = pluginName + '_structure_or_data';
|
||||
var dataDiv = '#' + pluginName + '_data';
|
||||
var structureDiv = '#' + pluginName + '_structure';
|
||||
var show = $('input[type=\'radio\'][name=\'' + radioFormName + '\']:checked').val();
|
||||
if (show === 'data') {
|
||||
$(dataDiv).slideDown('slow');
|
||||
$(structureDiv).slideUp('slow');
|
||||
} else {
|
||||
$(structureDiv).slideDown('slow');
|
||||
if (show === 'structure') {
|
||||
$(dataDiv).slideUp('slow');
|
||||
} else {
|
||||
$(dataDiv).slideDown('slow');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the disabling of the "save to file" options
|
||||
*/
|
||||
export function toggle_save_to_file () {
|
||||
var $ulSaveAsfile = $('#ul_save_asfile');
|
||||
if (!$('#radio_dump_asfile').prop('checked')) {
|
||||
$ulSaveAsfile.find('> li').fadeTo('fast', 0.4);
|
||||
$ulSaveAsfile.find('> li > input').prop('disabled', true);
|
||||
$ulSaveAsfile.find('> li > select').prop('disabled', true);
|
||||
} else {
|
||||
$ulSaveAsfile.find('> li').fadeTo('fast', 1);
|
||||
$ulSaveAsfile.find('> li > input').prop('disabled', false);
|
||||
$ulSaveAsfile.find('> li > select').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For SQL plugin, toggles the disabling of the "display comments" options
|
||||
*/
|
||||
export function toggle_sql_include_comments () {
|
||||
$('#checkbox_sql_include_comments').on('change', function () {
|
||||
var $ulIncludeComments = $('#ul_include_comments');
|
||||
if (!$('#checkbox_sql_include_comments').prop('checked')) {
|
||||
$ulIncludeComments.find('> li').fadeTo('fast', 0.4);
|
||||
$ulIncludeComments.find('> li > input').prop('disabled', true);
|
||||
} else {
|
||||
// If structure is not being exported, the comment options for structure should not be enabled
|
||||
if ($('#radio_sql_structure_or_data_data').prop('checked')) {
|
||||
$('#text_sql_header_comment').prop('disabled', false).parent('li').fadeTo('fast', 1);
|
||||
} else {
|
||||
$ulIncludeComments.find('> li').fadeTo('fast', 1);
|
||||
$ulIncludeComments.find('> li > input').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function check_table_select_all () {
|
||||
var total = $('input[name="table_select[]"]').length;
|
||||
var str_checked = $('input[name="table_structure[]"]:checked').length;
|
||||
var data_checked = $('input[name="table_data[]"]:checked').length;
|
||||
var str_all = $('#table_structure_all');
|
||||
var data_all = $('#table_data_all');
|
||||
|
||||
if (str_checked === total) {
|
||||
str_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', true);
|
||||
} else if (str_checked === 0) {
|
||||
str_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', false);
|
||||
} else {
|
||||
str_all
|
||||
.prop('indeterminate', true)
|
||||
.prop('checked', false);
|
||||
}
|
||||
|
||||
if (data_checked === total) {
|
||||
data_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', true);
|
||||
} else if (data_checked === 0) {
|
||||
data_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', false);
|
||||
} else {
|
||||
data_all
|
||||
.prop('indeterminate', true)
|
||||
.prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
export function check_table_select_struture_or_data () {
|
||||
var str_checked = $('input[name="table_structure[]"]:checked').length;
|
||||
var data_checked = $('input[name="table_data[]"]:checked').length;
|
||||
var auto_increment = $('#checkbox_sql_auto_increment');
|
||||
|
||||
var pluginName = $('select#plugins').val();
|
||||
var dataDiv = '#' + pluginName + '_data';
|
||||
var structureDiv = '#' + pluginName + '_structure';
|
||||
|
||||
if (str_checked === 0) {
|
||||
$(structureDiv).slideUp('slow');
|
||||
} else {
|
||||
$(structureDiv).slideDown('slow');
|
||||
}
|
||||
|
||||
if (data_checked === 0) {
|
||||
$(dataDiv).slideUp('slow');
|
||||
auto_increment.prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$(dataDiv).slideDown('slow');
|
||||
auto_increment.prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function toggle_table_select_all_str () {
|
||||
var str_all = $('#table_structure_all').is(':checked');
|
||||
if (str_all) {
|
||||
$('input[name="table_structure[]"]').prop('checked', true);
|
||||
} else {
|
||||
$('input[name="table_structure[]"]').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
export function toggle_table_select_all_data () {
|
||||
var data_all = $('#table_data_all').is(':checked');
|
||||
if (data_all) {
|
||||
$('input[name="table_data[]"]').prop('checked', true);
|
||||
} else {
|
||||
$('input[name="table_data[]"]').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
export function check_selected_tables (argument) {
|
||||
$('.export_table_select tbody tr').each(function () {
|
||||
check_table_selected(this);
|
||||
});
|
||||
}
|
||||
|
||||
export function check_table_selected (row) {
|
||||
var $row = $(row);
|
||||
var table_select = $row.find('input[name="table_select[]"]');
|
||||
var str_check = $row.find('input[name="table_structure[]"]');
|
||||
var data_check = $row.find('input[name="table_data[]"]');
|
||||
|
||||
var data = data_check.is(':checked:not(:disabled)');
|
||||
var structure = str_check.is(':checked:not(:disabled)');
|
||||
|
||||
if (data && structure) {
|
||||
table_select.prop({ checked: true, indeterminate: false });
|
||||
$row.addClass('marked');
|
||||
} else if (data || structure) {
|
||||
table_select.prop({ checked: true, indeterminate: true });
|
||||
$row.removeClass('marked');
|
||||
} else {
|
||||
table_select.prop({ checked: false, indeterminate: false });
|
||||
$row.removeClass('marked');
|
||||
}
|
||||
}
|
||||
|
||||
export function toggle_table_select (row) {
|
||||
var $row = $(row);
|
||||
var table_selected = $row.find('input[name="table_select[]"]').is(':checked');
|
||||
|
||||
if (table_selected) {
|
||||
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
|
||||
$row.addClass('marked');
|
||||
} else {
|
||||
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
|
||||
$row.removeClass('marked');
|
||||
}
|
||||
}
|
||||
|
||||
export function handleAddProcCheckbox () {
|
||||
if ($('#table_structure_all').is(':checked') === true
|
||||
&& $('#table_data_all').is(':checked') === true
|
||||
) {
|
||||
$('#checkbox_sql_procedure_function').prop('checked', true);
|
||||
} else {
|
||||
$('#checkbox_sql_procedure_function').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of options when quick and custom export are selected
|
||||
*/
|
||||
export function toggle_quick_or_custom () {
|
||||
if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
|
||||
|| $('#radio_custom_export').prop('checked') // custom
|
||||
) {
|
||||
$('#databases_and_tables').show();
|
||||
$('#rows').show();
|
||||
$('#output').show();
|
||||
$('#format_specific_opts').show();
|
||||
$('#output_quick_export').hide();
|
||||
var selected_plugin_name = $('#plugins').find('option:selected').val();
|
||||
$('#' + selected_plugin_name + '_options').show();
|
||||
} else { // quick
|
||||
$('#databases_and_tables').hide();
|
||||
$('#rows').hide();
|
||||
$('#output').hide();
|
||||
$('#format_specific_opts').hide();
|
||||
$('#output_quick_export').show();
|
||||
}
|
||||
}
|
||||
var time_out;
|
||||
export function check_time_out (time_limit) {
|
||||
if (typeof time_limit === 'undefined' || time_limit === 0) {
|
||||
return true;
|
||||
}
|
||||
// margin of one second to avoid race condition to set/access session variable
|
||||
time_limit = time_limit + 1;
|
||||
var href = 'export.php';
|
||||
var params = {
|
||||
'ajax_request' : true,
|
||||
'check_time_out' : true
|
||||
};
|
||||
clearTimeout(time_out);
|
||||
time_out = setTimeout(function () {
|
||||
$.get(href, params, function (data) {
|
||||
if (data.message === 'timeout') {
|
||||
PMA_ajaxShowMessage(
|
||||
'<div class="error">' +
|
||||
PMA_messages.strTimeOutError +
|
||||
'</div>',
|
||||
false
|
||||
);
|
||||
}
|
||||
});
|
||||
}, time_limit * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for Database/table alias select
|
||||
*
|
||||
* @param event object the event object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
export function aliasSelectHandler (event) {
|
||||
var sel = event.data.sel;
|
||||
var type = event.data.type;
|
||||
var inputId = $(this).val();
|
||||
var $label = $(this).next('label');
|
||||
$('input#' + $label.attr('for')).addClass('hide');
|
||||
$('input#' + inputId).removeClass('hide');
|
||||
$label.attr('for', inputId);
|
||||
$('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
|
||||
var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
|
||||
$inputWrapper.removeClass('hide');
|
||||
if (type === '_cols' && $inputWrapper.length > 0) {
|
||||
var outer = $inputWrapper[0].outerHTML;
|
||||
// Replace opening tags
|
||||
var regex = /<dummy_inp/gi;
|
||||
if (outer.match(regex)) {
|
||||
var newTag = outer.replace(regex, '<input');
|
||||
// Replace closing tags
|
||||
regex = /<\/dummy_inp/gi;
|
||||
newTag = newTag.replace(regex, '</input');
|
||||
// Assign replacement
|
||||
$inputWrapper.replaceWith(newTag);
|
||||
}
|
||||
} else if (type === '_tables') {
|
||||
$('.table_alias_select:visible').trigger('change');
|
||||
}
|
||||
$('#alias_modal').dialog('option', 'position', 'center');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for Alias dialog box
|
||||
*
|
||||
* @param event object the event object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
export function createAliasModal (event) {
|
||||
event.preventDefault();
|
||||
var dlgButtons = {};
|
||||
dlgButtons[PMA_messages.strSaveAndClose] = function () {
|
||||
$(this).dialog('close');
|
||||
$('#alias_modal').parent().appendTo($('form[name="dump"]'));
|
||||
};
|
||||
$('#alias_modal').dialog({
|
||||
width: Math.min($(window).width() - 100, 700),
|
||||
maxHeight: $(window).height(),
|
||||
modal: true,
|
||||
dialogClass: 'alias-dialog',
|
||||
buttons: dlgButtons,
|
||||
create: function () {
|
||||
$(this).css('maxHeight', $(window).height() - 150);
|
||||
var db = PMA_commonParams.get('db');
|
||||
if (db) {
|
||||
var option = $('<option></option>');
|
||||
option.text(db);
|
||||
option.attr('value', db);
|
||||
$('#db_alias_select').append(option).val(db).trigger('change');
|
||||
} else {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
type: 'list-databases'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.databases, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#db_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
close: function () {
|
||||
var isEmpty = true;
|
||||
$(this).find('input[type="text"]').each(function () {
|
||||
// trim empty input fields on close
|
||||
if ($(this).val()) {
|
||||
isEmpty = false;
|
||||
} else {
|
||||
$(this).parents('tr').remove();
|
||||
}
|
||||
});
|
||||
// Toggle checkbox based on aliases
|
||||
$('input#btn_alias_config').prop('checked', !isEmpty);
|
||||
},
|
||||
position: { my: 'center top', at: 'center top', of: window }
|
||||
});
|
||||
}
|
||||
|
||||
export function aliasToggleRow (elm) {
|
||||
var inputs = elm.parents('tr').find('input,button');
|
||||
if (elm.val()) {
|
||||
inputs.attr('disabled', false);
|
||||
} else {
|
||||
inputs.attr('disabled', true);
|
||||
}
|
||||
}
|
||||
|
||||
export function addAlias (type, name, field, value) {
|
||||
if (value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var row = $('#alias_data tfoot tr').clone();
|
||||
row.find('th').text(type);
|
||||
row.find('td:first').text(name);
|
||||
row.find('input').attr('name', field);
|
||||
row.find('input').val(value);
|
||||
row.find('.alias_remove').on('click', function () {
|
||||
$(this).parents('tr').remove();
|
||||
});
|
||||
|
||||
var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
|
||||
if (matching.length > 0) {
|
||||
matching.parents('tr').remove();
|
||||
}
|
||||
|
||||
$('#alias_data tbody').append(row);
|
||||
}
|
||||
41
js/src/functions/import.js
Normal file
41
js/src/functions/import.js
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Functions used in the import tab
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options
|
||||
* according to the currently selected plugin from the dropdown list
|
||||
*/
|
||||
export function changePluginOpts () {
|
||||
$('#format_specific_opts').find('div.format_specific_options').each(function () {
|
||||
$(this).hide();
|
||||
});
|
||||
var selected_plugin_name = $('#plugins').find('option:selected').val();
|
||||
$('#' + selected_plugin_name + '_options').fadeIn('slow');
|
||||
if (selected_plugin_name === 'csv') {
|
||||
$('#import_notification').text(PMA_messages.strImportCSV);
|
||||
} else {
|
||||
$('#import_notification').text('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options and sets the selected value
|
||||
* in the plugin dropdown list according to the format of the selected file
|
||||
*/
|
||||
export function matchFile (fname) {
|
||||
var fname_array = fname.toLowerCase().split('.');
|
||||
var len = fname_array.length;
|
||||
if (len !== 0) {
|
||||
var extension = fname_array[len - 1];
|
||||
if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
|
||||
len--;
|
||||
}
|
||||
// Only toggle if the format of the file can be imported
|
||||
if ($('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).length === 1) {
|
||||
$('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).prop('selected', true);
|
||||
changePluginOpts();
|
||||
}
|
||||
}
|
||||
}
|
||||
115
js/src/import.js
Normal file
115
js/src/import.js
Normal file
@ -0,0 +1,115 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
import { changePluginOpts, matchFile } from './functions/import';
|
||||
import { PMA_ajaxShowMessage } from './utils/show_ajax_messages';
|
||||
import { PMA_Messages as PMA_messages } from './variables/export_variables';
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
export function teardown1 () {
|
||||
$('#plugins').off('change');
|
||||
$('#input_import_file').off('change');
|
||||
$('#select_local_import_file').off('change');
|
||||
$('#input_import_file').off('change').off('focus');
|
||||
$('#select_local_import_file').off('focus');
|
||||
$('#text_csv_enclosed').add('#text_csv_escaped').off('keyup');
|
||||
}
|
||||
|
||||
export function onload1 () {
|
||||
// import_file_form validation.
|
||||
$(document).on('submit', '#import_file_form', function () {
|
||||
var radioLocalImport = $('#radio_local_import_file');
|
||||
var radioImport = $('#radio_import_file');
|
||||
var fileMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strImportDialogMessage + '</div>';
|
||||
|
||||
if (radioLocalImport.length !== 0) {
|
||||
// remote upload.
|
||||
|
||||
if (radioImport.is(':checked') && $('#input_import_file').val() === '') {
|
||||
$('#input_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (radioLocalImport.is(':checked')) {
|
||||
if ($('#select_local_import_file').length === 0) {
|
||||
PMA_ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strNoImportFile + ' </div>', false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($('#select_local_import_file').val() === '') {
|
||||
$('#select_local_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// local upload.
|
||||
if ($('#input_import_file').val() === '') {
|
||||
$('#input_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// show progress bar.
|
||||
$('#upload_form_status').css('display', 'inline');
|
||||
$('#upload_form_status_info').css('display', 'inline');
|
||||
});
|
||||
|
||||
// Initially display the options for the selected plugin
|
||||
changePluginOpts();
|
||||
|
||||
// Whenever the selected plugin changes, change the options displayed
|
||||
$('#plugins').on('change', function () {
|
||||
changePluginOpts();
|
||||
});
|
||||
|
||||
$('#input_import_file').on('change', function () {
|
||||
matchFile($(this).val());
|
||||
});
|
||||
|
||||
$('#select_local_import_file').on('change', function () {
|
||||
matchFile($(this).val());
|
||||
});
|
||||
|
||||
/*
|
||||
* When the "Browse the server" form is clicked or the "Select from the web server upload directory"
|
||||
* form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
|
||||
*/
|
||||
$('#input_import_file').on('focus change', function () {
|
||||
$('#radio_import_file').prop('checked', true);
|
||||
$('#radio_local_import_file').prop('checked', false);
|
||||
});
|
||||
$('#select_local_import_file').on('focus', function () {
|
||||
$('#radio_local_import_file').prop('checked', true);
|
||||
$('#radio_import_file').prop('checked', false);
|
||||
});
|
||||
|
||||
/**
|
||||
* Set up the interface for Javascript-enabled browsers since the default is for
|
||||
* Javascript-disabled browsers
|
||||
*/
|
||||
$('#scroll_to_options_msg').hide();
|
||||
$('#format_specific_opts').find('div.format_specific_options')
|
||||
.css({
|
||||
'border': 0,
|
||||
'margin': 0,
|
||||
'padding': 0
|
||||
})
|
||||
.find('h3')
|
||||
.remove();
|
||||
// $("form[name=import] *").unwrap();
|
||||
|
||||
/**
|
||||
* for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
|
||||
* as mysql allows just one character for these fields,
|
||||
* if first character is escape then allow two including escape character.
|
||||
*/
|
||||
$('#text_csv_enclosed').add('#text_csv_escaped').on('keyup', function () {
|
||||
if ($(this).val().length === 2 && $(this).val().charAt(0) !== '\\') {
|
||||
$(this).val($(this).val().substring(0, 1));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
91
js/src/replication.js
Normal file
91
js/src/replication.js
Normal file
@ -0,0 +1,91 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* for server_replication.php
|
||||
*
|
||||
*/
|
||||
var random_server_id = Math.floor(Math.random() * 10000000);
|
||||
var conf_prefix = 'server-id=' + random_server_id + '\nlog_bin=mysql-bin\nlog_error=mysql-bin.err\n';
|
||||
|
||||
function update_config () {
|
||||
var conf_ignore = 'binlog_ignore_db=';
|
||||
var conf_do = 'binlog_do_db=';
|
||||
var database_list = '';
|
||||
|
||||
if ($('#db_select option:selected').size() === 0) {
|
||||
$('#rep').text(conf_prefix);
|
||||
} else if ($('#db_type option:selected').val() === 'all') {
|
||||
$('#db_select option:selected').each(function () {
|
||||
database_list += conf_ignore + $(this).val() + '\n';
|
||||
});
|
||||
$('#rep').text(conf_prefix + database_list);
|
||||
} else {
|
||||
$('#db_select option:selected').each(function () {
|
||||
database_list += conf_do + $(this).val() + '\n';
|
||||
});
|
||||
$('#rep').text(conf_prefix + database_list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
export function teardown1 () {
|
||||
$('#db_type').off('change');
|
||||
$('#db_select').off('change');
|
||||
$('#master_status_href').off('click');
|
||||
$('#master_slaves_href').off('click');
|
||||
$('#slave_status_href').off('click');
|
||||
$('#slave_control_href').off('click');
|
||||
$('#slave_errormanagement_href').off('click');
|
||||
$('#slave_synchronization_href').off('click');
|
||||
$('#db_reset_href').off('click');
|
||||
$('#db_select_href').off('click');
|
||||
$('#reset_slave').off('click');
|
||||
}
|
||||
|
||||
export function onload1 () {
|
||||
$('#rep').text(conf_prefix);
|
||||
$('#db_type').on('change', update_config);
|
||||
$('#db_select').on('change', update_config);
|
||||
|
||||
$('#master_status_href').on('click', function () {
|
||||
$('#replication_master_section').toggle();
|
||||
});
|
||||
$('#master_slaves_href').on('click', function () {
|
||||
$('#replication_slaves_section').toggle();
|
||||
});
|
||||
$('#slave_status_href').on('click', function () {
|
||||
$('#replication_slave_section').toggle();
|
||||
});
|
||||
$('#slave_control_href').on('click', function () {
|
||||
$('#slave_control_gui').toggle();
|
||||
});
|
||||
$('#slave_errormanagement_href').on('click', function () {
|
||||
$('#slave_errormanagement_gui').toggle();
|
||||
});
|
||||
$('#slave_synchronization_href').on('click', function () {
|
||||
$('#slave_synchronization_gui').toggle();
|
||||
});
|
||||
$('#db_reset_href').on('click', function () {
|
||||
$('#db_select option:selected').prop('selected', false);
|
||||
$('#db_select').trigger('change');
|
||||
});
|
||||
$('#db_select_href').on('click', function () {
|
||||
$('#db_select option').prop('selected', true);
|
||||
$('#db_select').trigger('change');
|
||||
});
|
||||
$('#reset_slave').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var $anchor = $(this);
|
||||
var question = PMA_messages.strResetSlaveWarning;
|
||||
$anchor.PMA_confirm(question, $anchor.attr('href'), function (url) {
|
||||
PMA_ajaxShowMessage();
|
||||
AJAX.source = $anchor;
|
||||
var params = {
|
||||
'ajax_page_request': true,
|
||||
'ajax_request': true,
|
||||
};
|
||||
$.post(url, params, AJAX.responseHandler);
|
||||
});
|
||||
});
|
||||
}
|
||||
17
js/src/server_plugins.js
Normal file
17
js/src/server_plugins.js
Normal file
@ -0,0 +1,17 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions used in server plugins pages
|
||||
*/
|
||||
// import { jQuery as $ } from './utils/extend_jquery';
|
||||
export function onload1 () {
|
||||
// Make columns sortable, but only for tables with more than 1 data row
|
||||
var $tables = $('#plugins_plugins table:has(tbody tr + tr)');
|
||||
$tables.tablesorter({
|
||||
sortList: [[0, 0]],
|
||||
headers: {
|
||||
1: { sorter: false }
|
||||
}
|
||||
});
|
||||
$tables.find('thead th')
|
||||
.append('<div class="sorticon"></div>');
|
||||
}
|
||||
2180
js/src/server_status_monitor.js
Normal file
2180
js/src/server_status_monitor.js
Normal file
File diff suppressed because it is too large
Load Diff
37
js/src/server_status_queries.js
Normal file
37
js/src/server_status_queries.js
Normal file
@ -0,0 +1,37 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*/
|
||||
import { PMA_createProfilingChart } from './functions/chart';
|
||||
import { jQuery as $ } from './utils/extend_jquery';
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
import { initTableSorter } from './server_status_sorter';
|
||||
|
||||
export function teardown1 () {
|
||||
var queryPieChart = $('#serverstatusquerieschart').data('queryPieChart');
|
||||
if (queryPieChart) {
|
||||
queryPieChart.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
export function onload1 () {
|
||||
// Build query statistics chart
|
||||
var cdata = [];
|
||||
try {
|
||||
$.each($('#serverstatusquerieschart').data('chart'), function (key, value) {
|
||||
cdata.push([key, parseInt(value, 10)]);
|
||||
});
|
||||
$('#serverstatusquerieschart').data(
|
||||
'queryPieChart',
|
||||
PMA_createProfilingChart(
|
||||
'serverstatusquerieschart',
|
||||
cdata
|
||||
)
|
||||
);
|
||||
} catch (exception) {
|
||||
// Could not load chart, no big deal...
|
||||
}
|
||||
|
||||
initTableSorter('statustabs_queries');
|
||||
}
|
||||
73
js/src/server_status_sorter.js
Normal file
73
js/src/server_status_sorter.js
Normal file
@ -0,0 +1,73 @@
|
||||
import { jQuery as $ } from './utils/extend_jquery';
|
||||
import { PMA_Messages as PMA_messages } from './variables/export_variables';
|
||||
// TODO: tablesorter shouldn't sort already sorted columns
|
||||
export function initTableSorter (tabid) {
|
||||
var $table;
|
||||
var opts;
|
||||
switch (tabid) {
|
||||
case 'statustabs_queries':
|
||||
$table = $('#serverstatusqueriesdetails');
|
||||
opts = {
|
||||
sortList: [[3, 1]],
|
||||
headers: {
|
||||
// 1: { sorter: 'fancyNumber' },
|
||||
// 2: { sorter: 'fancyNumber' }
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
$table.tablesorter(opts);
|
||||
$table.find('tr:first th')
|
||||
.append('<div class="sorticon"></div>')
|
||||
.addClass('header');
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$.tablesorter.addParser({
|
||||
id: 'fancyNumber',
|
||||
is: function (s) {
|
||||
return (/^[0-9]?[0-9,\.]*\s?(k|M|GG|T|%)?$/).test(s);
|
||||
},
|
||||
format: function (s) {
|
||||
var num = $.tablesorter.formatFloat(
|
||||
s.replace(PMA_messages.strThousandsSeparator, '')
|
||||
.replace(PMA_messages.strDecimalSeparator, '.')
|
||||
);
|
||||
|
||||
var factor = 1;
|
||||
switch (s.charAt(s.length - 1)) {
|
||||
case '%':
|
||||
factor = -2;
|
||||
break;
|
||||
// Todo: Complete this list (as well as in the regexp a few lines up)
|
||||
case 'k':
|
||||
factor = 3;
|
||||
break;
|
||||
case 'M':
|
||||
factor = 6;
|
||||
break;
|
||||
case 'G':
|
||||
factor = 9;
|
||||
break;
|
||||
case 'T':
|
||||
factor = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return num * Math.pow(10, factor);
|
||||
},
|
||||
type: 'numeric'
|
||||
});
|
||||
|
||||
$.tablesorter.addParser({
|
||||
id: 'withinSpanNumber',
|
||||
is: function (s) {
|
||||
return (/<span class="original"/).test(s);
|
||||
},
|
||||
format: function (s, table, html) {
|
||||
var res = html.innerHTML.match(/<span(\s*style="display:none;"\s*)?\s*class="original">(.*)?<\/span>/);
|
||||
return (res && res.length >= 3) ? res[2] : 0;
|
||||
},
|
||||
type: 'numeric'
|
||||
});
|
||||
});
|
||||
45
js/src/server_user_groups.js
Normal file
45
js/src/server_user_groups.js
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
import { PMA_Messages as PMA_messages } from './variables/export_variables';
|
||||
import { PMA_sprintf } from './utils/sprintf';
|
||||
import { escapeHtml } from './utils/Sanitise';
|
||||
|
||||
export function teardown1 () {
|
||||
$(document).off('click', 'a.deleteUserGroup.ajax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind event handlers
|
||||
*/
|
||||
export function onload1 () {
|
||||
// update the checkall checkbox on Edit user group page
|
||||
$(checkboxes_sel).trigger('change');
|
||||
|
||||
$(document).on('click', 'a.deleteUserGroup.ajax', function (event) {
|
||||
event.preventDefault();
|
||||
var $link = $(this);
|
||||
var groupName = $link.parents('tr').find('td:first').text();
|
||||
var buttonOptions = {};
|
||||
buttonOptions[PMA_messages.strGo] = function () {
|
||||
$(this).dialog('close');
|
||||
$link.removeClass('ajax').trigger('click');
|
||||
};
|
||||
buttonOptions[PMA_messages.strClose] = function () {
|
||||
$(this).dialog('close');
|
||||
};
|
||||
$('<div/>')
|
||||
.attr('id', 'confirmUserGroupDeleteDialog')
|
||||
.append(PMA_sprintf(PMA_messages.strDropUserGroupWarning, escapeHtml(groupName)))
|
||||
.dialog({
|
||||
width: 300,
|
||||
minWidth: 200,
|
||||
modal: true,
|
||||
buttons: buttonOptions,
|
||||
title: PMA_messages.strConfirm,
|
||||
close: function () {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
113
js/src/server_variables.js
Normal file
113
js/src/server_variables.js
Normal file
@ -0,0 +1,113 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
import { PMA_Messages as PMA_messages } from './variables/export_variables';
|
||||
import { PMA_ajaxShowMessage, PMA_ajaxRemoveMessage } from './utils/show_ajax_messages';
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
export function teardown1 () {
|
||||
$(document).off('click', 'a.editLink');
|
||||
$('#serverVariables').find('.var-name').find('a img').remove();
|
||||
}
|
||||
|
||||
export function onload1 () {
|
||||
// var $editLink = $('a.editLink');
|
||||
var $saveLink = $('a.saveLink');
|
||||
var $cancelLink = $('a.cancelLink');
|
||||
|
||||
$('#serverVariables').find('.var-name').find('a').append(
|
||||
$('#docImage').clone().css('display', 'inline-block')
|
||||
);
|
||||
|
||||
/* Launches the variable editor */
|
||||
$(document).on('click', 'a.editLink', function (event) {
|
||||
event.preventDefault();
|
||||
editVariable(this);
|
||||
});
|
||||
|
||||
/* Allows the user to edit a server variable */
|
||||
function editVariable (link) {
|
||||
var $link = $(link);
|
||||
var $cell = $link.parent();
|
||||
var $valueCell = $link.parents('.var-row').find('.var-value');
|
||||
var varName = $link.data('variable');
|
||||
var $mySaveLink = $saveLink.clone().css('display', 'inline-block');
|
||||
var $myCancelLink = $cancelLink.clone().css('display', 'inline-block');
|
||||
var $msgbox = PMA_ajaxShowMessage();
|
||||
var $myEditLink = $cell.find('a.editLink');
|
||||
|
||||
$cell.addClass('edit'); // variable is being edited
|
||||
$myEditLink.remove(); // remove edit link
|
||||
|
||||
$mySaveLink.on('click', function () {
|
||||
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
||||
$.post($(this).attr('href'), {
|
||||
ajax_request: true,
|
||||
type: 'setval',
|
||||
varName: varName,
|
||||
varValue: $valueCell.find('input').val()
|
||||
}, function (data) {
|
||||
if (data.success) {
|
||||
$valueCell
|
||||
.html(data.variable)
|
||||
.data('content', data.variable);
|
||||
PMA_ajaxRemoveMessage($msgbox);
|
||||
} else {
|
||||
if (data.error === '') {
|
||||
PMA_ajaxShowMessage(PMA_messages.strRequestFailed, false);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(data.error, false);
|
||||
}
|
||||
$valueCell.html($valueCell.data('content'));
|
||||
}
|
||||
$cell.removeClass('edit').html($myEditLink);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$myCancelLink.on('click', function () {
|
||||
$valueCell.html($valueCell.data('content'));
|
||||
$cell.removeClass('edit').html($myEditLink);
|
||||
return false;
|
||||
});
|
||||
|
||||
$.get($mySaveLink.attr('href'), {
|
||||
ajax_request: true,
|
||||
type: 'getval',
|
||||
varName: varName
|
||||
}, function (data) {
|
||||
if (typeof data !== 'undefined' && data.success === true) {
|
||||
var $links = $('<div />')
|
||||
.append($myCancelLink)
|
||||
.append(' ')
|
||||
.append($mySaveLink);
|
||||
var $editor = $('<div />', { 'class': 'serverVariableEditor' })
|
||||
.append(
|
||||
$('<div/>').append(
|
||||
$('<input />', { type: 'text' }).val(data.message)
|
||||
)
|
||||
);
|
||||
// Save and replace content
|
||||
$cell
|
||||
.html($links)
|
||||
.children()
|
||||
.css('display', 'flex');
|
||||
$valueCell
|
||||
.data('content', $valueCell.html())
|
||||
.html($editor)
|
||||
.find('input')
|
||||
.focus()
|
||||
.on('keydown', function (event) { // Keyboard shortcuts
|
||||
if (event.keyCode === 13) { // Enter key
|
||||
$mySaveLink.trigger('click');
|
||||
} else if (event.keyCode === 27) { // Escape key
|
||||
$myCancelLink.trigger('click');
|
||||
}
|
||||
});
|
||||
PMA_ajaxRemoveMessage($msgbox);
|
||||
} else {
|
||||
$cell.removeClass('edit').html($myEditLink);
|
||||
PMA_ajaxShowMessage(data.error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,7 @@ class ServerPluginsController extends Controller
|
||||
$header = $this->response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
|
||||
$scripts->addFile('server_plugins.js');
|
||||
$scripts->addFile('server_plugins');
|
||||
|
||||
/**
|
||||
* Displays the page
|
||||
|
||||
@ -71,7 +71,7 @@ class ServerVariablesController extends Controller
|
||||
|
||||
$header = $this->response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_variables.js');
|
||||
$scripts->addFile('server_variables');
|
||||
|
||||
/**
|
||||
* Displays the sub-page heading
|
||||
|
||||
@ -22,7 +22,7 @@ PageSettings::showGroup('Export');
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('export.js');
|
||||
$scripts->addFile('export');
|
||||
|
||||
$export_page_title = __('View dump (schema) of databases') . "\n";
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ PageSettings::showGroup('Import');
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('import.js');
|
||||
$scripts->addFile('import');
|
||||
|
||||
/**
|
||||
* Does the common work
|
||||
|
||||
@ -26,7 +26,7 @@ $response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_privileges');
|
||||
$scripts->addFile('replication.js');
|
||||
$scripts->addFile('replication');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
|
||||
@ -30,8 +30,8 @@ $scripts->addFile('vendor/jqplot/plugins/jqplot.pieRenderer.js');
|
||||
$scripts->addFile('vendor/jqplot/plugins/jqplot.highlighter.js');
|
||||
$scripts->addFile('vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js');
|
||||
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
|
||||
$scripts->addFile('server_status_sorter.js');
|
||||
$scripts->addFile('server_status_queries.js');
|
||||
$scripts->addFile('server_status_sorter');
|
||||
$scripts->addFile('server_status_queries');
|
||||
|
||||
// Add the html content to the response
|
||||
$response->addHTML('<div>');
|
||||
|
||||
@ -23,7 +23,7 @@ if (! $GLOBALS['cfgRelation']['menuswork']) {
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_user_groups.js');
|
||||
$scripts->addFile('server_user_groups');
|
||||
|
||||
/**
|
||||
* Only allowed to superuser
|
||||
|
||||
Loading…
Reference in New Issue
Block a user