mirror of
https://github.com/Febbweiss/CloudBudget-AngularJS.git
synced 2026-03-04 22:35:38 +00:00
Feature: get user's accounts
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var HOST = 'http://cloudbudget.pavnay.fr/api';
|
||||
var HOST = 'http://cloudbudget-febbweiss.c9.io/api';
|
||||
|
||||
angular
|
||||
.module('cloudbudget', ['ngRoute', 'routes', 'ngCookies'])
|
||||
.module('cloudbudget', ['ngRoute', 'routes', 'ngCookies', 'xeditable'])
|
||||
.constant('apiRoutes', {
|
||||
'host': HOST,
|
||||
'port': "80",
|
||||
'login': HOST + '/users/login',
|
||||
'register': HOST + '/users',
|
||||
'unregister': HOST + '/users/'
|
||||
'host' : HOST,
|
||||
'port' : "80",
|
||||
'login' : HOST + '/users/login',
|
||||
'register' : HOST + '/users',
|
||||
'unregister' : HOST + '/users/',
|
||||
'accounts' : HOST + '/accounts/'
|
||||
})
|
||||
.run(run);
|
||||
|
||||
run.$inject = ['$rootScope', '$location', '$cookieStore', '$http', '$filter'];
|
||||
function run( $rootScope, $location, $cookieStore, $http, $filter) {
|
||||
run.$inject = ['$rootScope', '$location', '$cookieStore', '$http', '$filter', 'editableThemes', 'editableOptions'];
|
||||
function run( $rootScope, $location, $cookieStore, $http, $filter, editableThemes, editableOptions) {
|
||||
|
||||
editableThemes.bs3.inputClass = 'input-sm';
|
||||
editableThemes.bs3.buttonsClass = 'btn-sm';
|
||||
editableOptions.theme = 'bs3';
|
||||
|
||||
$rootScope.globals = $cookieStore.get('globals') || {};
|
||||
if( $rootScope.globals.user && $rootScope.globals.user.token) {
|
||||
$http.defaults.headers.common['Authorization'] = 'JWT ' + $rootScope.globals.user.token;
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
controllerAs: 'vm'
|
||||
})
|
||||
|
||||
.when('/accounts', {
|
||||
controller: 'AccountsController',
|
||||
templateUrl: 'accounts/accounts.view.html',
|
||||
controllerAs: 'vm'
|
||||
})
|
||||
|
||||
.otherwise({redirectTo: '/login'});
|
||||
|
||||
$locationProvider.html5Mode(true);
|
||||
|
||||
52
public/js/services/accounts.service.js
Normal file
52
public/js/services/accounts.service.js
Normal file
@@ -0,0 +1,52 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('cloudbudget')
|
||||
.factory('AccountsService', AccountsService);
|
||||
|
||||
AccountsService.$inject =['$http', 'apiRoutes'];
|
||||
|
||||
function AccountsService($http, apiRoute) {
|
||||
|
||||
var service = {};
|
||||
service.list = list;
|
||||
service.create = create;
|
||||
service.drop = drop;
|
||||
service.edit = edit;
|
||||
|
||||
return service;
|
||||
|
||||
function list() {
|
||||
return $http.get( apiRoute.accounts)
|
||||
.then(function handleSuccess(response) {
|
||||
return {success: true, accounts: response.data};
|
||||
}, handleError('Error during accounts listing'));
|
||||
}
|
||||
|
||||
function create(account) {
|
||||
return $http.post( apiRoute.accounts, account)
|
||||
.then(handleSuccess, handleError('Error creating account'));
|
||||
}
|
||||
|
||||
function drop(account) {
|
||||
return $http.delete(apiRoute.accounts + account._id)
|
||||
.then(handleSuccess, handleError('Error deleting account'));
|
||||
}
|
||||
|
||||
function edit(id, account) {
|
||||
return $http.put(apiRoute.accounts + id, account)
|
||||
.then(handleSuccess, handleError('Error updating account'));
|
||||
}
|
||||
|
||||
function handleSuccess(response) {
|
||||
return {success: true, account: response.data};
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
return function() {
|
||||
return {success: false, message: error};
|
||||
};
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -45,7 +45,6 @@
|
||||
|
||||
$http.defaults.headers.common['Authorization'] = 'JWT ' + user.token;
|
||||
$cookieStore.put('globals', $rootScope.globals);
|
||||
console.log( $cookieStore.get('globals'));
|
||||
}
|
||||
|
||||
function clearCredentials() {
|
||||
|
||||
Reference in New Issue
Block a user