Skip to content

Commit 0966f63

Browse files
committed
Exterminator duty
1 parent 9f156ee commit 0966f63

10 files changed

+109
-23
lines changed

app/assets/javascripts/angapp.js.coffee

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ app = angular.module('songSync', ['songSync.controllers', 'songSync.directives',
44
window.fixDisplay = () ->
55
document.getElementById('player-body').style.webkitTransform = 'scale(1)';
66

7+
window.ctrlDown = false
8+
window.shiftDown = false
9+
10+
document.addEventListener('keydown', (evt) ->
11+
e = window.event || evt
12+
key = e.which || e.keyCode
13+
if key==17 || key==18 ||key==91
14+
window.ctrlDown = true
15+
if key == 16
16+
window.shiftDown = true
17+
, false)
18+
19+
document.addEventListener('keyup', (evt) ->
20+
e = window.event || evt
21+
key = e.which || e.keyCode
22+
if key==17 || key==18 ||key==91
23+
window.ctrlDown = false
24+
if key == 16
25+
window.shiftDown = false
26+
, false)
27+
728
app.config(['$routeProvider', ($routeProvider) ->
829
$routeProvider.when '/login', {templateUrl: '/partial/login', controller: 'LoginCtrl' }
930
$routeProvider.when '/player', {templateUrl: '/partial/player', controller: 'PlayerCtrl' }

app/assets/javascripts/application.js

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//= require jquery
1414
//= require jquery_ujs
1515
//= require underscore.min
16+
//= require angular-file-upload-shim
1617
//= require angular
1718
//= require angular-route
1819
//= require angular-file-upload
@@ -25,3 +26,8 @@
2526
//= require services
2627
//= require directives
2728
//= require modal_controllers
29+
window.onload = function() {
30+
document.onselectstart = function() {
31+
return false;
32+
}
33+
}

app/assets/javascripts/controllers.js.coffee

+29-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ app.controller 'PlayerCtrl',['$scope', 'AuthFactory', 'ApiFactory', '$sce', '$ro
3232
$scope.currentTime = data.currentTime
3333
$scope.$on 'audio.play', () -> $scope.playing = true
3434
$scope.$on 'audio.pause', () -> $scope.playing = false
35+
$scope.$on 'audio.next', () ->
36+
index = _.indexOf($scope.current_playlist.songs, $scope.current_song)
37+
$scope.current_song = $scope.current_playlist.songs[index + 1]
38+
if !$scope.current_song
39+
$scope.current_song = $scope.current_playlist.songs[0]
40+
playlist = $scope.current_playlist
41+
song = $scope.current_song
42+
if $scope.selectedSongs().length == 1
43+
$scope.last_clicked_song.selected = false
44+
song.selected = true
45+
$scope.last_clicked_song = song
46+
$rootScope.$broadcast 'audio.set', $sce.trustAsResourceUrl(song.file_url), song, _.indexOf(playlist.songs, song)+1, playlist.songs.length
3547
window.setInterval( () ->
3648
ApiFactory.updatePlayback($scope.current_song.id, $scope.current_playlist.id, $scope.currentTime) if $scope.playing
3749
, 5000)
@@ -85,12 +97,24 @@ app.controller 'PlayerCtrl',['$scope', 'AuthFactory', 'ApiFactory', '$sce', '$ro
8597
alert val.errors.join(', ')
8698

8799
$scope.clickSong = (song) ->
88-
if $scope.last_clicked_song.id == song.id
89-
$scope.playSong(_.indexOf($scope.current_playlist.songs, song))
90-
else
91-
$scope.last_clicked_song.selected = false
100+
if song.dontgo == true
101+
song.dontgo = false
102+
else if window.ctrlDown
103+
song.selected = !song.selected
92104
$scope.last_clicked_song = song
93-
song.selected = true
105+
else if window.shiftDown
106+
min = Math.min($scope.last_clicked_song.id, song.id)
107+
max = Math.max($scope.last_clicked_song.id, song.id)
108+
_.each($scope.current_playlist.songs, (song) ->
109+
song.selected = song.id <= max && song.id >= min
110+
)
111+
else
112+
if $scope.last_clicked_song.id == song.id
113+
$scope.playSong(_.indexOf($scope.current_playlist.songs, song))
114+
else
115+
_.each($scope.current_playlist.songs, (song) -> song.selected = false)
116+
$scope.last_clicked_song = song
117+
song.selected = true
94118

95119
$scope.softClickSong = (song) ->
96120
if $scope.last_clicked_song

app/assets/javascripts/directives.js.coffee

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ app.directive('audioPlayer', ($rootScope) ->
2626
$scope.audio.addEventListener 'pause', ()-> $rootScope.$broadcast('audio.pause', this)
2727
$scope.audio.addEventListener 'timeupdate', ()-> $rootScope.$broadcast('audio.time', this)
2828
$scope.audio.addEventListener 'ended', ()-> $rootScope.$broadcast('audio.ended', this); $scope.next()
29-
$scope.audio.addEventListener 'loadedmetadata', () ->
29+
$scope.audio.addEventListener 'loadeddata', () ->
3030
if $scope.currentTime
3131
$scope.audio.currentTime = $scope.currentTime
3232
$scope.currentTime = undefined
33+
$scope.audio.play()
3334

34-
# set track & play it
35+
# set track
3536
$rootScope.$on 'audio.set', (r, file, info, currentNum, totalNum, start_time) ->
3637
playing = !$scope.audio.paused
3738
$scope.audio.src = file
38-
$scope.audio.volume = 0.1
3939
$scope.currentTime = start_time
4040
if playing
4141
a = $scope.audio.play()
@@ -44,8 +44,6 @@ app.directive('audioPlayer', ($rootScope) ->
4444
$scope.info = info
4545
$scope.currentNum = currentNum
4646
$scope.totalNum = totalNum
47-
$rootScope.$on 'audio.play', () ->
48-
a = $scope.audio.play()
4947
$rootScope.$on 'audio.settime', (r, time) ->
5048
$scope.currentTime = time
5149
console.log("Set time:", time)

app/assets/javascripts/modal_controllers.js.coffee

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
app = angular.module('songSync.controllers')
22

3-
app.controller 'localUploadCtrl', ['$scope', 'ApiFactory', '$upload', 'AuthFactory', 'playlist', ($scope, ApiFactory, $upload, AuthFactory, playlist)->
3+
app.controller 'localUploadCtrl', ['$scope', 'ApiFactory', '$upload', 'AuthFactory', 'playlist', '$modalInstance', ($scope, ApiFactory, $upload, AuthFactory, playlist, $modalInstance)->
4+
$scope.messages = []
45
$scope.onFileSelect = ($files) ->
56
_.each($files, (file) ->
67
$scope.upload = $upload.upload({
@@ -12,14 +13,20 @@ app.controller 'localUploadCtrl', ['$scope', 'ApiFactory', '$upload', 'AuthFacto
1213
}
1314
file: file
1415
}).progress( (e) ->
15-
console.log('percent: ' + parseInt(100.0 * e.loaded / e.total))
16+
$scope.progress = 100.0 * e.loaded/e.total
1617
).success( (data) ->
1718
console.log("Success", data)
18-
playlist.songs.push(data)
19+
if data.errors.length == 0
20+
$scope.messages.push("Successfully added: " + data.name)
21+
if playlist
22+
playlist.songs.push(data)
23+
else
24+
$scope.messages.push(data.errors.join(', '))
1925
).error( (data) ->
2026
console.log("Error", data)
2127
)
2228
)
29+
$scope.cancel = () -> $modalInstance.dismiss()
2330
]
2431

2532
app.controller 'AddToPlaylistCtrl',['$scope', 'AuthFactory', 'ApiFactory', 'songs', 'playlists', '$modalInstance', ($scope, AuthFactory, ApiFactory, songs, playlists, $modalInstance)->

app/assets/javascripts/services.js.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ app.factory 'ApiFactory', ['Restangular', (Restangular) ->
1616
Restangular.one('songs', id).get()
1717
uploadSong: (song) ->
1818
song = {
19-
name: song.name,
19+
name: song.name
2020
file: song.file.src
2121
}
2222
Restangular.all('songs').customPOST({song: song})
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="form-group now-playing">
22
<p>Now Playing: <span ng-show="!info">Nothing</span>{{info.name}}</p>
33
</div>
4-
<audio controls='disabled' id="theaudioplayer" src="{{src}}"></audio>
4+
<audio autoplay controls='disabled' id="theaudioplayer" src="{{src}}"></audio>

app/views/pages/partial/modal/local_upload.html.slim

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
.modal-body
44
h4 Select Files
55
input type='file' ng-file-select='onFileSelect($files)' multiple='true'
6-
.drop-file-box ng-file-drop="onFileSelect($files)" ng-file-drag-over-class="" Drop files here...
6+
.progress ng-show='progress'
7+
.progress-bar.progress-bar-striped.active role="progressbar" aria-valuenow="{{progress}}" aria-valuemin="0" aria-valuemax="100" style="width: {{progress}}%;"
8+
.drop-file-box ng-file-drop="onFileSelect($files)" ng-file-drag-over-class="" Drop files here...
79
.modal-footer
810
.pull-right.col-lg-12
9-
button.btn.btn-danger ng-click='close()' Cancel
11+
button.btn.btn-danger ng-click='cancel()' Cancel

app/views/pages/partial/player.html.slim

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
ul.dropdown-menu
4848
li: a href='javascript:void(0)' ng-click='openAddToPlaylistModal(selectedSongs(), playlists)' Add to Playlist
4949
li: a href='javascript:void(0)' ng-click='remove(selectedSongs())' Remove
50+
|
5051
.btn-group
5152
button.btn.btn-lg.btn-primary.dropdown-toggle data-toggle='dropdown'
5253
span.fui-plus
@@ -56,16 +57,13 @@
5657
li: a href='javascript:void(0)' ng-click='localUpload(playlist)' From your computer
5758
li: a href='javascript:void(0)' ng-click='youtubeImport(playlist)' From YouTube
5859
hr
59-
.row.hoverable ng-repeat='song in current_playlist.songs' style='padding: 2px;' ng-class="{'selected': song.selected}"
60-
.col-xs-1
61-
input type='checkbox' ng-model='song.selected' style='margin-top: 12px;'
62-
.col-xs-1
60+
.row.hoverable ng-click='clickSong(song)' ng-repeat='song in current_playlist.songs' style='padding: 2px;' ng-class="{'selected': song.selected}"
61+
.col-xs-10
6362
span.fui-play ng-click='playSong($index)'
64-
.col-xs-8 ng-click='clickSong(song)'
6563
| {{song.name}}
6664
.col-xs-2
6765
.btn-group
68-
button.btn.btn-primary.dropdown-toggle data-toggle='dropdown' ng-click='softClickSong(song)'
66+
button.btn.btn-primary.dropdown-toggle data-toggle='dropdown' ng-click='song.dontgo = true ; softClickSong(song)'
6967
| Options
7068
span.caret
7169
ul.dropdown-menu
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**!
2+
* AngularJS file upload shim for angular XHR HTML5 browsers
3+
* @author Danial <[email protected]>
4+
* @version 1.6.6
5+
*/
6+
if (window.XMLHttpRequest) {
7+
if (window.FormData) {
8+
// allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934
9+
XMLHttpRequest = (function(origXHR) {
10+
return function() {
11+
var xhr = new origXHR();
12+
xhr.setRequestHeader = (function(orig) {
13+
return function(header, value) {
14+
if (header === '__setXHR_') {
15+
var val = value(xhr);
16+
// fix for angular < 1.2.0
17+
if (val instanceof Function) {
18+
val(xhr);
19+
}
20+
} else {
21+
orig.apply(xhr, arguments);
22+
}
23+
}
24+
})(xhr.setRequestHeader);
25+
return xhr;
26+
}
27+
})(XMLHttpRequest);
28+
window.XMLHttpRequest.__isShim = true;
29+
}
30+
}

0 commit comments

Comments
 (0)