diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 63fc12d3df..16df2f6262 100644 --- a/services/web/app/views/project/editor.jade +++ b/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( diff --git a/services/web/public/coffee/app/ide/editor/Document.coffee b/services/web/public/coffee/app/ide/editor/Document.coffee index f65d45e265..4b7347b520 100644 --- a/services/web/public/coffee/app/ide/editor/Document.coffee +++ b/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 diff --git a/services/web/public/coffee/app/ide/editor/EditorManager.coffee b/services/web/public/coffee/app/ide/editor/EditorManager.coffee index 2906ca4f98..86052d1f29 100644 --- a/services/web/public/coffee/app/ide/editor/EditorManager.coffee +++ b/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) -> diff --git a/services/web/public/coffee/app/ide/editor/controllers/SavingNotificationController.coffee b/services/web/public/coffee/app/ide/editor/controllers/SavingNotificationController.coffee new file mode 100644 index 0000000000..edefe07ea9 --- /dev/null +++ b/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." + ] \ No newline at end of file