angular.module('materialscommons').component('mcFilesSelect', {
    templateUrl: 'app/global.services/select-items/mc-files-select.html',
    controller: MCFilesSelectComponentController,
    bindings: {
        project: '='
    }
});

function MCFilesSelectComponentController(fileTreeProjectService) {
    'ngInject';

    var ctrl = this;

    console.log('MCFilesSelectComponentController');

    //fileTreeProjectService.getProjectRoot(ctrl.project.id).then(function(files) {
        //ctrl.project.files = files;
        ctrl.files = ctrl.project.files;
        ctrl.files[0].data.childrenLoaded = true;
        ctrl.files[0].expand = true;
    //});

}

angular.module('materialscommons').directive('mcFilesSelectDir', MCFilesSelectDirDirective);
function MCFilesSelectDirDirective(RecursionHelper) {
    'ngInject';

    return {
        restrict: 'E',
        scope: {
            file: '=',
            project: '='
        },
        controller: MCFilesSelectDirDirectiveController,
        replace: true,
        controllerAs: 'ctrl',
        bindToController: true,
        templateUrl: 'app/global.services/select-items/mc-files-select-dir.html',
        compile: function(element) {
            return RecursionHelper.compile(element, function() {});
        }
    }
}

function MCFilesSelectDirDirectiveController(fileTreeProjectService) {
    'ngInject';

    console.log("MCFilesSelectDirDirectiveController", this.file.children);

    var ctrl = this;
    ctrl.files = ctrl.file.children;
    ctrl.setActive = setActive;
    ctrl.dirToggle = dirToggle;

    ////////////////////

    function setActive(file) {
        clearActiveStateInAllNodes();

        if (file.data.otype === 'file') {
            file.active = true;
        } else {
            if (!file.data.childrenLoaded) {
                fileTreeProjectService.getDirectory(ctrl.project.id, file.data.id).then(function(files) {
                    file.children = files;
                    file.active = true;
                    file.data.childrenLoaded = true;
                    file.expand = !file.expand;
                });
            } else {
                file.active = true;
                file.expand = !file.expand;
            }
        }
    }

    function clearActiveStateInAllNodes() {
        var treeModel = new TreeModel(),
            root = treeModel.parse(ctrl.project.files[0]);
        root.walk(function(treeNode) {
            treeNode.model.active = false;
        });
    }

    function dirToggle(dir) {
        if (!dir.data.childrenLoaded) {
            fileTreeProjectService.getDirectory(ctrl.project.id, dir.data.id).then(function(files) {
                dir.children = files;
                dir.active = true;
                dir.data.childrenLoaded = true;
                dir.children.forEach(function(f) {
                    if (f.data.otype === 'file') {
                        f.data.selected = dir.data.selected;
                    }
                });
            });
        } else {
            dir.children.forEach(function(f) {
                if (f.data.otype === 'file') {
                    f.data.selected = dir.data.selected;
                }
            });
        }
    }

    function showFile(file) {
        console.log('showFile', file);
    }
}

@@ -275,34 +275,12 @@
 ler(
-fileTreeProjectService
 ) %7B%0A
+
     
@@ -318,188 +318,8 @@
 s;%0A%0A
-    console.log('MCFilesSelectComponentController');%0A%0A    //fileTreeProjectService.getProjectRoot(ctrl.project.id).then(function(files) %7B%0A        //ctrl.project.files = files;%0A    
     
@@ -347,28 +347,24 @@
 ject.files;%0A
-    
     ctrl.fil
@@ -401,20 +401,16 @@
 ue;%0A    
-   
- 
 ctrl.fil
@@ -434,19 +434,8 @@
 ue;%0A
-    //%7D);%0A%0A
 %7D%0A%0Aa
@@ -958,16 +958,17 @@
 function
+ 
 (element
@@ -1031,20 +1031,34 @@
 function
+ 
 () %7B
+%0A            
 %7D);%0A    
@@ -1680,32 +1680,33 @@
 d).then(function
+ 
 (files) %7B%0A      
@@ -2205,16 +2205,17 @@
 function
+ 
 (treeNod
@@ -2442,16 +2442,17 @@
 function
+ 
 (files) 
@@ -2611,32 +2611,33 @@
 forEach(function
+ 
 (f) %7B%0A          
@@ -2854,16 +2854,17 @@
 function
+ 
 (f) %7B%0A  
@@ -2991,32 +2991,32 @@
             %7D);%0A
+
         %7D%0A    %7D%0A
@@ -3018,83 +3018,7 @@
    %7D
-%0A%0A    function showFile(file) %7B%0A        console.log('showFile', file);%0A    %7D
 %0A%7D%0A

Remove unused methods and imports.