Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-09-18 15:10:27 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
24523cf31d02033f3277cd42c6448320b48c2d70
24523cf3
1 parent
1d681e53
Added page autosave request failure notification
Closes #192
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletions
resources/assets/js/controllers.js
resources/assets/js/controllers.js
View file @
24523cf
...
...
@@ -336,6 +336,8 @@ module.exports = function (ngApp, events) {
$scope
.
editorChange
=
function
()
{};
}
let
lastSave
=
0
;
/**
* Start the AutoSave loop, Checks for content change
* before performing the costly AJAX request.
...
...
@@ -345,6 +347,8 @@ module.exports = function (ngApp, events) {
currentContent
.
html
=
$scope
.
editContent
;
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
newHtml
=
$scope
.
editContent
;
...
...
@@ -357,6 +361,7 @@ module.exports = function (ngApp, events) {
},
1000
*
autosaveFrequency
);
}
let
draftErroring
=
false
;
/**
* 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
;
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
();
$scope
.
draftText
=
responseData
.
data
.
message
+
moment
(
updateTime
).
format
(
'HH:mm'
);
if
(
!
$scope
.
isNewPageDraft
)
$scope
.
isUpdateDraft
=
true
;
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
;
});
}
...
...
Please
register
or
sign in
to post a comment