From 425a9b9db2dc585b7c256498bae0430701bc917d Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 2 Feb 2016 14:50:48 +0000 Subject: [PATCH] Add in option to compile in draft mode --- .../Features/Compile/ClsiManager.coffee | 7 ++-- .../Features/Compile/CompileController.coffee | 2 + .../web/app/views/project/editor/pdf.jade | 38 ++++++++++++++----- .../ide/pdf/controllers/PdfController.coffee | 6 +++ .../stylesheets/components/button-groups.less | 1 + .../stylesheets/components/dropdowns.less | 6 +++ .../coffee/Compile/ClsiManagerTests.coffee | 7 ++++ .../Compile/CompileControllerTests.coffee | 26 ++++++++----- 8 files changed, 71 insertions(+), 22 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 83eb72fcf7..8b7ef023bd 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -58,7 +58,7 @@ module.exports = ClsiManager = return outputFiles VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"] - _buildRequest: (project_id, settingsOverride={}, callback = (error, request) ->) -> + _buildRequest: (project_id, options={}, callback = (error, request) ->) -> Project.findById project_id, {compiler: 1, rootDoc_id: 1, imageName: 1}, (error, project) -> return callback(error) if error? return callback(new Errors.NotFoundError("project does not exist: #{project_id}")) if !project? @@ -82,7 +82,7 @@ module.exports = ClsiManager = content: doc.lines.join("\n") if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString() rootResourcePath = path - if settingsOverride.rootDoc_id? and doc._id.toString() == settingsOverride.rootDoc_id.toString() + if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() rootResourcePathOverride = path rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? @@ -101,8 +101,9 @@ module.exports = ClsiManager = compile: options: compiler: project.compiler - timeout: settingsOverride.timeout + timeout: options.timeout imageName: project.imageName + draft: !!options.draft rootResourcePath: rootResourcePath resources: resources } diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index 587f00647c..89fbc87e2e 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -25,6 +25,8 @@ module.exports = CompileController = options.rootDoc_id = req.body.settingsOverride.rootDoc_id if req.body?.compiler options.compiler = req.body.compiler + if req.body?.draft + options.draft = req.body.draft logger.log {options, project_id}, "got compile request" CompileManager.compile project_id, user_id, options, (error, status, outputFiles, output, limits) -> return next(error) if error? diff --git a/services/web/app/views/project/editor/pdf.jade b/services/web/app/views/project/editor/pdf.jade index 28d78480fe..aee8c9b152 100644 --- a/services/web/app/views/project/editor/pdf.jade +++ b/services/web/app/views/project/editor/pdf.jade @@ -1,16 +1,34 @@ div.full-size.pdf(ng-controller="PdfController") .toolbar.toolbar-tall - a.btn.btn-info( - href, - ng-disabled="pdf.compiling", - ng-click="recompile()" - ) - i.fa.fa-refresh( - ng-class="{'fa-spin': pdf.compiling }" + .btn-group(dropdown) + a.btn.btn-info( + href, + ng-disabled="pdf.compiling", + ng-click="recompile()" ) - |    - span(ng-show="!pdf.compiling") #{translate("recompile")} - span(ng-show="pdf.compiling") #{translate("compiling")}... + i.fa.fa-refresh( + ng-class="{'fa-spin': pdf.compiling }" + ) + |    + span(ng-show="!pdf.compiling") #{translate("recompile")} + span(ng-show="pdf.compiling") #{translate("compiling")}... + a.btn.btn-info.dropdown-toggle( + href, + ng-disabled="pdf.compiling", + dropdown-toggle + ) + span.caret + ul.dropdown-menu.dropdown-menu-right + li.dropdown-header #{translate("compile_mode")} + li + a(href, ng-click="draft = false") + i.fa.fa-fw(ng-class="{'fa-check': !draft}") + |  #{translate("normal")} + li + a(href, ng-click="draft = true") + i.fa.fa-fw(ng-class="{'fa-check': draft}") + |  #{translate("fast")}  + span.subdued [draft] a.log-btn( href ng-click="toggleLogs()" diff --git a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee index a87ef79060..f7e8ec0f35 100644 --- a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee +++ b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee @@ -12,6 +12,11 @@ define [ $scope.$on "pdf:error:display", () -> $scope.pdf.error = true + + $scope.draft = localStorage("draft:#{$scope.project_id}") or false + $scope.$watch "draft", (new_value, old_value) -> + if new_value? and old_value != new_value + localStorage("draft:#{$scope.project_id}", new_value) sendCompileRequest = (options = {}) -> url = "/project/#{$scope.project_id}/compile" @@ -19,6 +24,7 @@ define [ url += "?auto_compile=true" return $http.post url, { rootDoc_id: options.rootDocOverride_id or null + draft: $scope.draft _csrf: window.csrfToken } diff --git a/services/web/public/stylesheets/components/button-groups.less b/services/web/public/stylesheets/components/button-groups.less index 27eb796b89..1480481905 100755 --- a/services/web/public/stylesheets/components/button-groups.less +++ b/services/web/public/stylesheets/components/button-groups.less @@ -66,6 +66,7 @@ .btn-group > .btn:last-child:not(:first-child), .btn-group > .dropdown-toggle:not(:first-child) { .border-left-radius(0); + border-left: none; } // Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group) diff --git a/services/web/public/stylesheets/components/dropdowns.less b/services/web/public/stylesheets/components/dropdowns.less index f165165e7a..2b718026a1 100755 --- a/services/web/public/stylesheets/components/dropdowns.less +++ b/services/web/public/stylesheets/components/dropdowns.less @@ -67,6 +67,9 @@ line-height: @line-height-base; color: @dropdown-link-color; white-space: nowrap; // prevent links from randomly breaking onto new lines + .subdued { + color: #7a7a7a + } } } @@ -77,6 +80,9 @@ text-decoration: none; color: @dropdown-link-hover-color; background-color: @dropdown-link-hover-bg; + .subdued { + color: @dropdown-link-hover-color; + } } } diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee index 00e02af13e..baf2643c05 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee @@ -166,6 +166,7 @@ describe "ClsiManager", -> compiler: @compiler timeout : 100 imageName: @image + draft: false rootResourcePath: "main.tex" resources: [{ path: "main.tex" @@ -220,6 +221,12 @@ describe "ClsiManager", -> it "should return an error", -> expect(@error).to.exist + + describe "with the draft option", -> + it "should add the draft option into the request", (done) -> + @ClsiManager._buildRequest @project_id, {timeout:100, draft: true}, (error, request) => + request.compile.options.draft.should.equal true + done() describe '_postToClsi', -> diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index 85cdd55c50..26cf0a2e2d 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -43,14 +43,15 @@ describe "CompileController", -> @res = new MockResponse() describe "compile", -> + beforeEach -> + @req.params = + Project_id: @project_id + @req.session = {} + @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id") + @CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"]) describe "when not an auto compile", -> beforeEach -> - @req.params = - Project_id: @project_id - @req.session = {} - @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id") - @CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"], @output = "mock-output") @CompileController.compile @req, @res, @next it "should look up the user id", -> @@ -77,18 +78,25 @@ describe "CompileController", -> describe "when an auto compile", -> beforeEach -> - @req.params = - Project_id: @project_id @req.query = auto_compile: "true" - @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id") - @CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"]) @CompileController.compile @req, @res, @next it "should do the compile with the auto compile flag", -> @CompileManager.compile .calledWith(@project_id, @user_id, { isAutoCompile: true }) .should.equal true + + describe "with the draft attribute", -> + beforeEach -> + @req.body = + draft: true + @CompileController.compile @req, @res, @next + + it "should do the compile without the draft compile flag", -> + @CompileManager.compile + .calledWith(@project_id, @user_id, { isAutoCompile: false, draft: true }) + .should.equal true describe "downloadPdf", -> beforeEach ->