From 6a4e13d3c82b0e7710fb5eee5d8e0df42e8173a6 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 24 Mar 2016 09:35:11 +0000 Subject: [PATCH] added templates angular file forgoten in last commit --- .../web/public/coffee/main/templates.coffee | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 services/web/public/coffee/main/templates.coffee diff --git a/services/web/public/coffee/main/templates.coffee b/services/web/public/coffee/main/templates.coffee new file mode 100644 index 0000000000..717f7fb954 --- /dev/null +++ b/services/web/public/coffee/main/templates.coffee @@ -0,0 +1,49 @@ +define [ + "base" +], (App) -> + + 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 + 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 \ No newline at end of file