Skip to content

Commit

Permalink
Merge pull request #456 from mradionov/confirm-playlist-removal
Browse files Browse the repository at this point in the history
Feature: confirm playlist removal
  • Loading branch information
weblancaster committed Dec 7, 2015
2 parents 00c3b79 + 70e6f0d commit 4cb1cc4
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ <h4 id="playerUser" class="player_user" ng-click="goToUser($event)"></h4>

<!-- services/factories -->
<script src="public/js/common/queueService.js"></script>
<script src="public/js/common/rateLimitService.js"></script>
<script src="public/js/common/SCapiService.js"></script>
<script src="public/js/common/SC2apiService.js"></script>
<script src="public/js/common/playerService.js"></script>
<script src="public/js/common/notificationFactory.js"></script>
<script src="public/js/common/modalFactory.js"></script>

<!-- controllers -->
<script src="public/js/common/appCtrl.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions app/public/js/common/SC2apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ app.service('SC2apiService', function (
$window,
$http,
$q,
rateLimit
modalFactory
) {

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ app.service('SC2apiService', function (
*/
function onResponseError(response) {
if (response.status === 429) {
rateLimit.showNotification();
modalFactory.rateLimitReached();
}
return $q.reject(response.data);
}
Expand Down
4 changes: 2 additions & 2 deletions app/public/js/common/SCapiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ app.service('SCapiService', function (
$state,
$stateParams,
$rootScope,
rateLimit
modalFactory
) {

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ app.service('SCapiService', function (
return $http.get(url)
.then(function (response, status) {
if (response.status === 429) {
rateLimit.showNotification();
modalFactory.rateLimitReached();
return [];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
'use strict';

// Displays popup with a warning that rate limit is reached, with a link
// to SoundCloud docs attached. Call it when response returns 429 status
app.service('rateLimit', function (
app.factory('modalFactory', function (
$http,
ngDialog
) {
this.showNotification = function () {

var modalFactory = {
// Unified modal to ask for confirmation of some action
confirm: confirm,
// Displays modal with a warning that rate limit is reached, with a link
// to SoundCloud docs attached. Call it when response returns 429 status
rateLimitReached: rateLimitReached
};

return modalFactory;

//

function confirm(message) {
return ngDialog.openConfirm({
showClose: false,
template: 'views/common/modals/confirm.html',
controller: ['$scope', function ($scope) {

$scope.content = message;

$scope.closeModal = function () {
ngDialog.closeAll();
};
}]
});
}

function rateLimitReached() {
return ngDialog.open({
showClose: false,
template: 'views/common/modal.html',
template: 'views/common/modals/default.html',
controller: ['$scope', function ($scope) {
var urlGH = 'https://api.github.com/repos/Soundnode/soundnode-about/contents/rate-limit-reached.html';
var config = {
Expand All @@ -33,5 +59,6 @@ app.service('rateLimit', function (
});
}]
});
};
}

});
36 changes: 19 additions & 17 deletions app/public/js/playlists/playlistsCtrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

app.controller('PlaylistsCtrl', function ($scope, SCapiService, $rootScope, $log, $window, $http, $state, $stateParams, notificationFactory) {
app.controller('PlaylistsCtrl', function ($scope, SCapiService, $rootScope, $log, $window, $http, $state, $stateParams, notificationFactory, modalFactory) {
var endpoint = 'me/playlists'
, params = '';

Expand Down Expand Up @@ -80,23 +80,25 @@ app.controller('PlaylistsCtrl', function ($scope, SCapiService, $rootScope, $log
* @method removePlaylist
*/
$scope.removePlaylist = function(playlistId) {

SCapiService.removePlaylist(playlistId)
.then(function(response) {
if ( typeof response === 'object' ) {
notificationFactory.success("Playlist removed!");
}
}, function(error) {
notificationFactory.error("Something went wrong!");
})
.finally(function() {
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
modalFactory
.confirm('Do you really want to delete the playlist?')
.then(function () {
SCapiService.removePlaylist(playlistId)
.then(function(response) {
if ( typeof response === 'object' ) {
notificationFactory.success("Playlist removed!");
}
}, function(error) {
notificationFactory.error("Something went wrong!");
})
.finally(function() {
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
});
});

};

/**
Expand Down
2 changes: 1 addition & 1 deletion app/views/about/about.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="modalView">
<div ng-include="'views/common/closeModal.html'"></div>
<div ng-include="'views/common/modals/closeButton.html'"></div>

<div class="modalView_content" ng-bind-html="content"></div>

Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions app/views/common/modals/confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="modalView">
<div ng-include="'views/common/modals/closeButton.html'"></div>

<div class="modalView_content" ng-bind-html="content"></div>

<div class="modalView_footer">
<button class="button" ng-click="confirm()">Confirm</button>
<button class="button" ng-click="closeModal()">Cancel</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="modalView">
<div ng-include="'views/common/closeModal.html'"></div>
<div ng-include="'views/common/modals/closeButton.html'"></div>

<div class="modalView_content" ng-bind-html="content"></div>
</div>
4 changes: 2 additions & 2 deletions app/views/playlists/playlistDashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="playlistDashboard">
<div ng-include="'views/common/closeModal.html'"></div>
<div ng-include="'views/common/modals/closeButton.html'"></div>

<!-- create new playlist -->
<header class="playlistDashboard_title">
<p>Where do you want to add: <span class="playlistDashboard_selectedSong">{{ playlistSongName }}</span></p>
Expand Down

0 comments on commit 4cb1cc4

Please sign in to comment.