feat(collections): show collection Vote average

This commit is contained in:
OldHawk
2017-10-24 19:25:16 +08:00
parent 845de18161
commit 4da710b179
4 changed files with 39 additions and 5 deletions

View File

@@ -29,10 +29,23 @@
collectionId: $state.params.collectionId
}, function (data) {
vm.collection = data;
mtDebug.info(data);
$('.backdrop').css('backgroundImage', 'url("' + vm.tmdbConfig.backdropImgBaseUrl + vm.collection.backdrop_path + '")');
//vm.buildPager();
//count ave vote
var total = 0;
var count = 0;
var total_users = 0;
angular.forEach(vm.collection.torrents, function(t){
total += t.resource_detail_info.vote_average;
count += 1;
total_users += t.resource_detail_info.vote_count;
});
vm.collection.vote_count = total_users;
vm.collection.vote_average = Math.floor((total / count) * 10) / 10;
mtDebug.info(vm.collection);
});
};

View File

@@ -59,6 +59,24 @@
});
};
/**
* getVoteAverage
* @param c
* @returns {number}
*/
vm.getVoteAverage = function (c) {
var total = 0;
var count = 0;
var avg = 0;
angular.forEach(c.torrents, function (t) {
total += t.resource_detail_info.vote_average;
count += 1;
});
avg = Math.floor((total / count) * 10) / 10;
return avg || 0;
};
/**
* pageChanged

View File

@@ -12,8 +12,11 @@
</div>
<div class="col-sm-12">
<ul class="list-unstyled item-data list-inline">
<li><i class="fa fa-list text-info"> {{'COLLECTIONS.FILES_NUMBERS' | translate}}: {{vm.collection.torrents.length}}</i></li>
<li><i class="fa fa-star-half-o text-info"> {{'COLLECTIONS.VOTE_AVERAGE' | translate}}: 0</i></li>
<li><i class="fa fa-list text-info"> {{'COLLECTIONS.FILES_NUMBERS' | translate}}: {{vm.collection.torrents.length}}</i>
</li>
<li><i class="fa fa-star-half-o text-info"> {{'COLLECTIONS.VOTE_AVERAGE' | translate}}:
{{vm.collection.vote_average}} / {{vm.collection.vote_count}} {{ 'TMDB_FIELDS.VOTE_UNIT' | translate}}
</i></li>
</ul>
</div>
</div>

View File

@@ -42,7 +42,7 @@
</div>
<div class="col-xs-6 col-small-padding text-center">
<i class="fa fa-star-half-o text-info">
<strong> {{'COLLECTIONS.VOTE_AVERAGE' | translate}}: {{m.torrents.length}}</strong></i>
<strong> {{'COLLECTIONS.VOTE_AVERAGE' | translate}}: {{vm.getVoteAverage(m);}}</strong></i>
</div>
</div>
</div>