Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: confirm playlist removal #456

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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