Skip to content

Commit 4be2b55

Browse files
committed
Declare DesignerHistory properties explicitly in history.ts
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 97ad7e8 commit 4be2b55

2 files changed

Lines changed: 66 additions & 45 deletions

File tree

js/src/designer/history.ts

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ import { DesignerConfig } from './config.ts';
1010
* @requires move.js
1111
*/
1212

13-
var DesignerHistory = {};
14-
15-
/**
16-
* Global array to store history objects.
17-
* @type {any[]}
18-
*/
19-
DesignerHistory.historyArray = [];
20-
21-
/**
22-
* Global array to store information for columns which are used in select clause.
23-
* @type {any[]}
24-
*/
25-
DesignerHistory.selectField = [];
26-
27-
DesignerHistory.vqbEditor = null;
28-
2913
var gIndex;
3014

3115
/**
@@ -34,7 +18,7 @@ var gIndex;
3418
* @param {number} index index of DesignerHistory.historyArray where change is to be made
3519
* @return {string}
3620
*/
37-
DesignerHistory.detail = function (index) {
21+
const detail = function (index) {
3822
var type = DesignerHistory.historyArray[index].getType();
3923
var str;
4024
if (type === 'Where') {
@@ -70,7 +54,7 @@ DesignerHistory.detail = function (index) {
7054
* @param {number} finit last index of unsorted array
7155
* @return {string}
7256
*/
73-
DesignerHistory.display = function (init, finit) {
57+
const display = function (init, finit) {
7458
var str;
7559
var i;
7660
var j;
@@ -147,7 +131,7 @@ DesignerHistory.display = function (init, finit) {
147131
*
148132
* @param {number} index index of DesignerHistory.historyArray where change is to be made
149133
*/
150-
DesignerHistory.andOr = function (index): void {
134+
const andOr = function (index): void {
151135
if (DesignerHistory.historyArray[index].getAndOr()) {
152136
DesignerHistory.historyArray[index].setAndOr(0);
153137
} else {
@@ -164,7 +148,7 @@ DesignerHistory.andOr = function (index): void {
164148
*
165149
* @param {number} index of DesignerHistory.historyArray[] which is to be deleted
166150
*/
167-
DesignerHistory.historyDelete = function (index): void {
151+
const historyDelete = function (index): void {
168152
var fromArrayLength = window.fromArray.length;
169153
for (var k = 0; k < fromArrayLength; k++) {
170154
if (window.fromArray[k] === DesignerHistory.historyArray[index].getTab()) {
@@ -182,7 +166,7 @@ DesignerHistory.historyDelete = function (index): void {
182166
/**
183167
* @param {string} elementId
184168
*/
185-
DesignerHistory.changeStyle = function (elementId): void {
169+
const changeStyle = function (elementId): void {
186170
var element = document.getElementById(elementId);
187171
element.style.left = '530px';
188172
element.style.top = '130px';
@@ -197,7 +181,7 @@ DesignerHistory.changeStyle = function (elementId): void {
197181
*
198182
* @param {number} index index of DesignerHistory.historyArray where change is to be made
199183
*/
200-
DesignerHistory.historyEdit = function (index): void {
184+
const historyEdit = function (index): void {
201185
gIndex = index;
202186
var type = DesignerHistory.historyArray[index].getType();
203187
if (type === 'Where') {
@@ -224,7 +208,7 @@ DesignerHistory.historyEdit = function (index): void {
224208
*
225209
* @param {string} type of DesignerHistory.historyArray where change is to be made
226210
*/
227-
DesignerHistory.edit = function (type): void {
211+
const edit = function (type): void {
228212
if (type === 'Rename') {
229213
if (document.getElementById('e_rename').value !== '') {
230214
DesignerHistory.historyArray[gIndex].getObj().setRenameTo(document.getElementById('e_rename').value);
@@ -271,7 +255,7 @@ DesignerHistory.edit = function (type): void {
271255
* @param nType type of object
272256
*
273257
*/
274-
DesignerHistory.HistoryObj = function (nColumnName, nObj, nTab, nObjNo, nType) {
258+
const HistoryObj = function (nColumnName, nObj, nTab, nObjNo, nType) {
275259
var andOr;
276260
var obj;
277261
var tab;
@@ -346,7 +330,7 @@ DesignerHistory.HistoryObj = function (nColumnName, nObj, nTab, nObjNo, nType) {
346330
*
347331
*/
348332

349-
DesignerHistory.Where = function (nRelationOperator, nQuery) {
333+
const Where = function (nRelationOperator, nQuery) {
350334
var relationOperator;
351335
var query;
352336
this.setRelationOperator = function (nRelationOperator) {
@@ -374,7 +358,7 @@ DesignerHistory.Where = function (nRelationOperator, nQuery) {
374358
*
375359
* @param nOrder order, ASC or DESC
376360
*/
377-
DesignerHistory.OrderBy = function (nOrder) {
361+
const OrderBy = function (nOrder) {
378362
var order;
379363
this.setOrder = function (nOrder) {
380364
order = nOrder;
@@ -394,7 +378,7 @@ DesignerHistory.OrderBy = function (nOrder) {
394378
* @param nQuery stores value of value/sub-query
395379
* @param nOperator operator
396380
*/
397-
DesignerHistory.Having = function (nRelationOperator, nQuery, nOperator) {
381+
const Having = function (nRelationOperator, nQuery, nOperator) {
398382
var relationOperator;
399383
var query;
400384
var operator;
@@ -433,7 +417,7 @@ DesignerHistory.Having = function (nRelationOperator, nQuery, nOperator) {
433417
* @param nRenameTo new name information
434418
*
435419
*/
436-
DesignerHistory.Rename = function (nRenameTo) {
420+
const Rename = function (nRenameTo) {
437421
var renameTo;
438422
this.setRenameTo = function (nRenameTo) {
439423
renameTo = nRenameTo;
@@ -452,7 +436,7 @@ DesignerHistory.Rename = function (nRenameTo) {
452436
* @param nOperator aggregate operator
453437
*
454438
*/
455-
DesignerHistory.Aggregate = function (nOperator) {
439+
const Aggregate = function (nOperator) {
456440
var operator;
457441
this.setOperator = function (nOperator) {
458442
operator = nOperator;
@@ -472,7 +456,7 @@ DesignerHistory.Aggregate = function (nOperator) {
472456
* @return unique array
473457
*/
474458

475-
DesignerHistory.unique = function (arrayName) {
459+
const unique = function (arrayName) {
476460
var newArray = [];
477461
uniquetop:
478462
for (var i = 0; i < arrayName.length; i++) {
@@ -497,7 +481,7 @@ DesignerHistory.unique = function (arrayName) {
497481
* @param value value which is to be searched in the array
498482
*/
499483

500-
DesignerHistory.found = function (arrayName, value) {
484+
const found = function (arrayName, value) {
501485
var arrayNameLength = arrayName.length;
502486
for (var i = 0; i < arrayNameLength; i++) {
503487
if (arrayName[i] === value) {
@@ -516,7 +500,7 @@ DesignerHistory.found = function (arrayName, value) {
516500
*
517501
* @return {obj[]}
518502
*/
519-
DesignerHistory.addArray = function (add, arr) {
503+
const addArray = function (add, arr) {
520504
var addLength = add.length;
521505
for (var i = 0; i < addLength; i++) {
522506
arr.push(add[i]);
@@ -534,7 +518,7 @@ DesignerHistory.addArray = function (add, arr) {
534518
* @return {obj[]}
535519
*
536520
*/
537-
DesignerHistory.removeArray = function (rem, arr) {
521+
const removeArray = function (rem, arr) {
538522
var remLength = rem.length;
539523
for (var i = 0; i < remLength; i++) {
540524
var arrLength = arr.length;
@@ -552,7 +536,7 @@ DesignerHistory.removeArray = function (rem, arr) {
552536
* This function builds the groupby clause from history object
553537
* @return {string}
554538
*/
555-
DesignerHistory.queryGroupBy = function () {
539+
const queryGroupBy = function () {
556540
var i;
557541
var str = '';
558542
var historyArrayLength = DesignerHistory.historyArray.length;
@@ -571,7 +555,7 @@ DesignerHistory.queryGroupBy = function () {
571555
* This function builds the Having clause from the history object.
572556
* @return {string}
573557
*/
574-
DesignerHistory.queryHaving = function () {
558+
const queryHaving = function () {
575559
var i;
576560
var and = '(';
577561
var historyArrayLength = DesignerHistory.historyArray.length;
@@ -595,12 +579,11 @@ DesignerHistory.queryHaving = function () {
595579
return and;
596580
};
597581

598-
599582
/**
600583
* This function builds the orderby clause from the history object.
601584
* @return {string}
602585
*/
603-
DesignerHistory.queryOrderBy = function () {
586+
const queryOrderBy = function () {
604587
var i;
605588
var str = '';
606589
var historyArrayLength = DesignerHistory.historyArray.length;
@@ -616,12 +599,11 @@ DesignerHistory.queryOrderBy = function () {
616599
return str;
617600
};
618601

619-
620602
/**
621603
* This function builds the Where clause from the history object.
622604
* @return {string}
623605
*/
624-
DesignerHistory.queryWhere = function () {
606+
const queryWhere = function () {
625607
var i;
626608
var and = '(';
627609
var or = '(';
@@ -657,7 +639,7 @@ DesignerHistory.queryWhere = function () {
657639
return and;
658640
};
659641

660-
DesignerHistory.checkAggregate = function (idThis) {
642+
const checkAggregate = function (idThis) {
661643
var i;
662644
var historyArrayLength = DesignerHistory.historyArray.length;
663645
for (i = 0; i < historyArrayLength; i++) {
@@ -670,7 +652,7 @@ DesignerHistory.checkAggregate = function (idThis) {
670652
return '';
671653
};
672654

673-
DesignerHistory.checkRename = function (idThis) {
655+
const checkRename = function (idThis) {
674656
var i;
675657
var historyArrayLength = DesignerHistory.historyArray.length;
676658
for (i = 0; i < historyArrayLength; i++) {
@@ -689,7 +671,7 @@ DesignerHistory.checkRename = function (idThis) {
689671
*
690672
* @return {string}
691673
*/
692-
DesignerHistory.queryFrom = function () {
674+
const queryFrom = function () {
693675
var i;
694676
var tabLeft = [];
695677
var tabUsed = [];
@@ -810,7 +792,7 @@ DesignerHistory.queryFrom = function () {
810792
* @uses DesignerHistory.queryHaving()
811793
* @uses DesignerHistory.queryOrderBy()
812794
*/
813-
DesignerHistory.buildQuery = function () {
795+
const buildQuery = function () {
814796
var qSelect = 'SELECT ';
815797
var temp;
816798
var selectFieldLength = DesignerHistory.selectField.length;
@@ -887,6 +869,45 @@ DesignerHistory.buildQuery = function () {
887869
});
888870
};
889871

872+
const DesignerHistory = {
873+
/**
874+
* Global array to store history objects.
875+
*/
876+
historyArray: [],
877+
878+
/**
879+
* Global array to store information for columns which are used in select clause.
880+
*/
881+
selectField: [],
882+
883+
vqbEditor: null,
884+
detail: detail,
885+
display: display,
886+
andOr: andOr,
887+
historyDelete: historyDelete,
888+
changeStyle: changeStyle,
889+
historyEdit: historyEdit,
890+
edit: edit,
891+
HistoryObj: HistoryObj,
892+
Where: Where,
893+
OrderBy: OrderBy,
894+
Having: Having,
895+
Rename: Rename,
896+
Aggregate: Aggregate,
897+
unique: unique,
898+
found: found,
899+
addArray: addArray,
900+
removeArray: removeArray,
901+
queryGroupBy: queryGroupBy,
902+
queryHaving: queryHaving,
903+
queryOrderBy: queryOrderBy,
904+
queryWhere: queryWhere,
905+
checkAggregate: checkAggregate,
906+
checkRename: checkRename,
907+
queryFrom: queryFrom,
908+
buildQuery: buildQuery,
909+
};
910+
890911
declare global {
891912
interface Window {
892913
DesignerHistory: typeof DesignerHistory;

js/src/designer/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ AJAX.registerOnload('designer/init.js', function () {
236236
});
237237

238238
$('#query_builder').on('click', function () {
239-
DesignerHistory.buildQuery('SQL Query on Database', 0);
239+
DesignerHistory.buildQuery();
240240
});
241241

242242
$('#key_Left_Right').on('click', function () {
@@ -376,7 +376,7 @@ AJAX.registerOnload('designer/init.js', function () {
376376
});
377377

378378
$('#build_query_button').on('click', function () {
379-
DesignerHistory.buildQuery('SQL Query on Database', 0);
379+
DesignerHistory.buildQuery();
380380
});
381381

382382
$('#query_where_button').on('click', function () {

0 commit comments

Comments
 (0)