[ 
https://issues.apache.org/jira/browse/AIRAVATA-3324?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17091849#comment-17091849
 ] 

Marcus Christie commented on AIRAVATA-3324:
-------------------------------------------

Simple REST endpoint for testing with:

{code:title=views.py}
def test_autocomplete_search(request):
    """Find matching words for given search string."""
    search = request.GET['search']
    import re
    pattern = re.compile(search, re.IGNORECASE)
    matches = []
    with open("/usr/share/dict/words", 'r') as f:
        matches = [line.strip() for line in f if pattern.search(line)]
    return JsonResponse({
        "search": search,
        "results": [{"text": m, "value": m} for m in matches[:20]]
    })
{code}

{code:title=urls.py}
urlpatterns = [
...
    url(r'^test-autocomplete-search/', views.test_autocomplete_search),
]
{code}

> Custom input editor: autocomplete input editor
> ----------------------------------------------
>
>                 Key: AIRAVATA-3324
>                 URL: https://issues.apache.org/jira/browse/AIRAVATA-3324
>             Project: Airavata
>          Issue Type: New Feature
>          Components: Django Portal
>            Reporter: Marcus Christie
>            Assignee: Marcus Christie
>            Priority: Major
>
> Create an autocomplete input editor that allows user to type and get 
> autocompleted matching results in a dropdown. Selecting a dropdown item 
> populates the input editor with that value.
> The frontend component will make HTTP requests to a configured URL to fetch 
> matching results for the currently entered search string. It's up to the 
> backed URL to determine from where to get the matching results, for example, 
> it could retrieve them from a database or file or a third party service.
> h3. Configuring autocomplete input editor
> {code}
> {
>     "editor": {
>         "ui-component-id": "autocomplete-input-editor",
>         "config": {
>             "url": "/custom/search/"
>         }
>     }
> }
> {code}
> h3. Backend URL contract
> - URL is called with query parameter {{search}} with value of whatever the 
> user has currently typed
> - URL should return a JSON response with a {{search}} key and the value of 
> that key used for the search and an {{results}} key with a list matching 
> results, limited to the top 10. Each result should have a {{text}} key with 
> the text displayed to the user and a {{value}} key which is the value applied 
> to the experiment input if selected. For example:
> {code}
> {
>   "search": "mammal",
>   "results": [
>     {
>       "text": "Horse",
>       "value": "horse"
>     },
>     {
>       "text": "Mouse",
>       "value": "mouse"
>     }
>   ]
> }
> {code}
> h5. TODO
> - [ ] Load search results as user types



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to