Extract the tests and refactor some of the methods.

Extract some of the ACI Tree functionalities, and decouple it from the
main source. Also - create some abstractions from the repeated code
around the enable/disable the schema children object create/edit/delete
functionalities, and also created the dialog wrappers for backup and
restore dialogs.

Reviewed by: Khushboo and Ashesh
Refactored by: Ashesh
This commit is contained in:
Joao De Almeida Pereira
2018-06-05 16:42:59 +05:30
committed by Ashesh Vashi
parent 920934759f
commit 7dd6372eeb
75 changed files with 5186 additions and 1939 deletions
@@ -0,0 +1,72 @@
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////
/**
* This method received pgBrowser and new TreeNode object
*
* This method retrieves all the data that exists in the tree node and in
* `pgBrowser.Nodes` for all the parent node of the provided node.
*
* The 2 condition to get the information from pgBrowser.Nodes are:
* 1 - the variable _type of the tree node
* 2 - the presence of hasId in the pgBrowser.Nodes for the specific node
*
* Number 2 is used to ignore coll-* nodes as they do not add any useful
* information
*/
export function getTreeNodeHierarchyFromElement(pgBrowser, treeNode) {
return getTreeNodeHierarchy.call(pgBrowser, treeNode);
}
/**
* This method received an ACI Tree JQuery node
*
* NOTE: this function need to be called on pgBrowser instance.
* getTreeNodeHierarchyFromIdentifier.apply(pgBrowser, [aciTreeNodeIdentifier])
*
* This method retrieves all the data that exists in the tree node and in
* `pgBrowser.Nodes` for all the parent node of the provided node.
*
* The 2 condition to get the information from pgBrowser.Nodes are:
* 1 - the variable _type of the tree node
* 2 - the presence of hasId in the pgBrowser.Nodes for the specific node
*
* Number 2 is used to ignore coll-* nodes as they do not add any useful
* information
*/
export function getTreeNodeHierarchyFromIdentifier(aciTreeNodeIdentifier) {
let identifier = this.treeMenu.translateTreeNodeIdFromACITree(aciTreeNodeIdentifier);
let currentNode = this.treeMenu.findNode(identifier);
return getTreeNodeHierarchy.call(this, currentNode);
}
export function getTreeNodeHierarchy(currentNode) {
let idx = 0;
let result = {};
do {
const currentNodeData = currentNode.getData();
if (currentNodeData._type in this.Nodes && this.Nodes[currentNodeData._type].hasId) {
const nodeType = mapType(currentNodeData._type);
if (result[nodeType] === undefined) {
result[nodeType] = _.extend({}, currentNodeData, {
'priority': idx,
});
idx -= 1;
}
}
currentNode = currentNode.hasParent() ? currentNode.parent() : null;
} while (currentNode);
return result;
}
function mapType(type) {
return type === 'partition' ? 'table' : type;
}
+14 -4
View File
@@ -59,17 +59,20 @@ export class TreeNode {
tree.aciTreeApi.unload(this.domNode);
}
anyParent(condition) {
/*
* Find the ancestor with matches this condition
*/
ancestorNode(condition) {
let node = this;
while (node.hasParent()) {
node = node.parent();
if (condition(node)) {
return true;
return node;
}
}
return false;
return null;
}
/**
@@ -81,7 +84,10 @@ export class TreeNode {
return true;
}
return this.anyParent(condition);
return this.ancestorNode(condition) !== null;
}
anyParent(condition) {
return this.ancestorNode(condition) !== null;
}
}
@@ -210,3 +216,7 @@ function findInTree(rootNode, path) {
}
})(rootNode);
}
export function isValidTreeNodeData(treeNodeData) {
return !_.isUndefined(treeNodeData) && !_.isNull(treeNodeData);
}