Skip to content

Instantly share code, notes, and snippets.

@cdeckert
Created March 8, 2015 21:46
Show Gist options
  • Save cdeckert/3ddc1bb0b042324ded1f to your computer and use it in GitHub Desktop.
Save cdeckert/3ddc1bb0b042324ded1f to your computer and use it in GitHub Desktop.
treeviewHeidelbergApp
'use strict';
/**
* @ngdoc function
* @name treeviewHeidelbergApp.controller:HeidelbergtreeviewCtrl
* @description
* # HeidelbergtreeviewCtrl
* Controller of the treeviewHeidelbergApp
*/
var slice = [].slice;
angular.module('treeviewHeidelbergApp').controller('HeidelbergtreeviewCtrl', function($scope) {
var Node, getTreeView, transform_to_map;
$scope.machine = [
{
module: "A",
parameter: "p1",
fromDate: "20151031"
}, {
module: "A",
parameter: "p2",
fromDate: "20151032"
}, {
module: "B",
parameter: "p2",
fromDate: "20151032"
}, {
module: "A",
parameter: "p1",
fromDate: "20151033"
}
];
Node = (function() {
function Node(item, field) {
this.colapsed = true;
this.label = item[field];
this.children = [];
}
Node.prototype.push_back = function(node) {
return this.children.push(node);
};
return Node;
})();
transform_to_map = function() {
var field, fields, i, item, j, k, len, len1, len2, machine, temp;
machine = arguments[0], fields = 2 <= arguments.length ? slice.call(arguments, 1) : [];
temp = {};
for (i = 0, len = fields.length; i < len; i++) {
field = fields[i];
temp[field] = {};
}
for (j = 0, len1 = machine.length; j < len1; j++) {
item = machine[j];
for (k = 0, len2 = fields.length; k < len2; k++) {
field = fields[k];
if (temp[field][item.field] == null) {
temp[field][item[field]] = [];
}
temp[field][item[field]].push(item);
}
}
return temp;
};
getTreeView = function(machine) {
var fromDate, fromDateObj, i, id, item, itemObjec, j, len, len1, module, moduleMap, moduleOb, parameter, parameterOb, ref, tree;
moduleMap = {};
for (i = 0, len = machine.length; i < len; i++) {
item = machine[i];
if (moduleMap[item.module] == null) {
moduleMap[item.module] = {};
}
if (moduleMap[item.module][item.parameter] == null) {
moduleMap[item.module][item.parameter] = {};
}
if (moduleMap[item.module][item.parameter][item.fromDate] == null) {
moduleMap[item.module][item.parameter][item.fromDate] = [];
}
moduleMap[item.module][item.parameter][item.fromDate].push(item);
}
tree = [];
id = 0;
for (module in moduleMap) {
id++;
moduleOb = {
id: id,
label: module,
children: [],
collapsed: true
};
for (parameter in moduleMap[module]) {
id++;
parameterOb = {
id: id,
label: parameter,
children: [],
collapsed: true
};
for (fromDate in moduleMap[module][parameter]) {
id++;
fromDateObj = {
id: id,
label: fromDate,
children: [],
collapsed: true
};
ref = moduleMap[module][parameter][fromDate];
for (j = 0, len1 = ref.length; j < len1; j++) {
item = ref[j];
id++;
itemObjec = {
id: id,
label: item.name,
children: [],
collapsed: true
};
}
fromDateObj.children.push(itemObjec);
}
parameterOb.children.push(fromDateObj);
moduleOb.children.push(parameterOb);
}
tree.push(moduleOb);
}
return tree;
};
return $scope.treedata = getTreeView($scope.machine);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment