Skip to content

Commit 6ff57ac

Browse files
committed
split large angular directives in own files
1 parent 366b405 commit 6ff57ac

File tree

7 files changed

+696
-611
lines changed

7 files changed

+696
-611
lines changed

bindata.go

Lines changed: 438 additions & 350 deletions
Large diffs are not rendered by default.

webapp/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
<script src="js/controllers.js"></script>
5959
<script src="js/directives.js"></script>
6060
<script src="js/zsd-file-actions.js"></script>
61-
<script src="js/zsd-datasets.js"></script>
61+
<script src="js/zsd-datasets.js"></script>
62+
<script src="js/zsd-snapshots.js"></script>
63+
<script src="js/zsd-dir-browser.js"></script>
64+
<script src="js/zsd-file-diff.js"></script>
6265
<script src="js/services.js"></script>
6366
<script src="js/filters.js"></script>
6467
<script src="js/app.js"></script>

webapp/js/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var zsd = angular.module('ZFSSnapDiff',
22
['ngRoute', 'ngSanitize', 'ngAnimate',
3-
'zsdControllers', 'zsdUtils', 'zsdServices', 'zsdDirectives', 'zsdFileActions', 'zsdFilters', 'zsdDatasets']);
3+
'zsdControllers', 'zsdUtils', 'zsdServices', 'zsdDirectives', 'zsdFileActions', 'zsdFilters',
4+
'zsdDatasets', 'zsdSnapshots', 'zsdDirBrowser', 'zsdFileDiff']);
45

56
zsd.config(['$routeProvider', function($routeProvider){
67
$routeProvider.

webapp/js/directives.js

Lines changed: 1 addition & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,5 @@
11
angular.module('zsdDirectives', ['zsdUtils', 'zsdServices']).
22

3-
directive('zsdSnapshots', ['$location', '$anchorScroll', function($location, $anchorScroll){
4-
return {
5-
restrict: 'E',
6-
templateUrl: 'template-snapshots.html',
7-
scope: {
8-
snapshots: '=',
9-
title: '@',
10-
onSnapshotSelected: '&'
11-
},
12-
link: function(scope, element, attrs){
13-
14-
scope.snapshotSelected = function(snap){
15-
scope.hideSnapshots = true;
16-
scope.curSnap = snap;
17-
scope.onSnapshotSelected({snap: snap});
18-
};
19-
20-
scope.toggleHideSnapshots = function(){
21-
scope.hideSnapshots = ! scope.hideSnapshots;
22-
};
23-
24-
scope.showNewerSnapDisabled = function(){
25-
return snapUninitialized() || scope.snapshots.indexOf(scope.curSnap) === 0
26-
};
27-
28-
scope.showOlderSnapDisabled = function(){
29-
return snapUninitialized() || scope.snapshots.indexOf(scope.curSnap) === scope.snapshots.length - 1;
30-
};
31-
32-
scope.showOlderSnap = function(){
33-
var idx = scope.snapshots.indexOf(scope.curSnap);
34-
scope.snapshotSelected(scope.snapshots[idx + 1]);
35-
};
36-
37-
scope.showNewerSnap = function(){
38-
var idx = scope.snapshots.indexOf(scope.curSnap);
39-
scope.snapshotSelected(scope.snapshots[idx - 1]);
40-
};
41-
42-
scope.$watch('snapshots', function(){
43-
// new file selected
44-
scope.hideSnapshots = false;
45-
});
46-
47-
function snapUninitialized(){
48-
return typeof scope.curSnap === 'undefined' || typeof scope.snapshots === 'undefined';
49-
}
50-
}
51-
};
52-
}]).
53-
54-
55-
56-
57-
583

594
// https://github.com/angular/angular.js/issues/339
605
directive('zsdEmbedSrc', function () {
@@ -116,81 +61,6 @@ directive('zsdShowIfEmpty', function(){
11661
}).
11762

11863

119-
directive('zsdDirBrowser', ['Backend', 'PathUtils', function(Backend, PathUtils){
120-
return {
121-
restrict: 'E',
122-
templateUrl: 'template-dir-browser.html',
123-
scope: {
124-
start: '=',
125-
startEntries: '=',
126-
onFileSelected: '&',
127-
onDirSelected: '&'
128-
},
129-
link: function(scope, element, attrs){
130-
scope.fileSelected = false;
131-
132-
scope.filterHiddenEntries = function(entry){
133-
if(! scope.showHiddenEntries){
134-
if(entry.Path) return entry.Path.charAt(0) != '.';
135-
}
136-
return true;
137-
};
138-
139-
scope.isDirectory = function(entry){
140-
return entry.Type === "D"
141-
};
142-
143-
scope.isFile = function(entry){
144-
return entry.Type === "F"
145-
};
146-
147-
scope.open = function(entry){
148-
var idx = scope.entries.indexOf(entry);
149-
if(idx === -1){
150-
// user go deeper
151-
scope.entries = scope.entries.concat([entry]);
152-
}else{
153-
// user jump upward
154-
scope.entries = scope.entries.slice(0, idx + 1);
155-
}
156-
157-
158-
if(scope.isDirectory(entry)){
159-
scope.dirEntries = [{}];
160-
scope.fileSelected = false;
161-
scope.onDirSelected({entries: scope.entries});
162-
163-
var path = PathUtils.entriesToPath(scope.entries);
164-
Backend.listDir(path).then(function(dirListing){
165-
scope.dirListing = dirListing;
166-
});
167-
}else{
168-
scope.fileSelected = true;
169-
scope.onFileSelected({entries: scope.entries});
170-
}
171-
};
172-
173-
174-
175-
scope.$watch(function(){ return scope.start}, function(start){
176-
if(! angular.isDefined(start)) return;
177-
178-
scope.entries = [];
179-
scope.open({Type: 'D', Path: scope.start});
180-
});
181-
182-
scope.$watch(function(){ return scope.startEntries}, function(startEntries){
183-
if(! angular.isDefined(startEntries)) return;
184-
scope.entries = startEntries;
185-
186-
// start on last element
187-
scope.open(scope.entries[scope.entries.length - 1]);
188-
});
189-
190-
}
191-
};
192-
}]).
193-
19464
directive('zsdModal', [function(){
19565
return {
19666
restrict: 'E',
@@ -246,135 +116,7 @@ directive('zsdNotifications', ['$rootScope', '$timeout', 'Notifications', functi
246116
templateUrl: "template-notifications.html"
247117
}
248118
}]).
249-
250-
251-
252-
253-
254-
directive('zsdFileDiff', ['Backend', function(Backend){
255-
return {
256-
restrict: 'E',
257-
scope: {
258-
diffResult: '=',
259-
path: '=',
260-
curSnap: '='
261-
},
262-
templateUrl: 'template-file-diff.html',
263-
link: function(scope, element, attrs){
264-
//
265-
// scope actions
266-
//
267-
268-
scope.showRevertChangeConfirmation = function(idx){
269-
scope.revertChangeConfirmation = idx;
270-
};
271-
scope.showRevertChangeConfirmationFor = function(idx){
272-
return scope.revertChangeConfirmation == idx;
273-
};
274-
275-
scope.downloadPatch = function(idx){
276-
var patch = unescape(scope.diffResult.patches[idx]);
277-
var patchName = PathUtils.extractFileName(scope.pathInActual) + ".patch";
278-
279-
var link = $window.document.createElement('a');
280-
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(patch));
281-
link.setAttribute('download', patchName);
282-
link.click();
283-
};
284-
285-
scope.revertChange = function(idx){
286-
delete scope.revertChangeConfirmation;
287-
288-
Backend.revertChange(scope.path, scope.diffResult.deltas[idx]).then(function(res){
289-
Backend.diffFile(scope.path, scope.curSnap.Name).then(function(res){
290-
scope.diffResult = res;
291-
})
292-
})
293-
};
294-
295-
// returns 'active' if a given name equals the current diffType
296-
// * for diff type tabs
297-
scope.activeClassIfDiffTypeIs = function(name){
298-
if(scope.diffType === name){
299-
return "active";
300-
}
301-
};
302-
303-
304-
305-
306-
//
307-
// initializations
308-
//
309-
scope.$watch('curSnap', function(){
310-
delete scope.revertChangeConfirmation;
311-
});
312-
313-
}
314-
}
315-
}]).
316-
317-
directive('zsdSideBySideDiffRows', ['$compile', function($compile){
318-
return {
319-
restrict: 'A',
320-
transclude: 'element',
321-
scope: {
322-
blocks: '='
323-
},
324-
compile: function(element, attr, linker){
325-
return function($scope, $element, $attr) {
326-
var childScopes = [];
327-
328-
var parent = $element.parent();
329-
var header = parent.children();
330-
$scope.$watchCollection('blocks', function(blocks){
331-
for(var i in childScopes){
332-
childScopes[i].$destroy();
333-
}
334-
parent.html('');
335-
parent.append(header);
336-
337-
//FIXME: cleanup!!!
338-
// delegate to downloadPatch from the caller side
339-
$scope.downloadPatch = function(idx){
340-
$scope.$parent.downloadPatch(idx);
341-
}
342-
343-
//FIXME: cleanup!!!
344-
// delegate to revertChange from the caller side
345-
$scope.revertChange = function(idx){
346-
$scope.$parent.revertChange(idx);
347-
}
348-
349-
350-
// add new
351-
for(i in blocks){
352-
// create a new scope
353-
var childScope = $scope.$new();
354-
355-
// pass patch counter as zsdIndex in the scope
356-
childScope['zsdIndex'] = +i;
357-
358-
// FIXME: remove $scope.$parent ($emit / $broadcast?)
359-
// pass showRevertChangeConfirmation / showRevertChangeConfirmationFor in the scope
360-
childScope['showRevertChangeConfirmation'] = $scope.$parent.showRevertChangeConfirmation;
361-
childScope['showRevertChangeConfirmationFor'] = $scope.$parent.showRevertChangeConfirmationFor;
362-
363-
364-
linker(childScope, function(clone){
365-
// add to the DOM
366-
parent.append(clone);
367-
parent.append(blocks[i]);
368-
369-
childScopes.push(childScope);
370-
});
371-
}
372-
});
373-
}
374-
}
375-
}
376-
}]).
377-
119+
378120
directive('zsdScrollToTop', ['$window', function($window){
379121
return function(scope, element, attrs){
380122
element.bind('click', function(event){

webapp/js/zsd-dir-browser.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
angular.module('zsdDirBrowser', ['zsdServices']).
2+
directive('zsdDirBrowser', ['Backend', 'PathUtils', function(Backend, PathUtils){
3+
return {
4+
restrict: 'E',
5+
templateUrl: 'template-dir-browser.html',
6+
scope: {
7+
start: '=',
8+
startEntries: '=',
9+
onFileSelected: '&',
10+
onDirSelected: '&'
11+
},
12+
link: function(scope, element, attrs){
13+
scope.fileSelected = false;
14+
15+
scope.filterHiddenEntries = function(entry){
16+
if(! scope.showHiddenEntries){
17+
if(entry.Path) return entry.Path.charAt(0) != '.';
18+
}
19+
return true;
20+
};
21+
22+
scope.isDirectory = function(entry){
23+
return entry.Type === "D"
24+
};
25+
26+
scope.isFile = function(entry){
27+
return entry.Type === "F"
28+
};
29+
30+
scope.open = function(entry){
31+
var idx = scope.entries.indexOf(entry);
32+
if(idx === -1){
33+
// user go deeper
34+
scope.entries = scope.entries.concat([entry]);
35+
}else{
36+
// user jump upward
37+
scope.entries = scope.entries.slice(0, idx + 1);
38+
}
39+
40+
41+
if(scope.isDirectory(entry)){
42+
scope.dirEntries = [{}];
43+
scope.fileSelected = false;
44+
scope.onDirSelected({entries: scope.entries});
45+
46+
var path = PathUtils.entriesToPath(scope.entries);
47+
Backend.listDir(path).then(function(dirListing){
48+
scope.dirListing = dirListing;
49+
});
50+
}else{
51+
scope.fileSelected = true;
52+
scope.onFileSelected({entries: scope.entries});
53+
}
54+
};
55+
56+
57+
58+
scope.$watch(function(){ return scope.start}, function(start){
59+
if(! angular.isDefined(start)) return;
60+
61+
scope.entries = [];
62+
scope.open({Type: 'D', Path: scope.start});
63+
});
64+
65+
scope.$watch(function(){ return scope.startEntries}, function(startEntries){
66+
if(! angular.isDefined(startEntries)) return;
67+
scope.entries = startEntries;
68+
69+
// start on last element
70+
scope.open(scope.entries[scope.entries.length - 1]);
71+
});
72+
73+
}
74+
};
75+
}]);
76+

0 commit comments

Comments
 (0)