mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-28 03:33:37 +08:00
parent
1d681e53e4
commit
24523cf31d
|
@ -336,6 +336,8 @@ module.exports = function (ngApp, events) {
|
||||||
$scope.editorChange = function() {};
|
$scope.editorChange = function() {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastSave = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the AutoSave loop, Checks for content change
|
* Start the AutoSave loop, Checks for content change
|
||||||
* before performing the costly AJAX request.
|
* before performing the costly AJAX request.
|
||||||
|
@ -345,6 +347,8 @@ module.exports = function (ngApp, events) {
|
||||||
currentContent.html = $scope.editContent;
|
currentContent.html = $scope.editContent;
|
||||||
|
|
||||||
autoSave = $interval(() => {
|
autoSave = $interval(() => {
|
||||||
|
// Return if manually saved recently to prevent bombarding the server
|
||||||
|
if (Date.now() - lastSave < (1000*autosaveFrequency)/2) return;
|
||||||
var newTitle = $('#name').val();
|
var newTitle = $('#name').val();
|
||||||
var newHtml = $scope.editContent;
|
var newHtml = $scope.editContent;
|
||||||
|
|
||||||
|
@ -357,6 +361,7 @@ module.exports = function (ngApp, events) {
|
||||||
}, 1000 * autosaveFrequency);
|
}, 1000 * autosaveFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let draftErroring = false;
|
||||||
/**
|
/**
|
||||||
* Save a draft update into the system via an AJAX request.
|
* Save a draft update into the system via an AJAX request.
|
||||||
*/
|
*/
|
||||||
|
@ -369,11 +374,17 @@ module.exports = function (ngApp, events) {
|
||||||
if (isMarkdown) data.markdown = $scope.editContent;
|
if (isMarkdown) data.markdown = $scope.editContent;
|
||||||
|
|
||||||
let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft');
|
let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft');
|
||||||
$http.put(url, data).then((responseData) => {
|
$http.put(url, data).then(responseData => {
|
||||||
|
draftErroring = false;
|
||||||
var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
|
var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
|
||||||
$scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
|
$scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
|
||||||
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
|
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
|
||||||
showDraftSaveNotification();
|
showDraftSaveNotification();
|
||||||
|
lastSave = Date.now();
|
||||||
|
}, errorRes => {
|
||||||
|
if (draftErroring) return;
|
||||||
|
events.emit('error', 'Failed to save draft. Ensure you have internet connection before saving this page.')
|
||||||
|
draftErroring = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user