summaryrefslogtreecommitdiff
path: root/public/js/history.js
diff options
context:
space:
mode:
authorSheogorath2019-06-04 16:09:46 +0200
committerGitHub2019-06-04 16:09:46 +0200
commit6462968e84e8d92292dd23764a9e558d7800147d (patch)
tree03ab6b40402c79c766ffa05a0a09118c6987d540 /public/js/history.js
parentae32a129303fd14b3b2bd2f5b7bb0b0c0c8a7f81 (diff)
parent4da68597f701376307fe8849ed57edd3a80833ed (diff)
Merge pull request #97 from SISheogorath/fix/linting
Fix eslint warnings
Diffstat (limited to 'public/js/history.js')
-rw-r--r--public/js/history.js153
1 files changed, 77 insertions, 76 deletions
diff --git a/public/js/history.js b/public/js/history.js
index 27b8cd28..e0154185 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,4 +1,5 @@
/* eslint-env browser, jquery */
+/* eslint no-console: ["error", { allow: ["warn", "error", "debug"] }] */
/* global serverurl, moment */
import store from 'store'
@@ -12,11 +13,11 @@ import {
} from './utils'
import {
- checkIfAuth
+ checkIfAuth
} from './lib/common/login'
import {
- urlpath
+ urlpath
} from './lib/config'
window.migrateHistoryFromTempCallback = null
@@ -28,40 +29,40 @@ function migrateHistoryFromTemp () {
$.get(`${serverurl}/temp`, {
tempid: url('#tempid')
})
- .done(data => {
- if (data && data.temp) {
- getStorageHistory(olddata => {
- if (!olddata || olddata.length === 0) {
- saveHistoryToStorage(JSON.parse(data.temp))
+ .done(data => {
+ if (data && data.temp) {
+ getStorageHistory(olddata => {
+ if (!olddata || olddata.length === 0) {
+ saveHistoryToStorage(JSON.parse(data.temp))
+ }
+ })
+ }
+ })
+ .always(() => {
+ let hash = location.hash.split('#')[1]
+ hash = hash.split('&')
+ for (let i = 0; i < hash.length; i++) {
+ if (hash[i].indexOf('tempid') === 0) {
+ hash.splice(i, 1)
+ i--
}
- })
- }
- })
- .always(() => {
- let hash = location.hash.split('#')[1]
- hash = hash.split('&')
- for (let i = 0; i < hash.length; i++) {
- if (hash[i].indexOf('tempid') === 0) {
- hash.splice(i, 1)
- i--
}
- }
- hash = hash.join('&')
- location.hash = hash
- if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() }
- })
+ hash = hash.join('&')
+ location.hash = hash
+ if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() }
+ })
}
}
export function saveHistory (notehistory) {
checkIfAuth(
- () => {
- saveHistoryToServer(notehistory)
- },
- () => {
- saveHistoryToStorage(notehistory)
- }
- )
+ () => {
+ saveHistoryToServer(notehistory)
+ },
+ () => {
+ saveHistoryToStorage(notehistory)
+ }
+ )
}
function saveHistoryToStorage (notehistory) {
@@ -80,9 +81,9 @@ export function saveStorageHistoryToServer (callback) {
$.post(`${serverurl}/history`, {
history: data
})
- .done(data => {
- callback(data)
- })
+ .done(data => {
+ callback(data)
+ })
}
}
@@ -109,7 +110,7 @@ export function clearDuplicatedHistory (notehistory) {
}
function addHistory (id, text, time, tags, pinned, notehistory) {
- // only add when note id exists
+ // only add when note id exists
if (id) {
notehistory.push({
id,
@@ -135,14 +136,14 @@ export function removeHistory (id, notehistory) {
// used for inner
export function writeHistory (title, tags) {
checkIfAuth(
- () => {
- // no need to do this anymore, this will count from server-side
- // writeHistoryToServer(title, tags);
- },
- () => {
- writeHistoryToStorage(title, tags)
- }
- )
+ () => {
+ // no need to do this anymore, this will count from server-side
+ // writeHistoryToServer(title, tags);
+ },
+ () => {
+ writeHistoryToStorage(title, tags)
+ }
+ )
}
function writeHistoryToStorage (title, tags) {
@@ -163,7 +164,7 @@ if (!Array.isArray) {
}
function renderHistory (title, tags) {
- // console.debug(tags);
+ // console.debug(tags);
const id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1]
return {
id,
@@ -175,7 +176,7 @@ function renderHistory (title, tags) {
function generateHistory (title, tags, notehistory) {
const info = renderHistory(title, tags)
- // keep any pinned data
+ // keep any pinned data
let pinned = false
for (let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id === info.id && notehistory[i].pinned) {
@@ -192,25 +193,25 @@ function generateHistory (title, tags, notehistory) {
// used for outer
export function getHistory (callback) {
checkIfAuth(
- () => {
- getServerHistory(callback)
- },
- () => {
- getStorageHistory(callback)
- }
- )
+ () => {
+ getServerHistory(callback)
+ },
+ () => {
+ getStorageHistory(callback)
+ }
+ )
}
function getServerHistory (callback) {
$.get(`${serverurl}/history`)
- .done(data => {
- if (data.history) {
- callback(data.history)
- }
- })
- .fail((xhr, status, error) => {
- console.error(xhr.responseText)
- })
+ .done(data => {
+ if (data.history) {
+ callback(data.history)
+ }
+ })
+ .fail((xhr, status, error) => {
+ console.error(xhr.responseText)
+ })
}
export function getStorageHistory (callback) {
@@ -225,25 +226,25 @@ export function getStorageHistory (callback) {
export function parseHistory (list, callback) {
checkIfAuth(
- () => {
- parseServerToHistory(list, callback)
- },
- () => {
- parseStorageToHistory(list, callback)
- }
- )
+ () => {
+ parseServerToHistory(list, callback)
+ },
+ () => {
+ parseStorageToHistory(list, callback)
+ }
+ )
}
export function parseServerToHistory (list, callback) {
$.get(`${serverurl}/history`)
- .done(data => {
- if (data.history) {
- parseToHistory(list, data.history, callback)
- }
- })
- .fail((xhr, status, error) => {
- console.error(xhr.responseText)
- })
+ .done(data => {
+ if (data.history) {
+ parseToHistory(list, data.history, callback)
+ }
+ })
+ .fail((xhr, status, error) => {
+ console.error(xhr.responseText)
+ })
}
export function parseStorageToHistory (list, callback) {
@@ -269,15 +270,15 @@ function parseToHistory (list, notehistory, callback) {
} catch (err) {
console.error(err)
}
- // parse time to timestamp and fromNow
+ // parse time to timestamp and fromNow
const 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')
- // prevent XSS
+ // prevent XSS
notehistory[i].text = S(notehistory[i].text).escapeHTML().s
notehistory[i].tags = (notehistory[i].tags && notehistory[i].tags.length > 0) ? S(notehistory[i].tags).escapeHTML().s.split(',') : []
- // add to list
+ // add to list
if (notehistory[i].id && list.get('id', notehistory[i].id).length === 0) { list.add(notehistory[i]) }
}
}