restructured resources for caching

This commit is contained in:
2016-07-29 16:11:30 +02:00
parent f2745f4cd6
commit 4d3da2ac09
10 changed files with 29 additions and 28 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.tilman</groupId>
<artifactId>next-transactions</artifactId>
<version>1.3.4</version>
<version>1.4.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
@@ -35,7 +35,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
http.formLogin();
http.csrf().disable(); // XXX später wieder aktivieren
// http.headers().frameOptions().disable(); // for H2 console
// http.headers().frameOptions().disable(); // for dev H2 console
// configure caching
http.headers().cacheControl().disable();
@@ -48,14 +48,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void writeHeaders(HttpServletRequest request, HttpServletResponse response) {
String requestUri = request.getRequestURI();
if (requestUri.startsWith("/public")) {
response.setHeader("Cache-Control", "public, max-age=10000000");
// } else if (requestUri.startsWith("/api")) {
// // TODO handle API resources under common path (see application.properties)
// originalWriter.writeHeaders(request, response);
} else {
// response.setHeader("Cache-Control", "public, max-age=600000");
if (requestUri.startsWith("/public/")) {
response.setHeader("Cache-Control", "public, max-age=31536000"); // 1 year
} else if (requestUri.startsWith("/api/") || requestUri.startsWith("/app/") || requestUri.startsWith("/user")) {
originalWriter.writeHeaders(request, response);
} else {
response.setHeader("Cache-Control", "public, max-age=6048000"); // 10 weeks
}
}
});
+1 -1
View File
@@ -4,7 +4,7 @@ server.port=8084
server.session.cookie.max-age=1200000
server.session.timeout=1200000
#spring.data.rest.base-path=api
spring.data.rest.base-path=api
## PRODUCTION SETTINGS
#
@@ -2,13 +2,13 @@ var transactionsApp = angular.module('transactionsApp', ['ui.bootstrap', 'ngRout
transactionsApp.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/list', {
templateUrl : 'partials/transaction-list.html',
templateUrl : 'app/transaction-list.html',
controller : 'TransactionListCtrl'
}).when('/import', {
templateUrl : 'partials/import.html',
templateUrl : 'app/import.html',
controller : 'ImportCtrl'
}).when('/importList', {
templateUrl : 'partials/import-list.html',
templateUrl : 'app/import-list.html',
controller : 'ImportListCtrl'
}).otherwise({
redirectTo : '/list'
@@ -26,7 +26,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
// get outstandings (expenses and withdrawals) for all users of the account
var promises = new Array($scope.accountUsers.length);
for (i = 0; i < $scope.accountUsers.length; i++) {
var resource = $resource('/transactions/search/outstandings', { accountId: $scope.account.id, userId: $scope.accountUsers[i].id }).get();
var resource = $resource('/api/transactions/search/outstandings', { accountId: $scope.account.id, userId: $scope.accountUsers[i].id }).get();
promises[i] = resource.$promise;
}
@@ -85,7 +85,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
}
// get recent transactions
var transactions = $resource('/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc' }).get();
var transactions = $resource('/api/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc' }).get();
transactions.$promise.then(function(data) {
$scope.transactions = transactions._embedded.transactions;
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
@@ -112,12 +112,12 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
userinfo.$promise.then(function(data) {
$scope.userid = userinfo.name;
userinfo = $resource('/users/search/findByUsername', { username: $scope.userid }).get();
userinfo = $resource('/api/users/search/findByUsername', { username: $scope.userid }).get();
userinfo.$promise.then(function(data) {
$scope.userinfo = userinfo;
});
var accountInfo = $resource('/accounts/search/findByUserName', { username: $scope.userid }).get();
var accountInfo = $resource('/api/accounts/search/findByUserName', { username: $scope.userid }).get();
accountInfo.$promise.then(function(data) {
$scope.accounts = accountInfo._embedded.accounts;
if ($scope.account == undefined) {
@@ -130,7 +130,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
}
}
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.account.id }).get();
var categories = $resource('/api/categories/search/listForAccount', { accountId: $scope.account.id }).get();
categories.$promise.then(function(data) {
$scope.categories = categories._embedded.categories;
$scope.refreshList();
@@ -173,7 +173,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
$scope.moreTransactions = function() {
if ($scope.nextPageAvailable) {
$scope.pageNumber++;
var transactions = $resource('/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc', page: $scope.pageNumber }).get();
var transactions = $resource('/api/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc', page: $scope.pageNumber }).get();
transactions.$promise.then(function(data) {
for (i = 0; i < transactions._embedded.transactions.length; i++) {
transactions._embedded.transactions[i].amount = numberToAmount(transactions._embedded.transactions[i].amount);
@@ -188,7 +188,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara
};
$scope.updateSuggestions = function(val) {
var suggestions = $resource('/transactions/search/descriptions', { accountId: $scope.account.id, prefix: val.toLowerCase() }).get();
var suggestions = $resource('/api/transactions/search/descriptions', { accountId: $scope.account.id, prefix: val.toLowerCase() }).get();
return suggestions.$promise.then(function(data) {
var newSuggestions = new Array(suggestions._embedded.transactions.length);
for (i = 0; i < suggestions._embedded.transactions.length; i++) {
@@ -360,17 +360,17 @@ transactionControllers.controller('ImportCtrl', [ '$scope', '$resource', '$locat
userinfo.$promise.then(function(data) {
$scope.userid = userinfo.name;
userinfo = $resource('/users/search/findByUsername', { username: $scope.userid }).get();
userinfo = $resource('/api/users/search/findByUsername', { username: $scope.userid }).get();
userinfo.$promise.then(function(data) {
$scope.userinfo = userinfo;
});
var accountInfo = $resource('/accounts/search/findByUserName', { username: $scope.userid }).get();
var accountInfo = $resource('/api/accounts/search/findByUserName', { username: $scope.userid }).get();
accountInfo.$promise.then(function(data) {
$scope.accounts = accountInfo._embedded.accounts;
$scope.account = $scope.accounts[0];
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.account.id }).get();
var categories = $resource('/api/categories/search/listForAccount', { accountId: $scope.account.id }).get();
categories.$promise.then(function(data) {
$scope.categories = categories._embedded.categories;
@@ -394,7 +394,7 @@ transactionControllers.controller('ImportListCtrl', [ '$scope', '$resource', '$l
$scope.categories = ImportService.getCategories();
$scope.csv = Papa.parse(ImportService.getCSV()).data;
var matcherData = $resource('/matchers/search/listForAccount', { projection: 'full', accountId: $scope.account.id }).get();
var matcherData = $resource('/api/matchers/search/listForAccount', { projection: 'full', accountId: $scope.account.id }).get();
matcherData.$promise.then(function(data) {
matcherData = matcherData._embedded.matchers;
$scope.matchers = new Array(matcherData.length);
@@ -464,6 +464,9 @@ transactionControllers.controller('ImportListCtrl', [ '$scope', '$resource', '$l
$scope.importTransaction = function(line) {
if (line.targetCategory) {
console.log(line[1]);
console.log(line[1].substr(6,4) + "-" + line[1].substr(3,2) + "-" + line[1].substr(0,2));
var newTransaction = new Transaction({
"account" : $scope.account._links.self.href,
"amount" : line[4].replace(',', '.'),
@@ -1,7 +1,7 @@
var transactionServices = angular.module('transactionServices', [ 'ngResource' ]);
transactionServices.factory('Transaction', [ '$resource', function($resource) {
return $resource('/transactions/:id', { id: '@id' }, {
return $resource('/api/transactions/:id', { id: '@id' }, {
update : {
method : 'PUT'
},
+3 -3
View File
@@ -24,9 +24,9 @@
<script src="js/papaparse.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="app/app.js"></script>
<script src="app/controllers.js"></script>
<script src="app/services.js"></script>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>