aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wireless-transport/code-Carbon-SR1/ux/help/help-module/src/main/resources/help/help.tree.ts
blob: 3d1428042e3cf50b4300487d58a3e54bc6b353d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as angular from 'angularAMD';

export interface Node {
  label?: string,
  nodes?: Node[],
  versions?: {
    [version: string]: { 
      label: string,
      date: string,
      path: string
    }
  } 
}

const help = angular.module('app.help');

// class HelpTreeController implements ng.IController {
//   constructor(private $scope: ng.IScope & { rootNode: Node, data: Node[]}) {
//     $scope.$watch("rootNode", (n, o) => {
//       $scope.data = Object.keys($scope.rootNode).map(key => $scope.rootNode[key]);
//     });
//   }
// }

// help.controller("treeCtrl", ["$scope", HelpTreeController]);

const helpTree = function ($compile) {
  return {
    restrict: "E",
    transclude: true,
    scope: { rootNode: '=' },
    //controller: 'treeCtrl',
    template:
      '<ul>' +
      '<li ng-transclude></li>' +
      '<li ng-repeat="child in rootNode.nodes">' +
      '<tree root-node="child"><div ng-transclude></div></tree>' +
      '</li>' +
      '</ul>',
    compile: function (tElement, tAttr, transclude) {
      var contents = tElement.contents().remove();
      var compiledContents;
      return function (scope, iElement, iAttr) {
        if (!compiledContents) {
          compiledContents = $compile(contents, transclude);
        }
        compiledContents(scope, function (clone, scope) {
          iElement.append(clone);
        });
      };
    }
  };
};

help.directive("tree", ["$compile", helpTree]);