Selaa lähdekoodia

Send source of update to doc updater and allow external updates to be ignored in UI

James Allen 12 vuotta sitten
vanhempi
sitoutus
9f1a7c7396

+ 1 - 2
services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee

@@ -123,8 +123,7 @@ module.exports = DocumentUpdaterHandler =
 			url: url
 			url: url
 			json:
 			json:
 				lines: docLines
 				lines: docLines
-			headers:
-				"x-sl-update-source": source
+				source: source
 		logger.log project_id:project_id, doc_id: doc_id, source: source, "setting doc in document updater"
 		logger.log project_id:project_id, doc_id: doc_id, source: source, "setting doc in document updater"
 		request.post body, (error, res, body)->
 		request.post body, (error, res, body)->
 			timer.done()
 			timer.done()

+ 2 - 2
services/web/public/coffee/ide/editor/Document.coffee

@@ -210,10 +210,10 @@ define [
 
 
 		_bindToShareJsDocEvents: () ->
 		_bindToShareJsDocEvents: () ->
 			@doc.on "error", (error, meta) => @_onError error, meta
 			@doc.on "error", (error, meta) => @_onError error, meta
-			@doc.on "externalUpdate", () => 
+			@doc.on "externalUpdate", (update) => 
 				@ide.pushEvent "externalUpdate",
 				@ide.pushEvent "externalUpdate",
 					doc_id: @doc_id
 					doc_id: @doc_id
-				@trigger "externalUpdate"
+				@trigger "externalUpdate", update
 			@doc.on "remoteop", () => 
 			@doc.on "remoteop", () => 
 				@ide.pushEvent "remoteop",
 				@ide.pushEvent "remoteop",
 					doc_id: @doc_id
 					doc_id: @doc_id

+ 8 - 1
services/web/public/coffee/ide/editor/EditorManager.coffee

@@ -84,7 +84,8 @@ define [
 					"Sorry, this file has gone out of sync and we need to do a full refresh. Please let us know if this happens frequently."
 					"Sorry, this file has gone out of sync and we need to do a full refresh. Please let us know if this happens frequently."
 				)
 				)
 
 
-			sharejs_doc.on "externalUpdate", () =>
+			sharejs_doc.on "externalUpdate", (update) =>
+				return if @_ignoreExternalUpdates
 				@ide.showGenericMessageModal(
 				@ide.showGenericMessageModal(
 					"Document Updated Externally"
 					"Document Updated Externally"
 					"This document was just updated externally. Any recent changes you have made may have been overwritten. To see previous versions please look in the history."
 					"This document was just updated externally. Any recent changes you have made may have been overwritten. To see previous versions please look in the history."
@@ -98,3 +99,9 @@ define [
 
 
 		getCurrentDocId: () ->
 		getCurrentDocId: () ->
 			@$scope.editor.open_doc_id
 			@$scope.editor.open_doc_id
+			
+		startIgnoringExternalUpdates: () ->
+			@_ignoreExternalUpdates = true
+			
+		stopIgnoringExternalUpdates: () ->
+			@_ignoreExternalUpdates = false

+ 1 - 1
services/web/public/coffee/ide/editor/ShareJsDoc.coffee

@@ -57,7 +57,7 @@ define [
 				@_handleError(error)
 				@_handleError(error)
 
 
 			if message?.meta?.type == "external"
 			if message?.meta?.type == "external"
-				@trigger "externalUpdate"
+				@trigger "externalUpdate", message
 
 
 		catchUp: (updates) ->
 		catchUp: (updates) ->
 			for update, i in updates
 			for update, i in updates

+ 1 - 2
services/web/test/UnitTests/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee

@@ -227,8 +227,7 @@ describe 'Flushing documents :', ->
 						url: url
 						url: url
 						json:
 						json:
 							lines: @lines
 							lines: @lines
-						headers:
-							"x-sl-update-source": @source
+							source: @source
 					})
 					})
 					.should.equal true
 					.should.equal true