Extended search result not shown after clicking “search details” on quick search.
This commit is contained in:
parent
dfbe15cb0e
commit
8e8cc4555b
4 changed files with 43 additions and 46 deletions
|
@ -25,6 +25,10 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
|
||||
@throttledSearch = _.throttle @search, 200
|
||||
|
||||
@globalSearch = new App.GlobalSearch(
|
||||
render: @renderResult
|
||||
)
|
||||
|
||||
# rerender view, e. g. on langauge change
|
||||
@bind 'ui:rerender', =>
|
||||
@renderMenu()
|
||||
|
@ -127,15 +131,15 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
items = @getItems(navbar: @Config.get('NavBarRight'))
|
||||
|
||||
# get open tabs to repopen on rerender
|
||||
open_tab = {}
|
||||
openTab = {}
|
||||
@$('.open').children('a').each( (i,d) ->
|
||||
href = $(d).attr('href')
|
||||
open_tab[href] = true
|
||||
openTab[href] = true
|
||||
)
|
||||
|
||||
@$('.navbar-items-personal').html App.view('navigation/personal')(
|
||||
items: items
|
||||
open_tab: open_tab
|
||||
items: items
|
||||
openTab: openTab
|
||||
)
|
||||
|
||||
# only start avatar widget on existing session
|
||||
|
@ -151,6 +155,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
# remove result if not result exists
|
||||
if _.isEmpty(result)
|
||||
@searchContainer.removeClass('open')
|
||||
@globalSearch.close()
|
||||
@searchResult.html('')
|
||||
return
|
||||
|
||||
|
@ -275,6 +280,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
emptyAndClose: =>
|
||||
@searchInput.val('')
|
||||
@searchContainer.removeClass('filled').removeClass('open').removeClass('focused')
|
||||
@globalSearch.close()
|
||||
|
||||
# remove not needed popovers
|
||||
@delay(@anyPopoversDestroy, 100, 'removePopovers')
|
||||
|
@ -282,6 +288,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
andClose: =>
|
||||
@searchInput.blur()
|
||||
@searchContainer.removeClass('open')
|
||||
@globalSearch.close()
|
||||
@delay(@anyPopoversDestroy, 100, 'removePopovers')
|
||||
|
||||
search: =>
|
||||
|
@ -290,11 +297,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
|||
return if query is @query
|
||||
@query = query
|
||||
@searchContainer.toggleClass('filled', !!@query)
|
||||
|
||||
App.GlobalSearch.execute(
|
||||
query: @query
|
||||
render: @renderResult
|
||||
)
|
||||
@globalSearch.search(query: @query)
|
||||
|
||||
getItems: (data) ->
|
||||
navbar = _.values(data.navbar)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class App.Search extends App.Controller
|
||||
searchResultCache: {}
|
||||
elements:
|
||||
'.js-search': 'searchInput'
|
||||
|
||||
|
@ -25,6 +24,11 @@ class App.Search extends App.Controller
|
|||
|
||||
@throttledSearch = _.throttle @search, 200
|
||||
|
||||
@globalSearch = new App.GlobalSearch(
|
||||
render: @renderResult
|
||||
limit: 50
|
||||
)
|
||||
|
||||
@render()
|
||||
|
||||
# rerender view, e. g. on langauge change
|
||||
|
@ -52,10 +56,11 @@ class App.Search extends App.Controller
|
|||
@navupdate(url: '#search', type: 'menu')
|
||||
return if _.isEmpty(params.query)
|
||||
@$('.js-search').val(params.query).trigger('change')
|
||||
return if @shown
|
||||
@throttledSearch(true)
|
||||
|
||||
hide: ->
|
||||
# nothing
|
||||
@shown = false
|
||||
|
||||
changed: ->
|
||||
# nothing
|
||||
|
@ -117,11 +122,7 @@ class App.Search extends App.Controller
|
|||
@query = query
|
||||
@updateTask()
|
||||
|
||||
App.GlobalSearch.execute(
|
||||
query: @query
|
||||
render: @renderResult
|
||||
limit: 50
|
||||
)
|
||||
@globalSearch.search(query: @query)
|
||||
|
||||
renderResult: (result = []) =>
|
||||
@result = result
|
||||
|
|
|
@ -1,37 +1,27 @@
|
|||
class App.GlobalSearch
|
||||
_instance = undefined
|
||||
|
||||
@execute: (args) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _globalSearchSingleton
|
||||
_instance.execute(args)
|
||||
|
||||
class _globalSearchSingleton extends Spine.Module
|
||||
|
||||
class App.GlobalSearch extends App.Controller
|
||||
constructor: ->
|
||||
@searchResultCache = undefined
|
||||
@searchResultCacheByKey = {}
|
||||
super
|
||||
@searchResultCache = {}
|
||||
@lastQuery = undefined
|
||||
@apiPath = App.Config.get('api_path')
|
||||
@ajaxId = "search-#{Math.floor( Math.random() * 999999 )}"
|
||||
|
||||
execute: (params) ->
|
||||
query = params.query
|
||||
render = params.render
|
||||
limit = params.limit || 10
|
||||
cacheKey = "#{query}_#{limit}"
|
||||
search: (params) =>
|
||||
query = params.query
|
||||
|
||||
# use cache for search result
|
||||
currentTime = new Date
|
||||
if @searchResultCacheByKey[cacheKey] && @searchResultCacheByKey[cacheKey].time > currentTime.setSeconds(currentTime.getSeconds() - 20)
|
||||
@renderTry(render, @searchResultCacheByKey[cacheKey].result, cacheKey)
|
||||
if @searchResultCache[query] && @searchResultCache[query].time > currentTime.setSeconds(currentTime.getSeconds() - 20)
|
||||
@renderTry(@searchResultCache[query].result, query)
|
||||
return
|
||||
|
||||
App.Ajax.request(
|
||||
id: 'search'
|
||||
id: @ajaxId
|
||||
type: 'GET'
|
||||
url: "#{@apiPath}/search"
|
||||
data:
|
||||
query: query
|
||||
limit: limit
|
||||
limit: @limit || 10
|
||||
processData: true
|
||||
success: (data, status, xhr) =>
|
||||
App.Collection.loadAssets(data.assets)
|
||||
|
@ -49,21 +39,24 @@ class _globalSearchSingleton extends Spine.Module
|
|||
else
|
||||
App.Log.error('_globalSearchSingleton', "No such model App.#{item.type}")
|
||||
|
||||
@renderTry(render, result, cacheKey)
|
||||
@renderTry(result, query)
|
||||
)
|
||||
|
||||
renderTry: (render, result, cacheKey) =>
|
||||
renderTry: (result, query) =>
|
||||
|
||||
# if result hasn't changed, do not rerender
|
||||
diff = false
|
||||
if @searchResultCache
|
||||
diff = difference(@searchResultCache, result)
|
||||
if @lastQuery is query && @searchResultCache[query]
|
||||
diff = difference(@searchResultCache[query].result, result)
|
||||
return if diff isnt false && _.isEmpty(diff)
|
||||
@lastQuery = query
|
||||
|
||||
# cache search result
|
||||
@searchResultCache = result
|
||||
@searchResultCacheByKey[cacheKey] =
|
||||
@searchResultCache[query] =
|
||||
result: result
|
||||
time: new Date
|
||||
|
||||
render(result)
|
||||
@render(result)
|
||||
|
||||
close: =>
|
||||
@lastQuery = undefined
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<% for item in @items: %>
|
||||
<% if item.child: %>
|
||||
<li class="<% if item.class: %><%- item.class %><% end %> dropup <% if @open_tab[item.target] : %>open<% end %>">
|
||||
<li class="<% if item.class: %><%- item.class %><% end %> dropup <% if @openTab[item.target] : %>open<% end %>">
|
||||
<a class="list-button dropdown-toggle js-action" data-toggle="dropdown" href="<%= item.target %>" title="<% if item.translate: %><%- @Ti( item.name ) %><% else: %><%= item.name %><% end %>">
|
||||
<span class="dropdown-nose"></span>
|
||||
<% if item.class is 'user': %>
|
||||
|
@ -15,7 +15,7 @@
|
|||
<li class="divider"></li>
|
||||
<% end %>
|
||||
<% if item.navheader: %>
|
||||
<li class="dropdown-header"><%- @T( item.navheader ) %></li>
|
||||
<li class="dropdown-header"><%- @T(item.navheader) %></li>
|
||||
<% end %>
|
||||
<li>
|
||||
<a href="<%= item.target %>" class="horizontal center">
|
||||
|
|
Loading…
Reference in a new issue