From 9a72667e91a7525fb93bcb92fd380b6e00e0bf1a Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 14 Sep 2015 15:28:19 +0100 Subject: [PATCH] added word count UI feature. --- .../Features/Compile/CompileController.coffee | 2 +- .../app/views/project/editor/left-menu.jade | 48 ++++++++++++++++++- services/web/public/coffee/ide.coffee | 1 + .../controllers/WordCountController.coffee | 9 ++++ .../WordCountModalController.coffee | 17 +++++++ .../public/coffee/ide/wordcount/index.coffee | 4 ++ .../stylesheets/app/editor/left-menu.less | 6 +-- 7 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 services/web/public/coffee/ide/wordcount/controllers/WordCountController.coffee create mode 100644 services/web/public/coffee/ide/wordcount/controllers/WordCountModalController.coffee create mode 100644 services/web/public/coffee/ide/wordcount/index.coffee diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index d00a4375c7..36dd4bb5e6 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -109,4 +109,4 @@ module.exports = CompileController = CompileManager.wordCount project_id, file, (error, body) -> return next(error) if error? res.contentType("application/json") - res.send 200, body + res.send body diff --git a/services/web/app/views/project/editor/left-menu.jade b/services/web/app/views/project/editor/left-menu.jade index 319212f122..0c6cf8250e 100644 --- a/services/web/app/views/project/editor/left-menu.jade +++ b/services/web/app/views/project/editor/left-menu.jade @@ -22,7 +22,7 @@ aside#left-menu.full-size( i.fa.fa-file-pdf-o.fa-2x br | PDF - div.pdf-disabled( + div.link-disabled( ng-if="!pdf.url" tooltip="#{translate('please_compile_pdf_before_download')}" tooltip-placement="bottom" @@ -41,7 +41,15 @@ aside#left-menu.full-size( ) i.fa.fa-fw.fa-copy |    #{translate("copy_project")} + != moduleIncludes("editorLeftMenu:actions", locals) + li(ng-controller="WordCountController") + a(href, ng-if="pdf.url" ,ng-click="openWordCountModal()") + i.fa.fa-fw.fa-eye + span    #{translate("word_count")} + a.link-disabled(href, ng-if="!pdf.url" , tooltip="#{translate('please_compile_pdf_before_word_count')}") + i.fa.fa-fw.fa-eye + span.link-disabled    #{translate("word_count")} if (moduleIncludesAvailable("editorLeftMenu:sync")) div(ng-show="!anonymous") @@ -173,3 +181,41 @@ script(type='text/ng-template', id='cloneProjectModalTemplate') ) span(ng-hide="state.inflight") #{translate("copy")} span(ng-show="state.inflight") #{translate("copying")}... + +script(type='text/ng-template', id='wordCountModalTemplate') + .modal-header + h3 #{translate("word_count")} + .modal-body + div(ng-if="status.loading") + .loading(ng-show="!status.error && status.loading") + i.fa.fa-refresh.fa-spin.fa-fw + span   #{translate("loading")}... + div.pdf-disabled( + ng-if="!pdf.url" + tooltip="#{translate('please_compile_pdf_before_word_count')}" + tooltip-placement="bottom" + ) + div(ng-if="!status.loading") + .container-fluid + .row + .col-md-4 + .pull-right #{translate("total_words")} : + .col-md-6 {{data.textWords}} + .row + .col-md-4 + .pull-right #{translate("headers")} : + .col-md-6 {{data.headers}} + .row + .col-md-4 + .pull-right #{translate("math_inline")} : + .col-md-6 {{data.mathInline}} + .row + .col-md-4 + .pull-right #{translate("math_display")} : + .col-md-6 {{data.mathDisplay}} + .modal-footer + button.btn.btn-default( + ng-disabled="state.inflight" + ng-click="cancel()" + ) #{translate("done")} + diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 11544aaf19..0ea6165835 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -13,6 +13,7 @@ define [ "ide/chat/index" "ide/clone/index" "ide/hotkeys/index" + "ide/wordcount/index" "ide/directives/layout" "ide/services/ide" "__IDE_CLIENTSIDE_INCLUDES__" diff --git a/services/web/public/coffee/ide/wordcount/controllers/WordCountController.coffee b/services/web/public/coffee/ide/wordcount/controllers/WordCountController.coffee new file mode 100644 index 0000000000..41d22c9d39 --- /dev/null +++ b/services/web/public/coffee/ide/wordcount/controllers/WordCountController.coffee @@ -0,0 +1,9 @@ +define [ + "base" +], (App) -> + App.controller 'WordCountController', ($scope, $modal) -> + $scope.openWordCountModal = () -> + $modal.open { + templateUrl: "wordCountModalTemplate" + controller: "WordCountModalController" + } \ No newline at end of file diff --git a/services/web/public/coffee/ide/wordcount/controllers/WordCountModalController.coffee b/services/web/public/coffee/ide/wordcount/controllers/WordCountModalController.coffee new file mode 100644 index 0000000000..3c69d3e276 --- /dev/null +++ b/services/web/public/coffee/ide/wordcount/controllers/WordCountModalController.coffee @@ -0,0 +1,17 @@ +define [ + "base" +], (App) -> + App.controller 'WordCountModalController', ($scope, $modalInstance, ide, $http) -> + $scope.status = + loading:true + + $http.get("/project/#{ide.project_id}/wordcount") + .success (data) -> + $scope.status.loading = false + $scope.data = data.texcount + console.log $scope.data + .error () -> + $scope.status.error = true + + $scope.cancel = () -> + $modalInstance.dismiss('cancel') \ No newline at end of file diff --git a/services/web/public/coffee/ide/wordcount/index.coffee b/services/web/public/coffee/ide/wordcount/index.coffee new file mode 100644 index 0000000000..4da1c79318 --- /dev/null +++ b/services/web/public/coffee/ide/wordcount/index.coffee @@ -0,0 +1,4 @@ +define [ + "ide/wordcount/controllers/WordCountController" + "ide/wordcount/controllers/WordCountModalController" +], () -> \ No newline at end of file diff --git a/services/web/public/stylesheets/app/editor/left-menu.less b/services/web/public/stylesheets/app/editor/left-menu.less index cbe11965b0..a44b7289ac 100644 --- a/services/web/public/stylesheets/app/editor/left-menu.less +++ b/services/web/public/stylesheets/app/editor/left-menu.less @@ -47,6 +47,9 @@ padding: (@line-height-computed / 4); font-weight: 700; } + .link-disabled { + color: @gray-light; + } } ul.nav-downloads { @@ -57,9 +60,6 @@ a { color: @gray-dark; } - .pdf-disabled { - color: @gray-light; - } i { margin: (@line-height-computed / 4) 0; }