Explorar o código

Show saving notifications

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

+ 8 - 0
services/web/app/views/project/editor.jade

@@ -33,6 +33,14 @@ block content
 			.alert.alert-warning.small(ng-if="connection.reconnecting")
 				strong Reconnecting...
 
+			.div(ng-controller="SavingNotificationController")
+				.alert.alert-warning.small(
+					ng-repeat="(doc_id, state) in docSavingStatus"
+					ng-if="state.unsavedSeconds > 3"
+				)
+					| Saving {{ state.doc.name }}... ({{ state.unsavedSeconds }} seconds of unsaved changes)
+
+
 		include ./editor/left-menu
 
 		#chat-wrapper(

+ 4 - 0
services/web/public/coffee/app/ide/editor/Document.coffee

@@ -149,6 +149,10 @@ define [
 				@ide.connectionManager.disconnect()
 				return
 
+			if Math.random() < (@ide.ignoreRate or 0)
+				console.log "Simulating lost update"
+				return
+
 			if update?.doc == @doc_id and @doc?
 				@doc.processUpdateFromServer update
 

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

@@ -1,6 +1,7 @@
 define [
 	"ide/editor/Document"
 	"ide/editor/directives/aceEditor"
+	"ide/editor/controllers/SavingNotificationController"
 ], (Document) ->
 	class EditorManager
 		constructor: (@ide, @$scope) ->

+ 33 - 0
services/web/public/coffee/app/ide/editor/controllers/SavingNotificationController.coffee

@@ -0,0 +1,33 @@
+define [
+	"base"
+	"ide/editor/Document"
+], (App, Document) ->
+	App.controller "SavingNotificationController", ["$scope", "$interval", "ide", ($scope, $interval, ide) ->
+		$interval () ->
+			pollSavedStatus()
+		, 1000
+
+		$(window).bind 'beforeunload', () =>
+			warnAboutUnsavedChanges()
+
+		$scope.docSavingStatus = {}
+		pollSavedStatus = () ->
+			oldStatus = $scope.docSavingStatus
+			$scope.docSavingStatus = {}
+
+			for doc_id, doc of Document.openDocs
+				saving = doc.pollSavedStatus()
+				if !saving
+					if oldStatus[doc_id]?
+						$scope.docSavingStatus[doc_id] = oldStatus[doc_id]
+						$scope.docSavingStatus[doc_id].unsavedSeconds += 1
+					else
+						$scope.docSavingStatus[doc_id] = {
+							unsavedSeconds: 0
+							doc: ide.fileTreeManager.findEntityById(doc_id)
+						}
+
+		warnAboutUnsavedChanges = () ->
+			if Document.hasUnsavedChanges()
+				return "You have unsaved changes. If you leave now they will not be saved."
+	]