Don't show diffs of deleted docs (much simpler)

This commit is contained in:
James Allen 2014-06-06 14:24:45 +01:00
parent 02f48be825
commit 5c27ff4430
8 changed files with 69 additions and 36 deletions

View file

@ -30,9 +30,14 @@ module.exports = DocstoreManager =
logger.error err: error, project_id: project_id, "error getting all docs from docstore"
callback(error)
getDoc: (project_id, doc_id, callback = (error, lines, rev) ->) ->
logger.log project_id: project_id, doc_id: doc_id, "getting doc in docstore api"
getDoc: (project_id, doc_id, options = {}, callback = (error, lines, rev) ->) ->
if typeof(options) == "function"
callback = options
options = {}
logger.log project_id: project_id, doc_id: doc_id, options: options, "getting doc in docstore api"
url = "#{settings.apis.docstore.url}/project/#{project_id}/doc/#{doc_id}"
if options.include_deleted
url += "?include_deleted=true"
request.get {
url: url
json: true

View file

@ -111,8 +111,11 @@ module.exports = ProjectEntityHandler =
logger.log sl_req_id: sl_req_id, project_id: project_id, "removing root doc"
Project.update {_id:project_id}, {$unset: {rootDoc_id: true}}, {}, callback
getDoc: (project_id, doc_id, callback = (error, lines, rev) ->) ->
DocstoreManager.getDoc project_id, doc_id, callback
getDoc: (project_id, doc_id, options = {}, callback = (error, lines, rev) ->) ->
if typeof(options) == "function"
callback = options
options = {}
DocstoreManager.getDoc project_id, doc_id, options, callback
addDoc: (project_or_id, folder_id, docName, docLines, sl_req_id, callback = (error, doc, folder_id) ->)=>
{callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id)
@ -138,7 +141,7 @@ module.exports = ProjectEntityHandler =
restoreDoc: (project_id, doc_id, name, callback = (error, doc, folder_id) ->) ->
# getDoc will return the deleted doc's lines, but we don't actually remove
# the deleted doc, just create a new one from its lines.
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines) ->
ProjectEntityHandler.getDoc project_id, doc_id, include_deleted: true, (error, lines) ->
return callback(error) if error?
ProjectEntityHandler.addDoc project_id, null, name, lines, callback

View file

@ -470,11 +470,14 @@
script(type='text/template')#trackChangesDiffTemplate
.track-changes-diff-toolbar.btn-toolbar
.number-of-changes {{ changes }} in <strong>{{ name }}</strong>
a(href="#").restore.btn.btn-small.btn-danger Restore to before these changes
.change-info
.number-of-changes {{ changes }} in <strong>{{ name }}</strong>
a(href="#").restore.btn.btn-small.btn-danger Restore to before these changes
.deleted-info(style="display:none;")
span This file has been deleted
a(href="#").restore-deleted.btn.btn-small.btn-success Restore
strong {{ name }}
.controls
span This file has been deleted
a(href="#").restore-deleted.btn.btn-small.btn-success Restore
.track-changes-diff-editor
script(type='text/template')#changeListItemTemplate

View file

@ -20,12 +20,13 @@ define [
@trigger "restore-deleted"
initialize: () ->
@model.on "change:diff", () => @render()
if !@model.get("doc").get("deleted")
@model.on "change:diff", () => @render()
@model.fetch()
else
@render()
render: ->
diff = @model.get("diff")
return unless diff?
changes = @getNumberOfChanges()
html = Mustache.to_html @template, {
changes: "#{changes} change#{if changes == 1 then "" else "s"}"
@ -33,22 +34,26 @@ define [
}
@$el.html(html)
if !@model.get("from")? or !@model.get("to")? or changes == 0
@$(".restore").hide()
if @model.get("doc").get("deleted")
@$(".restore").hide()
@$(".change-info").hide()
@$(".deleted-info").show()
else
diff = @model.get("diff")
return unless diff?
if !@model.get("from")? or !@model.get("to")? or changes == 0
@$(".restore").hide()
@createAceEditor()
@aceEditor.setValue(@getPlainDiffContent())
@aceEditor.clearSelection()
@$ace = $(@aceEditor.renderer.container).find(".ace_scroller")
@insertMarkers()
@insertNameTag()
@insertMoreChangeLabels()
@bindToScrollEvents()
@scrollToFirstChange()
@createAceEditor()
@aceEditor.setValue(@getPlainDiffContent())
@aceEditor.clearSelection()
@$ace = $(@aceEditor.renderer.container).find(".ace_scroller")
@insertMarkers()
@insertNameTag()
@insertMoreChangeLabels()
@bindToScrollEvents()
@scrollToFirstChange()
return @
remove: () ->

View file

@ -184,8 +184,6 @@ define [
@ide.fileTreeManager.openDoc(doc_id)
, 1000
@diff.fetch()
@ide.fileTreeManager.selectEntity(@doc_id)

View file

@ -30,7 +30,7 @@
background-color: #282828;
color: white;
border-right: 1px solid white;
.number-of-changes, .restore, .deleted-info {
.number-of-changes, .restore {
position: absolute;
}
.number-of-changes {
@ -43,10 +43,13 @@
padding: 3px 9px;
}
.deleted-info {
right: 10px;
bottom: 5px;
a {
padding: 3px 9px;
.controls {
position: absolute;
right: 10px;
bottom: 5px;
a {
padding: 3px 9px;
}
}
}
}

View file

@ -131,6 +131,22 @@ describe "DocstoreManager", ->
}, "error getting doc from docstore")
.should.equal true
describe "with include_deleted=true", ->
beforeEach ->
@request.get = sinon.stub().callsArgWith(1, null, statusCode: 204, @doc)
@DocstoreManager.getDoc @project_id, @doc_id, include_deleted: true, @callback
it "should get the doc from the docstore api (including deleted)", ->
@request.get
.calledWith({
url: "#{@settings.apis.docstore.url}/project/#{@project_id}/doc/#{@doc_id}?include_deleted=true"
json: true
})
.should.equal true
it "should call the callback with the lines, version and rev", ->
@callback.calledWith(null, @lines, @rev).should.equal true
describe "getAllDocs", ->
describe "with a successful response code", ->
beforeEach ->

View file

@ -286,7 +286,7 @@ describe 'ProjectEntityHandler', ->
beforeEach ->
@lines = ["mock", "doc", "lines"]
@rev = 5
@DocstoreManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @rev)
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev)
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
it "should call the docstore", ->
@ -346,14 +346,14 @@ describe 'ProjectEntityHandler', ->
@doc = { "mock": "doc" }
@folder_id = "mock-folder-id"
@callback = sinon.stub()
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @lines)
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(3, null, @lines)
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
@ProjectEntityHandler.restoreDoc project_id, doc_id, @name, @callback
it 'should get the doc lines', ->
@ProjectEntityHandler.getDoc
.calledWith(project_id, doc_id)
.calledWith(project_id, doc_id, include_deleted: true)
.should.equal true
it "should add a new doc with these doc lines", ->