Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from dirkgroenen/development
Browse files Browse the repository at this point in the history
Fixed all issues for Milestone: 1.1.5
  • Loading branch information
dirkgroenen committed Feb 2, 2015
2 parents 458801a + 3f87078 commit 5ed84fc
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 113 deletions.
10 changes: 9 additions & 1 deletion src/app/account/services/spotify/spotify.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ angular.module("mopify.account.services.spotify", [
})


.controller("SpotifyServiceController", function SpotifyServiceController($scope, $location, ServiceManager, Settings, Spotify){
.controller("SpotifyServiceController", function SpotifyServiceController($scope, $location, ServiceManager, Settings, Spotify, SpotifyLogin){
if(!ServiceManager.isEnabled("spotify")){
$location.path("/account/services");
return;
Expand All @@ -30,6 +30,14 @@ angular.module("mopify.account.services.spotify", [
$scope.profile = data;
});

/**
* Disconnect and connect with Spotify
* @return {[type]} [description]
*/
$scope.reconnect = function(){
SpotifyLogin.disconnect();
SpotifyLogin.login();
};
})

.controller("SpotifyMenuController", function SpotifyMenuController($q, $scope, Spotify, SpotifyLogin){
Expand Down
15 changes: 15 additions & 0 deletions src/app/account/services/spotify/spotify.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,20 @@
<p>The profile name of the current logged in Spotfiy user.</p>
</div>
</div>
<div class="settingwrap row">
<div class="label col-md-2">
<label>Reconnect</label>
</div>
<div class="input col-md-4">
<div class="button white fullwidth" ng-click="reconnect()">
<span class="text">Reconnect with Spotify</span>
<i class="ss-icon ss-refresh"></i>
</div>
</div>
<div class="description col-md-4 col-md-offset-1">
<p>Use this button to reconnect with Spotify. This can be usefull if you wan't to login with an other account.</p>
</div>
</div>
</div>

</div>
38 changes: 38 additions & 0 deletions src/app/modals/playlistselect.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

angular.module('mopify.modal.playlistselect', [
"mopify.services.playlistmanager"
])

/**
* After defining the routes we create the controller for this module
*/
.controller("PlaylistSelectModalController", function PlaylistSelectModalController($scope, $modalInstance, PlaylistManager){

$scope.userplaylists = [];

// Get filtered user playlists
PlaylistManager.getPlaylists({
useronly: true
}).then(function(data){
$scope.userplaylists = data;
});


/**
* Cancel the modal
* @return {[type]} [description]
*/
$scope.cancel = function(){
$modalInstance.dismiss('cancel');
};

/**
* Close the modal and return the selected playlist
* @param {string} playlisturi the URI of the selected playlist
*/
$scope.addToPlaylist = function(playlisturi){
$modalInstance.close(playlisturi);
};

});
24 changes: 24 additions & 0 deletions src/app/modals/playlistselect.tmpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="modal-header">
<h4 class="modal-title ng-binding">Select playlist</h4>
</div>

<div class="selectplaylist row">
<div class="col-sm-6">
<ul class="playlists" role="menu">
<li ng-repeat="playlist in userplaylists" ng-if="$index % 2 == 0" ng-click="addToPlaylist(playlist.uri)">
{{ playlist.name }}
</li>
</ul>
</div>
<div class="col-sm-6">
<ul class="dropdown-menu" role="menu">
<li ng-repeat="playlist in userplaylists" ng-if="$index % 2 == 1" ng-click="addToPlaylist(playlist.uri)">
{{ playlist.name }}
</li>
</ul>
</div>
</div>

<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
8 changes: 5 additions & 3 deletions src/app/music/stations/stations.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ angular.module('mopify.music.stations', [
'mopify.services.station',
'mopify.services.util',
'mopify.services.servicemanager',
'mopify.widgets.directive.station'
'mopify.widgets.directive.station',
'mopify.services.settings'
])

/**
Expand All @@ -24,7 +25,7 @@ angular.module('mopify.music.stations', [
/**
* After defining the routes we create the controller for this module
*/
.controller("StationsController", function StationsController($scope, $timeout, localStorageService, Spotify, stationservice, util, ServiceManager, notifier){
.controller("StationsController", function StationsController($scope, $timeout, localStorageService, Spotify, stationservice, util, ServiceManager, notifier, Settings){

// Bind the localstorage to the $scope so we always have the latest stations
$scope.stations = localStorageService.get("stations");
Expand Down Expand Up @@ -71,9 +72,10 @@ angular.module('mopify.music.stations', [
typingTimeout = $timeout(function(){
$scope.wrapclass = "dropdownvisible";
var searchableItems = (!ServiceManager.isEnabled("spotify")) ? "album,artist,track" : "album,artist,track,playlist";
var country = Settings.get("country", "US");

Spotify.search($scope.searchQuery, searchableItems, {
market: "NL",
market: country,
limit: "3"
}).then(function(data){
$scope.searchResults = data;
Expand Down
7 changes: 6 additions & 1 deletion src/app/player/controls/controls.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ angular.module('mopify.player.controls', [

// Check for messages about the current playbackstate
$scope.$on('mopidy:event:playbackStateChanged', function(event, data) {
$scope.stateIcon = (data.new_state === 'playing') ? 'ss-pause' : "ss-play";
$scope.isPlaying = (data.new_state === 'playing');
});

$scope.$on('mopidy:event:volumeChanged', function(event, data){
$scope.volume = data.volume;
});

// If Mopidy is online we collect the init data about playback, volume and shuffle mode
$scope.$on('mopidy:state:online', function(){
// Get volume
Expand All @@ -37,7 +42,7 @@ angular.module('mopify.player.controls', [
// Get playback state
mopidyservice.getState().then(function(state){
$scope.isPlaying = (state === 'playing');
$scope.stateIcon = "ss-pause";
$scope.stateIcon = (state === 'playing') ? 'ss-pause' : "ss-play";
});

// Get shuffle
Expand Down
25 changes: 12 additions & 13 deletions src/app/player/player.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ angular.module('mopify.player', [
mopidyservice.getRandom().then(function(random){
$scope.isRandom = (random === true);
});
});

// Update information on a new track
$scope.$on('mopidy:event:trackPlaybackStarted', function(event, data) {
if(data.tl_track !== undefined){
if(data.tl_track.track.name.indexOf("[loading]") > -1){
mopidyservice.lookup(data.tl_track.track.uri).then(function(result){
updatePlayerInformation(result[0]);
});
}
else{
updatePlayerInformation(data.tl_track.track);
}
// Update information on a new track
$scope.$on('mopidy:event:trackPlaybackStarted', function(event, data) {
if(data.tl_track !== undefined){
if(data.tl_track.track.name.indexOf("[loading]") > -1){
mopidyservice.lookup(data.tl_track.track.uri).then(function(result){
updatePlayerInformation(result[0]);
});
}
});

else{
updatePlayerInformation(data.tl_track.track);
}
}
});

// Listen for messages
Expand Down
42 changes: 41 additions & 1 deletion src/app/player/seekbar/seekbar.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,35 @@ angular.module('mopify.player.seekbar', [
// Private vars
var isSeeking = false;
var checkPositionInterval;
var increaseCurrentTimeInterval;
var trackLength = 0;
var timePositionMS = 0;

$scope.seekbarWidth = 0;
$scope.timeCurrent = "0:00";
$scope.timeTotal = "0:00";

$scope.$on('mopidy:state:online', function() {
getTrackLength();
startIncreaser();
});

$scope.$on('mopidy:event:trackPlaybackStarted', function(event, data) {
getTrackLength();
startIncreaser();
});

$scope.$on('mopidy:event:playbackStateChanged', function(event, data) {
// Get the current timeposition
checkTimePosition();

// Check if we have to stop or start the timer
if(data.new_state == "playing"){
startIncreaser();
}
else{
$interval.cancel(increaseCurrentTimeInterval);
}
});

$scope.$on('mopidy:state:offline', function() {
Expand All @@ -36,12 +53,31 @@ angular.module('mopify.player.seekbar', [
function checkTimePosition() {
if (!isSeeking) {
mopidyservice.getTimePosition().then(function(timePosition) {
timePositionMS = timePosition;
$scope.seekbarWidth = (timePosition / trackLength) * 100;
$scope.timeCurrent = util.timeFromMilliSeconds(timePosition);
});
}
}

/**
* Start timePositionMS increaser
*/
function startIncreaser(){
// Clear previous interval
$interval.cancel(increaseCurrentTimeInterval);

// Start interval for every second
increaseCurrentTimeInterval = $interval(function(){
// Increate timePosition with 1 second
timePositionMS += 1000;

// Calculate the seekbarWidth and convert the MS time to human time
$scope.seekbarWidth = (timePositionMS / trackLength) * 100;
$scope.timeCurrent = util.timeFromMilliSeconds(timePositionMS);
}, 1000);
}

function getTrackLength(){
mopidyservice.getCurrentTrack().then(function(track){
if(track !== null){
Expand All @@ -50,9 +86,13 @@ angular.module('mopify.player.seekbar', [

mopidyservice.getState().then(function (state) {
if (state === 'playing') {
// Check the time
checkTimePosition();

// Start interval
checkPositionInterval = $interval(function() {
checkTimePosition();
}, 1000);
}, 10000);
}
});
}
Expand Down
27 changes: 23 additions & 4 deletions src/app/search/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('mopify.search', [
});
})

.controller("SearchController", function SearchController($scope, $routeParams, $route, $timeout, $location, Spotify, SpotifyLogin, mopidyservice, stationservice, util){
.controller("SearchController", function SearchController($scope, $routeParams, $route, $timeout, $location, Spotify, SpotifyLogin, mopidyservice, stationservice, util, Settings){

$scope.query = $routeParams.query;
var typingTimeout = null;
Expand All @@ -37,6 +37,13 @@ angular.module('mopify.search', [
playlists: []
};

$scope.searchLimits = {
artists: 12,
albums: 12,
tracks: 10,
playlists: 12
};

$scope.topresult = {};

/*
Expand All @@ -47,8 +54,8 @@ angular.module('mopify.search', [
var resultsloaded = 0;

Spotify.search($scope.query, searchableItems, {
market: "NL",
limit: "12"
market: Settings.get("country", "US"),
limit: "50"
}).then(function(data){
$scope.results.artists = data.artists;
$scope.results.albums = data.albums;
Expand All @@ -61,7 +68,7 @@ angular.module('mopify.search', [

mopidyservice.search($scope.query).then(function(data){
if(data[0].tracks !== undefined){
$scope.results.tracks = data[0].tracks.splice(0,10);
$scope.results.tracks = data[0].tracks.splice(0,100);
}

// Check if all data is loaded and if it is; calculate the topresult
Expand Down Expand Up @@ -96,6 +103,18 @@ angular.module('mopify.search', [
stationservice.startFromSpotifyUri($scope.topresult.item.uri);
};

/**
* Toggle the number of results that should be shown
* @param {string} item category: artists, albums, tracks, playlists
* @return {[type]} [description]
*/
$scope.searchLimitsToggle = function(item){
if($scope.searchLimits[item] == 50)
$scope.searchLimits[item] = 12;
else
$scope.searchLimits[item] = 50;
};

/**
* Get the top matching resutls from the given batch
* @param {string} search The search string to check against
Expand Down
Loading

0 comments on commit 5ed84fc

Please sign in to comment.