Refactor DB designer JS to use modules

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-02-04 18:26:08 -03:00
parent 3bafef8f2b
commit ede1e82c28
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
8 changed files with 392 additions and 392 deletions

View File

@ -233,4 +233,5 @@ var DesignerOfflineDB = (function () {
// Export the designerDB object.
return designerDB;
}());
window.DesignerOfflineDB = DesignerOfflineDB;
export { DesignerOfflineDB };

View File

@ -1,5 +1,4 @@
import $ from 'jquery';
import { AJAX } from '../modules/ajax.js';
import { Functions } from '../modules/functions.js';
import getImageTag from '../modules/functions/getImageTag.js';
@ -13,48 +12,58 @@ import getImageTag from '../modules/functions/getImageTag.js';
/* global themeImagePath */ // templates/javascript/variables.twig
var DesignerHistory = {};
window.DesignerHistory = DesignerHistory;
var historyArray = []; // Global array to store history objects
var selectField = []; // Global array to store information for columns which are used in select clause
/**
* Global array to store history objects.
* @type {Array}
*/
DesignerHistory.historyArray = [];
/**
* Global array to store information for columns which are used in select clause.
* @type {Array}
*/
DesignerHistory.selectField = [];
DesignerHistory.vqbEditor = null;
var gIndex;
var vqbEditor = null;
/**
* To display details of objects(where,rename,Having,aggregate,groupby,orderby,having)
*
* @param {number} index index of historyArray where change is to be made
* @param {number} index index of DesignerHistory.historyArray where change is to be made
* @return {string}
*/
DesignerHistory.detail = function (index) {
var type = historyArray[index].getType();
var type = DesignerHistory.historyArray[index].getType();
var str;
if (type === 'Where') {
str = 'Where ' + historyArray[index].getColumnName() + historyArray[index].getObj().getRelationOperator() + historyArray[index].getObj().getQuery();
str = 'Where ' + DesignerHistory.historyArray[index].getColumnName() + DesignerHistory.historyArray[index].getObj().getRelationOperator() + DesignerHistory.historyArray[index].getObj().getQuery();
} else if (type === 'Rename') {
str = 'Rename ' + historyArray[index].getColumnName() + ' To ' + historyArray[index].getObj().getRenameTo();
str = 'Rename ' + DesignerHistory.historyArray[index].getColumnName() + ' To ' + DesignerHistory.historyArray[index].getObj().getRenameTo();
} else if (type === 'Aggregate') {
str = 'Select ' + historyArray[index].getObj().getOperator() + '( ' + historyArray[index].getColumnName() + ' )';
str = 'Select ' + DesignerHistory.historyArray[index].getObj().getOperator() + '( ' + DesignerHistory.historyArray[index].getColumnName() + ' )';
} else if (type === 'GroupBy') {
str = 'GroupBy ' + historyArray[index].getColumnName();
str = 'GroupBy ' + DesignerHistory.historyArray[index].getColumnName();
} else if (type === 'OrderBy') {
str = 'OrderBy ' + historyArray[index].getColumnName() + ' ' + historyArray[index].getObj().getOrder();
str = 'OrderBy ' + DesignerHistory.historyArray[index].getColumnName() + ' ' + DesignerHistory.historyArray[index].getObj().getOrder();
} else if (type === 'Having') {
str = 'Having ';
if (historyArray[index].getObj().getOperator() !== 'None') {
str += historyArray[index].getObj().getOperator() + '( ' + historyArray[index].getColumnName() + ' )';
str += historyArray[index].getObj().getRelationOperator() + historyArray[index].getObj().getQuery();
if (DesignerHistory.historyArray[index].getObj().getOperator() !== 'None') {
str += DesignerHistory.historyArray[index].getObj().getOperator() + '( ' + DesignerHistory.historyArray[index].getColumnName() + ' )';
str += DesignerHistory.historyArray[index].getObj().getRelationOperator() + DesignerHistory.historyArray[index].getObj().getQuery();
} else {
str = 'Having ' + historyArray[index].getColumnName() + historyArray[index].getObj().getRelationOperator() + historyArray[index].getObj().getQuery();
str = 'Having ' + DesignerHistory.historyArray[index].getColumnName() + DesignerHistory.historyArray[index].getObj().getRelationOperator() + DesignerHistory.historyArray[index].getObj().getQuery();
}
}
return str;
};
/**
* Sorts historyArray[] first,using table name as the key and then generates the HTML code for history tab,
* Sorts DesignerHistory.historyArray[] first,using table name as the key and then generates the HTML code for history tab,
* clubbing all objects of same tables together
* This function is called whenever changes are made in historyArray[]
* This function is called whenever changes are made in DesignerHistory.historyArray[]
*
*
* @param {number} init starting index of unsorted array
@ -70,44 +79,44 @@ DesignerHistory.display = function (init, finit) {
var temp;
// this part sorts the history array based on table name,this is needed for clubbing all object of same name together.
for (i = init; i < finit; i++) {
sto = historyArray[i];
temp = historyArray[i].getTab();// + '.' + historyArray[i].getObjNo(); for Self JOINS
sto = DesignerHistory.historyArray[i];
temp = DesignerHistory.historyArray[i].getTab();// + '.' + DesignerHistory.historyArray[i].getObjNo(); for Self JOINS
for (j = 0; j < i; j++) {
if (temp > (historyArray[j].getTab())) {// + '.' + historyArray[j].getObjNo())) { //for Self JOINS
if (temp > (DesignerHistory.historyArray[j].getTab())) {// + '.' + DesignerHistory.historyArray[j].getObjNo())) { //for Self JOINS
for (k = i; k > j; k--) {
historyArray[k] = historyArray[k - 1];
DesignerHistory.historyArray[k] = DesignerHistory.historyArray[k - 1];
}
historyArray[j] = sto;
DesignerHistory.historyArray[j] = sto;
break;
}
}
}
// this part generates HTML code for history tab.adds delete,edit,and/or and detail features with objects.
str = ''; // string to store Html code for history tab
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
temp = historyArray[i].getTab(); // + '.' + historyArray[i].getObjNo(); for Self JOIN
temp = DesignerHistory.historyArray[i].getTab(); // + '.' + DesignerHistory.historyArray[i].getObjNo(); for Self JOIN
str += '<h3 class="tiger"><a href="#">' + temp + '</a></h3>';
str += '<div class="toggle_container">\n';
while ((historyArray[i].getTab()) === temp) { // + '.' + historyArray[i].getObjNo()) === temp) {
while ((DesignerHistory.historyArray[i].getTab()) === temp) { // + '.' + DesignerHistory.historyArray[i].getObjNo()) === temp) {
str += '<div class="block"> <table class="table table-sm w-auto mb-0">';
str += '<thead><tr><td>';
if (historyArray[i].getAndOr()) {
if (DesignerHistory.historyArray[i].getAndOr()) {
str += '<img src="' + themeImagePath + 'designer/or_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="OR"></td>';
} else {
str += '<img src="' + themeImagePath + 'designer/and_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="AND"></td>';
}
str += '<td style="padding-left: 5px;" class="text-end">' + getImageTag('b_sbrowse', window.Messages.strColumnName) + '</td>' +
'<td width="175" style="padding-left: 5px">' + $('<div/>').text(historyArray[i].getColumnName()).html() + '<td>';
if (historyArray[i].getType() === 'GroupBy' || historyArray[i].getType() === 'OrderBy') {
'<td width="175" style="padding-left: 5px">' + $('<div/>').text(DesignerHistory.historyArray[i].getColumnName()).html() + '<td>';
if (DesignerHistory.historyArray[i].getType() === 'GroupBy' || DesignerHistory.historyArray[i].getType() === 'OrderBy') {
var detailDescGroupBy = $('<div/>').text(DesignerHistory.detail(i)).html();
str += '<td class="text-center">' + getImageTag('s_info', DesignerHistory.detail(i)) + '</td>' +
'<td title="' + detailDescGroupBy + '">' + historyArray[i].getType() + '</td>' +
'<td title="' + detailDescGroupBy + '">' + DesignerHistory.historyArray[i].getType() + '</td>' +
'<td onclick=DesignerHistory.historyDelete(' + i + ')>' + getImageTag('b_drop', window.Messages.strDelete) + '</td>';
} else {
var detailDesc = $('<div/>').text(DesignerHistory.detail(i)).html();
str += '<td class="text-center">' + getImageTag('s_info', DesignerHistory.detail(i)) + '</td>' +
'<td title="' + detailDesc + '">' + historyArray[i].getType() + '</td>' +
'<td title="' + detailDesc + '">' + DesignerHistory.historyArray[i].getType() + '</td>' +
'<td onclick=DesignerHistory.historyEdit(' + i + ')>' + getImageTag('b_edit', window.Messages.strEdit) + '</td>' +
'<td onclick=DesignerHistory.historyDelete(' + i + ')>' + getImageTag('b_drop', window.Messages.strDelete) + '</td>';
}
@ -128,14 +137,14 @@ DesignerHistory.display = function (init, finit) {
* To change And/Or relation in history tab
*
*
* @param {number} index index of historyArray where change is to be made
* @param {number} index index of DesignerHistory.historyArray where change is to be made
* @return {void}
*/
DesignerHistory.andOr = function (index) {
if (historyArray[index].getAndOr()) {
historyArray[index].setAndOr(0);
if (DesignerHistory.historyArray[index].getAndOr()) {
DesignerHistory.historyArray[index].setAndOr(0);
} else {
historyArray[index].setAndOr(1);
DesignerHistory.historyArray[index].setAndOr(1);
}
var existingDiv = document.getElementById('ab');
existingDiv.innerHTML = DesignerHistory.display(0, 0);
@ -143,20 +152,20 @@ DesignerHistory.andOr = function (index) {
};
/**
* Deletes entry in historyArray
* Deletes entry in DesignerHistory.historyArray
*
* @param {number} index of historyArray[] which is to be deleted
* @param {number} index of DesignerHistory.historyArray[] which is to be deleted
* @return {void}
*/
DesignerHistory.historyDelete = function (index) {
var fromArrayLength = window.fromArray.length;
for (var k = 0; k < fromArrayLength; k++) {
if (window.fromArray[k] === historyArray[index].getTab()) {
if (window.fromArray[k] === DesignerHistory.historyArray[index].getTab()) {
window.fromArray.splice(k, 1);
break;
}
}
historyArray.splice(index, 1);
DesignerHistory.historyArray.splice(index, 1);
var existingDiv = document.getElementById('ab');
existingDiv.innerHTML = DesignerHistory.display(0, 0);
$('#ab').accordion('refresh');
@ -179,61 +188,61 @@ DesignerHistory.changeStyle = function (elementId) {
/**
* To show where,rename,aggregate,having forms to edit a object
*
* @param {number} index index of historyArray where change is to be made
* @param {number} index index of DesignerHistory.historyArray where change is to be made
* @return {void}
*/
DesignerHistory.historyEdit = function (index) {
gIndex = index;
var type = historyArray[index].getType();
var type = DesignerHistory.historyArray[index].getType();
if (type === 'Where') {
document.getElementById('eQuery').value = historyArray[index].getObj().getQuery();
document.getElementById('erel_opt').value = historyArray[index].getObj().getRelationOperator();
document.getElementById('eQuery').value = DesignerHistory.historyArray[index].getObj().getQuery();
document.getElementById('erel_opt').value = DesignerHistory.historyArray[index].getObj().getRelationOperator();
DesignerHistory.changeStyle('query_where');
} else if (type === 'Having') {
document.getElementById('hQuery').value = historyArray[index].getObj().getQuery();
document.getElementById('hrel_opt').value = historyArray[index].getObj().getRelationOperator();
document.getElementById('hoperator').value = historyArray[index].getObj().getOperator();
document.getElementById('hQuery').value = DesignerHistory.historyArray[index].getObj().getQuery();
document.getElementById('hrel_opt').value = DesignerHistory.historyArray[index].getObj().getRelationOperator();
document.getElementById('hoperator').value = DesignerHistory.historyArray[index].getObj().getOperator();
DesignerHistory.changeStyle('query_having');
} else if (type === 'Rename') {
document.getElementById('e_rename').value = historyArray[index].getObj().getRenameTo();
document.getElementById('e_rename').value = DesignerHistory.historyArray[index].getObj().getRenameTo();
DesignerHistory.changeStyle('query_rename_to');
} else if (type === 'Aggregate') {
document.getElementById('e_operator').value = historyArray[index].getObj().getOperator();
document.getElementById('e_operator').value = DesignerHistory.historyArray[index].getObj().getOperator();
DesignerHistory.changeStyle('query_Aggregate');
}
};
/**
* Make changes in historyArray when Edit button is clicked
* Make changes in DesignerHistory.historyArray when Edit button is clicked
* checks for the type of object and then sets the new value
*
* @param {string} type of historyArray where change is to be made
* @param {string} type of DesignerHistory.historyArray where change is to be made
* @return {void}
*/
DesignerHistory.edit = function (type) {
if (type === 'Rename') {
if (document.getElementById('e_rename').value !== '') {
historyArray[gIndex].getObj().setRenameTo(document.getElementById('e_rename').value);
DesignerHistory.historyArray[gIndex].getObj().setRenameTo(document.getElementById('e_rename').value);
document.getElementById('e_rename').value = '';
}
document.getElementById('query_rename_to').style.visibility = 'hidden';
} else if (type === 'Aggregate') {
if (document.getElementById('e_operator').value !== '---') {
historyArray[gIndex].getObj().setOperator(document.getElementById('e_operator').value);
DesignerHistory.historyArray[gIndex].getObj().setOperator(document.getElementById('e_operator').value);
document.getElementById('e_operator').value = '---';
}
document.getElementById('query_Aggregate').style.visibility = 'hidden';
} else if (type === 'Where') {
if (document.getElementById('erel_opt').value !== '--' && document.getElementById('eQuery').value !== '') {
historyArray[gIndex].getObj().setQuery(document.getElementById('eQuery').value);
historyArray[gIndex].getObj().setRelationOperator(document.getElementById('erel_opt').value);
DesignerHistory.historyArray[gIndex].getObj().setQuery(document.getElementById('eQuery').value);
DesignerHistory.historyArray[gIndex].getObj().setRelationOperator(document.getElementById('erel_opt').value);
}
document.getElementById('query_where').style.visibility = 'hidden';
} else if (type === 'Having') {
if (document.getElementById('hrel_opt').value !== '--' && document.getElementById('hQuery').value !== '') {
historyArray[gIndex].getObj().setQuery(document.getElementById('hQuery').value);
historyArray[gIndex].getObj().setRelationOperator(document.getElementById('hrel_opt').value);
historyArray[gIndex].getObj().setOperator(document.getElementById('hoperator').value);
DesignerHistory.historyArray[gIndex].getObj().setQuery(document.getElementById('hQuery').value);
DesignerHistory.historyArray[gIndex].getObj().setRelationOperator(document.getElementById('hrel_opt').value);
DesignerHistory.historyArray[gIndex].getObj().setOperator(document.getElementById('hoperator').value);
}
document.getElementById('query_having').style.visibility = 'hidden';
}
@ -502,10 +511,10 @@ DesignerHistory.removeArray = function (rem, arr) {
DesignerHistory.queryGroupBy = function () {
var i;
var str = '';
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
if (historyArray[i].getType() === 'GroupBy') {
str += '`' + historyArray[i].getColumnName() + '`, ';
if (DesignerHistory.historyArray[i].getType() === 'GroupBy') {
str += '`' + DesignerHistory.historyArray[i].getColumnName() + '`, ';
}
}
str = str.substring(0, str.length - 2);
@ -519,14 +528,14 @@ DesignerHistory.queryGroupBy = function () {
DesignerHistory.queryHaving = function () {
var i;
var and = '(';
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
if (historyArray[i].getType() === 'Having') {
if (historyArray[i].getObj().getOperator() !== 'None') {
and += historyArray[i].getObj().getOperator() + '(`' + historyArray[i].getColumnName() + '`) ' + historyArray[i].getObj().getRelationOperator();
and += ' ' + historyArray[i].getObj().getQuery() + ', ';
if (DesignerHistory.historyArray[i].getType() === 'Having') {
if (DesignerHistory.historyArray[i].getObj().getOperator() !== 'None') {
and += DesignerHistory.historyArray[i].getObj().getOperator() + '(`' + DesignerHistory.historyArray[i].getColumnName() + '`) ' + DesignerHistory.historyArray[i].getObj().getRelationOperator();
and += ' ' + DesignerHistory.historyArray[i].getObj().getQuery() + ', ';
} else {
and += '`' + historyArray[i].getColumnName() + '` ' + historyArray[i].getObj().getRelationOperator() + ' ' + historyArray[i].getObj().getQuery() + ', ';
and += '`' + DesignerHistory.historyArray[i].getColumnName() + '` ' + DesignerHistory.historyArray[i].getObj().getRelationOperator() + ' ' + DesignerHistory.historyArray[i].getObj().getQuery() + ', ';
}
}
}
@ -546,11 +555,11 @@ DesignerHistory.queryHaving = function () {
DesignerHistory.queryOrderBy = function () {
var i;
var str = '';
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
if (historyArray[i].getType() === 'OrderBy') {
str += '`' + historyArray[i].getColumnName() + '` ' +
historyArray[i].getObj().getOrder() + ', ';
if (DesignerHistory.historyArray[i].getType() === 'OrderBy') {
str += '`' + DesignerHistory.historyArray[i].getColumnName() + '` ' +
DesignerHistory.historyArray[i].getObj().getOrder() + ', ';
}
}
str = str.substring(0, str.length - 2);
@ -566,14 +575,14 @@ DesignerHistory.queryWhere = function () {
var i;
var and = '(';
var or = '(';
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
if (historyArray[i].getType() === 'Where') {
if (historyArray[i].getAndOr() === 0) {
and += '( `' + historyArray[i].getColumnName() + '` ' + historyArray[i].getObj().getRelationOperator() + ' ' + historyArray[i].getObj().getQuery() + ')';
if (DesignerHistory.historyArray[i].getType() === 'Where') {
if (DesignerHistory.historyArray[i].getAndOr() === 0) {
and += '( `' + DesignerHistory.historyArray[i].getColumnName() + '` ' + DesignerHistory.historyArray[i].getObj().getRelationOperator() + ' ' + DesignerHistory.historyArray[i].getObj().getQuery() + ')';
and += ' AND ';
} else {
or += '( `' + historyArray[i].getColumnName() + '` ' + historyArray[i].getObj().getRelationOperator() + ' ' + historyArray[i].getObj().getQuery() + ')';
or += '( `' + DesignerHistory.historyArray[i].getColumnName() + '` ' + DesignerHistory.historyArray[i].getObj().getRelationOperator() + ' ' + DesignerHistory.historyArray[i].getObj().getQuery() + ')';
or += ' OR ';
}
}
@ -596,11 +605,11 @@ DesignerHistory.queryWhere = function () {
DesignerHistory.checkAggregate = function (idThis) {
var i;
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
var temp = '`' + historyArray[i].getTab() + '`.`' + historyArray[i].getColumnName() + '`';
if (temp === idThis && historyArray[i].getType() === 'Aggregate') {
return historyArray[i].getObj().getOperator() + '(' + idThis + ')';
var temp = '`' + DesignerHistory.historyArray[i].getTab() + '`.`' + DesignerHistory.historyArray[i].getColumnName() + '`';
if (temp === idThis && DesignerHistory.historyArray[i].getType() === 'Aggregate') {
return DesignerHistory.historyArray[i].getObj().getOperator() + '(' + idThis + ')';
}
}
return '';
@ -608,11 +617,11 @@ DesignerHistory.checkAggregate = function (idThis) {
DesignerHistory.checkRename = function (idThis) {
var i;
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
var temp = '`' + historyArray[i].getTab() + '`.`' + historyArray[i].getColumnName() + '`';
if (temp === idThis && historyArray[i].getType() === 'Rename') {
return ' AS `' + historyArray[i].getObj().getRenameTo() + '`';
var temp = '`' + DesignerHistory.historyArray[i].getTab() + '`.`' + DesignerHistory.historyArray[i].getColumnName() + '`';
if (temp === idThis && DesignerHistory.historyArray[i].getType() === 'Rename') {
return ' AS `' + DesignerHistory.historyArray[i].getObj().getRenameTo() + '`';
}
}
return '';
@ -645,9 +654,9 @@ DesignerHistory.queryFrom = function () {
// the constraints that have been used in the LEFT JOIN
var constraintsAdded = [];
var historyArrayLength = historyArray.length;
var historyArrayLength = DesignerHistory.historyArray.length;
for (i = 0; i < historyArrayLength; i++) {
window.fromArray.push(historyArray[i].getTab());
window.fromArray.push(DesignerHistory.historyArray[i].getTab());
}
window.fromArray = DesignerHistory.unique(window.fromArray);
tabLeft = window.fromArray;
@ -740,17 +749,17 @@ DesignerHistory.queryFrom = function () {
DesignerHistory.buildQuery = function () {
var qSelect = 'SELECT ';
var temp;
var selectFieldLength = selectField.length;
var selectFieldLength = DesignerHistory.selectField.length;
if (selectFieldLength > 0) {
for (var i = 0; i < selectFieldLength; i++) {
temp = DesignerHistory.checkAggregate(selectField[i]);
temp = DesignerHistory.checkAggregate(DesignerHistory.selectField[i]);
if (temp !== '') {
qSelect += temp;
temp = DesignerHistory.checkRename(selectField[i]);
temp = DesignerHistory.checkRename(DesignerHistory.selectField[i]);
qSelect += temp + ', ';
} else {
temp = DesignerHistory.checkRename(selectField[i]);
qSelect += selectField[i] + temp + ', ';
temp = DesignerHistory.checkRename(DesignerHistory.selectField[i]);
qSelect += DesignerHistory.selectField[i] + temp + ', ';
}
}
qSelect = qSelect.substring(0, qSelect.length - 2);
@ -780,10 +789,10 @@ DesignerHistory.buildQuery = function () {
qSelect += '\nORDER BY ' + qOrderBy;
}
$('#buildQuerySubmitButton').on('click', function () {
if (vqbEditor) {
if (DesignerHistory.vqbEditor) {
var $elm = $('#buildQueryModal').find('textarea');
vqbEditor.save();
$elm.val(vqbEditor.getValue());
DesignerHistory.vqbEditor.save();
$elm.val(DesignerHistory.vqbEditor.getValue());
}
$('#vqb_form').trigger('submit');
});
@ -797,12 +806,12 @@ DesignerHistory.buildQuery = function () {
* to the query textarea.
*/
var $elm = $('#buildQueryModal').find('textarea');
if (! vqbEditor) {
vqbEditor = Functions.getSqlEditor($elm);
if (! DesignerHistory.vqbEditor) {
DesignerHistory.vqbEditor = Functions.getSqlEditor($elm);
}
if (vqbEditor) {
vqbEditor.setValue(qSelect);
vqbEditor.focus();
if (DesignerHistory.vqbEditor) {
DesignerHistory.vqbEditor.setValue(qSelect);
DesignerHistory.vqbEditor.focus();
} else {
$elm.val(qSelect);
$elm.trigger('focus');
@ -810,28 +819,7 @@ DesignerHistory.buildQuery = function () {
});
};
AJAX.registerTeardown('designer/history.js', function () {
vqbEditor = null;
historyArray = [];
selectField = [];
$('#ok_edit_rename').off('click');
$('#ok_edit_having').off('click');
$('#ok_edit_Aggr').off('click');
$('#ok_edit_where').off('click');
});
// @ts-ignore
window.DesignerHistory = DesignerHistory;
AJAX.registerOnload('designer/history.js', function () {
$('#ok_edit_rename').on('click', function () {
DesignerHistory.edit('Rename');
});
$('#ok_edit_having').on('click', function () {
DesignerHistory.edit('Having');
});
$('#ok_edit_Aggr').on('click', function () {
DesignerHistory.edit('Aggregate');
});
$('#ok_edit_where').on('click', function () {
DesignerHistory.edit('Where');
});
$('#ab').accordion({ collapsible: true, active: 'none' });
});
export { DesignerHistory };

View File

@ -1,16 +1,261 @@
import $ from 'jquery';
import { AJAX } from '../modules/ajax.js';
import { DesignerOfflineDB } from './database.js';
import { DesignerHistory } from './history.js';
import { DesignerMove } from './move.js';
import { DesignerPage } from './page.js';
/**
* Initializes the data required to run Designer, then fires it up.
*/
/* global DesignerOfflineDB */ // js/designer/database.js
/* global DesignerHistory */ // js/designer/history.js
/* global DesignerMove */ // js/designer/move.js
/* global DesignerPage */ // js/designer/page.js
/* global designerConfig */ // templates/database/designer/main.twig
AJAX.registerTeardown('designer/init.js', function () {
DesignerHistory.vqbEditor = null;
DesignerHistory.historyArray = [];
DesignerHistory.selectField = [];
$('#ok_edit_rename').off('click');
$('#ok_edit_having').off('click');
$('#ok_edit_Aggr').off('click');
$('#ok_edit_where').off('click');
});
AJAX.registerOnload('designer/init.js', function () {
$('#ok_edit_rename').on('click', function () {
DesignerHistory.edit('Rename');
});
$('#ok_edit_having').on('click', function () {
DesignerHistory.edit('Having');
});
$('#ok_edit_Aggr').on('click', function () {
DesignerHistory.edit('Aggregate');
});
$('#ok_edit_where').on('click', function () {
DesignerHistory.edit('Where');
});
$('#ab').accordion({ collapsible: true, active: 'none' });
});
AJAX.registerTeardown('designer/init.js', function () {
$(document).off('fullscreenchange');
$('#selflink').show();
});
AJAX.registerOnload('designer/init.js', function () {
var $content = $('#page_content');
var $img = $('#toggleFullscreen').find('img');
var $span = $img.siblings('span');
$content.css({ 'margin-left': '3px' });
$(document).on('fullscreenchange', function () {
if (! document.fullscreenElement) {
$content.removeClass('content_fullscreen')
.css({ 'width': 'auto', 'height': 'auto' });
$('#osn_tab').css({ 'width': 'auto', 'height': 'auto' });
$img.attr('src', $img.data('enter'))
.attr('title', $span.data('enter'));
$span.text($span.data('enter'));
// Saving the fullscreen state in config when
// designer exists fullscreen mode via ESC key
var valueSent = 'off';
DesignerMove.saveValueInConfig('full_screen', valueSent);
}
});
$('#selflink').hide();
});
AJAX.registerTeardown('designer/init.js', function () {
$('#side_menu').off('mouseenter mouseleave');
$('#key_Show_left_menu').off('click');
$('#toggleFullscreen').off('click');
$('#newPage').off('click');
$('#editPage').off('click');
$('#savePos').off('click');
$('#SaveAs').off('click');
$('#delPages').off('click');
$('#StartTableNew').off('click');
$('#rel_button').off('click');
$('#StartTableNew').off('click');
$('#display_field_button').off('click');
$('#reloadPage').off('click');
$('#angular_direct_button').off('click');
$('#grid_button').off('click');
$('#key_SB_all').off('click');
$('#SmallTabInvert').off('click');
$('#relLineInvert').off('click');
$('#exportPages').off('click');
$('#query_builder').off('click');
$('#key_Left_Right').off('click');
$('#pin_Text').off('click');
$('#canvas').off('click');
$('#key_HS_all').off('click');
$('#key_HS').off('click');
$('.scroll_tab_struct').off('click');
$('.scroll_tab_checkbox').off('click');
$('#id_scroll_tab').find('tr').off('click', '.designer_Tabs2,.designer_Tabs');
$('.designer_tab').off('click', '.select_all_1');
$('.designer_tab').off('click', '.small_tab,.small_tab2');
$('.designer_tab').off('click', '.small_tab_pref_1');
$('.tab_zag_noquery').off('mouseover');
$('.tab_zag_noquery').off('mouseout');
$('.tab_zag_query').off('mouseover');
$('.tab_zag_query').off('mouseout');
$('.designer_tab').off('click', '.tab_field_2,.tab_field_3,.tab_field');
$('.designer_tab').off('click', '.select_all_store_col');
$('.designer_tab').off('click', '.small_tab_pref_click_opt');
$('#del_button').off('click');
$('#cancel_button').off('click');
$('#ok_add_object').off('click');
$('#cancel_close_option').off('click');
$('#ok_new_rel_panel').off('click');
$('#cancel_new_rel_panel').off('click');
$('#page_content').off('mouseup');
$('#page_content').off('mousedown');
$('#page_content').off('mousemove');
});
AJAX.registerOnload('designer/init.js', function () {
$('#key_Show_left_menu').on('click', function () {
DesignerMove.showLeftMenu(this);
return false;
});
$('#toggleFullscreen').on('click', function () {
DesignerMove.toggleFullscreen();
return false;
});
$('#addOtherDbTables').on('click', function () {
DesignerMove.addOtherDbTables();
return false;
});
$('#newPage').on('click', function () {
DesignerMove.new();
return false;
});
$('#editPage').on('click', function () {
DesignerMove.editPages();
return false;
});
$('#savePos').on('click', function () {
DesignerMove.save3();
return false;
});
$('#SaveAs').on('click', function () {
DesignerMove.saveAs();
$(document).on('ajaxStop', function () {
$('#selected_value').on('click', function () {
$('#savePageNewRadio').prop('checked', true);
});
});
return false;
});
$('#delPages').on('click', function () {
DesignerMove.deletePages();
return false;
});
$('#StartTableNew').on('click', function () {
DesignerMove.startTableNew();
return false;
});
$('#rel_button').on('click', function () {
DesignerMove.startRelation();
return false;
});
$('#display_field_button').on('click', function () {
DesignerMove.startDisplayField();
return false;
});
$('#reloadPage').on('click', function () {
DesignerMove.loadPage(window.selectedPage);
});
$('#angular_direct_button').on('click', function () {
DesignerMove.angularDirect();
return false;
});
$('#grid_button').on('click', function () {
DesignerMove.grid();
return false;
});
$('#key_SB_all').on('click', function () {
DesignerMove.smallTabAll(this);
return false;
});
$('#SmallTabInvert').on('click', function () {
DesignerMove.smallTabInvert();
return false;
});
$('#relLineInvert').on('click', function () {
DesignerMove.relationLinesInvert();
return false;
});
$('#exportPages').on('click', function () {
DesignerMove.exportPages();
return false;
});
$('#query_builder').on('click', function () {
DesignerHistory.buildQuery('SQL Query on Database', 0);
});
$('#key_Left_Right').on('click', function () {
DesignerMove.sideMenuRight(this);
return false;
});
$('#side_menu').on('mouseenter', function () {
DesignerMove.showText();
return false;
});
$('#side_menu').on('mouseleave', function () {
DesignerMove.hideText();
return false;
});
$('#pin_Text').on('click', function () {
DesignerMove.pinText(this);
return false;
});
$('#canvas').on('click', function (event) {
DesignerMove.canvasClick(this, event);
});
$('#key_HS_all').on('click', function () {
DesignerMove.hideTabAll(this);
return false;
});
$('#key_HS').on('click', function () {
DesignerMove.noHaveConstr(this);
return false;
});
$('.designer_tab').each(DesignerMove.enableTableEvents);
$('.designer_tab').each(DesignerMove.addTableToTablesList);
$('input#del_button').on('click', function () {
DesignerMove.updRelation();
});
$('input#cancel_button').on('click', function () {
document.getElementById('layer_upd_relation').style.display = 'none';
DesignerMove.reload();
});
$('input#ok_add_object').on('click', function () {
DesignerMove.addObject(
$('#ok_add_object_db_name').val(),
$('#ok_add_object_table_name').val(),
$('#ok_add_object_col_name').val(),
$('#ok_add_object_db_and_table_name_url').val()
);
});
$('input#cancel_close_option').on('click', function () {
DesignerMove.closeOption();
});
$('input#ok_new_rel_panel').on('click', function () {
DesignerMove.newRelation();
});
$('input#cancel_new_rel_panel').on('click', function () {
document.getElementById('layer_new_relation').style.display = 'none';
});
DesignerMove.enablePageContentEvents();
});
AJAX.registerTeardown('designer/init.js', function () {
$('.trigger').off('click');
});

View File

@ -1,58 +1,21 @@
import $ from 'jquery';
import { AJAX } from '../modules/ajax.js';
import { Functions } from '../modules/functions.js';
import { CommonParams } from '../modules/common.js';
import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.js';
import refreshMainContent from '../modules/functions/refreshMainContent.js';
import { Navigation } from '../modules/navigation.js';
import { DesignerObjects } from './objects.js';
import { DesignerHistory } from './history.js';
import { DesignerPage } from './page.js';
/**
* @package PhpMyAdmin-Designer
*/
/* global DesignerObjects */ // js/designer/objects.js
/* global DesignerHistory, historyArray, selectField */ // js/designer/history.js
/* global DesignerPage */ // js/designer/page.js
/* global themeImagePath */ // templates/javascript/variables.twig
var DesignerMove = {};
window.DesignerMove = DesignerMove;
var change = 0; // variable to track any change in designer layout.
var showRelationLines = true;
var alwaysShowText = false;
AJAX.registerTeardown('designer/move.js', function () {
$(document).off('fullscreenchange');
$('#selflink').show();
});
AJAX.registerOnload('designer/move.js', function () {
var $content = $('#page_content');
var $img = $('#toggleFullscreen').find('img');
var $span = $img.siblings('span');
$content.css({ 'margin-left': '3px' });
$(document).on('fullscreenchange', function () {
if (! document.fullscreenElement) {
$content.removeClass('content_fullscreen')
.css({ 'width': 'auto', 'height': 'auto' });
$('#osn_tab').css({ 'width': 'auto', 'height': 'auto' });
$img.attr('src', $img.data('enter'))
.attr('title', $span.data('enter'));
$span.text($span.data('enter'));
// Saving the fullscreen state in config when
// designer exists fullscreen mode via ESC key
var valueSent = 'off';
DesignerMove.saveValueInConfig('full_screen', valueSent);
}
});
$('#selflink').hide();
});
DesignerMove.markSaved = function () {
change = 0;
$('#saved_state').text('');
@ -1832,13 +1795,13 @@ DesignerMove.selectAll = function (tableName, dbName, idSelectAll) {
this.disabled = parentIsChecked;
});
if (parentIsChecked) {
selectField.push('`' + tableName + '`.*');
DesignerHistory.selectField.push('`' + tableName + '`.*');
window.fromArray.push(tableName);
} else {
var i;
for (i = 0; i < selectField.length; i++) {
if (selectField[i] === ('`' + tableName + '`.*')) {
selectField.splice(i, 1);
for (i = 0; i < DesignerHistory.selectField.length; i++) {
if (DesignerHistory.selectField[i] === ('`' + tableName + '`.*')) {
DesignerHistory.selectField.splice(i, 1);
}
}
var k;
@ -1868,7 +1831,7 @@ DesignerMove.tableOnOver = function (idThis, val, buil) {
};
/**
* This function stores selected column information in selectField[]
* This function stores selected column information in DesignerHistory.selectField[]
* In case column is checked it add else it deletes
*
* @param {string} tableName
@ -1880,12 +1843,12 @@ DesignerMove.storeColumn = function (tableName, colName, checkboxId) {
var k;
var selectKeyField = '`' + tableName + '`.`' + colName + '`';
if (document.getElementById(checkboxId).checked === true) {
selectField.push(selectKeyField);
DesignerHistory.selectField.push(selectKeyField);
window.fromArray.push(tableName);
} else {
for (i = 0; i < selectField.length; i++) {
if (selectField[i] === selectKeyField) {
selectField.splice(i, 1);
for (i = 0; i < DesignerHistory.selectField.length; i++) {
if (DesignerHistory.selectField[i] === selectKeyField) {
DesignerHistory.selectField.splice(i, 1);
break;
}
}
@ -1899,9 +1862,9 @@ DesignerMove.storeColumn = function (tableName, colName, checkboxId) {
};
/**
* This function builds object and adds them to historyArray
* This function builds object and adds them to DesignerHistory.historyArray
* first it does a few checks on each object, then makes an object(where,rename,groupby,aggregate,orderby)
* then a new history object is made and finally all these history objects are added to historyArray[]
* then a new history object is made and finally all these history objects are added to DesignerHistory.historyArray[]
*
* @param {string} dbName
* @param {string} tableName
@ -1913,7 +1876,7 @@ DesignerMove.addObject = function (dbName, tableName, colName, dbTableNameUrl) {
var whereObj;
var rel = document.getElementById('rel_opt');
var sum = 0;
var init = historyArray.length;
var init = DesignerHistory.historyArray.length;
if (rel.value !== '--') {
if (document.getElementById('Query').value === '') {
ajaxShowMessage(window.sprintf(window.Messages.strQueryEmpty));
@ -1921,22 +1884,22 @@ DesignerMove.addObject = function (dbName, tableName, colName, dbTableNameUrl) {
}
p = document.getElementById('Query');
whereObj = new DesignerHistory.Where(rel.value, p.value);// make where object
historyArray.push(new DesignerHistory.HistoryObj(colName, whereObj, tableName, window.hTabs[dbTableNameUrl], 'Where'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, whereObj, tableName, window.hTabs[dbTableNameUrl], 'Where'));
sum = sum + 1;
}
if (document.getElementById('new_name').value !== '') {
var renameObj = new DesignerHistory.Rename(document.getElementById('new_name').value);// make Rename object
historyArray.push(new DesignerHistory.HistoryObj(colName, renameObj, tableName, window.hTabs[dbTableNameUrl], 'Rename'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, renameObj, tableName, window.hTabs[dbTableNameUrl], 'Rename'));
sum = sum + 1;
}
if (document.getElementById('operator').value !== '---') {
var aggregateObj = new DesignerHistory.Aggregate(document.getElementById('operator').value);
historyArray.push(new DesignerHistory.HistoryObj(colName, aggregateObj, tableName, window.hTabs[dbTableNameUrl], 'Aggregate'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, aggregateObj, tableName, window.hTabs[dbTableNameUrl], 'Aggregate'));
sum = sum + 1;
// make aggregate operator
}
if (document.getElementById('groupby').checked === true) {
historyArray.push(new DesignerHistory.HistoryObj(colName, 'GroupBy', tableName, window.hTabs[dbTableNameUrl], 'GroupBy'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, 'GroupBy', tableName, window.hTabs[dbTableNameUrl], 'GroupBy'));
sum = sum + 1;
// make groupby
}
@ -1949,20 +1912,20 @@ DesignerMove.addObject = function (dbName, tableName, colName, dbTableNameUrl) {
document.getElementById('having').value,
document.getElementById('h_operator').value
);// make where object
historyArray.push(new DesignerHistory.HistoryObj(colName, whereObj, tableName, window.hTabs[dbTableNameUrl], 'Having'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, whereObj, tableName, window.hTabs[dbTableNameUrl], 'Having'));
sum = sum + 1;
// make having
}
if (document.getElementById('orderby').value !== '---') {
var orderByObj = new DesignerHistory.OrderBy(document.getElementById('orderby').value);
historyArray.push(new DesignerHistory.HistoryObj(colName, orderByObj, tableName, window.hTabs[dbTableNameUrl], 'OrderBy'));
DesignerHistory.historyArray.push(new DesignerHistory.HistoryObj(colName, orderByObj, tableName, window.hTabs[dbTableNameUrl], 'OrderBy'));
sum = sum + 1;
// make orderby
}
ajaxShowMessage(window.sprintf(window.Messages.strObjectsCreated, sum));
// output sum new objects created
var existingDiv = document.getElementById('ab');
existingDiv.innerHTML = DesignerHistory.display(init, historyArray.length);
existingDiv.innerHTML = DesignerHistory.display(init, DesignerHistory.historyArray.length);
DesignerMove.closeOption();
$('#ab').accordion('refresh');
};
@ -2031,190 +1994,4 @@ DesignerMove.enableTableEvents = function (index, element) {
DesignerMove.enablePageContentEvents();
};
AJAX.registerTeardown('designer/move.js', function () {
$('#side_menu').off('mouseenter mouseleave');
$('#key_Show_left_menu').off('click');
$('#toggleFullscreen').off('click');
$('#newPage').off('click');
$('#editPage').off('click');
$('#savePos').off('click');
$('#SaveAs').off('click');
$('#delPages').off('click');
$('#StartTableNew').off('click');
$('#rel_button').off('click');
$('#StartTableNew').off('click');
$('#display_field_button').off('click');
$('#reloadPage').off('click');
$('#angular_direct_button').off('click');
$('#grid_button').off('click');
$('#key_SB_all').off('click');
$('#SmallTabInvert').off('click');
$('#relLineInvert').off('click');
$('#exportPages').off('click');
$('#query_builder').off('click');
$('#key_Left_Right').off('click');
$('#pin_Text').off('click');
$('#canvas').off('click');
$('#key_HS_all').off('click');
$('#key_HS').off('click');
$('.scroll_tab_struct').off('click');
$('.scroll_tab_checkbox').off('click');
$('#id_scroll_tab').find('tr').off('click', '.designer_Tabs2,.designer_Tabs');
$('.designer_tab').off('click', '.select_all_1');
$('.designer_tab').off('click', '.small_tab,.small_tab2');
$('.designer_tab').off('click', '.small_tab_pref_1');
$('.tab_zag_noquery').off('mouseover');
$('.tab_zag_noquery').off('mouseout');
$('.tab_zag_query').off('mouseover');
$('.tab_zag_query').off('mouseout');
$('.designer_tab').off('click', '.tab_field_2,.tab_field_3,.tab_field');
$('.designer_tab').off('click', '.select_all_store_col');
$('.designer_tab').off('click', '.small_tab_pref_click_opt');
$('#del_button').off('click');
$('#cancel_button').off('click');
$('#ok_add_object').off('click');
$('#cancel_close_option').off('click');
$('#ok_new_rel_panel').off('click');
$('#cancel_new_rel_panel').off('click');
$('#page_content').off('mouseup');
$('#page_content').off('mousedown');
$('#page_content').off('mousemove');
});
AJAX.registerOnload('designer/move.js', function () {
$('#key_Show_left_menu').on('click', function () {
DesignerMove.showLeftMenu(this);
return false;
});
$('#toggleFullscreen').on('click', function () {
DesignerMove.toggleFullscreen();
return false;
});
$('#addOtherDbTables').on('click', function () {
DesignerMove.addOtherDbTables();
return false;
});
$('#newPage').on('click', function () {
DesignerMove.new();
return false;
});
$('#editPage').on('click', function () {
DesignerMove.editPages();
return false;
});
$('#savePos').on('click', function () {
DesignerMove.save3();
return false;
});
$('#SaveAs').on('click', function () {
DesignerMove.saveAs();
$(document).on('ajaxStop', function () {
$('#selected_value').on('click', function () {
$('#savePageNewRadio').prop('checked', true);
});
});
return false;
});
$('#delPages').on('click', function () {
DesignerMove.deletePages();
return false;
});
$('#StartTableNew').on('click', function () {
DesignerMove.startTableNew();
return false;
});
$('#rel_button').on('click', function () {
DesignerMove.startRelation();
return false;
});
$('#display_field_button').on('click', function () {
DesignerMove.startDisplayField();
return false;
});
$('#reloadPage').on('click', function () {
DesignerMove.loadPage(window.selectedPage);
});
$('#angular_direct_button').on('click', function () {
DesignerMove.angularDirect();
return false;
});
$('#grid_button').on('click', function () {
DesignerMove.grid();
return false;
});
$('#key_SB_all').on('click', function () {
DesignerMove.smallTabAll(this);
return false;
});
$('#SmallTabInvert').on('click', function () {
DesignerMove.smallTabInvert();
return false;
});
$('#relLineInvert').on('click', function () {
DesignerMove.relationLinesInvert();
return false;
});
$('#exportPages').on('click', function () {
DesignerMove.exportPages();
return false;
});
$('#query_builder').on('click', function () {
DesignerHistory.buildQuery('SQL Query on Database', 0);
});
$('#key_Left_Right').on('click', function () {
DesignerMove.sideMenuRight(this);
return false;
});
$('#side_menu').on('mouseenter', function () {
DesignerMove.showText();
return false;
});
$('#side_menu').on('mouseleave', function () {
DesignerMove.hideText();
return false;
});
$('#pin_Text').on('click', function () {
DesignerMove.pinText(this);
return false;
});
$('#canvas').on('click', function (event) {
DesignerMove.canvasClick(this, event);
});
$('#key_HS_all').on('click', function () {
DesignerMove.hideTabAll(this);
return false;
});
$('#key_HS').on('click', function () {
DesignerMove.noHaveConstr(this);
return false;
});
$('.designer_tab').each(DesignerMove.enableTableEvents);
$('.designer_tab').each(DesignerMove.addTableToTablesList);
$('input#del_button').on('click', function () {
DesignerMove.updRelation();
});
$('input#cancel_button').on('click', function () {
document.getElementById('layer_upd_relation').style.display = 'none';
DesignerMove.reload();
});
$('input#ok_add_object').on('click', function () {
DesignerMove.addObject(
$('#ok_add_object_db_name').val(),
$('#ok_add_object_table_name').val(),
$('#ok_add_object_col_name').val(),
$('#ok_add_object_db_and_table_name_url').val()
);
});
$('input#cancel_close_option').on('click', function () {
DesignerMove.closeOption();
});
$('input#ok_new_rel_panel').on('click', function () {
DesignerMove.newRelation();
});
$('input#cancel_new_rel_panel').on('click', function () {
document.getElementById('layer_new_relation').style.display = 'none';
});
DesignerMove.enablePageContentEvents();
});
export { DesignerMove };

View File

@ -19,4 +19,5 @@ var DesignerObjects = {
this.y = y;
}
};
window.DesignerObjects = DesignerObjects;
export { DesignerObjects };

View File

@ -1,13 +1,11 @@
import $ from 'jquery';
import { ajaxShowMessage } from '../modules/ajax-message.js';
import { escapeHtml } from '../modules/functions/escape.js';
/* global DesignerOfflineDB */ // js/designer/database.js
/* global DesignerMove */ // js/designer/move.js
/* global DesignerObjects */ // js/designer/objects.js
import { DesignerOfflineDB } from './database.js';
import { DesignerMove } from './move.js';
import { DesignerObjects } from './objects.js';
var DesignerPage = {};
window.DesignerPage = DesignerPage;
DesignerPage.showTablesInLandingPage = function (db) {
DesignerPage.loadFirstPage(db, function (page) {
@ -179,3 +177,5 @@ DesignerPage.getRandom = function (max, min) {
var val = Math.random() * (max - min) + min;
return Math.floor(val);
};
export { DesignerPage };

View File

@ -207,14 +207,7 @@ class DesignerController extends AbstractController
$header = $this->response->getHeader();
$header->setBodyId('designer_body');
$this->addScriptFiles([
'designer/database.js',
'designer/objects.js',
'designer/page.js',
'designer/history.js',
'designer/move.js',
'designer/init.js',
]);
$this->addScriptFiles(['designer/init.js']);
// Embed some data into HTML, later it will be read
// by designer/init.js and converted to JS variables.

View File

@ -26,12 +26,7 @@ module.exports = [
'database/structure': './js/src/database/structure.js',
'database/tracking': './js/src/database/tracking.js',
'database/triggers': './js/src/database/triggers.js',
'designer/database': './js/src/designer/database.js',
'designer/history': './js/src/designer/history.js',
'designer/init': './js/src/designer/init.js',
'designer/move': './js/src/designer/move.js',
'designer/objects': './js/src/designer/objects.js',
'designer/page': './js/src/designer/page.js',
'drag_drop_import': './js/src/drag_drop_import.js',
'error_report': './js/src/error_report.js',
'export': './js/src/export.js',