Showing
1 changed file
with
12 additions
and
1 deletions
| ... | @@ -336,6 +336,8 @@ module.exports = function (ngApp, events) { | ... | @@ -336,6 +336,8 @@ module.exports = function (ngApp, events) { |
| 336 | $scope.editorChange = function() {}; | 336 | $scope.editorChange = function() {}; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | + let lastSave = 0; | ||
| 340 | + | ||
| 339 | /** | 341 | /** |
| 340 | * Start the AutoSave loop, Checks for content change | 342 | * Start the AutoSave loop, Checks for content change |
| 341 | * before performing the costly AJAX request. | 343 | * before performing the costly AJAX request. |
| ... | @@ -345,6 +347,8 @@ module.exports = function (ngApp, events) { | ... | @@ -345,6 +347,8 @@ module.exports = function (ngApp, events) { |
| 345 | currentContent.html = $scope.editContent; | 347 | currentContent.html = $scope.editContent; |
| 346 | 348 | ||
| 347 | autoSave = $interval(() => { | 349 | autoSave = $interval(() => { |
| 350 | + // Return if manually saved recently to prevent bombarding the server | ||
| 351 | + if (Date.now() - lastSave < (1000*autosaveFrequency)/2) return; | ||
| 348 | var newTitle = $('#name').val(); | 352 | var newTitle = $('#name').val(); |
| 349 | var newHtml = $scope.editContent; | 353 | var newHtml = $scope.editContent; |
| 350 | 354 | ||
| ... | @@ -357,6 +361,7 @@ module.exports = function (ngApp, events) { | ... | @@ -357,6 +361,7 @@ module.exports = function (ngApp, events) { |
| 357 | }, 1000 * autosaveFrequency); | 361 | }, 1000 * autosaveFrequency); |
| 358 | } | 362 | } |
| 359 | 363 | ||
| 364 | + let draftErroring = false; | ||
| 360 | /** | 365 | /** |
| 361 | * Save a draft update into the system via an AJAX request. | 366 | * Save a draft update into the system via an AJAX request. |
| 362 | */ | 367 | */ |
| ... | @@ -369,11 +374,17 @@ module.exports = function (ngApp, events) { | ... | @@ -369,11 +374,17 @@ module.exports = function (ngApp, events) { |
| 369 | if (isMarkdown) data.markdown = $scope.editContent; | 374 | if (isMarkdown) data.markdown = $scope.editContent; |
| 370 | 375 | ||
| 371 | let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft'); | 376 | let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft'); |
| 372 | - $http.put(url, data).then((responseData) => { | 377 | + $http.put(url, data).then(responseData => { |
| 378 | + draftErroring = false; | ||
| 373 | var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate(); | 379 | var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate(); |
| 374 | $scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm'); | 380 | $scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm'); |
| 375 | if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true; | 381 | if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true; |
| 376 | showDraftSaveNotification(); | 382 | showDraftSaveNotification(); |
| 383 | + lastSave = Date.now(); | ||
| 384 | + }, errorRes => { | ||
| 385 | + if (draftErroring) return; | ||
| 386 | + events.emit('error', 'Failed to save draft. Ensure you have internet connection before saving this page.') | ||
| 387 | + draftErroring = true; | ||
| 377 | }); | 388 | }); |
| 378 | } | 389 | } |
| 379 | 390 | ... | ... |
-
Please register or sign in to post a comment