Explorar o código

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

James Allen %!s(int64=12) %!d(string=hai) anos
pai
achega
9f1a7c7396

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

@@ -123,8 +123,7 @@ module.exports = DocumentUpdaterHandler =
 			url: url
 			json:
 				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"
 		request.post body, (error, res, body)->
 			timer.done()

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

@@ -210,10 +210,10 @@ define [
 
 		_bindToShareJsDocEvents: () ->
 			@doc.on "error", (error, meta) => @_onError error, meta
-			@doc.on "externalUpdate", () => 
+			@doc.on "externalUpdate", (update) => 
 				@ide.pushEvent "externalUpdate",
 					doc_id: @doc_id
-				@trigger "externalUpdate"
+				@trigger "externalUpdate", update
 			@doc.on "remoteop", () => 
 				@ide.pushEvent "remoteop",
 					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."
 				)
 
-			sharejs_doc.on "externalUpdate", () =>
+			sharejs_doc.on "externalUpdate", (update) =>
+				return if @_ignoreExternalUpdates
 				@ide.showGenericMessageModal(
 					"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."
@@ -98,3 +99,9 @@ define [
 
 		getCurrentDocId: () ->
 			@$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)
 
 			if message?.meta?.type == "external"
-				@trigger "externalUpdate"
+				@trigger "externalUpdate", message
 
 		catchUp: (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
 						json:
 							lines: @lines
-						headers:
-							"x-sl-update-source": @source
+							source: @source
 					})
 					.should.equal true