Add persistent login
This commit is contained in:
parent
f052a5c1dc
commit
8e61af59a3
3 changed files with 19 additions and 40 deletions
|
@ -41,39 +41,9 @@
|
|||
<ui-view></ui-view>
|
||||
</div>
|
||||
|
||||
<script id="playlists-template" type="text/x-handlebars-template">
|
||||
{{#list playlists}}
|
||||
<a class="pl_item list-group-item has-spinner" href="/pl/{{pl_uid}}/{{pl_id}}">
|
||||
{{pl_name}}
|
||||
<span class="spinner"><i class="icon-spin icon-refresh"></i></span>
|
||||
<i class="glyphicon glyphicon-chevron-right"></i>
|
||||
</a>
|
||||
{{/list}}
|
||||
</script>
|
||||
|
||||
<script id="user-profile-template" type="text/x-handlebars-template">
|
||||
Logged in as {{display_name}}
|
||||
</script>
|
||||
|
||||
<script id="dups-template" type="text/x-handlebars-template">
|
||||
<h2>Duplicates in {{pl_name}}</h2>
|
||||
{{message}}
|
||||
{{#list dups}}
|
||||
<div class="list-group-item">{{dup_trackname}} - {{dup_artist}}</div>
|
||||
{{/list}}
|
||||
</script>
|
||||
|
||||
<script id="error-template" type="text/x-handlebars-template">
|
||||
<div class="alert alert-danger alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
|
||||
aria-hidden="true">×</span></button>
|
||||
<strong>{{err_title}}</strong> {{{err_content}}}.
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.1/handlebars.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.4/angular.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.6/ngStorage.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
|
||||
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<h2 class="pull-left">Playlist</h2>
|
||||
</div>
|
||||
<div class="list-group ">
|
||||
<a ng-class="playlist == current?'list-group-item active':'list-group-item'" ng-repeat="playlist in playlists" ng-click="open(playlist)">
|
||||
<a ng-class="current.playlistId == playlist.id?'list-group-item active':'list-group-item'" ng-repeat="playlist in playlists" ng-click="open(playlist)">
|
||||
{{playlist.name}}
|
||||
</a>
|
||||
</div>
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
(function(){
|
||||
|
||||
var app = angular.module('app',['ui.router']);
|
||||
var app = angular.module('app',['ui.router', 'ngStorage']);
|
||||
|
||||
app.config(['$stateProvider','$urlRouterProvider',function($stateProvider, $urlRouterProvider){
|
||||
$stateProvider
|
||||
|
@ -41,10 +41,19 @@
|
|||
$urlRouterProvider.otherwise("/");
|
||||
}]);
|
||||
|
||||
app.run(['$rootScope', '$state',function($rootScope, $state){
|
||||
$rootScope.access_token = "";
|
||||
$rootScope.refresh_token = "";
|
||||
app.run(['$rootScope', '$state', '$localStorage',function($rootScope, $state, $localStorage){
|
||||
$rootScope.$storage = $localStorage.$default({
|
||||
access_token: "",
|
||||
refresh_token: ""
|
||||
});
|
||||
$rootScope.access_token = $rootScope.$storage.access_token;
|
||||
$rootScope.refresh_token = $rootScope.$storage.refresh_token;
|
||||
|
||||
$rootScope.$watch('access_token', function(newVal, oldVal, scope){
|
||||
|
||||
$rootScope.$storage.access_token = $rootScope.access_token;
|
||||
$rootScope.$storage.refresh_token = $rootScope.refresh_token;
|
||||
|
||||
if(oldVal == "" && newVal != ""){
|
||||
$state.go('finder.playlist');
|
||||
} else if (oldVal != "" && newVal == ""){
|
||||
|
@ -65,7 +74,7 @@
|
|||
}]);
|
||||
|
||||
app.controller("MainCtrl",['$scope', '$state',function($scope, $state){
|
||||
|
||||
$scope.current = {playlistId: undefined};
|
||||
}]);
|
||||
|
||||
app.controller("PlaylistCtrl",['$scope', '$http', '$state',function($scope, $http, $state){
|
||||
|
@ -82,9 +91,8 @@
|
|||
}
|
||||
})
|
||||
};
|
||||
$scope.current = undefined;
|
||||
$scope.open = function(playlist) {
|
||||
$scope.current = playlist;
|
||||
$scope.current.playlistId = playlist.id;
|
||||
$state.go('finder.playlist.dups',{uid: playlist.owner.id, id: playlist.id})
|
||||
};
|
||||
$scope.load();
|
||||
|
@ -93,6 +101,7 @@
|
|||
app.controller("DupsCtrl",['$scope', '$stateParams', '$http',function($scope, $stateParams, $http){
|
||||
$scope.uid = $stateParams['uid'];
|
||||
$scope.id = $stateParams['id'];
|
||||
$scope.current.playlistId = $scope.id;
|
||||
$scope.tracks = [];
|
||||
$scope.loaded = false;
|
||||
$scope.load = function () {
|
||||
|
|
Loading…
Reference in a new issue