Merge branch 'master' into webpack-frontend

This commit is contained in:
Yukai Huang 2016-10-11 18:39:15 +08:00
commit 6e651c8108
527 changed files with 2584 additions and 601 deletions

View file

@ -58,7 +58,7 @@ function saveHistoryToStorage(notehistory) {
if (store.enabled)
store.set('notehistory', JSON.stringify(notehistory));
else
saveHistoryToStorage(notehistory);
saveHistoryToCookie(notehistory);
}
function saveHistoryToCookie(notehistory) {
@ -107,8 +107,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];
}
@ -150,7 +150,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);
@ -176,8 +177,8 @@ function writeHistoryToServer(view) {
var newnotehistory = generateHistory(view, notehistory);
saveHistoryToServer(newnotehistory);
})
.fail(function () {
writeHistoryToStorage(view);
.fail(function (xhr, status, error) {
console.error(xhr.responseText);
});
}
@ -257,7 +258,7 @@ function renderHistory(view) {
return {
id: id,
text: title,
time: moment().format('MMMM Do YYYY, h:mm:ss a'),
time: moment().valueOf(),
tags: tags
};
}
@ -297,8 +298,8 @@ function getServerHistory(callback) {
callback(data.history);
}
})
.fail(function () {
getStorageHistory(callback);
.fail(function (xhr, status, error) {
console.error(xhr.responseText);
});
}
@ -338,8 +339,8 @@ function parseServerToHistory(list, callback) {
parseToHistory(list, data.history, callback);
}
})
.fail(function () {
parseStorageToHistory(list, callback);
.fail(function (xhr, status, error) {
console.error(xhr.responseText);
});
}
@ -368,9 +369,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]);
}
@ -378,6 +380,31 @@ 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);
});
}
module.exports = {
writeHistory: writeHistory,
parseHistory: parseHistory,
@ -385,5 +412,7 @@ module.exports = {
getHistory: getHistory,
saveHistory: saveHistory,
removeHistory: removeHistory,
parseStorageToHistory: parseStorageToHistory
parseStorageToHistory: parseStorageToHistory,
postHistoryToServer: postHistoryToServer,
deleteServerHistory: deleteServerHistory
}