Skip to content

Commit

Permalink
Section in Dashboard "Recommended for you" #53
Browse files Browse the repository at this point in the history
  • Loading branch information
dularion committed Feb 19, 2017
1 parent 4b9fb24 commit dfb1cdd
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
Expand Up @@ -97,6 +97,12 @@ angular.module('streama').controller('dashCtrl',
$scope.loadingMovies = false;
});

$scope.loadingRecommendations = true;
apiService.dash.listRecommendations().success(function (data) {
$scope.recommendations = data;
$scope.loadingRecommendations = false;
});

$scope.loadingGenericVideos = true;
apiService.dash.listGenericVideos().success(function (data) {
$scope.genericVideos = data;
Expand Down
4 changes: 4 additions & 0 deletions grails-app/assets/javascripts/streama/services/api-service.js
Expand Up @@ -281,6 +281,10 @@ angular.module('streama').factory('apiService', function ($http, $rootScope, con

listNewReleases: function () {
return $http.get('dash/listNewReleases.json');
},

listRecommendations: function () {
return $http.get('dash/listRecommendations.json');
}
},

Expand Down
31 changes: 30 additions & 1 deletion grails-app/assets/javascripts/streama/templates/dash.tpl.htm
Expand Up @@ -73,6 +73,36 @@ <h4>Continue "<span ng-bind="::(viewingStatus.video.title || viewingStatus.video
<hr/>
</div>


<div ng-if="recommendations.length && !selectedGenre">
<h3>{{'DASHBOARD.RECOMMENDATIONS' | translate}}</h3>


<div class="media-list media-list-continue-watching">
<div class="media-list-item media-poster-item" ng-repeat="video in recommendations track by video.id">
<div class="media-item" >

<img ng-if="video.poster_image_src" ng-src="{{::video.poster_image_src}}"/>
<img ng-if="!video.poster_image_src && video.poster_path"
ng-src="https://image.tmdb.org/t/p/w300/{{::video.poster_path}}"/>
<img ng-if="!video.poster_path && !video.poster_image_src"
ng-src="{{basePath}}assets/poster-not-found.png"/>

<div class="play-text">
<h4 ng-bind="::(video.title || video.show.name)"></h4>
<p ng-show="video.isEpisode"><span ng-bind="::video.episodeString"></span></p>
</div>

<i class="info-icon ion-ios-information" ng-click="showDetails(video)"></i>
<a class="play-icon ion-ios-play" ui-sref="player({videoId: video.id})"></a>
</div>
</div>
</div>


<hr/>
</div>

<div>
<h3>
<span ng-show="!selectedGenre">{{'DASHBOARD.DISCOVER_SHOWS' | translate}}</span>
Expand Down Expand Up @@ -112,7 +142,6 @@ <h3>

<div class="play-text">
<h4 ng-bind="::tvShow.name"></h4>
<p><span ng-bind="::tvShow.firstEpisode.episodeString"></span> - <span ng-bind="::tvShow.firstEpisode.name"></span></p>
</div>

<i class="info-icon ion-ios-information" ng-click="showDetails(tvShow)"></i>
Expand Down
Expand Up @@ -13,6 +13,7 @@ angular.module('streama.translations').config(function ($translateProvider) {
},
DASHBOARD: {
TITLE: 'Dashboard',
RECOMMENDATIONS: 'Recommendations for you',
NEW_RELEASES: 'New Releases',
CONTINUE_WATCHING: 'Continue Watching',
DISCOVER_SHOWS: 'Discover Shows',
Expand Down
37 changes: 29 additions & 8 deletions grails-app/controllers/streama/DashController.groovy
Expand Up @@ -41,19 +41,40 @@ class DashController {
}


def firstEpisodeForShow(TvShow tvShow){
Episode firstEpisode = tvShow.episodes?.find{it.files && it.season_number != "0"}

tvShow.episodes.each{ Episode episode ->
if((episode.season_number == firstEpisode?.season_number) && (episode.episode_number < firstEpisode?.episode_number) && episode.files){
firstEpisode = episode
def listRecommendations(){
User currentUser = springSecurityService.currentUser
List<Video> result = []
def favoriteGenreNames = currentUser.favoriteGenres*.name

if(!favoriteGenreNames){
respond (result as JSON)
}
def movies = Movie.where{
genre{
name in favoriteGenreNames
}
else if(episode.season_number < firstEpisode?.season_number && episode.files && episode.season_number != "0"){
firstEpisode = episode
deleted != true
}.list().findAll{it.hasFiles()}

def tvShows = TvShow.where{
genre{
name in favoriteGenreNames
}
episodes.size() > 0
deleted != true
}.list()
result = movies + tvShows*.firstEpisode

JSON.use ('dashViewingStatus') {
render (result as JSON)
}
}

if(firstEpisode && firstEpisode.files){

def firstEpisodeForShow(TvShow tvShow){
Episode firstEpisode = tvShow.firstEpisode
if(firstEpisode){
respond firstEpisode
}else{
respond status: NOT_FOUND
Expand Down
18 changes: 18 additions & 0 deletions grails-app/domain/streama/TvShow.groovy
Expand Up @@ -59,4 +59,22 @@ class TvShow {
return null
}
}


def getFirstEpisode(){
Episode firstEpisode = this.episodes?.find{it.files && it.season_number != "0"}

this.episodes.each{ Episode episode ->
if((episode.season_number == firstEpisode?.season_number) && (episode.episode_number < firstEpisode?.episode_number) && episode.files){
firstEpisode = episode
}
else if(episode.season_number < firstEpisode?.season_number && episode.files && episode.season_number != "0"){
firstEpisode = episode
}
}

if(firstEpisode && firstEpisode.files){
return firstEpisode
}
}
}

0 comments on commit dfb1cdd

Please sign in to comment.