Author: ymartel Date: 2014-08-12 17:17:05 +0200 (Tue, 12 Aug 2014) New Revision: 434 Url: http://forge.chorem.org/projects/chorem/repository/revisions/434 Log: review list page of ExpenseAccounts, use a filter on dates Added: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccountListCtrl.js Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-08-12 08:11:13 UTC (rev 433) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-08-12 15:17:05 UTC (rev 434) @@ -50,7 +50,6 @@ import org.chorem.webmotion.bean.financial.ExpenseAccountEntryBean; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; -import org.nuiton.util.DateUtil; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; @@ -72,53 +71,48 @@ * </ul> * * @param client - * @param year - * @param month + * @param startTime + * @param endTime * @param page * @param count * @return */ - public PaginatedResult<ExpenseAccountBean> findAllExpenseAccounts(ChoremClient client, Integer year, Integer month, int page, int count) { + public PaginatedResult<ExpenseAccountBean> findAllExpenseAccounts(ChoremClient client, Long startTime, Long endTime, int page, int count) { - Date refStartDate; - Date refEndDate; + WikittyQueryMaker totalQueryMaker = new WikittyQueryMaker() + .select().count(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE).where().and() + .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT); - if (month == null && year != null) { - // only year is given : search for all year - refStartDate = DateUtil.createDate(1, 1, year); - refEndDate = DateUtil.createDate(31, 12, year); - - } else if (month == null && year == null) { - // no month, no year, give current month ? - Date today = new Date(); - refStartDate = DateUtil.setFirstDayOfMonth(today); - refEndDate = DateUtil.setLastDayOfMonth(today); - - } else { - // we have a month and a year : just search ones corresponding to this month - refStartDate = DateUtil.createDate(1, month, year); - refEndDate = DateUtil.setLastDayOfMonth(refStartDate); - + if (endTime != null) { + Date refEndDate = new Date(endTime); + totalQueryMaker.le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refEndDate); } + if (startTime != null) { + Date refStartDate = new Date(startTime); + totalQueryMaker.ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refStartDate); + } - WikittyQuery totalQuery = new WikittyQueryMaker() - .select().count(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE).where().and() - .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT) - .le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refEndDate) - .ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refStartDate) - .end(); + WikittyQuery totalQuery = totalQueryMaker.end(); Integer nbExpenseAccounts = client.findByQuery(Integer.class, totalQuery); PaginatedResult<ExpenseAccountBean> paginatedResult; if (nbExpenseAccounts > 0) { - WikittyQuery expAccountsQuery = new WikittyQueryMaker() + WikittyQueryMaker listingQueryMaker = new WikittyQueryMaker() .where().and() - .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT) - .le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refEndDate) - .ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refStartDate) - .end() + .exteq(ExpenseAccount.EXT_EXPENSEACCOUNT); + + if (endTime != null) { + Date refEndDate = new Date(endTime); + listingQueryMaker.le(ExpenseAccount.ELEMENT_FIELD_INTERVAL_BEGINDATE, refEndDate); + } + if (startTime != null) { + Date refStartDate = new Date(startTime); + listingQueryMaker.ge(ExpenseAccount.ELEMENT_FIELD_INTERVAL_ENDDATE, refStartDate); + } + + WikittyQuery expAccountsQuery = listingQueryMaker.end() .setOffset((page - 1) * count) .setLimit(page * count); Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-08-12 08:11:13 UTC (rev 433) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-08-12 15:17:05 UTC (rev 434) @@ -21,7 +21,7 @@ <td><input type="text" ng-model="newExpenseAccountEntry.justificationNumber" name="newExpenseAccountEntry.justificationNumber" size="10" style='width:100%'></td> <td> - <input class="form-control" type="text" ng-model="newExpenseAccountEntry.emittedDate" datepicker-popup="dd/MM/yyyy" is-open="emittedDateOpened" ng-click="emittedDateOpened = true" size="10" maxlength="10" style='width:90%'> + <input class="form-control" type="text" ng-model="newExpenseAccountEntry.emittedDate" datepicker-popup="dd/MM/yyyy" is-open="emittedDateOpened" ng-click="emittedDateOpened = true" size="10" maxlength="10" style='width:90%' /> </td> <td> <input type="text" ng-model="newExpenseAccountEntry.projectName" name="newExpenseAccountEntry.project" size="4" style='width:100%' id="text-newExpenseAccountEntry-project" auto-complete data-source="Project" data-model="newExpenseAccountEntry" data-base-field="project"> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp 2014-08-12 08:11:13 UTC (rev 433) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccounts.jsp 2014-08-12 15:17:05 UTC (rev 434) @@ -30,6 +30,8 @@ <link data-require="ng-table@*" data-semver="0.3.0" rel="stylesheet" href="<c:url value='http://bazalt-cms.com/assets/ng-table/0.3.0/ng-table.css'/>" /> <link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="<c:url value='http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'/>" /> <script type="text/javascript" src="<c:url value='/js/paginationTable.js'/>"></script> + <script type="text/javascript" src="<c:url value='/js/financial/expenseAccountListCtrl.js'/>"></script> + <script type="text/javascript" src="<c:url value='/js/angular-ui-bootstrap-tpls-0.11.0.js'/>"></script> <script> angular.module('Pagination').value('paginationInit', { url : "<c:url value="/rest/financial/expenseAccounts"/>", @@ -38,8 +40,13 @@ </script> </head> -<div ng-app="Pagination" ng-controller="PageCtrl"> +<div ng-app="expenseAccountPagination" ng-controller="expenseAccountListCtrl"> + <div> + From <input type="text" ng-model="startTime" datepicker-popup="dd/MM/yyyy" is-open="startDateOpened" ng-click="startDateOpened = true"> + to <input type="text" ng-model="endTime" datepicker-popup="dd/MM/yyyy" is-open="endDateOpened" ng-click="endDateOpened = true"/> + </div> + <div loading-container="tableParams.settings().$loading"> <table ng-table="tableParams" show-filter="false" class="table"> <tbody ng-repeat="expenseAccount in elements"> Added: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccountListCtrl.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccountListCtrl.js (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccountListCtrl.js 2014-08-12 15:17:05 UTC (rev 434) @@ -0,0 +1,60 @@ +/* + * #%L + * Chorem :: webmotion + * %% + * Copyright (C) 2011 - 2014 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +var app = angular.module('expenseAccountPagination', ['ngResource', 'ui.bootstrap', 'Pagination']); + +app.controller("expenseAccountListCtrl", function($scope, $resource, $timeout, $controller, ngTableParams, paginationInit) { + + var date = new Date(); + var firstDay = new Date(date.getFullYear(), date.getMonth(), 1); + var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0); + $scope.startTime = paginationInit.params.startTime = firstDay.getTime(); + $scope.endTime = paginationInit.params.endTime = lastDay.getTime(); + + $controller("PageCtrl", {$scope : $scope, paginationInit : paginationInit, ngTableParams : ngTableParams}); + + console.log($scope.tableParams); + + $scope.load = function() { + + if ($scope.tableParams.$params.startTime instanceof Date) { + $scope.tableParams.$params.startTime = $scope.tableParams.$params.startTime.getTime(); + } + + if ($scope.tableParams.$params.endTime instanceof Date) { + $scope.tableParams.$params.endTime = $scope.tableParams.$params.endTime.getTime(); + } + $scope.tableParams.reload(); + } + + $scope.$watch("startTime", function () { + if ($scope.startTime instanceof Date) { + $scope.tableParams.$params.startTime = $scope.startTime.getTime(); + } + $scope.tableParams.reload(); + }); + + $scope.$watch("endTime", function () { + if ($scope.endTime instanceof Date) { + $scope.tableParams.$params.endTime = $scope.endTime.getTime(); + } + $scope.tableParams.reload(); + }); +}); \ No newline at end of file