Load playlists

This commit is contained in:
Philippe Vienne 2016-04-17 21:47:17 +02:00
parent 156f06bc20
commit 0bc8f06c3e
6 changed files with 50 additions and 35 deletions

View file

@ -38,35 +38,7 @@
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<h1>Duplicates finder
<button class="btn btn-default has-spinner" id="obtain-new-token">
Refresh token <span class="spinner"><i class="icon-spin icon-refresh"></i></span>
</button>
<span id="login">
<a href="/login" class="btn btn-lg btn-success">Log in with Spotify</a>
</span>
</h1>
<div id="error"></div>
<div id="loggedin">
<div id="user-profile">
</div>
<div class="media">
<div class="pull-left">
<h2 id="playlists-title">Playlists
<button class="btn btn-default has-spinner" id="get-playlists">
Refresh <span class="spinner"><i class="icon-spin icon-refresh"></i></span>
</button>
</h2>
<div id="playlists">
</div>
</div>
<div class="media-body">
<div id="dups">
</div>
</div>
</div>
</div>
<ui-view></ui-view>
</div>
<script id="playlists-template" type="text/x-handlebars-template">

View file

@ -0,0 +1,2 @@
<p>UID: {{uid}}</p>
<p>ID: {{id}}</p>

View file

@ -0,0 +1 @@
<p>Please connect to Spotify to access to the app.</p>

View file

@ -0,0 +1,4 @@
<div class="container row">
<div class="col-md-3" ui-view="playlist"></div>
<div class="col-md-9" ui-view="dups"></div>
</div>

View file

@ -0,0 +1,9 @@
<div>
<h2 class="pull-left">Playlist</h2>
<a class="btn btn-default pull-right" ng-click="load()">Load</a>
</div>
<div class="list-group">
<div class="list-group-item" ng-repeat="playlist in playlists" ng-click="open(playlist)">
{{playlist.name}}
</div>
</div>

View file

@ -26,7 +26,7 @@
}
})
.state('finder.playlist.dups',{
url: '/playlist/:id',
url: '/playlist/:uid/:id',
views: {
dups: {
templateUrl: 'partials/dups.html',
@ -37,9 +37,20 @@
$urlRouterProvider.otherwise("/");
}]);
app.run(['$rootScope',function($rootScope){
app.run(['$rootScope', '$state',function($rootScope, $state){
$rootScope.access_token = "";
$rootScope.refresh_token = "";
$rootScope.$watch('access_token',function(newVal, oldVal, scope){
if(oldVal == "" && newVal != ""){
$state.go('finder.playlist');
} else if (oldVal != "" && newVal == ""){
$state.go('finder_public');
}
});
if($rootScope.access_token == "")
$state.go('finder_public');
else
$state.go('finder.playlist');
}]);
app.controller("HomeCtrl",['$scope',function($scope){
@ -50,12 +61,28 @@
}]);
app.controller("PlaylistCtrl",['$scope',function($scope){
app.controller("PlaylistCtrl",['$scope', '$http', '$state',function($scope, $http, $state){
$scope.playlists = [];
$scope.load = function(){
$http.get('/get_playlists', {
params:{
access_token: $scope.access_token
}
}).then(function(result){
var r = result.data;
if(r.data){
$scope.playlists = r.data;
}
})
};
$scope.open = function(playlist) {
$state.go('finder.playlist.dups',{uid: playlist.owner.id, id: playlist.id})
}
}]);
app.controller("DupsCtrl",['$scope',function($scope){
app.controller("DupsCtrl",['$scope', '$stateParams',function($scope, $stateParams){
$scope.uid = $stateParams['uid'];
$scope.id = $stateParams['id'];
}]);
app.controller('AuthCtrl',['$scope', '$rootScope', '$interval', '$http', function($scope, $rootScope, $interval, $http){