hledger/hledger-api/examples/angular/hledger-client.js
Simon Michael 0ab008ed5e api: merge tomk's WIP angular client, cleanups
- api routes (but not /swagger.json) are now under /api/v1
- the api has changed a bit, more to come
- files are served from the current directory by default, simplifying naming
- the startup message is more informative
- added some startup hints for the angular client
2016-01-24 13:37:34 -08:00

60 lines
1.3 KiB
JavaScript

var hledger = angular.module('hledger', [
'ui.router',
'ngResource'
])
hledger.api_root = '/api/v1';
hledger.config(function($stateProvider, $urlRouterProvider) {
//$urlRouterProvider.otherwise("/");
$stateProvider
.state('dashboard', {
url: ""
})
.state('accounts', {
abstract: true,
url: "/accounts",
templateUrl: "accounts/index.html"
})
.state('accounts.show', {
url: "/:id",
templateUrl: 'accounts/show.html',
resolve: {
Account: 'Account',
account: function(Account, $stateParams) {
return Account.get($stateParams);
}
}
})
.state('help', {
url: "/help",
templateUrl: "help/index.html"
});
});
hledger.factory('Journal', function($resource) {
return($resource(hledger.api_root + "/journals/:id"));
});
hledger.controller("JournalController", function($scope, Journal) {
Journal.query(function(data) {
$scope.journal = data;
});
});
hledger.factory('Account', function($resource) {
return($resource(hledger.api_root + "/accounts/:id"));
});
hledger.controller("AccountsController", function($scope, Account) {
Account.query(function(data) {
$scope.accounts = data;
});
});
hledger.filter("accountNameNode", function() {
return function(account) {
return account.replace(/^.*:/, '');
};
});