Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify bottom menu showing parents/brothers from depth 2. #46

Merged
merged 1 commit into from
Feb 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ module.exports = function (grunt) {
* @param parent
* @returns {*}
*/
function parseChilds(childs, parent) {
function parseChilds(childs, parent, depth) {
var childsOrdered = [],
chronologicalChilds;

Expand All @@ -903,8 +903,16 @@ module.exports = function (grunt) {
// Parse the content and set the classification of the node.
setNodeContent(child.node);

// Add parent information
if (parent.guid !== firstNode) {
// Add depth.
if (typeof depth === 'undefined') {
child.node._depth = 1;
}
else {
child.node._depth = depth+1;
}

// Add parent information.
if (parent.guid !== firstNode && child.node._depth > 2) {
child.node.parent = _.pick(parent, 'guid');
child.node.parent.name = getName(parent);
}
Expand All @@ -913,7 +921,7 @@ module.exports = function (grunt) {
child.node.hasChronologicalChildren = false;

// Look up for more generations of childrens.
child.node.children = getChilds(child.node);
child.node.children = getChilds(child.node, child.node._depth);

// If a chronological node have grandchildSet the granchild.parent like the father parent.
if (child.node.type === 'chronological' && child.node.children.length > 0) {
Expand All @@ -930,7 +938,7 @@ module.exports = function (grunt) {
// Get the siblings nodes.
child.node.brothers = [];

if (child.node.type !== 'chronological' && !child.node.hasChronologicalChildren) {
if (child.node.type !== 'chronological' && !child.node.hasChronologicalChildren && child.node._depth > 1) {
child.node.brothers = _.filter(setSiblingsInfo(childs), function(brother) {
// Clean the name property.
var label = undefined;
Expand Down Expand Up @@ -976,17 +984,18 @@ module.exports = function (grunt) {
* Get childs of the node.
*
* @param node
* @param depth
* @returns {*}
*/
function getChilds(node) {
function getChilds(node, depth) {
var childsOrdered = [],
childs = [];

grunt.log.ok('Parsing node: ' + node.guid);
childs = _.union( _.where(nodesLinks, {idA: node.guid, dir: '1'}), _.where(nodesLinks, {idB: node.guid, dir: '2'}) );

if (childs.length) {
childsOrdered = parseChilds(childs, node);
childsOrdered = parseChilds(childs, node, depth);
}

return childsOrdered;
Expand Down