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:
Henry Oswald 2014-02-27 17:35:35 +00:00
parent 029077fe6e
commit 303a0e985b
7 changed files with 121 additions and 16 deletions

View file

@ -37,6 +37,10 @@ module.exports =
logger.log user_id:user_id, project_id:project_id, "reciving request to unpublish project as template"
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)->
if compiler?
ProjectOptionsHandler.setCompiler project_id, compiler, callback

View file

@ -17,5 +17,15 @@ module.exports =
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)->
url = "#{settings.apis.templates_api.url}/templates-api/user/#{user_id}/project/#{project_id}"

View file

@ -358,3 +358,7 @@ module.exports = class Router
client.on "getLastTimePollHappned", (callback)->
EditorController.getLastTimePollHappned(callback)
client.on "getPublishedDetails", (user_id, callback)->
AuthorizationManager.ensureClientCanViewProject client, (error, project_id) =>
TemplatesController.getTemplateDetails user_id, project_id, callback

View file

@ -289,18 +289,25 @@
|   Share URL
script(type="text/template")#publishProject
script(type="text/template")#publishProjectTemplate
-if(session && session.user && session.user.isAdmin)
.box
.page-header
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
.btn#publishProjectAsTemplate Publish project as template
.btn#unPublishProjectAsTemplate unpublish project as template
.row
textarea.span6#projectDescription {{description}}
script(type="text/template")#settingsPanelTemplate
.fullEditorArea.projectSettings
include project/partials/manage

View file

@ -167,7 +167,7 @@ define [
@options.manager.removeMember(@model)
PublishProjectView = Backbone.View.extend
template: $("#publishProject").html()
template: $("#publishProjectTemplate").html()
events:
"click #publishProjectAsTemplate": "publishProjectAsTemplate"
@ -181,18 +181,63 @@ define [
this.model.bind('change', this.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))
@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: ->
newDescription = $('#projectDescription').val()
this.model.set("description", newDescription)
publishProjectAsTemplate: ->
@ide.socket.emit "publishProjectAsTemplate", @ide.user.get("id"), ->
unPublishProjectAsTemplate: ->
@ide.socket.emit "unPublishProjectAsTemplate", @ide.user.get("id"), ->
@model.set("description", newDescription)
SocialSharingView = Backbone.View.extend
template: $("#socialSharingTemplate").html()

View file

@ -24,6 +24,7 @@ describe 'Templates Controller', ->
@TemplatesPublisher =
publish: sinon.stub()
unpublish:sinon.stub()
getTemplateDetails: sinon.stub()
@controller = SandboxedModule.require modulePath, requires:
'../Uploads/ProjectUploadManager':@ProjectUploadManager
'../Project/ProjectOptionsHandler':@ProjectOptionsHandler
@ -132,4 +133,18 @@ describe 'Templates Controller', ->
@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()

View file

@ -4,7 +4,7 @@ assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, '../../../../app/js/Features/Templates/TemplatesPublisher'
expect = require("chai").expect
describe 'Templates publish', ->
@ -12,6 +12,7 @@ describe 'Templates publish', ->
@request =
post: sinon.stub().callsArgWith(1)
del: sinon.stub().callsArgWith(1)
get: sinon.stub()
@settings =
apis:
templates_api:
@ -39,4 +40,23 @@ describe 'Templates publish', ->
@TemplatesPublisher.unpublish @user_id, @project_id, =>
uri = "#{@settings.apis.templates_api.url}/templates-api/user/#{@user_id}/project/#{@project_id}"
@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()