From 4da710b179f90fb3d6e92f2bf4fb798e51bbbc58 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Tue, 24 Oct 2017 19:25:16 +0800 Subject: [PATCH] feat(collections): show collection Vote average --- .../collections-view.client.controller.js | 17 +++++++++++++++-- .../collections.client.controller.js | 18 ++++++++++++++++++ .../views/collection-view.client.view.html | 7 +++++-- .../client/views/collections.client.view.html | 2 +- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/modules/collections/client/controllers/collections-view.client.controller.js b/modules/collections/client/controllers/collections-view.client.controller.js index ad3be258..258002e4 100644 --- a/modules/collections/client/controllers/collections-view.client.controller.js +++ b/modules/collections/client/controllers/collections-view.client.controller.js @@ -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); }); }; diff --git a/modules/collections/client/controllers/collections.client.controller.js b/modules/collections/client/controllers/collections.client.controller.js index 45d59926..4d1f8629 100644 --- a/modules/collections/client/controllers/collections.client.controller.js +++ b/modules/collections/client/controllers/collections.client.controller.js @@ -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 diff --git a/modules/collections/client/views/collection-view.client.view.html b/modules/collections/client/views/collection-view.client.view.html index 6f9a0428..99d4eb71 100644 --- a/modules/collections/client/views/collection-view.client.view.html +++ b/modules/collections/client/views/collection-view.client.view.html @@ -12,8 +12,11 @@
diff --git a/modules/collections/client/views/collections.client.view.html b/modules/collections/client/views/collections.client.view.html index 2de826ca..33e1b17e 100644 --- a/modules/collections/client/views/collections.client.view.html +++ b/modules/collections/client/views/collections.client.view.html @@ -42,7 +42,7 @@
- {{'COLLECTIONS.VOTE_AVERAGE' | translate}}: {{m.torrents.length}} + {{'COLLECTIONS.VOTE_AVERAGE' | translate}}: {{vm.getVoteAverage(m);}}