Initial version of the new tree implementation.

This is the first version of our Tree implementation. At this point is a
very simple tree without no abstractions and with code that eventually
is not very performant, but this is only the first iteration and we are
trying to follow the 'Last Responsible Moment Principle' [1].

Implemention details:
- Creation of PGBrowser.treeMenu
- Initial version of the Tree Adaptor 'pgadmin/static/js/tree/tree.js'
- TreeFake test double that can replace the Tree for testing purposes
- Tests, As an interesting asside because Fake’s need to behave like
  the real object you will noticed that there are tests for this type
  of double and they the same as of the real object.

[1] https://medium.com/@aidanjcasey/guiding-principles-for-an-evolutionary-software-architecture-b6dc2cb24680

Patched by: Victoria && Joao
Reviewed by: Khushboo & Ashesh
This commit is contained in:
Joao De Almeida Pereira
2018-05-14 17:56:04 +05:30
committed by Ashesh Vashi
parent a34b3f27d4
commit bc4d16eb83
4 changed files with 705 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import {Tree} from '../../../pgadmin/static/js/tree/tree';
export class TreeFake extends Tree {
constructor() {
super();
this.aciTreeToOurTreeTranslator = {};
this.aciTreeApi = jasmine.createSpyObj(
['ACITreeApi'], ['setInode', 'unload', 'deselect', 'select']);
}
addNewNode(id, data, domNode, path) {
this.aciTreeToOurTreeTranslator[id] = [id];
if (path !== null && path !== undefined) {
this.aciTreeToOurTreeTranslator[id] = path.concat(id);
}
return super.addNewNode(id, data, domNode, path);
}
addChild(parent, child) {
child.setParent(parent);
this.aciTreeToOurTreeTranslator[child.id] = this.aciTreeToOurTreeTranslator[parent.id].concat(child.id);
parent.children.push(child);
}
hasParent(aciTreeNode) {
return this.translateTreeNodeIdFromACITree(aciTreeNode).length > 1;
}
parent(aciTreeNode) {
if (this.hasParent(aciTreeNode)) {
let path = this.translateTreeNodeIdFromACITree(aciTreeNode);
return [{id: this.findNode(path).parent().id}];
}
return null;
}
translateTreeNodeIdFromACITree(aciTreeNode) {
if(aciTreeNode === undefined || aciTreeNode[0] === undefined) {
return null;
}
return this.aciTreeToOurTreeTranslator[aciTreeNode[0].id];
}
itemData(aciTreeNode) {
let node = this.findNodeByDomElement(aciTreeNode);
if (node === undefined || node === null) {
return undefined;
}
return node.getData();
}
selected() {
return this.selectedNode;
}
selectNode(selectedNode) {
this.selectedNode = selectedNode;
}
}