System search using Angularjs and java

Asked

Viewed 84 times

2

I have a Java back-end: JPA, Hibernate. Entities working correctly, I even have a class Searchresource

@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 at 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);
})();

Which 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.configurationPatient); } init(); }

})();

html listing.

            <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="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;">
                    </td>
                </tr>
            </tfoot>
        </table>

the Canvas:

inserir a descrição da imagem aqui

So, the search there implemented does not work, nor the ordination. I would like to understand the directive of angular in the aspect of how information "walks" on my front, if what is being practiced so far is on a project descent path and how I put this search to work?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.