mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-15 03:42:23 +01:00
164 lines
4.4 KiB
JavaScript
164 lines
4.4 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users')
|
|
.controller('UploadedController', UploadedController);
|
|
|
|
UploadedController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'Notification', 'TorrentsService',
|
|
'MeanTorrentConfig', '$window', '$filter', 'DownloadService'];
|
|
|
|
function UploadedController($scope, $state, $translate, $timeout, Authentication, Notification, TorrentsService, MeanTorrentConfig,
|
|
$window, $filter, DownloadService) {
|
|
var vm = this;
|
|
vm.user = Authentication.user;
|
|
vm.tmdbConfig = MeanTorrentConfig.meanTorrentConfig.tmdbConfig;
|
|
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);
|
|
});
|
|
});
|
|
};
|
|
|
|
/**
|
|
* getUploadedTorrend
|
|
*/
|
|
vm.getUploadedTorrend = function () {
|
|
TorrentsService.get({
|
|
userid: vm.user._id,
|
|
torrent_type: 'all',
|
|
torrent_status: 'all'
|
|
}, function (items) {
|
|
vm.uploadedList = items.rows;
|
|
vm.buildPager();
|
|
}, function (err) {
|
|
Notification.error({
|
|
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('UPLOADED_LIST_ERROR')
|
|
});
|
|
});
|
|
};
|
|
|
|
/**
|
|
* getTagTitle
|
|
* @param tag: tag name
|
|
* @returns {*}
|
|
*/
|
|
vm.getTagTitle = function (tag, item) {
|
|
var tmp = tag;
|
|
var find = false;
|
|
var r = undefined;
|
|
|
|
switch (item.torrent_type) {
|
|
case 'tvserial':
|
|
r = vm.resourcesTags.tv;
|
|
break;
|
|
case 'music':
|
|
r = vm.resourcesTags.music;
|
|
break;
|
|
case 'other':
|
|
r = vm.resourcesTags.other;
|
|
break;
|
|
default:
|
|
r = vm.resourcesTags.movie;
|
|
}
|
|
|
|
angular.forEach(r.radio, function (item) {
|
|
angular.forEach(item.value, function (sitem) {
|
|
if (sitem.name === tag) {
|
|
tmp = item.name;
|
|
find = true;
|
|
}
|
|
});
|
|
});
|
|
|
|
if (!find) {
|
|
angular.forEach(r.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: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENTS_DOWNLOAD_SUCCESSFULLY')
|
|
});
|
|
}
|
|
}, function (err) {
|
|
Notification.error({
|
|
title: 'ERROR',
|
|
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_DOWNLOAD_ERROR')
|
|
});
|
|
});
|
|
};
|
|
|
|
/**
|
|
* openTorrentInfo
|
|
* @param id
|
|
*/
|
|
vm.openTorrentInfo = function (id) {
|
|
var url = $state.href('torrents.view', {torrentId: id});
|
|
$window.open(url, '_blank');
|
|
};
|
|
}
|
|
}());
|