Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete site locations #38

Closed
ferblape opened this issue Nov 11, 2016 · 2 comments
Closed

Autocomplete site locations #38

ferblape opened this issue Nov 11, 2016 · 2 comments
Assignees

Comments

@ferblape
Copy link
Member

ferblape commented Nov 11, 2016

Site entity association will be available, for the moment, just for municipalities.

To get the list of municipalities we are going to use The Big Indexer municipalities collection.

The endpoint to obtain the suggestions is to a given query is https://tbi.populate.tools/gobierto/collections/c-municipios-espanya/suggestions.

It requires a parameter query and an authorization header:

  • query: contains the query argument to the suggestions.
  • authorization: Bearer <TOKEN_BODY>

(I'll provide the token body in private). Maybe it'll make sense to set that token as an installation setting, because I suspect we are going to use The Big Indexer in some places in the future.

In javascript you can do this:

var settings = {
  "crossDomain": true,
  "url": "https://tbi.populate.tools/gobierto/collections/c-municipios-espanya/suggestions",
  "method": "GET",
  "dataType": "json",
  "data": { "query": "foo"},
  "headers": {
    "authorization": "Bearer <TOKEN_BODY>"
  }
}

$.ajax(settings).done(function(response) {
  console.log(response);
});

The output of the endpoint is an object with a key suggestions and all the suggestions, composed of a value, and a raw data object:

{
"suggestions": [
  {
    "value": "Abarán",
    "data": {
      "id": "30002",
      "name": "Abarán",
      "slug": "abaran",
      "municipality_id": 30002,
      "province_id": 30,
      "autonomous_region_id": 14
    }
  },
  {
    "value": "Abárzuza/Abartzuza",
    "data": {
      "id": "31002",
      "name": "Abárzuza/Abartzuza",
      "slug": "abarzuza-abartzuza",
      "municipality_id": 31002,
      "province_id": 31,
      "autonomous_region_id": 15
    }
  },
  {
    "value": "Abarca de Campos",
    "data": {
      "id": "34001",
      "name": "Abarca de Campos",
      "slug": "abarca-de-campos",
      "municipality_id": 34001,
      "province_id": 34,
      "autonomous_region_id": 7
    }
  }
]}
@ferblape ferblape self-assigned this Nov 11, 2016
@ferblape
Copy link
Member Author

Issue updated @danguita

@danguita
Copy link
Contributor

danguita commented Nov 12, 2016

Looks good, let's go for it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants