Created
July 1, 2014 09:14
-
-
Save hedgerh/1d54326e00b671388bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['angular', 'util/messaging', 'util/messagingClient', 'content/contentServices'], | |
function(angular, messaging, client, services) { | |
'use strict'; | |
return angular.module('seaApp.controllers', ['seaApp.services']) | |
// content controller | |
.controller('StreamController', ['$scope', '$location', '$q', 'streamService', 'Groups', | |
function($scope, $location, $q, streamService, Groups) { | |
require(['content/controllers/streamController'], function(StreamController) { | |
angular.injector(['ng']).invoke(StreamController, this, { | |
'$scope': $scope, | |
'$location': $location, | |
'$q': $q, | |
'streamService': streamService, | |
'Groups': Groups | |
}); | |
}); | |
} | |
]) | |
.controller('GroupController', ['$scope', '$rootScope', '$location', 'Groups', | |
function($scope, $rootScope, $location, Groups) { | |
require(['content/controllers/groupController'], function(GroupController) { | |
angular.injector(['ng']).invoke(GroupController, this, { | |
'$scope': $scope, | |
'$rootScope': $rootScope, | |
'$location': $location, | |
'Groups': Groups | |
}); | |
}); | |
} | |
]) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['angular', 'staticConfig'], function(angular, sc) { | |
'use strict'; | |
angular.module('seaApp.services', []) | |
/* Group Factory Service */ | |
.factory('Groups', function() { | |
var groups = [{ | |
name: 'None', | |
artists: [] | |
}, { | |
name: 'Trap Artists', | |
artists: [2051971, 16730, 515070] | |
}, { | |
name: 'Something', | |
artists: [1520490, 92661, 188783] | |
}]; | |
var activeGroup = []; | |
return { | |
all: function getAll() { | |
return groups; | |
} | |
}; | |
}) | |
/* Soundcloud Factory Service */ | |
.factory('Soundcloud', function($http, $rootScope, $timeout, $q) { | |
var request = function(method, path, params) { | |
_.extend(params, { | |
client_id: sc.soundcloud.client_id, | |
oauth_token: sc.soundcloud.access_token | |
}); | |
var deferred = $q.defer(); | |
$http({ | |
method: method, | |
url: sc.soundcloud.api.host + path, | |
params: params | |
}) | |
.success(function(data) { | |
deferred.resolve(data); | |
}) | |
.error(function(reason) { | |
deferred.reject(reason); | |
}); | |
return deferred.promise; | |
}; | |
return { | |
get: function(path, params) { | |
return request('GET', path, params); | |
}, | |
put: function(path, params) { | |
return request('PUT', path, params); | |
}, | |
post: function(path, params) { | |
return request('POST', path, params); | |
}, | |
delete: function(path, params) { | |
return request('DELETE', path, params); | |
} | |
}; | |
}) | |
/* Soundcloud Factory Service */ | |
.factory('streamService', ['$http', '$rootScope', '$timeout', '$q', 'Soundcloud', | |
function($http, $rootScope, $timeout, $q, Soundcloud) { | |
function getTrackData(id) { | |
return Soundcloud.get('/users/' + id + '/tracks', { | |
limit: 5 | |
}); | |
} | |
function getPlaylists(id) { | |
return Soundcloud.get('/users/' + id + '/playlists', { | |
limit: 5 | |
}); | |
} | |
function getArtistData(id) { | |
return $q.all({tracks: getTrackData(id), | |
playlists: getPlaylists(id)}); | |
} | |
function _buildStream(artistIds) { | |
var _stream = []; | |
return $q.all(artistIds.map(getArtistData)).then(function(infos) { | |
return infos.reduce(function(stream, info) { | |
return stream.concat(info.tracks, info.playlists); | |
}, _stream); | |
}); | |
} | |
return { | |
buildStream: _buildStream | |
}; | |
} | |
]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Controller for the stream view | |
*/ | |
define(['util/messagingClient', 'logging'], | |
function(client, logging) { | |
var log = new logging(true, 'GroupController', client); | |
return ['$scope', '$rootScope', '$location', '$http', 'Groups', function($scope, $rootScope, $location, $http, Groups) { | |
log.debug('Group controller started'); | |
function getGroups() { | |
$scope.groups = Groups.all(); | |
} | |
getGroups(); | |
$scope.activeGroup = []; | |
$scope.setActiveGroup = function setActiveGroup(group) { | |
if ($scope.activeGroup != group) { | |
$scope.activeGroup = group; | |
$rootScope.$broadcast('activeGroupChanged', group); | |
} | |
}; | |
$scope.$apply(); | |
}]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Controller for the stream view | |
*/ | |
define(['util/messagingClient', 'logging'], | |
function(client, logging) { | |
var log = new logging(true, 'StreamController', client); | |
return ['$scope', '$location', '$q', 'streamService', 'Groups', function($scope, $location, $q, streamService, Groups) { | |
log.debug('Stream controller started'); | |
// listen for group change and get the new stream | |
$scope.$on('activeGroupChanged', function buildActiveStream(event, group) { | |
streamService.buildStream(group.artists).then(function(stream) { | |
$scope.stream = stream; | |
}); | |
}); | |
$scope.$apply(); | |
}]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment