From 209c8ebbfc4b78172454b88b115cee35dbc7fee9 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 18 Mar 2016 11:31:50 +0000 Subject: [PATCH 01/10] wip --- services/web/app/views/wiki/page.jade | 27 ++++++++++- .../coffee/analytics/AbTestingManager.coffee | 48 +++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index 054697cee9..e93206310a 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -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 diff --git a/services/web/public/coffee/analytics/AbTestingManager.coffee b/services/web/public/coffee/analytics/AbTestingManager.coffee index 53524c8d5d..bc40f0ce6f 100644 --- a/services/web/public/coffee/analytics/AbTestingManager.coffee +++ b/services/web/public/coffee/analytics/AbTestingManager.coffee @@ -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) From 9cfbbfa504c9d3053bcb2e74dbf536cedfd98b81 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 22 Mar 2016 22:16:38 +0000 Subject: [PATCH 02/10] template search works nicely, needs styling --- services/web/app/views/wiki/page.jade | 53 ++++++++++--------- .../coffee/analytics/AbTestingManager.coffee | 8 +-- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index e93206310a..a18b49b6ec 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -3,34 +3,35 @@ extends ../layout block content .content.content-alt(ng-cloak) .container.wiki - .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" - ) + .row.template-page-header .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 + + .row + .col-xs-3.contents(ng-non-bindable) | !{contents.content} - .col-xs-9.page - .card + .col-xs-9.page(ng-controller="SearchWikiController") + .row + .col-md-12 + 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" + ) + .row + .col-md-12(ng-cloak) + ul.list-unstyled + li(ng-repeat='hit in hits') + .searchResult + .row + .col.-md-12 + a(ng-href='{{hit.url}}') + span(ng-bind-html='hit.name') + + .card(ng-non-bindable) .page-header h1 #{title} diff --git a/services/web/public/coffee/analytics/AbTestingManager.coffee b/services/web/public/coffee/analytics/AbTestingManager.coffee index bc40f0ce6f..23741dbaa9 100644 --- a/services/web/public/coffee/analytics/AbTestingManager.coffee +++ b/services/web/public/coffee/analytics/AbTestingManager.coffee @@ -86,10 +86,11 @@ define [ $scope.$apply(fn) buildHitViewModel = (hit)-> - page_underscored = hit.title.replace(/\s/g,'_') + page_underscored = hit.pageName.replace(/\s/g,'_') + section_underscored = hit.sectionName.replace(/\s/g,'_') result = - name : hit._highlightResult.title.value - url :"/learn/#{page_underscored}" + name : hit._highlightResult.pageName.value + " - " + hit._highlightResult.sectionName.value + url :"/learn/#{page_underscored}##{section_underscored}" console.log result return result @@ -99,6 +100,7 @@ define [ $scope.search = -> query = $scope.searchQueryText + console.log query if !query? or query.length == 0 updateHits [] return From de0aa1035de239cda2bccf8a3ec5e43bb6e599fd Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 22 Mar 2016 22:29:18 +0000 Subject: [PATCH 03/10] pulled tempaltes search into its own file --- .../coffee/analytics/AbTestingManager.coffee | 48 ------------------- services/web/public/coffee/main.coffee | 1 + 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/services/web/public/coffee/analytics/AbTestingManager.coffee b/services/web/public/coffee/analytics/AbTestingManager.coffee index 23741dbaa9..950f4f89f8 100644 --- a/services/web/public/coffee/analytics/AbTestingManager.coffee +++ b/services/web/public/coffee/analytics/AbTestingManager.coffee @@ -64,54 +64,6 @@ define [ bucketIndex = parseInt(hash.toString().slice(0,2), 16) % (buckets?.length or 2) 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)-> testKeys = _.keys(window.ab) diff --git a/services/web/public/coffee/main.coffee b/services/web/public/coffee/main.coffee index 40c6bd753d..de36e33c34 100644 --- a/services/web/public/coffee/main.coffee +++ b/services/web/public/coffee/main.coffee @@ -16,6 +16,7 @@ define [ "main/register-users" "main/subscription/group-subscription-invite-controller" "main/contact-us" + "main/templates" "analytics/AbTestingManager" "directives/asyncForm" "directives/stopPropagation" From 90092a0c6184ac0ad914f87e53f484a93415646b Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 23 Mar 2016 16:05:38 +0000 Subject: [PATCH 04/10] improved styling, not perefect still --- services/web/app/views/wiki/page.jade | 24 +++++++++---------- services/web/public/stylesheets/app/wiki.less | 5 ++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index a18b49b6ec..2270b8237b 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -11,23 +11,23 @@ block content | !{contents.content} .col-xs-9.page(ng-controller="SearchWikiController") .row - .col-md-12 - 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" - ) + + form.project-search.form-horizontal.col-md-12(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" + ) .row .col-md-12(ng-cloak) ul.list-unstyled li(ng-repeat='hit in hits') - .searchResult + .searchResult.thumbnail .row - .col.-md-12 + .col-md-12 a(ng-href='{{hit.url}}') span(ng-bind-html='hit.name') diff --git a/services/web/public/stylesheets/app/wiki.less b/services/web/public/stylesheets/app/wiki.less index cd4022dd89..c8e3a6538c 100644 --- a/services/web/public/stylesheets/app/wiki.less +++ b/services/web/public/stylesheets/app/wiki.less @@ -104,4 +104,9 @@ /*]]>*/ + .thumbnail { + margin-bottom:0px; + margin-top:5px; + } + } \ No newline at end of file From 7634fcf3af4bab3ac080233647d40382243aca34 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 23 Mar 2016 18:23:09 +0000 Subject: [PATCH 05/10] added missing page button (not wired up) to /learn --- services/web/app/views/wiki/page.jade | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index 2270b8237b..77b938c465 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -11,8 +11,7 @@ block content | !{contents.content} .col-xs-9.page(ng-controller="SearchWikiController") .row - - form.project-search.form-horizontal.col-md-12(role="form") + form.project-search.form-horizontal.col-md-9(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 @@ -21,6 +20,9 @@ block content style="cursor: pointer;", ng-show="searchQueryText.length > 0" ) + .col-md-2 + a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("missing_page")} + .row .col-md-12(ng-cloak) ul.list-unstyled From 6a4e13d3c82b0e7710fb5eee5d8e0df42e8173a6 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 24 Mar 2016 09:35:11 +0000 Subject: [PATCH 06/10] 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 From ce2cfeaa5b503657cb782f864cb073e20f5a4758 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 24 Mar 2016 09:52:19 +0000 Subject: [PATCH 07/10] don't show search bar in templates if its not configured --- services/web/app/views/wiki/page.jade | 47 ++++++++++--------- .../web/public/coffee/main/templates.coffee | 7 +-- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index 77b938c465..53d4fad401 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -9,29 +9,32 @@ block content .row .col-xs-3.contents(ng-non-bindable) | !{contents.content} - .col-xs-9.page(ng-controller="SearchWikiController") - .row - form.project-search.form-horizontal.col-md-9(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-2 - a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("missing_page")} - .row - .col-md-12(ng-cloak) - ul.list-unstyled - li(ng-repeat='hit in hits') - .searchResult.thumbnail - .row - .col-md-12 - a(ng-href='{{hit.url}}') - span(ng-bind-html='hit.name') + .col-xs-9.page + - if(typeof(settings.algolia) != "undefined" && typeof(settings.algolia.indexes) != "undefined" && typeof(settings.algolia.indexes.wiki) != "undefined") + span(ng-controller="SearchWikiController") + .row + form.project-search.form-horizontal.col-md-9(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-2 + a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("missing_page")} + + .row + .col-md-12(ng-cloak) + ul.list-unstyled + li(ng-repeat='hit in hits') + .searchResult.thumbnail + .row + .col-md-12 + a(ng-href='{{hit.url}}') + span(ng-bind-html='hit.name') .card(ng-non-bindable) .page-header diff --git a/services/web/public/coffee/main/templates.coffee b/services/web/public/coffee/main/templates.coffee index 717f7fb954..b9a1d3bc5d 100644 --- a/services/web/public/coffee/main/templates.coffee +++ b/services/web/public/coffee/main/templates.coffee @@ -3,9 +3,10 @@ define [ ], (App) -> App.factory "algoliawiki", -> - client = new AlgoliaSearch("SK53GL4JLY", "e398f35d3074fde57ca6d6c88d8be37c") - index = client.initIndex("lean-wiki-index") - return index + if window.sharelatex?.algolia? and window.sharelatex.algolia?.indexes?.wiki? + client = new AlgoliaSearch(window.sharelatex.algolia?.app_id, window.sharelatex.algolia?.api_key) + index = client.initIndex(window.sharelatex.algolia?.indexes?.wiki) + return index App.controller "SearchWikiController", ($scope, algoliawiki, _) -> algolia = algoliawiki From 9b84e1b1646b9fabd2148239724f231d4823d9b0 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 24 Mar 2016 11:38:56 +0000 Subject: [PATCH 08/10] Improve styling of wiki search --- services/web/app/views/wiki/page.jade | 14 ++++------- .../web/public/coffee/main/templates.coffee | 14 ++++++++++- services/web/public/stylesheets/app/wiki.less | 24 ++++++++++++++++--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index 53d4fad401..c7cc876408 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -23,20 +23,16 @@ block content style="cursor: pointer;", ng-show="searchQueryText.length > 0" ) - .col-md-2 + .col-md-3.text-right a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("missing_page")} .row .col-md-12(ng-cloak) - ul.list-unstyled - li(ng-repeat='hit in hits') - .searchResult.thumbnail - .row - .col-md-12 - a(ng-href='{{hit.url}}') - span(ng-bind-html='hit.name') + a(ng-href='{{hit.url}}',ng-repeat='hit in hits').search-result.card.card-thin + span(ng-bind-html='hit.name') + div.search-result-content(ng-show="hit.content != ''", ng-bind-html='hit.content') - .card(ng-non-bindable) + .card.row-spaced(ng-non-bindable) .page-header h1 #{title} diff --git a/services/web/public/coffee/main/templates.coffee b/services/web/public/coffee/main/templates.coffee index b9a1d3bc5d..3d05d4ea0f 100644 --- a/services/web/public/coffee/main/templates.coffee +++ b/services/web/public/coffee/main/templates.coffee @@ -26,10 +26,22 @@ define [ buildHitViewModel = (hit)-> page_underscored = hit.pageName.replace(/\s/g,'_') section_underscored = hit.sectionName.replace(/\s/g,'_') + content = hit._highlightResult.content.value + # Replace many new lines + content = content.replace(/\n\n+/g, "\n\n") + lines = content.split("\n") + # Only show the lines that have a highlighted match + matching_lines = [] + for line in lines + if !line.match(/^\[edit\]/) + content += line + "\n" + if line.match(//) + matching_lines.push line + content = matching_lines.join("\n...\n") result = name : hit._highlightResult.pageName.value + " - " + hit._highlightResult.sectionName.value url :"/learn/#{page_underscored}##{section_underscored}" - console.log result + content: content return result updateHits = (hits)-> diff --git a/services/web/public/stylesheets/app/wiki.less b/services/web/public/stylesheets/app/wiki.less index c8e3a6538c..053d0b0619 100644 --- a/services/web/public/stylesheets/app/wiki.less +++ b/services/web/public/stylesheets/app/wiki.less @@ -104,9 +104,27 @@ /*]]>*/ - .thumbnail { - margin-bottom:0px; - margin-top:5px; + a.search-result { + display: block; + margin-top: @line-height-computed / 2; + .search-result-content { + margin-top: @line-height-computed / 4; + white-space: pre-wrap; + font-size: 0.8em; + color: @gray-dark; + em { + font-weight: bold; + } + } + + &:hover { + text-decoration: none; + .search-result-content { + color: @gray-darker; + + } + box-shadow: 0 2px 4px rgba(0,0,0,0.35); + } } } \ No newline at end of file From 63c183402c12b15f9d0aaf95cd9c257601b3bb10 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 24 Mar 2016 11:42:48 +0000 Subject: [PATCH 09/10] Style active and focus states of search results too --- services/web/public/stylesheets/app/wiki.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/public/stylesheets/app/wiki.less b/services/web/public/stylesheets/app/wiki.less index 053d0b0619..210230989c 100644 --- a/services/web/public/stylesheets/app/wiki.less +++ b/services/web/public/stylesheets/app/wiki.less @@ -117,7 +117,7 @@ } } - &:hover { + &:hover, &:active, &:focus { text-decoration: none; .search-result-content { color: @gray-darker; From 6662d4c2cdf94446982fdd02f8f4e73ade63c5da Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 24 Mar 2016 12:05:54 +0000 Subject: [PATCH 10/10] wired up modal for learn and added translations --- services/web/app/views/contact-us-modal.jade | 14 +-- services/web/app/views/wiki/page.jade | 33 ++++++- services/web/public/coffee/main.coffee | 2 +- services/web/public/coffee/main/learn.coffee | 92 ++++++++++++++++++++ 4 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 services/web/public/coffee/main/learn.coffee diff --git a/services/web/app/views/contact-us-modal.jade b/services/web/app/views/contact-us-modal.jade index dade3a7730..32e096b7d5 100644 --- a/services/web/app/views/contact-us-modal.jade +++ b/services/web/app/views/contact-us-modal.jade @@ -5,26 +5,26 @@ script(type='text/ng-template', id='supportModalTemplate') data-dismiss="modal" ng-click="close()" ) × - h3 Contact Us + h3 #{translate("contact_us")} .modal-body.contact-us-modal span(ng-show="sent == false") label - | Subject + | #{translate("subject")} .form-group input.field.text.medium.span8.form-control(ng-model="form.subject", maxlength='255', tabindex='1', onkeyup='') label.desc - | Email + | #{translate("email")} .form-group input.field.text.medium.span8.form-control(ng-model="form.email", ng-init="form.email = '#{getUserEmail()}'", type='email', spellcheck='false', value='', maxlength='255', tabindex='2') label#title12.desc - | Project URL (optional) + | #{translate("project_url")} (#{translate("optional")}) .form-group input.field.text.medium.span8.form-control(ng-model="form.project_url", tabindex='3', onkeyup='') label.desc - | Message + | #{translate("suggestion")} .form-group textarea.field.text.medium.span8.form-control(ng-model="form.message",type='text', value='', maxlength='255', tabindex='4', onkeyup='') .form-group.text-center - input.btn-success.btn.btn-lg(type='submit', ng-disabled="sending", ng-click="contactUs()" value='Get in Touch') + input.btn-success.btn.btn-lg(type='submit', ng-disabled="sending", ng-click="contactUs()" value='#{translate("contact_us")}') span(ng-show="sent") - p Request Sent, Thank you. \ No newline at end of file + p #{translate("request_sent_thank_you")} \ No newline at end of file diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade index c7cc876408..6a6bea2202 100644 --- a/services/web/app/views/wiki/page.jade +++ b/services/web/app/views/wiki/page.jade @@ -24,7 +24,7 @@ block content ng-show="searchQueryText.length > 0" ) .col-md-3.text-right - a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("missing_page")} + a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("suggest_new_doc")} .row .col-md-12(ng-cloak) @@ -36,4 +36,33 @@ block content .page-header h1 #{title} - | !{page.content} \ No newline at end of file + | !{page.content} + + + + + script(type="text/ng-template", id="missingWikiPageModal") + .modal-header + button.close( + type="button" + data-dismiss="modal" + ng-click="close()" + ) × + h3 #{translate("suggest_new_doc")} + .modal-body.contact-us-modal + span(ng-show="sent == false") + label.desc + | #{translate("email")} (#{translate("optional")}) + .form-group + input.field.text.medium.span8.form-control(ng-model="form.email", ng-init="form.email = '#{getUserEmail()}'", type='email', spellcheck='false', value='', maxlength='255', tabindex='2') + label.desc + | #{translate("suggestion")} + .form-group + textarea.field.text.medium.span8.form-control(ng-model="form.message",type='text', value='', maxlength='255', tabindex='4', onkeyup='') + span(ng-show="sent") + p #{translate("request_sent_thank_you")} + .modal-footer + button.btn.btn-default(ng-click="close()") + span #{translate("dismiss")} + button.btn-success.btn(type='submit', ng-disabled="sending", ng-click="contactUs()") #{translate("contact_us")} + diff --git a/services/web/public/coffee/main.coffee b/services/web/public/coffee/main.coffee index de36e33c34..d85d89cfe8 100644 --- a/services/web/public/coffee/main.coffee +++ b/services/web/public/coffee/main.coffee @@ -16,7 +16,7 @@ define [ "main/register-users" "main/subscription/group-subscription-invite-controller" "main/contact-us" - "main/templates" + "main/learn" "analytics/AbTestingManager" "directives/asyncForm" "directives/stopPropagation" diff --git a/services/web/public/coffee/main/learn.coffee b/services/web/public/coffee/main/learn.coffee new file mode 100644 index 0000000000..57053bd4fa --- /dev/null +++ b/services/web/public/coffee/main/learn.coffee @@ -0,0 +1,92 @@ +define [ + "base" +], (App) -> + + App.factory "algoliawiki", -> + if window.sharelatex?.algolia? and window.sharelatex.algolia?.indexes?.wiki? + client = new AlgoliaSearch(window.sharelatex.algolia?.app_id, window.sharelatex.algolia?.api_key) + index = client.initIndex(window.sharelatex.algolia?.indexes?.wiki) + return index + + App.controller "SearchWikiController", ($scope, algoliawiki, _, $modal) -> + 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,'_') + content = hit._highlightResult.content.value + # Replace many new lines + content = content.replace(/\n\n+/g, "\n\n") + lines = content.split("\n") + # Only show the lines that have a highlighted match + matching_lines = [] + for line in lines + if !line.match(/^\[edit\]/) + content += line + "\n" + if line.match(//) + matching_lines.push line + content = matching_lines.join("\n...\n") + result = + name : hit._highlightResult.pageName.value + " - " + hit._highlightResult.sectionName.value + url :"/learn/#{page_underscored}##{section_underscored}" + content: content + 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 + + $scope.showMissingTemplateModal = () -> + modalInstance = $modal.open( + templateUrl: "missingWikiPageModal" + controller: "MissingWikiPageController" + ) + + + App.controller 'MissingWikiPageController', ($scope, $modalInstance) -> + $scope.form = {} + $scope.sent = false + $scope.sending = false + $scope.contactUs = -> + if !$scope.form.message? + console.log "message not set" + return + $scope.sending = true + ticketNumber = Math.floor((1 + Math.random()) * 0x10000).toString(32) + params = + email: $scope.form.email or "support@sharelatex.com" + message: $scope.form.message or "" + subject: "new wiki page sujection - [#{ticketNumber}]" + labels: "support wiki" + + Groove.createTicket params, (err, json)-> + $scope.sent = true + $scope.$apply() + + $scope.close = () -> + $modalInstance.close()