mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-11 16:34:28 +00:00
Show saving notifications
This commit is contained in:
parent
b61da1a9f0
commit
a4afc70f9b
4 changed files with 46 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -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,6 +1,7 @@
|
|||
define [
|
||||
"ide/editor/Document"
|
||||
"ide/editor/directives/aceEditor"
|
||||
"ide/editor/controllers/SavingNotificationController"
|
||||
], (Document) ->
|
||||
class EditorManager
|
||||
constructor: (@ide, @$scope) ->
|
||||
|
|
|
@ -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."
|
||||
]
|
Loading…
Reference in a new issue