From 4d3da2ac099c8f87f04d4b9d6d793b658b3ce18e Mon Sep 17 00:00:00 2001 From: tliero Date: Fri, 29 Jul 2016 16:11:30 +0200 Subject: [PATCH] restructured resources for caching --- pom.xml | 2 +- .../transactions/SecurityConfiguration.java | 14 +++++------ src/main/resources/application.properties | 2 +- src/main/resources/static/{js => app}/app.js | 6 ++--- .../static/{js => app}/controllers.js | 25 +++++++++++-------- .../static/{partials => app}/import-list.html | 0 .../static/{partials => app}/import.html | 0 .../resources/static/{js => app}/services.js | 2 +- .../{partials => app}/transaction-list.html | 0 src/main/resources/static/index.html | 6 ++--- 10 files changed, 29 insertions(+), 28 deletions(-) rename src/main/resources/static/{js => app}/app.js (76%) rename src/main/resources/static/{js => app}/controllers.js (91%) rename src/main/resources/static/{partials => app}/import-list.html (100%) rename src/main/resources/static/{partials => app}/import.html (100%) rename src/main/resources/static/{js => app}/services.js (92%) rename src/main/resources/static/{partials => app}/transaction-list.html (100%) diff --git a/pom.xml b/pom.xml index 18528be..15bcf1b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.tilman next-transactions - 1.3.4 + 1.4.0 org.springframework.boot diff --git a/src/main/java/de/tilman/transactions/SecurityConfiguration.java b/src/main/java/de/tilman/transactions/SecurityConfiguration.java index aa68ef8..0076ee0 100644 --- a/src/main/java/de/tilman/transactions/SecurityConfiguration.java +++ b/src/main/java/de/tilman/transactions/SecurityConfiguration.java @@ -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 } } }); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 213b9c2..cba0c13 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 # diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/app/app.js similarity index 76% rename from src/main/resources/static/js/app.js rename to src/main/resources/static/app/app.js index 3c965a5..175abf4 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/app/app.js @@ -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' diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/app/controllers.js similarity index 91% rename from src/main/resources/static/js/controllers.js rename to src/main/resources/static/app/controllers.js index ac02f68..f39872e 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/app/controllers.js @@ -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(',', '.'), diff --git a/src/main/resources/static/partials/import-list.html b/src/main/resources/static/app/import-list.html similarity index 100% rename from src/main/resources/static/partials/import-list.html rename to src/main/resources/static/app/import-list.html diff --git a/src/main/resources/static/partials/import.html b/src/main/resources/static/app/import.html similarity index 100% rename from src/main/resources/static/partials/import.html rename to src/main/resources/static/app/import.html diff --git a/src/main/resources/static/js/services.js b/src/main/resources/static/app/services.js similarity index 92% rename from src/main/resources/static/js/services.js rename to src/main/resources/static/app/services.js index 4c6749b..bcacc72 100644 --- a/src/main/resources/static/js/services.js +++ b/src/main/resources/static/app/services.js @@ -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' }, diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/app/transaction-list.html similarity index 100% rename from src/main/resources/static/partials/transaction-list.html rename to src/main/resources/static/app/transaction-list.html diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 50f7bac..b52edbb 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -24,9 +24,9 @@ - - - + + +