I have a Java backend: JPA, HIbernate. Entities working correctly, I even have a SearchResource class
@Path("/search")
@ApiDefinitionBase
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Api(value = "Search", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
authorizations = {
@Authorization(value = "jwt")
}
)
public class SearchResource {
@Inject
private SearchService searchService;
@POST
@Path("/paciente")
@ApiOperation(value = "Consulta os pacientes com paginacao", notes = "", httpMethod = "POST", code = 201, response = PageResult.class)
public Response pacienteFiltro(
@ApiParam(value = "Pagina atual", required = true) @QueryParam("page") int page,
@ApiParam(value = "ASC ou DESC") @QueryParam("sortType") String sortType, @ApiParam(value = "propriedade para ordernar") @QueryParam("orderBy") String orderBy,
@ApiParam(value = "Quantidade maxima de itens por pagina") @QueryParam(value = "pageSize") int pageSize, PacienteFilter filter) {
PageResult result;
int maxPageSize = pageSize <= 0 ? PageResult.DEFAULT_MAX_PAGE_SIZE : pageSize;
if (Objects.isNull(orderBy)) {
result = searchService.search(filter, SearchConfig.of(page, maxPageSize));
} else {
result = searchService.search(filter, SearchConfig.of(page, maxPageSize, orderBy, SortType.enumByValue(sortType)));
}
return Response.status(Status.CREATED).entity(result).build();
}
}
My difficulty is on the front. Angularjs, I even have an implementation that uses this SearchService class.
(function () {
'use strict';
var PARAMETROS_DEFAULTS = [{
page: 1
}, {
sortType: 'asc'
}];
function _adicionarParamentrosParaUrl(url, parametos) {
if (parametos instanceof Array && parametos.length > 0) {
url = url.concat('?');
for (var index = parametos.length - 1; index >= 0; index--) {
for (var atributo in parametos[index]) {
var parametro = parametos[index];
url = url.concat(atributo).concat('=').concat(parametro[atributo]).concat('&');
}
}
return url.substring(0, url.lastIndexOf('&'));
}
}
/**
* @ngInject
*/
function FiltroConsulta(requestApi) {
function Paginacao(result) {
return {
totalCount: result.totalCount,
maxPageSize: result.maxPageSize,
data: result.data
};
}
function filtroCb(result) {
return new Paginacao(result.data);
}
function filtrar(callback, search, configuracao) {
var promise = requestApi.returnPost(_adicionarParamentrosParaUrl(configuracao.rota, search.parametos), search)
.then(filtroCb)
.then(callback);
}
return {
filtrar: filtrar,
configuracaoPaciente: {
rota: 'api/search/paciente',
filterOnLoad: true,
search: {
parametos: PARAMETROS_DEFAULTS
}
},
configuracaoColaborador: {
rota: 'api/filtro/colaborador',
filterOnLoad: false,
search: {
parametos: PARAMETROS_DEFAULTS.concat([{
pageSize: '7'
}])
}
}
};
}
angular.module('Intra.main').factory('FiltroConsulta', FiltroConsulta);
})();
What is used like this:
(function() {
'use strict';
angular.module('Intra.pages.paciente')
.controller('PacienteListagemController', PacienteListagemController);
/** @ngInject */
function PacienteListagemController($scope, FiltroConsulta) {
var vm = this;
function init() {
$scope.configuracaoFiltro = angular.copy(FiltroCons
ulta.configuracaoPaciente); } init (); }
}) ();
listing.html
<thead>
<tr class="sortable ">
<th class="table-id" st-sort="id" st-sort-default="true">#</th>
<th st-sort="firstName">Descrição</th>
<th>Medida</th>
<th>Ações</th>
</tr>
<tr>
<th><input placeholder="buscar por Data" class="input-sm form-control search-input" type="search" /></th>
<th><input st-search="firstName" placeholder="Buscar por id" class="input-sm form-control search-input"
type="search" /></th>
<th><input placeholder="buscar por CPF" class="input-sm form-control search-input" type="search" /></th>
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="itemAtivo in filtroResult.data">
<td class="table-id" data-ng-bind="itemAtivo.prontuario"></td>
<td data-ng-bind="itemAtivo.nome"></td>
<td data-ng-bind="itemAtivo.cpf"></td>
<td>
<div class="buttons" ng-show="!rowform.$visible">
<button class="btn btn-primary editable-table-button btn-xs" ng-click="systemUri.goTo(systemUri.itemEdicao(item.id))">Editar</button>
<button class="btn btn-danger editable-table-button btn-xs" ng-hide="false">Deletar</button>
</div>
</td>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="6" class="text-center">
<minha-empresa-pagination-count data-ng-show="filtroResult.totalCount > 0" filtro-result="filtroResult"
pagina="pagina"></minha-empresa-pagination-count>
<ul uib-pagination total-items="filtroResult.totalCount" max-size="(isMobile ? applicationSettings.maxPaginationMobile : applicationSettings.maxPaginationDesktop)"
force-ellipses="true" boundary-links="true" items-per-page="filtroResult.maxPageSize"
ng-model="pagina" ng-change="trocarPagina()" num-pages class="pagination-sm"
previous-text="‹" next-text="›" first-text="«" last-text="»">
</td>
</tr>
</tfoot>
</table>
Screen:
Thenthesearchimplementedtheredoesnotwork,nordoestheordering.Iwouldliketounderstandtheangulardirectiveintheaspectofhowtheinformation"walks" on my front, if what is being practiced so far is in a decent way of design and how do I put this search to work?