(function () { 'use strict'; angular .module('users') .controller('UploadedController', UploadedController); UploadedController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'Notification', 'TorrentsService', 'MeanTorrentConfig', '$window', '$filter', 'DownloadService', 'DebugConsoleService', 'TorrentGetInfoServices']; function UploadedController($scope, $state, $translate, $timeout, Authentication, Notification, TorrentsService, MeanTorrentConfig, $window, $filter, DownloadService, mtDebug, TGI) { var vm = this; vm.TGI = TGI; vm.user = Authentication.user; vm.resourcesTags = MeanTorrentConfig.meanTorrentConfig.resourcesTags; vm.torrentSalesType = MeanTorrentConfig.meanTorrentConfig.torrentSalesType; vm.searchTags = []; /** * If user is not signed in then redirect back home */ if (!Authentication.user) { $state.go('authentication.signin'); } /** * buildPager */ vm.buildPager = function () { vm.pagedItems = []; vm.itemsPerPage = 15; vm.currentPage = 1; vm.figureOutItemsToDisplay(); }; /** * figureOutItemsToDisplay */ vm.figureOutItemsToDisplay = function (callback) { vm.filteredItems = $filter('filter')(vm.uploadedList, { $: vm.search }); vm.filterLength = vm.filteredItems.length; var begin = ((vm.currentPage - 1) * vm.itemsPerPage); var end = begin + vm.itemsPerPage; vm.pagedItems = vm.filteredItems.slice(begin, end); if (callback) callback(); }; /** * pageChanged */ vm.pageChanged = function () { var element = angular.element('#top_of_torrent_list'); $('.tb-v-middle').fadeTo(100, 0.01, function () { vm.figureOutItemsToDisplay(function () { $timeout(function () { $('.tb-v-middle').fadeTo(400, 1, function () { //window.scrollTo(0, element[0].offsetTop - 60); $('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200); }); }, 100); }); }); }; /** * getUploadedTorrent */ vm.getUploadedTorrent = function () { TorrentsService.get({ userid: vm.user._id, torrent_type: 'all', torrent_status: 'all', torrent_vip: false }, function (items) { vm.uploadedList = items.rows; mtDebug.info(items); vm.buildPager(); }, function (err) { Notification.error({ message: ' ' + $translate.instant('UPLOADED_LIST_ERROR') }); }); }; /** * getTagTitle * @param tag: tag name * @returns {*} */ vm.getTagTitle = function (tag, item) { var tmp = tag; var find = false; angular.forEach(vm.resourcesTags.radio, function (item) { angular.forEach(item.value, function (sitem) { if (sitem.name === tag) { tmp = item.name; find = true; } }); }); if (!find) { angular.forEach(vm.resourcesTags.checkbox, function (item) { angular.forEach(item.value, function (sitem) { if (sitem.name === tag) { tmp = item.name; } }); }); } return tmp; }; /** * downloadTorrent * @param id */ vm.downloadTorrent = function (id) { var url = '/api/torrents/download/' + id; DownloadService.downloadFile(url, null, function (status) { if (status === 200) { Notification.success({ message: ' ' + $translate.instant('TORRENTS_DOWNLOAD_SUCCESSFULLY') }); } }, function (err) { Notification.error({ title: 'ERROR', message: ' ' + $translate.instant('TORRENT_DOWNLOAD_ERROR') }); }); }; /** * openTorrentInfo * @param id */ vm.openTorrentInfo = function (id) { var url = $state.href('torrents.view', {torrentId: id}); $window.open(url, '_blank'); }; } }());