2015-10-25 06:17:45 +01:00
|
|
|
# Pony.fm - A community for pony fan music.
|
2018-04-21 06:25:36 +02:00
|
|
|
# Copyright (C) 2015 Feld0
|
2015-10-25 06:17:45 +01:00
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-08-31 17:42:21 +02:00
|
|
|
window.pfm.preloaders['dashboard'] = [
|
2015-10-25 03:35:37 +01:00
|
|
|
'dashboard'
|
|
|
|
(dashboard) -> dashboard.refresh(true)
|
2015-08-31 17:42:21 +02:00
|
|
|
]
|
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
module.exports = angular.module('ponyfm').controller "dashboard", [
|
2016-12-29 00:47:39 +01:00
|
|
|
'$scope', 'dashboard', 'auth', '$http', 'announcements', '$compile', 'tracks', 'player'
|
|
|
|
($scope, dashboard, auth, $http, announcements, $compile, tracks, player) ->
|
2016-03-16 05:37:17 +01:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
$scope.recentTracks = null
|
|
|
|
$scope.popularTracks = null
|
2016-11-11 20:39:31 +01:00
|
|
|
$scope.announcementClass = 'disabled'
|
|
|
|
$scope.announceWrapperClass = 'disabled'
|
|
|
|
|
2016-12-29 00:47:39 +01:00
|
|
|
$scope.play = (track) ->
|
|
|
|
index = _.indexOf $scope.announcement.parsedTracks, (t) -> t.id == track.id
|
|
|
|
player.playTracks $scope.announcement.parsedTracks, index
|
|
|
|
|
2016-11-11 20:39:31 +01:00
|
|
|
$scope.loadAnnouncementTemplate = (url) ->
|
|
|
|
$http.get('/templates/' + url).success (templateContent) ->
|
|
|
|
compiledHtml = $compile(templateContent)($scope)
|
|
|
|
$('#announcement').append(compiledHtml)
|
2016-12-29 00:47:39 +01:00
|
|
|
if $scope.announcement.tracks.length > 0
|
|
|
|
console.log($scope.announcement.tracks)
|
|
|
|
$scope.announcement.parsedTracks = []
|
2016-12-29 01:14:52 +01:00
|
|
|
tempTracks = []
|
|
|
|
|
|
|
|
# Not the greatest, but sod it
|
|
|
|
for track, i in $scope.announcement.tracks
|
|
|
|
console.log(i)
|
2016-12-29 00:47:39 +01:00
|
|
|
tracks.fetch(track, false).done (trackResponse) ->
|
2016-12-29 01:14:52 +01:00
|
|
|
theTrack = trackResponse.track
|
|
|
|
$scope.announcement.tracks.map((obj, index) ->
|
|
|
|
if obj == theTrack.id
|
|
|
|
theTrack.place = index
|
|
|
|
)
|
|
|
|
tempTracks.push(theTrack)
|
|
|
|
|
|
|
|
console.log(tempTracks)
|
|
|
|
if tempTracks.length == $scope.announcement.tracks.length
|
|
|
|
tempTracks.sort((a,b) ->
|
|
|
|
return a.place - b.place
|
|
|
|
)
|
|
|
|
$scope.announcement.parsedTracks = tempTracks
|
|
|
|
|
|
|
|
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
dashboard.refresh().done (res) ->
|
|
|
|
$scope.recentTracks = res.recent_tracks
|
|
|
|
$scope.popularTracks = res.popular_tracks
|
2016-11-11 20:39:31 +01:00
|
|
|
|
|
|
|
announcements.refresh().done (ann) ->
|
|
|
|
$scope.announcement = ann
|
|
|
|
if $scope.announcement != null
|
|
|
|
if parseInt($.cookie('hide-announcement')) != parseInt($scope.announcement.id)
|
|
|
|
$scope.announcement.dismiss = () ->
|
|
|
|
$scope.announceWrapperClass = 'disabled'
|
|
|
|
|
|
|
|
$scope.announcement.dontShowAgain = () ->
|
|
|
|
$scope.announcement.dismiss()
|
|
|
|
$.cookie('hide-announcement', $scope.announcement.id)
|
|
|
|
|
|
|
|
switch $scope.announcement.announcement_type_id
|
|
|
|
when 1
|
|
|
|
$scope.announcementClass = "simple-announce " + $scope.announcement.css_class
|
|
|
|
$scope.announceWrapperClass = null
|
|
|
|
$scope.loadAnnouncementTemplate('partials/default-announcement.html')
|
|
|
|
when 2
|
|
|
|
$scope.announcementClass = "alert-announce " + $scope.announcement.css_class
|
|
|
|
$scope.announceWrapperClass = null
|
|
|
|
$scope.loadAnnouncementTemplate('partials/alert-announcement.html')
|
|
|
|
when 3
|
|
|
|
$scope.announcementClass = "serious-alert-announce " + $scope.announcement.css_class
|
|
|
|
$scope.announceWrapperClass = null
|
|
|
|
$scope.loadAnnouncementTemplate('partials/alert-announcement.html')
|
|
|
|
when 4
|
2016-11-27 04:58:13 +01:00
|
|
|
console.log $scope.announcement.template_file
|
2016-11-11 20:39:31 +01:00
|
|
|
$scope.announcementClass = $scope.announcement.css_class
|
|
|
|
$scope.announceWrapperClass = null
|
2016-11-27 04:58:13 +01:00
|
|
|
$scope.loadAnnouncementTemplate($scope.announcement.template_file)
|
2015-09-16 21:55:15 +02:00
|
|
|
]
|