diff --git a/services/web/app/coffee/Features/Templates/TemplatesController.coffee b/services/web/app/coffee/Features/Templates/TemplatesController.coffee index 28f68d4c19..0f6c896bb9 100644 --- a/services/web/app/coffee/Features/Templates/TemplatesController.coffee +++ b/services/web/app/coffee/Features/Templates/TemplatesController.coffee @@ -17,13 +17,14 @@ module.exports = TemplatesController = data.templateId = templateId data.name = req.query.templateName data.compiler = ProjectHelper.compilerFromV1Engine(req.query.latexEngine) + data.imageName = req.query.texImage data.mainFile = req.query.mainFile data.brandVariationId = req.query.brandVariationId res.render path.resolve(__dirname, "../../../views/project/editor/new_from_template"), data createProjectFromV1Template: (req, res, next)-> user_id = AuthenticationController.getLoggedInUserId(req) - TemplatesManager.createProjectFromV1Template req.body.brandVariationId, req.body.compiler, req.body.mainFile, req.body.templateId, req.body.templateName, req.body.templateVersionId, user_id, (err, project) -> + TemplatesManager.createProjectFromV1Template req.body.brandVariationId, req.body.compiler, req.body.mainFile, req.body.templateId, req.body.templateName, req.body.templateVersionId, user_id, req.body.imageName, (err, project) -> return next err if err? delete req.session.templateData res.redirect "/project/#{project._id}" diff --git a/services/web/app/coffee/Features/Templates/TemplatesManager.coffee b/services/web/app/coffee/Features/Templates/TemplatesManager.coffee index 15aa302d5a..88844ea03c 100644 --- a/services/web/app/coffee/Features/Templates/TemplatesManager.coffee +++ b/services/web/app/coffee/Features/Templates/TemplatesManager.coffee @@ -11,7 +11,7 @@ settings = require "settings-sharelatex" uuid = require "uuid" module.exports = TemplatesManager = - createProjectFromV1Template: (brandVariationId, compiler, mainFile, templateId, templateName, templateVersionId, user_id, callback) -> + createProjectFromV1Template: (brandVariationId, compiler, mainFile, templateId, templateName, templateVersionId, user_id, imageName, callback) -> zipUrl = "#{settings.apis.v1.url}/api/v1/sharelatex/templates/#{templateVersionId}" zipReq = request zipUrl, { auth: @@ -34,7 +34,7 @@ module.exports = TemplatesManager = return callback err async.series [ (cb) -> TemplatesManager._setCompiler project._id, compiler, cb - (cb) -> TemplatesManager._setImage project._id, "wl_texlive:2018.1", cb + (cb) -> TemplatesManager._setImage project._id, imageName, cb (cb) -> TemplatesManager._setMainFile project._id, mainFile, cb (cb) -> TemplatesManager._setBrandVariationId project._id, brandVariationId, cb ], (err) -> @@ -54,7 +54,7 @@ module.exports = TemplatesManager = ProjectOptionsHandler.setCompiler project_id, compiler, callback _setImage: (project_id, imageName, callback) -> - return callback() unless imageName? + imageName ||= "wl_texlive:2018.1" ProjectOptionsHandler.setImageName project_id, imageName, callback _setMainFile: (project_id, mainFile, callback) -> diff --git a/services/web/app/views/project/editor/new_from_template.pug b/services/web/app/views/project/editor/new_from_template.pug index cc474b98db..3c38b6256f 100644 --- a/services/web/app/views/project/editor/new_from_template.pug +++ b/services/web/app/views/project/editor/new_from_template.pug @@ -24,6 +24,7 @@ block content input(type="hidden" name="templateVersionId" value=templateVersionId) input(type="hidden" name="templateName" value=name) input(type="hidden" name="compiler" value=compiler) + input(type="hidden" name="imageName" value=imageName) input(type="hidden" name="mainFile" value=mainFile) if brandVariationId input(type="hidden" name="brandVariationId" value=brandVariationId) diff --git a/services/web/test/unit/coffee/Templates/TemplatesManagerTests.coffee b/services/web/test/unit/coffee/Templates/TemplatesManagerTests.coffee index d182cfd3e4..58900711f7 100644 --- a/services/web/test/unit/coffee/Templates/TemplatesManagerTests.coffee +++ b/services/web/test/unit/coffee/Templates/TemplatesManagerTests.coffee @@ -15,6 +15,7 @@ describe 'TemplatesManager', -> @project_id = "project-id" @brandVariationId = "brand-variation-id" @compiler = "pdflatex" + @imageName = "TL2017" @mainFile = "main.tex" @templateId = "template-id" @templateName = "template name" @@ -78,7 +79,7 @@ describe 'TemplatesManager', -> describe "when all options passed", -> beforeEach -> - @TemplatesManager.createProjectFromV1Template @brandVariationId, @compiler, @mainFile, @templateId, @templateName, @templateVersionId, @user_id, @callback + @TemplatesManager.createProjectFromV1Template @brandVariationId, @compiler, @mainFile, @templateId, @templateName, @templateVersionId, @user_id, @imageName, @callback it "should fetch zip from v1 based on template id", -> @request.should.have.been.calledWith "#{@v1Url}/api/v1/sharelatex/templates/#{@templateVersionId}" @@ -94,7 +95,7 @@ describe 'TemplatesManager', -> it "should set project options when passed", -> @ProjectOptionsHandler.setCompiler.should.have.been.calledWithMatch @project_id, @compiler - @ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, "wl_texlive:2018.1" + @ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, @imageName @ProjectRootDocManager.setRootDocFromName.should.have.been.calledWithMatch @project_id, @mainFile @ProjectOptionsHandler.setBrandVariationId.should.have.been.calledWithMatch @project_id, @brandVariationId @@ -103,9 +104,10 @@ describe 'TemplatesManager', -> describe "when some options not set", -> beforeEach -> - @TemplatesManager.createProjectFromV1Template null, null, null, @templateId, @templateName, @templateVersionId, @user_id, @callback + @TemplatesManager.createProjectFromV1Template null, null, null, @templateId, @templateName, @templateVersionId, @user_id, null, @callback it "should not set missing project options", -> @ProjectOptionsHandler.setCompiler.called.should.equal false @ProjectRootDocManager.setRootDocFromName.called.should.equal false @ProjectOptionsHandler.setBrandVariationId.called.should.equal false + @ProjectOptionsHandler.setImageName.should.have.been.calledWithMatch @project_id, "wl_texlive:2018.1"