-
Notifications
You must be signed in to change notification settings - Fork 983
/
dash-ctrl.js
171 lines (141 loc) · 5.87 KB
/
dash-ctrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
angular.module('streama').controller('dashCtrl',
function ($scope, apiService, $state, $rootScope, localStorageService, modalService, $stateParams, mediaListService, currentUser ) {
var vm = this;
var LIST_MAX = 30;
vm.fetchFirstEpisodeAndPlay = fetchFirstEpisodeAndPlay;
vm.showDetails = showDetails;
vm.markCompleted = markCompleted;
vm.loadingRecommendations = true;
vm.isDashSectionHidden = isDashSectionHidden;
$scope.$on('changedGenre', onChangedGenre);
init();
function init() {
if ($rootScope.currentUser.isAdmin) {
showInitialSettingsWarning();
}
if ($stateParams.mediaModal) {
modalService.mediaDetailModal({mediaId: $stateParams.mediaModal, mediaType: $stateParams.mediaType, isApiMovie: false});
}
if(!localStorageService.get('currentProfile')){
apiService.profile.getUserProfiles().success(function(data) {
localStorageService.set('currentProfile', data[0]);
initMedia();
}
).error(function (data) {
alertify.error(data.message);
});
} else {
initMedia();
}
}
function initMedia() {
vm.movie = mediaListService.init(apiService.dash.listMovies, {sort: 'title', order: 'ASC'}, currentUser.data);
vm.tvShow = mediaListService.init(apiService.dash.listShows, {sort: 'name', order: 'ASC'}, currentUser.data);
vm.genericVideo = mediaListService.init(apiService.dash.listGenericVideos, {sort: 'title', order: 'ASC'}, currentUser.data);
apiService.tag.list().success(onTagsLoaded);
apiService.dash.listNewReleases().success(onNewReleasesLoaded);
apiService.dash.listContinueWatching().success(onContinueWatchingLoaded);
apiService.dash.listRecommendations().success(onRecommendedLoaded);
apiService.dash.listGenres().success(onGenreLoaded);
}
// HOISTED FUNCTIONS BELOW
function onRecommendedLoaded(data) {
vm.recommendations = data;
vm.loadingRecommendations = false;
}
function fetchData(mediaConfig) {
mediaConfig.fetch({max: LIST_MAX, offset: mediaConfig.currentOffset, sort: mediaConfig.currentSort.sort, order: mediaConfig.currentSort.order}).success(function (response) {
mediaConfig.total = response.total;
if(mediaConfig.currentOffset > 0){
mediaConfig.list = _.unionBy(mediaConfig.list, response.list, 'id');
}else{
mediaConfig.list = response.list;
}
mediaConfig.isLoading = false;
});
}
function onContinueWatchingLoaded(data) {
vm.continueWatching = data;
}
function onNewReleasesLoaded(data) {
vm.newReleases = data;
}
function onTagsLoaded(data) {
vm.tags = data;
}
function onGenreLoaded(data) {
$rootScope.genres = data;
if ($stateParams.genreId) {
$rootScope.selectedGenre = _.find(data, {id: parseInt($stateParams.genreId)});
vm.movie.filter.genre = [$rootScope.selectedGenre];
vm.tvShow.filter.genre = [$rootScope.selectedGenre];
}
}
function showInitialSettingsWarning() {
apiService.settings.list().success(function (data) {
$scope.settings = data;
var TheMovieDbAPI = _.find(data, {settingsKey: 'Upload Directory'});
if (!TheMovieDbAPI.value) {
alertify.alert('You need to fill out some required base-settings. You will be redirected to the settings page now.', function () {
$state.go('settings.settings');
});
}
});
}
function onChangedGenre(e, genre) {
$rootScope.selectedGenre = genre;
if ($rootScope.selectedGenre) {
vm.movie.filter.genre = [$rootScope.selectedGenre];
vm.tvShow.filter.genre = [$rootScope.selectedGenre];
} else {
vm.movie.filter.genre = [];
vm.tvShow.filter.genre = [];
}
}
function fetchFirstEpisodeAndPlay(tvShow) {
apiService.dash.firstEpisodeForShow(tvShow.id).success(function (data) {
$state.go('player', {videoId: data.id});
});
}
function showDetails(media) {
//modalService.mediaDetailModal((media.tvShowId || media.id), media.mediaType); //{videoId: data.id}
if(media.mediaType === 'episode'){
modalService.mediaDetailModal({mediaId: media.tvShowId, mediaType: 'tvShow', isApiMovie: false});
}else{
modalService.mediaDetailModal({mediaId: media.id, mediaType: media.mediaType, isApiMovie: false});
}
}
function applyFilter(item, filterObj) {
var showItemArray = [];
_.forEach(filterObj, function (filterVal, key) {
if (_.isArray(filterVal) && filterVal.length) {
var intersection = _.intersectionBy(item[key], filterVal, 'id');
var isVisible = (intersection.length ? true : false);
showItemArray.push(isVisible);
}
if (_.isString(filterVal) && filterVal.length >= 1) {
var isVisible = (_.includes(item[key].toLowerCase(), filterVal.toLowerCase()) ? true : false);
showItemArray.push(isVisible);
}
});
return (showItemArray.indexOf(false) < 0);
}
function markCompleted(viewingStatus) {
alertify.set({buttonReverse: true, labels: {ok: "Yes", cancel: "Cancel"}});
alertify.confirm("Are you sure you want to mark this video as completed?", function (confirmed) {
if (confirmed) {
apiService.viewingStatus.delete(viewingStatus.id).success(function (data) {
_.remove(vm.continueWatching, {'id': viewingStatus.id});
});
}
})
}
function isDashSectionHidden(sectionName) {
var hiddenDashSectionSetting = _.find($scope.settings, {name: 'hidden_dash_sections'});
if(hiddenDashSectionSetting.value){
var hiddenDashSections = hiddenDashSectionSetting.value.split(',');
return (hiddenDashSections.indexOf(sectionName) > -1);
}
}
});