This commit is contained in:
Henry Oswald 2016-03-18 11:31:50 +00:00
parent c980382196
commit 209c8ebbfc
2 changed files with 69 additions and 6 deletions

View file

@ -1,9 +1,32 @@
extends ../layout
block content
.content.content-alt(ng-non-bindable)
.content.content-alt(ng-cloak)
.container.wiki
.row
.row.template-page-header(ng-controller="SearchWikiController")
.col-xs-3
.col-md-8
form.project-search.form-horizontal(role="form")
.form-group.has-feedback.has-feedback-left.col-md-12
input.form-control.col-md-12(type='text', ng-model='searchQueryText', ng-keyup='search()', placeholder="Search help library....")
i.fa.fa-search.form-control-feedback-left
i.fa.fa-times.form-control-feedback(
ng-click="clearSearchText()",
style="cursor: pointer;",
ng-show="searchQueryText.length > 0"
)
.col-md-8(ng-cloak)
ul.list-unstyled
li(ng-repeat='hit in hits')
.thumbnail.searchResult
.row
a(ng-href='{{hit.url}}')
.col-md-3
img(ng-src='{{hit.image_url}}')
.col-md-7
h1(ng-bind-html='hit.name')
p(ng-bind-html='hit.description')
.row(ng-non-bindable)
.col-xs-3.contents
| !{contents.content}
.col-xs-9.page

View file

@ -22,24 +22,20 @@ define [
_buildCookieKey = (testName, bucket)->
key = "sl_abt_#{testName}_#{bucket}"
#console.log key
return key
_getTestCookie = (testName, bucket)->
cookieKey = _buildCookieKey(testName, bucket)
cookie = ipCookie(cookieKey)
#console.log cookieKey, cookie
return cookie
_persistCookieStep = (testName, bucket, newStep)->
cookieKey = _buildCookieKey(testName, bucket)
ipCookie(cookieKey, {step:newStep}, {expires:100, path:"/"})
#console.log("persisting", cookieKey, {step:newStep})
ga('send', 'event', 'ab_tests', "#{testName}:#{bucket}", "step-#{newStep}")
_checkIfStepIsNext = (cookieStep, newStep)->
#console.log cookieStep, newStep, "checking if step is next"
if !cookieStep? and newStep != 0
return false
else if newStep == 0
@ -69,6 +65,50 @@ define [
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.title.replace(/\s/g,'_')
result =
name : hit._highlightResult.title.value
url :"/learn/#{page_underscored}"
console.log result
return result
updateHits = (hits)->
$scope.safeApply ->
$scope.hits = hits
$scope.search = ->
query = $scope.searchQueryText
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)->
testKeys = _.keys(window.ab)