|
1 | 1 | angular.module('zsdDirectives', ['zsdUtils', 'zsdServices']). |
2 | 2 |
|
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 | | - |
58 | 3 |
|
59 | 4 | // https://github.com/angular/angular.js/issues/339 |
60 | 5 | directive('zsdEmbedSrc', function () { |
@@ -116,81 +61,6 @@ directive('zsdShowIfEmpty', function(){ |
116 | 61 | }). |
117 | 62 |
|
118 | 63 |
|
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 | | - |
194 | 64 | directive('zsdModal', [function(){ |
195 | 65 | return { |
196 | 66 | restrict: 'E', |
@@ -246,135 +116,7 @@ directive('zsdNotifications', ['$rootScope', '$timeout', 'Notifications', functi |
246 | 116 | templateUrl: "template-notifications.html" |
247 | 117 | } |
248 | 118 | }]). |
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 | + |
378 | 120 | directive('zsdScrollToTop', ['$window', function($window){ |
379 | 121 | return function(scope, element, attrs){ |
380 | 122 | element.bind('click', function(event){ |
|
0 commit comments