(function () { "use strict"; var streamApp = angular.module('streamApp'); streamApp.directive('streamDirective', ['streamService', StreamDirective]); function StreamDirective(streamService) { return { restrict: 'E', transclude: true, scope: { callback: '=', id: '=', reverse: '=', stream: '=' }, templateUrl: '/App/Directives/stream/streamDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.dropUploading = streamService.isUploading(finishedUpload); scope.reverse = !!scope.reverse; scope.uploading = []; if (scope.dropUploading) { scope.uploading.push(true); }; function finishedUpload() { scope.uploading.pop(); scrollTo('drop_' + scope.dropUploading); let indexOf = scope.stream.findIndex(s => s.drop === scope.dropUploading); if (indexOf >= 0) { streamService.getMemory(scope.dropUploading).then(memory => scope.stream[indexOf] = memory); } }; scope.zoom = function (img) { scope.bigImage = img; }; scope.hideImage = function () { scope.bigImage = false; }; let once = true; scope.reload = function () { if (once) { streamUp = []; streamDown = []; once = false; scope.callback( scope.id, true, scope.stream ).then(function (data) { scope.stream = data; once = true; }).catch(() => once = true); } }; var streamUp = []; var streamDown = []; scope.showLess = function () { if (scope.stream && scope.stream.length > 20) { let tempStream = scope.stream.splice(10); streamDown = tempStream.concat(streamDown); } if (streamUp.length) { let tempStream = streamUp.splice(-10).concat(scope.stream); scope.stream = tempStream; } }; scope.showMore = function () { if (once && !streamDown.length) { once = false; scope.callback( scope.id, false, scope.stream ).then(function (data) { scope.stream = data; removeFromUp(); once = true; }); } else { removeFromUp(); let tempStream = streamDown.splice(0, 10); scope.stream = scope.stream.concat(tempStream); } }; function removeFromUp() { if (scope.stream && scope.stream.length > 20) { streamUp = streamUp.concat(scope.stream.splice(0, 10)); } } scope.reload(); } }; } }());