mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
pulled tempaltes search into its own file
This commit is contained in:
@@ -64,54 +64,6 @@ define [
|
|||||||
bucketIndex = parseInt(hash.toString().slice(0,2), 16) % (buckets?.length or 2)
|
bucketIndex = parseInt(hash.toString().slice(0,2), 16) % (buckets?.length or 2)
|
||||||
return buckets[bucketIndex]
|
return buckets[bucketIndex]
|
||||||
|
|
||||||
|
|
||||||
App.factory "algoliawiki", ->
|
|
||||||
client = new AlgoliaSearch("SK53GL4JLY", "e398f35d3074fde57ca6d6c88d8be37c")
|
|
||||||
index = client.initIndex("lean-wiki-index")
|
|
||||||
return index
|
|
||||||
|
|
||||||
App.controller "SearchWikiController", ($scope, algoliawiki, _) ->
|
|
||||||
algolia = algoliawiki
|
|
||||||
$scope.hits = []
|
|
||||||
|
|
||||||
$scope.clearSearchText = ->
|
|
||||||
$scope.searchQueryText = ""
|
|
||||||
updateHits []
|
|
||||||
|
|
||||||
$scope.safeApply = (fn)->
|
|
||||||
phase = $scope.$root.$$phase
|
|
||||||
if(phase == '$apply' || phase == '$digest')
|
|
||||||
$scope.$eval(fn)
|
|
||||||
else
|
|
||||||
$scope.$apply(fn)
|
|
||||||
|
|
||||||
buildHitViewModel = (hit)->
|
|
||||||
page_underscored = hit.pageName.replace(/\s/g,'_')
|
|
||||||
section_underscored = hit.sectionName.replace(/\s/g,'_')
|
|
||||||
result =
|
|
||||||
name : hit._highlightResult.pageName.value + " - " + hit._highlightResult.sectionName.value
|
|
||||||
url :"/learn/#{page_underscored}##{section_underscored}"
|
|
||||||
console.log result
|
|
||||||
return result
|
|
||||||
|
|
||||||
updateHits = (hits)->
|
|
||||||
$scope.safeApply ->
|
|
||||||
$scope.hits = hits
|
|
||||||
|
|
||||||
$scope.search = ->
|
|
||||||
query = $scope.searchQueryText
|
|
||||||
console.log query
|
|
||||||
if !query? or query.length == 0
|
|
||||||
updateHits []
|
|
||||||
return
|
|
||||||
|
|
||||||
algolia.search query, (err, response)->
|
|
||||||
if response.hits.length == 0
|
|
||||||
updateHits []
|
|
||||||
else
|
|
||||||
hits = _.map response.hits, buildHitViewModel
|
|
||||||
updateHits hits
|
|
||||||
|
|
||||||
App.controller "AbTestController", ($scope, abTestManager)->
|
App.controller "AbTestController", ($scope, abTestManager)->
|
||||||
testKeys = _.keys(window.ab)
|
testKeys = _.keys(window.ab)
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ define [
|
|||||||
"main/register-users"
|
"main/register-users"
|
||||||
"main/subscription/group-subscription-invite-controller"
|
"main/subscription/group-subscription-invite-controller"
|
||||||
"main/contact-us"
|
"main/contact-us"
|
||||||
|
"main/templates"
|
||||||
"analytics/AbTestingManager"
|
"analytics/AbTestingManager"
|
||||||
"directives/asyncForm"
|
"directives/asyncForm"
|
||||||
"directives/stopPropagation"
|
"directives/stopPropagation"
|
||||||
|
|||||||
Reference in New Issue
Block a user