require('../polyfill'); /** * Mixin type that allows path items (Depot, Dir, and File) to operate like a * tree easily. * * A node requires that the implementing class provide certain basic properties: * * 1. `this.children`: If the node contains children, this should be defined as an * empty array. * * 2. `this.pathId`: This should be an array of path names indicating the * absolute location in an easily comparable way. * * 3. `this.name`: The comparable string 'name' of the item * * @mixin */ var Node = { /** * */ sortChildren: function() { this.children.sort(function(a, b) { return a.name.localeCompare(b.name); }); }, /** * Inserts the child into the tree, if it belongs. * * @param child * @return {boolean} Returns true if the child is inserted */ insert: function (child) { if (!this.children) { return false; } if (child.isChildRelation(this)) { this.children.push(child); return true; } for (var index = 0; index < this.children.length; index++) { if (this.children[index].insert(child)) { return true; } } return false; }, /** * Validates that the current node could be a child of the indicated parent. * * @param parent The potential parent */ isChildRelation: function (parent) { return (this.pathId.length == (parent.pathId.length + 1)) && (this.getParentName() == parent.name); }, /** * Returns the parent name of this node. * * @return {string} */ getParentName: function () { if (this.pathId.length > 1) { return this.pathId[this.pathId.length - 2]; } return undefined; } }; module.exports = Node;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/source/helix_web_services_client_js/models/Node.js | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services_client_js/models/Node.js | |||||
#2 | 14151 | tjuricek |
Add depot tree control and selection to the create projects page. Styling and error checking is kept to a minimum for the time being. Our goal is just internal workflow and feedback. |
||
#1 | 14108 | tjuricek |
Added models for handling Perforce server depot listing and traversal. This is not complete, however, the models are a start to making it easy to generate a tree control. (Most tree controls in the wild assume you know the tree structure from the start, which is not true in our case.) The tricky bit is making it easy to build the tree out given that you're visiting only one directory at a time. |