mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
41 lines
933 B
JavaScript
41 lines
933 B
JavaScript
/* global angular */
|
|
angular.module('codexen.states')
|
|
.controller('SnippetsListController', function ($auth, Snippet, $scope) {
|
|
var vm = this
|
|
|
|
vm.isLoaded = false
|
|
|
|
var laodSnippets = function () {
|
|
if ($auth.isAuthenticated) {
|
|
console.log($auth.getPayload())
|
|
var userId = $auth.getPayload().sub
|
|
Snippet.findByUser(userId)
|
|
.success(function (data) {
|
|
console.log('snippets fetched', data.snippets)
|
|
vm.isLoaded = true
|
|
vm.snippets = data.snippets
|
|
vm.isGuest = false
|
|
})
|
|
}else {
|
|
vm.isLoaded = true
|
|
vm.isGuest = true
|
|
vm.snippets = void 0
|
|
}
|
|
}
|
|
|
|
laodSnippets()
|
|
|
|
$scope.$on('userSignIn', function () {
|
|
laodSnippets()
|
|
})
|
|
|
|
$scope.$on('userSignOut', function () {
|
|
laodSnippets()
|
|
})
|
|
|
|
$scope.$on('snippetUpdated', function () {
|
|
laodSnippets()
|
|
})
|
|
|
|
})
|