From b6e68b2d36c15b7cd91f8820b766f929c01721ad Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:49:42 +0800 Subject: Fix saveHistoryToStorage not correctly fallback to cookie --- public/js/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js/history.js') diff --git a/public/js/history.js b/public/js/history.js index 0840580d..c974612b 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -47,7 +47,7 @@ function saveHistoryToStorage(notehistory) { if (store.enabled) store.set('notehistory', JSON.stringify(notehistory)); else - saveHistoryToStorage(notehistory); + saveHistoryToCookie(notehistory); } function saveHistoryToCookie(notehistory) { -- cgit v1.2.3 From dc343978eb29da741b7f52137e042996ab78b63a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:50:01 +0800 Subject: Fix get or set history on server ajax should not fallback to browser storage to avoid some internet edge cases --- public/js/history.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'public/js/history.js') diff --git a/public/js/history.js b/public/js/history.js index c974612b..f9ce2267 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -165,8 +165,8 @@ function writeHistoryToServer(view) { var newnotehistory = generateHistory(view, notehistory); saveHistoryToServer(newnotehistory); }) - .fail(function () { - writeHistoryToStorage(view); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } @@ -286,8 +286,8 @@ function getServerHistory(callback) { callback(data.history); } }) - .fail(function () { - getStorageHistory(callback); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } @@ -327,8 +327,8 @@ function parseServerToHistory(list, callback) { parseToHistory(list, data.history, callback); } }) - .fail(function () { - parseStorageToHistory(list, callback); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } -- cgit v1.2.3 From 36a1900ce3496f2d71ae4c41609dc52d24636be2 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:55:33 +0800 Subject: Update to make note history count in server-side when user logged --- public/js/history.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'public/js/history.js') diff --git a/public/js/history.js b/public/js/history.js index f9ce2267..9be68104 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -139,7 +139,8 @@ function removeHistory(id, notehistory) { function writeHistory(view) { checkIfAuth( function () { - writeHistoryToServer(view); + // no need to do this anymore, this will count from server-side + // writeHistoryToServer(view); }, function () { writeHistoryToStorage(view); @@ -365,4 +366,29 @@ function parseToHistory(list, notehistory, callback) { } } callback(list, notehistory); +} + +function postHistoryToServer(noteId, data, callback) { + $.post(serverurl + '/history/' + noteId, data) + .done(function (result) { + return callback(null, result); + }) + .fail(function (xhr, status, error) { + console.error(xhr.responseText); + return callback(error, null); + }); +} + +function deleteServerHistory(noteId, callback) { + $.ajax({ + url: serverurl + '/history' + (noteId ? '/' + noteId : ""), + type: 'DELETE' + }) + .done(function (result) { + return callback(null, result); + }) + .fail(function (xhr, status, error) { + console.error(xhr.responseText); + return callback(error, null); + }); } \ No newline at end of file -- cgit v1.2.3 From c06b2f483898669b224321728321b7a3a8e9e37c Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 11 Oct 2016 16:46:50 +0800 Subject: Fix history time should save in UNIX timestamp to avoid time offset issue --- public/js/history.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'public/js/history.js') diff --git a/public/js/history.js b/public/js/history.js index 9be68104..324a9da2 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -96,8 +96,8 @@ function clearDuplicatedHistory(notehistory) { var id = notehistory[i].id.replace(/\=+$/, ''); var newId = newnotehistory[j].id.replace(/\=+$/, ''); if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) { - var time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'); - var newTime = moment(newnotehistory[j].time, 'MMMM Do YYYY, h:mm:ss a'); + var time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); + var newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); if(time >= newTime) { newnotehistory[j] = notehistory[i]; } @@ -247,7 +247,7 @@ function renderHistory(view) { return { id: id, text: title, - time: moment().format('MMMM Do YYYY, h:mm:ss a'), + time: moment().valueOf(), tags: tags }; } @@ -358,9 +358,10 @@ function parseToHistory(list, notehistory, callback) { else if (notehistory && notehistory.length > 0) { for (var i = 0; i < notehistory.length; i++) { //parse time to timestamp and fromNow - notehistory[i].timestamp = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').valueOf(); - notehistory[i].fromNow = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').fromNow(); - notehistory[i].time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').format('llll'); + var timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); + notehistory[i].timestamp = timestamp.valueOf(); + notehistory[i].fromNow = timestamp.fromNow(); + notehistory[i].time = timestamp.format('llll'); if (notehistory[i].id && list.get('id', notehistory[i].id).length == 0) list.add(notehistory[i]); } -- cgit v1.2.3