Skip to content

Commit d2739ff

Browse files
committed
search features now pageable compliant
1 parent 8aa0d81 commit d2739ff

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

src/main/celerio/angularjs/assets/js/entity/EntityController.e.vm.js

+27-23
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,32 @@ scope.refreshByPage = function (page, size, addMode) {
113113
scope.selectAll = false;
114114
};
115115

116+
/** Executes the search with criteria on the server side */
117+
scope.startSearch = function(item) {
118+
log.info("startSearch, criteria: " + scope.item);
119+
120+
// call search on the server side and refresh the grid
121+
${entity.model.var}RestService.search(item, function success(result){
122+
log.info("receiving info from server side");
123+
124+
// refresh data and so the grid
125+
scope.data = result.content;
126+
127+
// fill pagination variables
128+
scope.pagination.first = result.first;
129+
scope.pagination.last = result.last;
130+
scope.pagination.totalElements = result.totalElements;
131+
scope.pagination.totalPages = result.totalPages;
132+
scope.pagination.number = result.number;
133+
134+
log.info("data post refresh:" + scope.data.length);
135+
log.info("page number: " + scope.pagination.number);
136+
});
137+
138+
// close the search aside
139+
hideForm(searchAside);
140+
};
141+
116142
/** Gets first page */
117143
scope.first = function () {
118144
log.info("call method first inside ${entity.model.type}Controller for page: 0");
@@ -177,23 +203,6 @@ scope.searchItem = function() {
177203
showForm(searchAside);
178204
};
179205

180-
/** Executes the classical search on the server side */
181-
scope.startSearch = function(item) {
182-
log.info("startSearch, criteria: " + scope.item);
183-
184-
// call search on the server side and refresh the grid
185-
${entity.model.var}RestService.search(item, function success(result){
186-
log.info("receiving info from server side");
187-
188-
// refresh data and so the grid
189-
scope.data = result;
190-
log.info("data post refresh:" + result);
191-
});
192-
193-
// close the search aside
194-
hideForm(searchAside);
195-
};
196-
197206
/** Executes the Elastic search on the server side */
198207
scope.startElasticSearch = function(item) {
199208
// get criteria
@@ -479,12 +488,7 @@ app.factory('${entity.model.type}RestService', function (${dollar}resource) {
479488
'create': { method:'POST', url: 'api/${entity.model.vars}/$str6'},
480489
'update': { method:'PUT', url: 'api/${entity.model.vars}/$str6'},
481490
'delete': { method:'DELETE', url: 'api/${entity.model.vars}/$str6' },
482-
'search': { method: 'POST', url: 'api/${entity.model.vars}/search/', isArray: true,
483-
transformResponse: function (data) {
484-
data = angular.fromJson(data);
485-
return data;
486-
}
487-
}
491+
'search': { method: 'POST', url: 'api/${entity.model.vars}/search/', isArray: false}
488492
## dedicated method for system entities
489493
#if ($entity.model.type == "AppParameter")
490494
,'getParameter': {method: 'GET',

src/main/celerio/springboot/src/main/java/rest/EntityResource.e.vm.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
$output.require("java.util.ArrayList")##
5757
$output.require("org.springframework.jdbc.core.BeanPropertyRowMapper")##
5858
$output.require("org.springframework.beans.factory.annotation.Autowired")##
59+
$output.require("org.springframework.data.domain.PageImpl")##
5960
6061
@RestController
6162
@RequestMapping("/api/${entity.model.vars}")
@@ -376,14 +377,15 @@ public ResponseEntity<Boolean> exists($str3) throws URISyntaxException {
376377
/**
377378
* Search $entity.model.vars.
378379
*/
379-
// FIXME must return a Page like in method findAllByPage
380380
@RequestMapping(value = "/search",
381381
method = RequestMethod.POST,
382382
produces = MediaType.APPLICATION_JSON_VALUE)
383-
public ResponseEntity<List<$entity.model.type>> search(@RequestBody $entity.model.type $entity.model.var, Pageable pageable) throws URISyntaxException {
383+
public Page<$entity.model.type> search(@RequestBody $entity.model.type $entity.model.var, Pageable pageable) throws URISyntaxException {
384384
log.debug("Search $entity.model.vars, page: " + pageable.getPageNumber() + ", size: " + pageable.getPageSize());
385385
log.debug("$entity.model.var: " + $entity.model.var);
386386
387+
long total = ${entity.model.var}Repository.count();
388+
387389
String sqlMainPart = "select * from (select $str10 from $entity.getTableName() where 1=1";
388390
String sqlSecondaryPart = "";
389391
@@ -411,7 +413,9 @@ public ResponseEntity<Boolean> exists($str3) throws URISyntaxException {
411413
values.toArray(),
412414
new BeanPropertyRowMapper<$entity.model.type>(${entity.model.type}.class));
413415
414-
return new ResponseEntity<>($entity.model.vars, new HttpHeaders(), HttpStatus.OK);
416+
Page<$entity.model.type> page = new PageImpl<$entity.model.type>($entity.model.vars, pageable, total);
417+
418+
return page;
415419
}
416420
417421
## dedicated method for system entities

0 commit comments

Comments
 (0)