Files
meanTorrent/modules/core/client/controllers/home.client.controller.js

198 lines
5.4 KiB
JavaScript
Raw Normal View History

(function () {
'use strict';
2014-02-10 13:09:31 +02:00
angular
.module('core')
.controller('HomeController', HomeController);
2017-05-17 18:46:33 +08:00
HomeController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'TorrentsService', 'Notification', 'MeanTorrentConfig',
'getStorageLangService', 'DownloadService', '$timeout', 'localStorageService'];
2017-05-17 18:46:33 +08:00
function HomeController($scope, $state, $translate, Authentication, TorrentsService, Notification, MeanTorrentConfig, getStorageLangService,
DownloadService, $timeout, localStorageService) {
var vm = this;
vm.tmdbConfig = MeanTorrentConfig.meanTorrentConfig.tmdbConfig;
vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app;
2017-05-16 16:42:06 +08:00
2017-05-16 19:33:47 +08:00
vm.movieTopOne = undefined;
2017-04-04 01:02:21 +08:00
vm.movieTopList = undefined;
2017-05-16 16:42:06 +08:00
vm.movieNewList = undefined;
vm.TVTopOne = undefined;
vm.TVTopList = undefined;
vm.TVNewList = undefined;
2017-04-01 14:22:11 +08:00
$(document).ready(function () {
$('#warning_popup').popup({
outline: false,
focusdelay: 400,
vertical: 'top',
autoopen: false,
opacity: 0.6,
closetransitionend: function () {
$('.popup_wrapper').remove();
}
});
});
/**
* If user is not signed in then redirect back signin
*/
if (!Authentication.user) {
$state.go('authentication.signin');
}
/**
2017-05-16 19:33:47 +08:00
* initTopOneInfo
*/
vm.initTopOneMovieInfo = function () {
if (vm.movieTopOne.resource_detail_info.backdrop_path) {
$('.movie-backdrop').css('backgroundImage', 'url(' + vm.tmdbConfig.backdrop_img_base_url + vm.movieTopOne.resource_detail_info.backdrop_path + ')');
}
};
/**
* initTopOneTVInfo
*/
vm.initTopOneTVInfo = function () {
if (vm.TVTopOne.resource_detail_info.backdrop_path) {
$('.tv-backdrop').css('backgroundImage', 'url(' + vm.tmdbConfig.backdrop_img_base_url + vm.TVTopOne.resource_detail_info.backdrop_path + ')');
}
2017-04-01 14:22:11 +08:00
};
2017-04-04 01:02:21 +08:00
/**
* getTopInfo
*/
2017-04-04 01:02:21 +08:00
vm.getTopInfo = function () {
vm.getMovieTopInfo();
vm.getTVTopInfo();
var sw = localStorageService.get('showed_warning');
if(vm.appConfig.show_warning_popup && !sw) {
$timeout(function () {
$('#warning_popup').popup('show');
//$('.warning_popup_open').trigger('click');
//angular.element('#myselector').triggerHandler('click');
}, 300);
localStorageService.set('showed_warning', true);
}
2017-04-04 01:02:21 +08:00
};
/**
* getMovieTopInfo
*/
2017-04-04 01:02:21 +08:00
vm.getMovieTopInfo = function () {
2017-04-27 09:36:56 +08:00
vm.moviesInfo = TorrentsService.get({
2017-05-16 16:42:06 +08:00
torrent_status: 'reviewed',
torrent_type: 'movie',
2017-05-16 19:33:47 +08:00
limit: 9
2017-04-04 01:02:21 +08:00
}, function (items) {
if (items.rows.length > 0) {
vm.movieTopOne = items.rows[0];
items.rows.splice(0, 1);
vm.movieTopList = items.rows;
2017-05-16 19:33:47 +08:00
vm.initTopOneMovieInfo();
}
2017-04-04 01:02:21 +08:00
}, function (err) {
Notification.error({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TOP_MOVIE_INFO_ERROR')
});
});
2017-05-16 16:42:06 +08:00
vm.moviesInfo = TorrentsService.get({
torrent_status: 'reviewed',
torrent_type: 'movie',
newest: true,
2017-05-16 19:33:47 +08:00
limit: 14
2017-05-16 16:42:06 +08:00
}, function (items) {
if (items.rows.length > 0) {
vm.movieNewList = items.rows;
}
2017-05-16 16:42:06 +08:00
}, function (err) {
Notification.error({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TOP_MOVIE_INFO_ERROR')
});
});
2017-04-04 01:02:21 +08:00
};
/**
* getTVTopInfo
*/
vm.getTVTopInfo = function () {
vm.tvsInfo = TorrentsService.get({
torrent_status: 'reviewed',
torrent_type: 'tvserial',
limit: 9
}, function (items) {
if (items.rows.length > 0) {
vm.TVTopOne = items.rows[0];
items.rows.splice(0, 1);
vm.TVTopList = items.rows;
vm.initTopOneTVInfo();
}
});
vm.moviesInfo = TorrentsService.get({
torrent_status: 'reviewed',
torrent_type: 'tvserial',
newest: true,
limit: 14
}, function (items) {
if (items.rows.length > 0) {
vm.TVNewList = items.rows;
}
});
};
/**
* openTorrentInfo
* @param id
*/
vm.openTorrentInfo = function (id) {
var url = $state.href('torrents.view', {torrentId: id});
2017-04-09 01:35:09 +08:00
window.open(url, '_blank');
};
2017-05-17 18:46:33 +08:00
/**
* getDirector
* @returns {string}
*/
vm.getDirector = function () {
var n = '-';
if (vm.movieTopOne && vm.movieTopOne.resource_detail_info) {
angular.forEach(vm.movieTopOne.resource_detail_info.credits.crew, function (item) {
if (item.job === 'Director') {
n = item.name;
}
});
}
return n;
};
2017-05-17 18:46:33 +08:00
/**
* 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')
});
});
};
}
}());