mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
improved the publish button process so it talks to the templates-api and lets the user know what is going on
This commit is contained in:
parent
029077fe6e
commit
303a0e985b
7 changed files with 121 additions and 16 deletions
|
@ -37,6 +37,10 @@ module.exports =
|
||||||
logger.log user_id:user_id, project_id:project_id, "reciving request to unpublish project as template"
|
logger.log user_id:user_id, project_id:project_id, "reciving request to unpublish project as template"
|
||||||
TemplatesPublisher.unpublish user_id, project_id, callback
|
TemplatesPublisher.unpublish user_id, project_id, callback
|
||||||
|
|
||||||
|
getTemplateDetails: (user_id, project_id, callback)->
|
||||||
|
TemplatesPublisher.getTemplateDetails user_id, project_id, callback
|
||||||
|
|
||||||
|
|
||||||
setCompiler = (project_id, compiler, callback)->
|
setCompiler = (project_id, compiler, callback)->
|
||||||
if compiler?
|
if compiler?
|
||||||
ProjectOptionsHandler.setCompiler project_id, compiler, callback
|
ProjectOptionsHandler.setCompiler project_id, compiler, callback
|
||||||
|
|
|
@ -17,5 +17,15 @@ module.exports =
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
|
||||||
|
getTemplateDetails: (user_id, project_id, callback)->
|
||||||
|
url = buildUrl(user_id, project_id)+"/details"
|
||||||
|
request.get url, (err, res, body)->
|
||||||
|
try
|
||||||
|
json = JSON.parse body
|
||||||
|
catch err
|
||||||
|
return callback err
|
||||||
|
callback(err, json)
|
||||||
|
|
||||||
|
|
||||||
buildUrl = (user_id, project_id)->
|
buildUrl = (user_id, project_id)->
|
||||||
url = "#{settings.apis.templates_api.url}/templates-api/user/#{user_id}/project/#{project_id}"
|
url = "#{settings.apis.templates_api.url}/templates-api/user/#{user_id}/project/#{project_id}"
|
||||||
|
|
|
@ -358,3 +358,7 @@ module.exports = class Router
|
||||||
|
|
||||||
client.on "getLastTimePollHappned", (callback)->
|
client.on "getLastTimePollHappned", (callback)->
|
||||||
EditorController.getLastTimePollHappned(callback)
|
EditorController.getLastTimePollHappned(callback)
|
||||||
|
|
||||||
|
client.on "getPublishedDetails", (user_id, callback)->
|
||||||
|
AuthorizationManager.ensureClientCanViewProject client, (error, project_id) =>
|
||||||
|
TemplatesController.getTemplateDetails user_id, project_id, callback
|
||||||
|
|
|
@ -289,18 +289,25 @@
|
||||||
| Share URL
|
| Share URL
|
||||||
|
|
||||||
|
|
||||||
script(type="text/template")#publishProject
|
script(type="text/template")#publishProjectTemplate
|
||||||
-if(session && session.user && session.user.isAdmin)
|
-if(session && session.user && session.user.isAdmin)
|
||||||
.box
|
.box
|
||||||
.page-header
|
.page-header
|
||||||
h2 Publish Project
|
h2 Publish Project
|
||||||
|
|
||||||
|
#publishedAsTemplateArea(style="display:none;")
|
||||||
|
a#templateLink(href='{{canonicalUrl}}') View Template
|
||||||
|
.btn.btn-warning#unPublishProjectAsTemplate unpublish project as template
|
||||||
|
#problemWithPublishingArea(style="display:none;")
|
||||||
|
p There is a problem with our publishing service, please try again in a few minutes.
|
||||||
|
#publishWorkingArea(style="display:none;")
|
||||||
|
p Working.....
|
||||||
|
#unpublishedAsTemplateArea(style="display:none;")
|
||||||
|
.btn.btn-success#publishProjectAsTemplate Publish project as template
|
||||||
div
|
div
|
||||||
.btn#publishProjectAsTemplate Publish project as template
|
|
||||||
.btn#unPublishProjectAsTemplate unpublish project as template
|
|
||||||
.row
|
|
||||||
textarea.span6#projectDescription {{description}}
|
textarea.span6#projectDescription {{description}}
|
||||||
|
|
||||||
|
|
||||||
script(type="text/template")#settingsPanelTemplate
|
script(type="text/template")#settingsPanelTemplate
|
||||||
.fullEditorArea.projectSettings
|
.fullEditorArea.projectSettings
|
||||||
include project/partials/manage
|
include project/partials/manage
|
||||||
|
|
|
@ -167,7 +167,7 @@ define [
|
||||||
@options.manager.removeMember(@model)
|
@options.manager.removeMember(@model)
|
||||||
|
|
||||||
PublishProjectView = Backbone.View.extend
|
PublishProjectView = Backbone.View.extend
|
||||||
template: $("#publishProject").html()
|
template: $("#publishProjectTemplate").html()
|
||||||
|
|
||||||
events:
|
events:
|
||||||
"click #publishProjectAsTemplate": "publishProjectAsTemplate"
|
"click #publishProjectAsTemplate": "publishProjectAsTemplate"
|
||||||
|
@ -181,18 +181,63 @@ define [
|
||||||
this.model.bind('change', this.render)
|
this.model.bind('change', this.render)
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
viewModel = description:@model.get("description")
|
viewModel =
|
||||||
|
description: @model.get("description")
|
||||||
|
canonicalUrl: @model.get("template.canonicalUrl")
|
||||||
|
isPublished: @model.get("template.isPublished")
|
||||||
|
|
||||||
$(@el).html $(Mustache.to_html(@template, viewModel))
|
$(@el).html $(Mustache.to_html(@template, viewModel))
|
||||||
|
@publishedArea = $('#publishedAsTemplateArea')
|
||||||
|
@unpublishedArea = $('#unpublishedAsTemplateArea')
|
||||||
|
@refreshPublishStatus()
|
||||||
|
|
||||||
|
|
||||||
|
refreshPublishStatus: ->
|
||||||
|
@ide.socket.emit "getPublishedDetails", @ide.user.get("id"), (err, details)=>
|
||||||
|
if err?
|
||||||
|
return @showError()
|
||||||
|
|
||||||
|
@model.set("template.isPublished", details.exists)
|
||||||
|
if details.exists
|
||||||
|
@model.set("template.canonicalUrl", details.canonicalUrl)
|
||||||
|
@publishedArea.show()
|
||||||
|
@unpublishedArea.hide()
|
||||||
|
else
|
||||||
|
@publishedArea.hide()
|
||||||
|
@unpublishedArea.show()
|
||||||
|
|
||||||
|
showError: ->
|
||||||
|
$('#problemWithPublishingArea').show()
|
||||||
|
|
||||||
|
showWorking: ->
|
||||||
|
$('#publishWorkingArea').show()
|
||||||
|
|
||||||
|
hideWorking: ->
|
||||||
|
$('#publishWorkingArea').hide()
|
||||||
|
|
||||||
|
publishProjectAsTemplate: ->
|
||||||
|
@showWorking()
|
||||||
|
@unpublishedArea.hide()
|
||||||
|
@ide.socket.emit "publishProjectAsTemplate", @ide.user.get("id"), (err)=>
|
||||||
|
@hideWorking()
|
||||||
|
if err?
|
||||||
|
@showError()
|
||||||
|
else
|
||||||
|
@refreshPublishStatus()
|
||||||
|
|
||||||
|
unPublishProjectAsTemplate: ->
|
||||||
|
@showWorking()
|
||||||
|
@publishedArea.hide()
|
||||||
|
@ide.socket.emit "unPublishProjectAsTemplate", @ide.user.get("id"), (err)=>
|
||||||
|
@hideWorking()
|
||||||
|
if err?
|
||||||
|
@showError()
|
||||||
|
else
|
||||||
|
@refreshPublishStatus()
|
||||||
|
|
||||||
updateDescription: ->
|
updateDescription: ->
|
||||||
newDescription = $('#projectDescription').val()
|
newDescription = $('#projectDescription').val()
|
||||||
this.model.set("description", newDescription)
|
@model.set("description", newDescription)
|
||||||
|
|
||||||
publishProjectAsTemplate: ->
|
|
||||||
@ide.socket.emit "publishProjectAsTemplate", @ide.user.get("id"), ->
|
|
||||||
|
|
||||||
unPublishProjectAsTemplate: ->
|
|
||||||
@ide.socket.emit "unPublishProjectAsTemplate", @ide.user.get("id"), ->
|
|
||||||
|
|
||||||
SocialSharingView = Backbone.View.extend
|
SocialSharingView = Backbone.View.extend
|
||||||
template: $("#socialSharingTemplate").html()
|
template: $("#socialSharingTemplate").html()
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe 'Templates Controller', ->
|
||||||
@TemplatesPublisher =
|
@TemplatesPublisher =
|
||||||
publish: sinon.stub()
|
publish: sinon.stub()
|
||||||
unpublish:sinon.stub()
|
unpublish:sinon.stub()
|
||||||
|
getTemplateDetails: sinon.stub()
|
||||||
@controller = SandboxedModule.require modulePath, requires:
|
@controller = SandboxedModule.require modulePath, requires:
|
||||||
'../Uploads/ProjectUploadManager':@ProjectUploadManager
|
'../Uploads/ProjectUploadManager':@ProjectUploadManager
|
||||||
'../Project/ProjectOptionsHandler':@ProjectOptionsHandler
|
'../Project/ProjectOptionsHandler':@ProjectOptionsHandler
|
||||||
|
@ -132,4 +133,18 @@ describe 'Templates Controller', ->
|
||||||
@controller.createProjectFromZipTemplate @req, res
|
@controller.createProjectFromZipTemplate @req, res
|
||||||
|
|
||||||
|
|
||||||
describe '', ->
|
describe 'getTemplateDetails', ->
|
||||||
|
|
||||||
|
it "should return an error the templatePublisher", (done)->
|
||||||
|
error = "error"
|
||||||
|
@TemplatesPublisher.getTemplateDetails.callsArgWith(2, error)
|
||||||
|
@controller.getTemplateDetails @user_id, @project_id, (passedError)=>
|
||||||
|
passedError.should.equal error
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should return the details", (done)->
|
||||||
|
details = {exists:true}
|
||||||
|
@TemplatesPublisher.getTemplateDetails.callsArgWith(2, null, details)
|
||||||
|
@controller.getTemplateDetails @user_id, @project_id, (err, passedDetails)=>
|
||||||
|
details.should.equal passedDetails
|
||||||
|
done()
|
||||||
|
|
|
@ -4,7 +4,7 @@ assert = require('assert')
|
||||||
path = require('path')
|
path = require('path')
|
||||||
sinon = require('sinon')
|
sinon = require('sinon')
|
||||||
modulePath = path.join __dirname, '../../../../app/js/Features/Templates/TemplatesPublisher'
|
modulePath = path.join __dirname, '../../../../app/js/Features/Templates/TemplatesPublisher'
|
||||||
|
expect = require("chai").expect
|
||||||
|
|
||||||
describe 'Templates publish', ->
|
describe 'Templates publish', ->
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ describe 'Templates publish', ->
|
||||||
@request =
|
@request =
|
||||||
post: sinon.stub().callsArgWith(1)
|
post: sinon.stub().callsArgWith(1)
|
||||||
del: sinon.stub().callsArgWith(1)
|
del: sinon.stub().callsArgWith(1)
|
||||||
|
get: sinon.stub()
|
||||||
@settings =
|
@settings =
|
||||||
apis:
|
apis:
|
||||||
templates_api:
|
templates_api:
|
||||||
|
@ -40,3 +41,22 @@ describe 'Templates publish', ->
|
||||||
uri = "#{@settings.apis.templates_api.url}/templates-api/user/#{@user_id}/project/#{@project_id}"
|
uri = "#{@settings.apis.templates_api.url}/templates-api/user/#{@user_id}/project/#{@project_id}"
|
||||||
@request.del.calledWith(uri).should.equal true
|
@request.del.calledWith(uri).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
describe "getTemplateDetails", ->
|
||||||
|
it "should make a get request to templates api", (done)->
|
||||||
|
body =
|
||||||
|
exists:true
|
||||||
|
@request.get.callsArgWith(1, null, null, JSON.stringify(body))
|
||||||
|
@TemplatesPublisher.getTemplateDetails @user_id, @project_id, (err, details)=>
|
||||||
|
uri = "#{@settings.apis.templates_api.url}/templates-api/user/#{@user_id}/project/#{@project_id}/details"
|
||||||
|
@request.get.calledWith(uri).should.equal true
|
||||||
|
assert.deepEqual details, body
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
it "should catch an error thrown from trying to parse bad json", (done)->
|
||||||
|
@request.get.callsArgWith(1, null, null, "<not json>")
|
||||||
|
@TemplatesPublisher.getTemplateDetails @user_id, @project_id, (err, details)=>
|
||||||
|
expect(err).to.exist
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue