diff --git a/core/utils/string.py b/core/utils/string.py index 3506273..bce02d6 100644 --- a/core/utils/string.py +++ b/core/utils/string.py @@ -11,4 +11,31 @@ def rreplace(string, pattern, sub): """ Replaces 'pattern' in 'string' with 'sub' if 'pattern' ends 'string'. """ - return re.sub('%s$' % pattern, sub, string) \ No newline at end of file + return re.sub('%s$' % pattern, sub, string) + +def is_number(s): + try: + if len(s) > 0: + float(s) + return True + except ValueError: + pass + except IndexError: + pass + except Exception: + pass + + return False + +def trunc_lines(s, linecount): + ret = "" + cur = 0 + for line in s.splitlines(): + if cur < linecount: + ret += line + "\n" + cur += 1 + else: + break + + return ret + diff --git a/spa/api/v1/MixResource.py b/spa/api/v1/MixResource.py index 5dfb400..33e0b07 100644 --- a/spa/api/v1/MixResource.py +++ b/spa/api/v1/MixResource.py @@ -1,4 +1,4 @@ -from django.db.models.aggregates import Count +from django.template.loader import render_to_string from tastypie import fields from tastypie.authorization import Authorization from tastypie.constants import ALL_WITH_RELATIONS @@ -33,9 +33,6 @@ class MixResource(BackboneCompatibleResource): def dehydrate_mix_image(self, bundle): return bundle.obj.get_image_url() - def dehydrate_description(self, bundle): - return bundle.obj.description.replace("\n", "
") - def dehydrate(self, bundle): bundle.data['waveform_url'] = bundle.obj.get_waveform_url() bundle.data['user_name'] = bundle.obj.user.nice_name() @@ -44,7 +41,7 @@ class MixResource(BackboneCompatibleResource): bundle.data['play_count'] = bundle.obj.plays.count() bundle.data['like_count'] = bundle.obj.likes.count() bundle.data['mode'] = 'mix' - + bundle.data['tooltip'] = render_to_string('inc/player_tooltip.html', {'item': bundle.obj}) bundle.data['comment_count'] = bundle.obj.comments.count() bundle.data['liked'] = bundle.obj.is_liked(bundle.request.user) diff --git a/spa/templatetags/spa_extras.py b/spa/templatetags/spa_extras.py index 2349dc4..91b0040 100644 --- a/spa/templatetags/spa_extras.py +++ b/spa/templatetags/spa_extras.py @@ -2,8 +2,10 @@ import urlparse from allauth.socialaccount.models import SocialAccount from django import template from django.db.models import get_model +from django.template.defaultfilters import linenumbers from django_gravatar.helpers import has_gravatar, get_gravatar_url from core.analytics.google import ShowGoogleAnalyticsJS +from core.utils.string import is_number, trunc_lines from dss import settings from spa.models import _BaseModel @@ -79,4 +81,13 @@ def bind_lookup(parser, token): @register.tag def googleanalyticsjs(parser, token): - return ShowGoogleAnalyticsJS() \ No newline at end of file + return ShowGoogleAnalyticsJS() + +@register.filter +def truncmixlist(value): + if len(value) > 0: + if not is_number(value[0]): + value = linenumbers(value) + + value = trunc_lines(value, 5) + return value \ No newline at end of file diff --git a/static/css/deepsouthsounds.css b/static/css/deepsouthsounds.css index d9062ef..312e2a2 100644 --- a/static/css/deepsouthsounds.css +++ b/static/css/deepsouthsounds.css @@ -571,4 +571,4 @@ div.event-content td { padding: 15px 0 15px 70px; background: url(../img/whats-on.png) no-repeat left; margin: 0; -} \ No newline at end of file +} diff --git a/static/js/app/views/mix.js b/static/js/app/views/mix.js index 8d9e1af..7cf4ed4 100644 --- a/static/js/app/views/mix.js +++ b/static/js/app/views/mix.js @@ -12,6 +12,7 @@ window.MixListItemView = Backbone.View.extend({ "click .play-button-small-start":"startMix", "click .play-button-small-resume":"resume", "click .play-button-small-pause":"pauseMix", + "click .mix-link":"mixLink", "click .like-button a":"likeMix", "click .favourite-button a":"favouriteMix", "click .share-button":"shareLink", @@ -27,7 +28,13 @@ window.MixListItemView = Backbone.View.extend({ var id = this.model.get("id"); this.setLikeButton(id, this.model.get('liked')); this.setFavouriteButton(id, this.model.get('favourited')); - + $('#mix-link-' + id, this.el).popover({ + animation: true, + placement: 'bottom', + trigger: 'hover', + html: 'true', + delay: { show: 500, hide: 500 } + }); return this; }, setLikeButton:function (id, liked) { @@ -55,6 +62,9 @@ window.MixListItemView = Backbone.View.extend({ var mode = $(e.currentTarget).data("mode"); com.podnoms.utils.downloadURL("/audio/download/" + id); }, + mixLink:function (e) { + $(e.currentTarget).popover('hide'); + }, likeMix:function (e) { var id = $(e.currentTarget).data("id"); var mode = $(e.currentTarget).data("mode"); diff --git a/static/js/app/views/sidebar.js b/static/js/app/views/sidebar.js index ac0607c..753fbea 100644 --- a/static/js/app/views/sidebar.js +++ b/static/js/app/views/sidebar.js @@ -12,7 +12,7 @@ window.SidebarView = Backbone.View.extend({ "click #sidebar-play-pause-button-small":"togglePlayState", "click #sidebar-listen-live":"playLive" }, - initialize: function(){ + initialize:function () { this.render(); _.bindAll(this, "trackChanged"); _.bindAll(this, "trackPlaying"); @@ -26,7 +26,7 @@ window.SidebarView = Backbone.View.extend({ $("#live-now-playing", this.el).text(data.title); }); }, - render: function(){ + render:function () { $(this.el).html(this.template()); return this; }, @@ -41,14 +41,33 @@ window.SidebarView = Backbone.View.extend({ trackPlaying:function (data) { $(this.el).find('#header-play-button-icon').removeClass('icon-play'); $(this.el).find('#header-play-button-icon').addClass('icon-pause'); - }, trackPaused:function (data) { $(this.el).find('#header-play-button-icon').removeClass('icon-pause'); $(this.el).find('#header-play-button-icon').addClass('icon-play'); }, playLive:function () { - com.podnoms.player.playLive(); + var liveButton = $(this.el).find('#sidebar-listen-live'); + if ((liveButton).hasClass('btn-danger')) { + com.podnoms.player.stopPlaying(); + liveButton.removeClass('btn-danger').addClass('btn-success').text('Listen live'); + liveButton.blur(); + } else { + liveButton.button('loading'); + com.podnoms.player.playLive({ + success:function () { + $.getJSON( + 'ajax/live_now_playing/', + function (data) { + $('#live-now-playing', el).text(data.title); + data.title += " (live)"; + _eventAggregator.trigger("track_changed", data); + }); + liveButton.button('reset'); + liveButton.removeClass('btn-success').addClass('btn-danger').text('Stop listening'); + } + }); + } _eventAggregator.trigger("track_playing") var button = $(this.el).find('#sidebar-play-pause-button-small'); var el = this.el; @@ -56,12 +75,5 @@ window.SidebarView = Backbone.View.extend({ .removeClass('play-button-smallstart') .removeClass('play-button-small-loading') .addClass('play-button-small-pause'); - $.getJSON( - 'ajax/live_now_playing/', - function (data) { - $('#live-now-playing', el).text(data.title); - data.title += " (live)"; - _eventAggregator.trigger("track_changed", data); - }); } }); \ No newline at end of file diff --git a/static/js/com.podnoms.player.js b/static/js/com.podnoms.player.js index 9b9782f..c2bebb4 100644 --- a/static/js/com.podnoms.player.js +++ b/static/js/com.podnoms.player.js @@ -91,7 +91,8 @@ com.podnoms.player = { .addClass('play-button-smallstart'); this.currentId = null; - success(); + if (success != undefined) + success(); }, _parseOptions:function (options) { this.currentId = options.id; @@ -157,8 +158,12 @@ com.podnoms.player = { } }); }, + stopPlaying: function(){ + this._destroyCurrent(); + }, playLive:function () { var ref = this; + var args = arguments; this._destroyCurrent(function () { ref.currentSound = soundManager.createSound({ id:'com.podnoms.player-live', @@ -169,6 +174,7 @@ com.podnoms.player = { }); if (ref.currentSound) { ref.currentSound.play(); + args[0].success(); } else { com.podnoms.utils.showError('Oooopsies', 'Error playing sound..'); diff --git a/templates/base.html b/templates/base.html index 587e506..79d2abc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -84,13 +84,16 @@ -{% if debug %} + + + + @@ -141,7 +144,6 @@ {% endcompress %} - {% block footerscripts %} {% endblock %} diff --git a/templates/inc/_MixItemInsert.html b/templates/inc/_MixItemInsert.html index 4ae0e6b..7c17a63 100644 --- a/templates/inc/_MixItemInsert.html +++ b/templates/inc/_MixItemInsert.html @@ -6,7 +6,16 @@
-

<%= item.title %>

+

+ <%= item.title %> + +

{% if user.is_authenticated %} - <% if (item.download_allowed) { %> - - <% } %> + <% if (item.download_allowed) { %> + + <% } %> {% endif %} {% if user.is_staff %} - + {% endif %} diff --git a/templates/inc/player_tooltip.html b/templates/inc/player_tooltip.html new file mode 100644 index 0000000..209aeaa --- /dev/null +++ b/templates/inc/player_tooltip.html @@ -0,0 +1 @@ +{% load spa_extras %}{{ item.description|truncmixlist|linebreaksbr }} \ No newline at end of file diff --git a/templates/inc/side-player.html b/templates/inc/side-player.html index dd694bc..60af17d 100644 --- a/templates/inc/side-player.html +++ b/templates/inc/side-player.html @@ -19,7 +19,7 @@
Now on DSS Radio -