-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
93 lines (73 loc) · 2.92 KB
/
app.js
File metadata and controls
93 lines (73 loc) · 2.92 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// TODO: This is messy. Move to browserify/grunt workflow.
(function iife() {
/// ANGULAR
angular.module('Folder.Directives',[]);
var folderApp = angular.module('folderApp',['Folder.Directives']);
// CONTROLLERS
folderApp.controller('folderController', ['$scope', 'folderService' , function folderController($scope, folderService) {
console.log(folderService);
$scope.folders = [];
folderService.getJson().then(
function(data) {
$scope.folders = data.data;
console.log($scope.folders);
}
);
/* TODO: Refactor this to work with the directive
for(var i=0; i<$scope.folders.length; i++ ) {
$scope.folders[i].showSubFolders = false;
}
$scope.toggleSubs = function(id) {
id = id-1; // starting at 1....
// again, nesting is an issue here - this only really works at the top level. Should be a way to do this better.
$scope.folders[id].showSubFolders = $scope.folders[id].showSubFolders === false ? true : false;
};
console.log($scope.folders);
*/
}]);
//SERVICES
folderApp.factory('folderService', ['$http', function folderFactory($http) {
return {
getJson: function() {
return $http.get('http://agileproapi.azurewebsites.net/api/MyFolders')
.success(function(json) { return json; })
.error(function(err) { return err; })
}
}
}]);
// folder-list is a top level piece that contains lists of folder-items
angular.module('Folder.Directives').directive('folderList', function () {
return {
restrict: "E",
replace: true,
// isolate scope for our current list of folders
// changed to list because <folder-list folder-list=> seems a bit awkward.
scope: {
list: '=list'
},
// setup the actual repeating for all folders
template: "<ul><folder ng-repeat='folder in list' folder='folder'></folder></ul>"
}
});
angular.module('Folder.Directives').directive('folder', function ($compile) {
return {
restrict: "E",
replace: true,
scope: {
folder: '='
},
template: "<li>{{folder.Name}}</li>",
link: function (scope, element, attrs) {
if (angular.isArray(scope.folder.Folders)) {
// Magic! if the Folders array exists tack a new element onto it
element.append("<folder-list list='folder.Folders'></folder-list>");
// Compile the element against the scope and calls/renders the folderList directive, force refresh
// TODO: I have concerns about performance here - perhaps transclusion would be better,
// or maybe transclusion just calls $compile. Look into that.
// It is DOM manipulation, so link seems like the right place for now.
$compile(element.contents())(scope)
}
}
}
});
})();