Show saving notifications

This commit is contained in:
James Allen 2014-07-02 17:41:07 +01:00
parent b61da1a9f0
commit a4afc70f9b
4 changed files with 46 additions and 0 deletions

View file

@ -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(

View file

@ -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

View file

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

View file

@ -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."
]