Skip to content

Commit 5fed528

Browse files
committed
fix toastr request, code refactoring
1 parent 72d9c6f commit 5fed528

File tree

5 files changed

+139
-146
lines changed

5 files changed

+139
-146
lines changed

app/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ <h4 id="playerUser" class="player_user" ng-click="goToUser($event)"></h4>
209209
require(`${nodeModulesPath}/ng-infinite-scroll/build/ng-infinite-scroll.min.js`);
210210
require(`${nodeModulesPath}/angular-sanitize/angular-sanitize.min.js`);
211211
require(`${nodeModulesPath}/ng-dialog/js/ngDialog.min.js`);
212-
require(`${nodeModulesPath}/toastr/build/toastr.min.js`);
213212
</script>
214213

215214
<!-- app -->
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
11
"use strict";
22

3-
app.directive('favoriteSong', function(
4-
$rootScope,
5-
SCapiService,
6-
notificationFactory
3+
app.directive('favoriteSong', function (
4+
$rootScope,
5+
SCapiService,
6+
notificationFactory
77
) {
8-
return {
9-
restrict: 'A',
10-
scope: {
11-
favorite: "=",
12-
count: "="
13-
},
14-
link: function($scope, elem, attrs) {
15-
var userId
16-
, songId;
8+
return {
9+
restrict: 'A',
10+
scope: {
11+
favorite: "=",
12+
count: "="
13+
},
14+
link: function ($scope, elem, attrs) {
15+
var userId, songId;
1716

18-
elem.bind('click', function() {
19-
userId = $rootScope.userId;
20-
songId = attrs.songId;
17+
elem.bind('click', function () {
18+
userId = $rootScope.userId;
19+
songId = attrs.songId;
2120

22-
if ( this.classList.contains('liked') ) {
23-
24-
SCapiService.deleteFavorite(userId, songId)
25-
.then(function(status) {
26-
if ( typeof status == "object" ) {
27-
notificationFactory.warn("Song removed from likes!");
28-
$scope.favorite = false;
29-
$scope.count -= 1;
30-
$rootScope.$broadcast("track::unfavorited", songId);
31-
}
32-
}, function() {
33-
notificationFactory.error("Something went wrong!");
34-
})
35-
} else {
36-
SCapiService.saveFavorite(userId, songId)
37-
.then(function(status) {
38-
if ( typeof status == "object" ) {
39-
notificationFactory.success("Song added to likes!");
40-
$scope.favorite = true;
41-
$scope.count += 1;
42-
$rootScope.$broadcast("track::favorited", songId);
43-
}
44-
}, function(status) {
45-
notificationFactory.error("Something went wrong!");
46-
});
47-
}
21+
if (this.classList.contains('liked')) {
4822

23+
SCapiService.deleteFavorite(userId, songId)
24+
.then(function (status) {
25+
if (typeof status == "object") {
26+
notificationFactory.warn("Song removed from likes!");
27+
$scope.favorite = false;
28+
$scope.count -= 1;
29+
$rootScope.$broadcast("track::unfavorited", songId);
30+
}
31+
}, function () {
32+
notificationFactory.error("Something went wrong!");
33+
})
34+
} else {
35+
SCapiService.saveFavorite(userId, songId)
36+
.then(function (status) {
37+
if (typeof status == "object") {
38+
notificationFactory.success("Song added to likes!");
39+
$scope.favorite = true;
40+
$scope.count += 1;
41+
$rootScope.$broadcast("track::favorited", songId);
42+
}
43+
}, function () {
44+
notificationFactory.error("Something went wrong!");
4945
});
5046
}
47+
48+
});
5149
}
50+
}
5251
});
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
'use strict';
22

3+
const toastr = require(`../node_modules/toastr/build/toastr.min.js`);
4+
35
app.factory('notificationFactory', function () {
4-
return {
5-
success: function (message) {
6-
toastr.success(message, "Success");
7-
},
8-
warn: function (message) {
9-
toastr.warning(message, "Hey");
10-
},
11-
info: function (message) {
12-
toastr.info(message, "FYI");
13-
},
14-
error: function (message) {
15-
toastr.error(message, "Oh No");
16-
}
17-
};
6+
return {
7+
success: function (message) {
8+
toastr.success(message, "Success");
9+
},
10+
warn: function (message) {
11+
toastr.warning(message, "Hey");
12+
},
13+
info: function (message) {
14+
toastr.info(message, "FYI");
15+
},
16+
error: function (message) {
17+
toastr.error(message, "Oh No");
18+
}
19+
};
1820
});
Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
'use strict';
22

33
app.directive('repostedSong', function (
4-
$rootScope,
5-
SCapiService,
6-
notificationFactory
4+
$rootScope,
5+
SCapiService,
6+
notificationFactory
77
) {
8-
return {
9-
restrict: 'A',
10-
scope: {
11-
reposted: '='
12-
},
13-
link: function ($scope, elem, attrs) {
14-
var songId;
15-
16-
elem.bind('click', function () {
17-
songId = attrs.songId;
18-
19-
if (this.classList.contains('reposted')) {
20-
21-
SCapiService.deleteRepost(songId)
22-
.then(function (status) {
23-
if (angular.isObject(status)) {
24-
notificationFactory.success('Song removed from reposts!');
25-
$scope.reposted = false;
26-
}
27-
})
28-
.catch(function () {
29-
notificationFactory.error('Something went wrong!');
30-
});
31-
32-
} else {
33-
34-
SCapiService.createRepost(songId)
35-
.then(function (status) {
36-
if (angular.isObject(status)) {
37-
notificationFactory.success('Song added to reposts!');
38-
$scope.reposted = true;
39-
}
40-
})
41-
.catch(function () {
42-
notificationFactory.error('Something went wrong!');
43-
});
44-
45-
}
8+
return {
9+
restrict: 'A',
10+
scope: {
11+
reposted: '='
12+
},
13+
link: function ($scope, elem, attrs) {
14+
var songId;
15+
16+
elem.bind('click', function () {
17+
songId = attrs.songId;
18+
19+
if (this.classList.contains('reposted')) {
20+
21+
SCapiService.deleteRepost(songId)
22+
.then(function (status) {
23+
if (angular.isObject(status)) {
24+
notificationFactory.warn('Song removed from reposts!');
25+
$scope.reposted = false;
26+
}
27+
})
28+
.catch(function () {
29+
notificationFactory.error('Something went wrong!');
30+
});
4631

32+
} else {
33+
34+
SCapiService.createRepost(songId)
35+
.then(function (status) {
36+
if (angular.isObject(status)) {
37+
notificationFactory.success('Song added to reposts!');
38+
$scope.reposted = true;
39+
}
40+
})
41+
.catch(function () {
42+
notificationFactory.error('Something went wrong!');
4743
});
4844

4945
}
50-
};
46+
47+
});
48+
49+
}
50+
};
5151
});

app/views/common/tracks.html

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,62 @@
1-
<div class="songList_item_container_artwork"
2-
ng-class="{ active: hover }"
3-
ng-mouseover="hover = true"
4-
ng-mouseleave="hover = false">
5-
<span class="songList_item_song_button"
6-
id="{{ data.id }}"
7-
song
8-
data-song-url="{{ data.stream_url }}"
9-
data-song-thumbnail="{{ data.artwork_url }}"
10-
data-song-title="{{ data.title }}"
11-
data-song-user="{{ data.user.username }}"
12-
data-song-user-id="{{ data.user.id }}"
13-
data-song-id="{{ data.id }}" >
1+
<div class="songList_item_container_artwork" ng-class="{ active: hover }" ng-mouseover="hover = true" ng-mouseleave="hover = false">
2+
<span class="songList_item_song_button" id="{{ data.id }}" song data-song-url="{{ data.stream_url }}" data-song-thumbnail="{{ data.artwork_url }}"
3+
data-song-title="{{ data.title }}" data-song-user="{{ data.user.username }}" data-song-user-id="{{ data.user.id }}" data-song-id="{{ data.id }}">
144

155
<i class="fa fa-play"></i>
166
<i class="fa fa-pause"></i>
177
</span>
18-
<img ng-controller="AppCtrl" ng-src="{{ showBigArtwork (data.artwork_url) }}" onerror="if (this.src != 'public/img/logo-short.png') this.src = 'public/img/logo-short.png';" alt="{{ data.title }}" class="songList_item_artwork">
19-
<div class="songList_item_song_social_details">
20-
<span class="songList_comment_count">
8+
<img ng-controller="AppCtrl" ng-src="{{ showBigArtwork (data.artwork_url) }}" onerror="if (this.src != 'public/img/logo-short.png') this.src = 'public/img/logo-short.png';"
9+
alt="{{ data.title }}" class="songList_item_artwork">
10+
<div class="songList_item_song_social_details">
11+
<span class="songList_comment_count">
2112
<i class="fa fa-comments"></i>{{data.comment_count | round}}
2213
</span>
23-
<span class="songList_likes_count">
14+
<span class="songList_likes_count">
2415
<i class="fa fa-heart"></i>{{data.likes_count || data.favoritings_count | round}}
2516
</span>
26-
<span class="songList_reposts_count" ng-if="data.reposts_count">
17+
<span class="songList_reposts_count" ng-if="data.reposts_count">
2718
<i class="fa fa-retweet"></i>{{data.reposts_count | round}}
2819
</span>
29-
</div>
20+
</div>
3021
</div>
3122

3223
<section class="songList_item_inner">
33-
<h2 class="songList_item_song_tit selectable-text" title="{{ data.title }}" ui-sref="track({id: {{data.id}}})">{{ data.title }}</h2>
24+
<h2 class="songList_item_song_tit selectable-text" title="{{ data.title }}" ui-sref="track({id: {{data.id}}})">{{ data.title }}</h2>
3425

35-
<h3 class="songList_item_song_info clearfix">
36-
<div class="songList_item_song_user selectable-text">
37-
<a class="pointer" ui-sref="profile({id: {{data.user.id}}})">
26+
<h3 class="songList_item_song_info clearfix">
27+
<div class="songList_item_song_user selectable-text">
28+
<a class="pointer" ui-sref="profile({id: {{data.user.id}}})">
3829
{{ data.user.username }}
3930
</a>
40-
<span class="songList_item_repost" ng-if="type === 'track-repost'">
31+
<span class="songList_item_repost" ng-if="type === 'track-repost'">
4132
<i class="fa fa-retweet"></i>
4233
<a class="pointer" ui-sref="profile({ id: {{ user.id }} })" title="Reposted by {{ user.username }}">
4334
{{ user.username }}
4435
</a>
4536
</span>
46-
</div>
47-
<div ng-controller="AppCtrl" class="songList_item_song_length">
48-
{{ formatSongDuration (data.duration) }}
49-
</div>
50-
</h3>
37+
</div>
38+
<div ng-controller="AppCtrl" class="songList_item_song_length">
39+
{{ formatSongDuration (data.duration) }}
40+
</div>
41+
</h3>
5142

52-
<div class="songList_item_song_details">
53-
<div class="songList_item_actions">
54-
<a favorite-song data-song-id="{{ data.id }}" favorite="data.user_favorite" count="data.favoritings_count" ng-class="{liked: data.user_favorite}" title="{{data.user_favorite ? 'Unlike' : 'Like'}}">
55-
<i class="fa fa-heart"></i>
56-
</a>
57-
<a reposted-song data-song-id="{{ data.id }}" reposted="data.user_reposted" ng-class="{ reposted: data.user_reposted }" title="{{data.user_reposted ? 'Unpost' : 'Repost'}}" ng-if="data.user.id !== $root.userId">
58-
<i class="fa fa-retweet"></i>
59-
</a>
60-
<a data-song-id="{{ data.id }}" data-song-name="{{ data.title }}" playlist title="Add to playlist"> <i class="fa fa-bookmark"></i></a>
61-
<a href="{{ data.permalink_url }}" open-external target="_blank" title="Permalink"> <i class="fa fa-external-link"></i></a>
62-
<a copy-directive data-copy="{{ data.permalink_url }}" title="Copy"> <i class="fa fa-clipboard"></i></a>
63-
</div>
64-
<div class="songList_item_additional_details">
65-
<span class="songList_item_genre" ui-sref="tag({name: data.genre})">#{{ data.genre }}</span>
66-
<span class="songList_item_license">{{ data.license }}</span>
67-
</div>
68-
</div>
69-
</section>
43+
<div class="songList_item_song_details">
44+
<div class="songList_item_actions">
45+
<a favorite-song data-song-id="{{ data.id }}" favorite="data.user_favorite" count="data.favoritings_count" ng-class="{liked: data.user_favorite}"
46+
title="{{data.user_favorite ? 'Unlike' : 'Like'}}">
47+
<i class="fa fa-heart"></i>
48+
</a>
49+
<a reposted-song data-song-id="{{ data.id }}" reposted="data.user_reposted" ng-class="{ reposted: data.user_reposted }" title="{{data.user_reposted ? 'Unpost' : 'Repost'}}"
50+
ng-if="data.user.id !== $root.userId">
51+
<i class="fa fa-retweet"></i>
52+
</a>
53+
<a data-song-id="{{ data.id }}" data-song-name="{{ data.title }}" playlist title="Add to playlist"> <i class="fa fa-bookmark"></i></a>
54+
<a href="{{ data.permalink_url }}" open-external target="_blank" title="Permalink"> <i class="fa fa-external-link"></i></a>
55+
<a copy-directive data-copy="{{ data.permalink_url }}" title="Copy"> <i class="fa fa-clipboard"></i></a>
56+
</div>
57+
<div class="songList_item_additional_details">
58+
<span class="songList_item_genre" ui-sref="tag({name: data.genre})">#{{ data.genre }}</span>
59+
<span class="songList_item_license">{{ data.license }}</span>
60+
</div>
61+
</div>
62+
</section>

0 commit comments

Comments
 (0)