mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
#2: The track editor now updates the list of tracks in the account section.
This commit is contained in:
parent
46b95cadc0
commit
dda46768fb
6 changed files with 31 additions and 192 deletions
|
@ -1,7 +1,7 @@
|
|||
<div class="two-pane-view" ng-class="{open: data.selectedTrack != null, closed: data.selectedTrack == null}">
|
||||
<div class="list">
|
||||
<ul class="account-tracks-listing stretch-to-bottom">
|
||||
<li ng-repeat="track in tracks" ng-class="{selected: track.id == data.selectedTrack.id, 'is-not-published': !track.is_published}">
|
||||
<li ng-repeat="track in tracks track by track.id" ng-class="{selected: track.id == data.selectedTrack.id, 'is-not-published': !track.is_published}">
|
||||
<a href="/account/tracks/edit/{{track.id}}" ng-click="selectTrack(track)">
|
||||
<img class="image" ng-src="{{track.cover_url}}" />
|
||||
<span class="title">{{track.title}}</span>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<i ng-show="isSaving" class="icon-cog icon-spin icon-large"></i>
|
||||
</button>
|
||||
</li>
|
||||
<li class="delete"><a ng-class="{disabled: isSaving}" class="btn btn-danger" href="#" ng-click="deleteTrack(data.selectedTrack)" pfm-eat-click>Delete Track</a></li>
|
||||
<li class="delete"><a ng-class="{disabled: isSaving}" class="btn btn-danger" href="#" ng-click="deleteTrack()" pfm-eat-click>Delete Track</a></li>
|
||||
</ul>
|
||||
<div class="stretch-to-bottom">
|
||||
<div class="form-row" ng-class="{'has-error': errors.title != null}">
|
||||
|
|
|
@ -14,151 +14,9 @@
|
|||
# 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/>.
|
||||
|
||||
#window.pfm.preloaders['account-track'] = [
|
||||
# 'account-tracks', 'account-albums', 'taxonomies', '$state'
|
||||
# (tracks, albums, taxonomies, state) ->
|
||||
# $.when.all [albums.refresh(), taxonomies.refresh(), tracks.getEdit(state.params.track_id, true)]
|
||||
#]
|
||||
|
||||
angular.module('ponyfm').controller "account-track", [
|
||||
'$scope', '$state', 'taxonomies', '$dialog', 'account-albums', 'account-tracks', 'images'
|
||||
($scope, $state, taxonomies, $dialog, albums, tracks, images) ->
|
||||
'$scope', '$state'
|
||||
($scope, $state) ->
|
||||
# All the fun stuff happens in the pfmTrackEditor directive.
|
||||
$scope.trackId = $state.params.track_id
|
||||
# $scope.isDirty = false
|
||||
# $scope.isSaving = false
|
||||
# $scope.taxonomies = taxonomies
|
||||
# $scope.selectedSongsTitle = 'None'
|
||||
# $scope.selectedSongs = {}
|
||||
# $scope.albums = []
|
||||
# $scope.selectedAlbum = null
|
||||
#
|
||||
# albumsDb = {}
|
||||
# albums.refresh().done (albums) ->
|
||||
# $scope.albums.legnth = 0
|
||||
# albumsDb = {}
|
||||
# for album in albums
|
||||
# albumsDb[album.id] = album
|
||||
# $scope.albums.push album
|
||||
#
|
||||
# $scope.selectAlbum = (album) ->
|
||||
# $scope.selectedAlbum = album
|
||||
# $scope.edit.album_id = if album then album.id else null
|
||||
# $scope.isDirty = true
|
||||
#
|
||||
# $scope.setCover = (image, type) ->
|
||||
# delete $scope.edit.cover_id
|
||||
# delete $scope.edit.cover
|
||||
#
|
||||
# if image == null
|
||||
# $scope.edit.remove_cover = true
|
||||
# else if type == 'file'
|
||||
# $scope.edit.cover = image
|
||||
# else if type == 'gallery'
|
||||
# $scope.edit.cover_id = image.id
|
||||
#
|
||||
# $scope.isDirty = true
|
||||
#
|
||||
# updateSongDisplay = () ->
|
||||
# if _.size $scope.selectedSongs
|
||||
# $scope.selectedSongsTitle = (_.map _.values($scope.selectedSongs), (s) -> s.title).join(', ')
|
||||
# else
|
||||
# $scope.selectedSongsTitle = 'None'
|
||||
#
|
||||
# $scope.toggleSong = (song) ->
|
||||
# $scope.isDirty = true
|
||||
# if $scope.selectedSongs[song.id]
|
||||
# delete $scope.selectedSongs[song.id]
|
||||
# else
|
||||
# $scope.selectedSongs[song.id] = song
|
||||
#
|
||||
# updateSongDisplay()
|
||||
#
|
||||
# $scope.updateIsVocal = () ->
|
||||
# delete $scope.errors.lyrics if !$scope.edit.is_vocal
|
||||
#
|
||||
# $scope.updateTrack = () ->
|
||||
# xhr = new XMLHttpRequest()
|
||||
# xhr.onload = -> $scope.$apply ->
|
||||
# $scope.isSaving = false
|
||||
# if xhr.status != 200
|
||||
# errors =
|
||||
# if xhr.getResponseHeader('content-type') == 'application/json'
|
||||
# $.parseJSON(xhr.responseText).errors
|
||||
# else
|
||||
# ['There was an unknown error!']
|
||||
#
|
||||
# $scope.errors = {}
|
||||
# _.each errors, (value, key) -> $scope.errors[key] = value.join ', '
|
||||
# return
|
||||
#
|
||||
# track = $.parseJSON(xhr.responseText)
|
||||
#
|
||||
# trackDbItem = $scope.data.selectedTrack
|
||||
# trackDbItem.title = $scope.edit.title
|
||||
# trackDbItem.is_explicit = $scope.edit.is_explicit
|
||||
# trackDbItem.is_vocal = $scope.edit.is_vocal
|
||||
# trackDbItem.genre_id = $scope.edit.genre_id
|
||||
# trackDbItem.is_published = true
|
||||
# trackDbItem.cover_url = track.real_cover_url
|
||||
# $scope.isDirty = false
|
||||
# $scope.errors = {}
|
||||
# images.refresh true
|
||||
#
|
||||
# formData = new FormData();
|
||||
# _.each $scope.edit, (value, name) ->
|
||||
# if name == 'cover'
|
||||
# return if value == null
|
||||
# if typeof(value) == 'object'
|
||||
# formData.append name, value, value.name
|
||||
# else if value != null
|
||||
# formData.append name, value
|
||||
#
|
||||
# if parseInt($scope.edit.track_type_id) == 2
|
||||
# formData.append 'show_song_ids', _.map(_.values($scope.selectedSongs), (s) -> s.id).join()
|
||||
#
|
||||
# xhr.open 'POST', '/api/web/tracks/edit/' + $scope.edit.id, true
|
||||
# xhr.setRequestHeader 'X-XSRF-TOKEN', $.cookie('XSRF-TOKEN')
|
||||
# $scope.isSaving = true
|
||||
# xhr.send formData
|
||||
#
|
||||
#
|
||||
# tracks.getEdit($state.params.track_id).done (track) ->
|
||||
# $scope.edit =
|
||||
# id: track.id
|
||||
# title: track.title
|
||||
# description: track.description
|
||||
# lyrics: track.lyrics
|
||||
# is_explicit: track.is_explicit
|
||||
# is_downloadable: track.is_downloadable
|
||||
# is_vocal: track.is_vocal
|
||||
# license_id: track.license_id
|
||||
# genre_id: track.genre_id
|
||||
# track_type_id: track.track_type_id
|
||||
# released_at: if track.released_at then track.released_at.date else ''
|
||||
# remove_cover: false
|
||||
# cover: track.cover_url
|
||||
# album_id: track.album_id
|
||||
# is_published: track.is_published
|
||||
# is_listed: track.is_listed
|
||||
#
|
||||
# $scope.selectedAlbum = if track.album_id then albumsDb[track.album_id] else null
|
||||
# $scope.selectedSongs = {}
|
||||
# $scope.selectedSongs[song.id] = song for song in track.show_songs
|
||||
# updateSongDisplay()
|
||||
#
|
||||
# $scope.touchModel = -> $scope.isDirty = true
|
||||
#
|
||||
# $scope.deleteTrack = (track) ->
|
||||
# $dialog.messageBox('Delete ' + track.title, 'Are you sure you want to delete "' + track.title + '"?', [
|
||||
# {result: 'ok', label: 'Yes', cssClass: 'btn-danger'}, {result: 'cancel', label: 'No', cssClass: 'btn-primary'}
|
||||
# ]).open().then (res) ->
|
||||
# return if res == 'cancel'
|
||||
# $.post('/api/web/tracks/delete/' + track.id)
|
||||
# .then -> $scope.$apply ->
|
||||
# $scope.$emit 'track-deleted'
|
||||
# $state.transitionTo 'account.tracks'
|
||||
#
|
||||
# $scope.$on '$locationChangeStart', (e) ->
|
||||
# return if !$scope.isDirty
|
||||
# e.preventDefault() if !confirm('Are you sure you want to leave this page without saving your changes?')
|
||||
]
|
||||
|
|
|
@ -54,7 +54,12 @@ angular.module('ponyfm').controller "account-tracks", [
|
|||
else
|
||||
$scope.selectTrack null
|
||||
|
||||
$scope.$on 'track-updated', (track) ->
|
||||
tracks.clearCache()
|
||||
$scope.refreshList()
|
||||
|
||||
$scope.$on 'track-deleted', () ->
|
||||
$state.transitionTo 'account.tracks'
|
||||
tracks.clearCache()
|
||||
$scope.refreshList()
|
||||
]
|
||||
|
|
|
@ -14,19 +14,8 @@
|
|||
# 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/>.
|
||||
|
||||
window.pfm.preloaders['track-edit'] = [
|
||||
'tracks', '$state', 'playlists'
|
||||
(tracks, $state, playlists) ->
|
||||
$.when.all [tracks.fetch $state.params.id, playlists.refreshOwned(true)]
|
||||
]
|
||||
|
||||
angular.module('ponyfm').controller "track-edit", [
|
||||
'$scope', 'tracks', '$state', 'playlists', 'auth', 'favourites', '$dialog'
|
||||
($scope, tracks, $state, playlists, auth, favourites, $dialog) ->
|
||||
track = null
|
||||
|
||||
tracks.fetch($state.params.id).done (trackResponse) ->
|
||||
$scope.track = trackResponse.track
|
||||
track = trackResponse.track
|
||||
|
||||
'$scope', '$state'
|
||||
($scope, $state) ->
|
||||
]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Pony.fm - A community for pony fan music.
|
||||
# Copyright (C) 2015 Peter Deltchev
|
||||
# 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
|
||||
|
@ -14,14 +14,6 @@
|
|||
# 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/>.
|
||||
|
||||
#
|
||||
#window.pfm.preloaders['account-track'] = [
|
||||
# 'account-albums', 'taxonomies'
|
||||
# (albums, taxonomies, state) ->
|
||||
# $.when.all [albums.refresh(), taxonomies.refresh()]
|
||||
#]
|
||||
|
||||
|
||||
angular.module('ponyfm').directive 'pfmTrackEditor', () ->
|
||||
restrict: 'E'
|
||||
templateUrl: '/templates/directives/track-editor.html'
|
||||
|
@ -29,8 +21,8 @@ angular.module('ponyfm').directive 'pfmTrackEditor', () ->
|
|||
trackId: '=trackId'
|
||||
|
||||
controller: [
|
||||
'$scope', 'auth', 'account-tracks', 'account-albums', 'taxonomies', 'images'
|
||||
($scope, auth, tracks, albums, taxonomies, images) ->
|
||||
'$scope', '$dialog', 'auth', 'account-tracks', 'account-albums', 'taxonomies', 'images'
|
||||
($scope, $dialog, auth, tracks, albums, taxonomies, images) ->
|
||||
$scope.isDirty = false
|
||||
$scope.isSaving = false
|
||||
$scope.taxonomies = taxonomies
|
||||
|
@ -94,14 +86,9 @@ angular.module('ponyfm').directive 'pfmTrackEditor', () ->
|
|||
return
|
||||
|
||||
track = $.parseJSON(xhr.responseText)
|
||||
$scope.$emit('track-updated', track)
|
||||
|
||||
# trackDbItem = $scope.data.selectedTrack
|
||||
# trackDbItem.title = $scope.track.title
|
||||
# trackDbItem.is_explicit = $scope.track.is_explicit
|
||||
# trackDbItem.is_vocal = $scope.track.is_vocal
|
||||
# trackDbItem.genre_id = $scope.track.genre_id
|
||||
# trackDbItem.is_published = true
|
||||
# trackDbItem.cover_url = track.real_cover_url
|
||||
$scope.track.is_published = true
|
||||
$scope.isDirty = false
|
||||
$scope.errors = {}
|
||||
images.refresh true
|
||||
|
@ -123,24 +110,32 @@ angular.module('ponyfm').directive 'pfmTrackEditor', () ->
|
|||
$scope.isSaving = true
|
||||
xhr.send formData
|
||||
|
||||
$scope.deleteTrack = (track) ->
|
||||
$dialog.messageBox('Delete ' + track.title, 'Are you sure you want to delete "' + track.title + '"?', [
|
||||
$scope.deleteTrack = () ->
|
||||
$dialog.messageBox('Delete ' + $scope.track.title, 'Are you sure you want to delete "' + $scope.track.title + '"?', [
|
||||
{result: 'ok', label: 'Yes', cssClass: 'btn-danger'},
|
||||
{result: 'cancel', label: 'No', cssClass: 'btn-primary'}
|
||||
]).open().then (res) ->
|
||||
return if res == 'cancel'
|
||||
$.post('/api/web/tracks/delete/' + track.id)
|
||||
$.post('/api/web/tracks/delete/' + $scope.track.id)
|
||||
.then -> $scope.$apply ->
|
||||
$scope.$emit 'track-deleted'
|
||||
$state.transitionTo 'account.tracks'
|
||||
|
||||
## Bootstrap this thing
|
||||
|
||||
# ========================================
|
||||
# The part where everything gets loaded!
|
||||
# ========================================
|
||||
$.when(
|
||||
albums.refresh(),
|
||||
taxonomies.refresh(),
|
||||
tracks.getEdit($scope.trackId)
|
||||
).done (albums, taxonomies, track)->
|
||||
# Update album data
|
||||
$scope.albums.length = 0
|
||||
albumsDb = {}
|
||||
for album in albums
|
||||
albumsDb[album.id] = album
|
||||
$scope.albums.push album
|
||||
|
||||
# Update track data
|
||||
$scope.track =
|
||||
id: track.id
|
||||
title: track.title
|
||||
|
@ -164,14 +159,6 @@ angular.module('ponyfm').directive 'pfmTrackEditor', () ->
|
|||
$scope.selectedSongs[song.id] = song for song in track.show_songs
|
||||
updateSongDisplay()
|
||||
|
||||
|
||||
albums.refresh().done (albums) ->
|
||||
$scope.albums.legnth = 0
|
||||
albumsDb = {}
|
||||
for album in albums
|
||||
albumsDb[album.id] = album
|
||||
$scope.albums.push album
|
||||
|
||||
$scope.touchModel = -> $scope.isDirty = true
|
||||
|
||||
$scope.$on '$locationChangeStart', (e) ->
|
||||
|
|
Loading…
Reference in a new issue