From 152e1e1fb6eb3e011a89b954da50a0797972d993 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Mon, 2 May 2016 23:25:54 +0100 Subject: [PATCH] Passing stats data to the front end --- public/templates/tracks/show.html | 1 + public/templates/tracks/stats.html | 1 + resources/assets/scripts/app/app.coffee | 5 +++ .../app/controllers/track-stats.coffee | 27 ++++++++++++++++ .../scripts/app/services/track-stats.coffee | 32 +++++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 public/templates/tracks/stats.html create mode 100644 resources/assets/scripts/app/controllers/track-stats.coffee create mode 100644 resources/assets/scripts/app/services/track-stats.coffee diff --git a/public/templates/tracks/show.html b/public/templates/tracks/show.html index 21807294..eadb69fc 100644 --- a/public/templates/tracks/show.html +++ b/public/templates/tracks/show.html @@ -22,6 +22,7 @@
  • Plays: {{::track.stats.plays}}
  • Downloads: {{::track.stats.downloads}}
  • Favourites: {{::track.stats.favourites}}
  • +
  • View more stats
  • diff --git a/public/templates/tracks/stats.html b/public/templates/tracks/stats.html new file mode 100644 index 00000000..5dd6b44b --- /dev/null +++ b/public/templates/tracks/stats.html @@ -0,0 +1 @@ +

    THERE ARE NO STATS HERE BECAUSE I HAVEN'T CODED THAT YET BUT AT LEAST YOU'RE READING THIS WHICH MEANS NOT EVERYTHING IS BROKEN

    diff --git a/resources/assets/scripts/app/app.coffee b/resources/assets/scripts/app/app.coffee index f223b598..9f87c38b 100644 --- a/resources/assets/scripts/app/app.coffee +++ b/resources/assets/scripts/app/app.coffee @@ -174,6 +174,11 @@ ponyfm.config [ templateUrl: '/templates/tracks/edit.html' controller: 'track-edit' + state.state 'content.track.stats', + url: '/stats' + templateUrl: '/templates/tracks/stats.html' + controller: 'track-stats' + # Albums diff --git a/resources/assets/scripts/app/controllers/track-stats.coffee b/resources/assets/scripts/app/controllers/track-stats.coffee new file mode 100644 index 00000000..e7a2cf08 --- /dev/null +++ b/resources/assets/scripts/app/controllers/track-stats.coffee @@ -0,0 +1,27 @@ +# Pony.fm - A community for pony fan music. +# Copyright (C) 2016 Peter Deltchev +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +module.exports = angular.module('ponyfm').controller "track-stats", [ + '$scope', '$state', 'track-stats' + ($scope, $state, statsService) -> + $scope.trackId = parseInt($state.params.id) + + statsLoaded = (stats) -> + console.log(stats) + + statsService.loadStats($scope.trackId).done statsLoaded +] diff --git a/resources/assets/scripts/app/services/track-stats.coffee b/resources/assets/scripts/app/services/track-stats.coffee new file mode 100644 index 00000000..907ff06c --- /dev/null +++ b/resources/assets/scripts/app/services/track-stats.coffee @@ -0,0 +1,32 @@ +# Pony.fm - A community for pony fan music. +# Copyright (C) 2016 Peter Deltchev +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +module.exports = angular.module('ponyfm').factory('track-stats', [ + '$rootScope', '$http' + ($rootScope, $http) -> + stats = [] + + self = + loadStats: (id) -> + return def if def + def = new $.Deferred() + $http.get('/api/web/tracks/' + id + '/stats').success (stats) -> + def.resolve stats + + def.promise() + + self +])