\
\
@@ -64,15 +64,16 @@ var options = {
})
]
};
-var historyList = new List('history', options);
+const historyList = new List('history', options);
migrateHistoryFromTempCallback = pageInit;
-loginStateChangeEvent = pageInit;
+setloginStateChangeEvent(pageInit);
+
pageInit();
function pageInit() {
checkIfAuth(
- function (data) {
+ data => {
$('.ui-signin').hide();
$('.ui-or').hide();
$('.ui-welcome').show();
@@ -83,7 +84,7 @@ function pageInit() {
$(".ui-history").click();
parseServerToHistory(historyList, parseHistoryCallback);
},
- function () {
+ () => {
$('.ui-signin').show();
$('.ui-or').show();
$('.ui-welcome').hide();
@@ -100,14 +101,14 @@ $(".masthead-nav li").click(function () {
$(this).addClass("active");
});
-$(".ui-home").click(function () {
+$(".ui-home").click(() => {
if (!$("#home").is(':visible')) {
$(".section:visible").hide();
$("#home").fadeIn();
}
});
-$(".ui-history").click(function () {
+$(".ui-history").click(() => {
if (!$("#history").is(':visible')) {
$(".section:visible").hide();
$("#history").fadeIn();
@@ -120,7 +121,7 @@ function checkHistoryList() {
$(".ui-import-from-browser").hide();
} else if ($("#history-list").children().length == 0) {
$(".ui-nohistory").slideDown();
- getStorageHistory(function (data) {
+ getStorageHistory(data => {
if (data && data.length > 0 && getLoginState() && historyList.items.length == 0) {
$(".ui-import-from-browser").slideDown();
}
@@ -130,35 +131,35 @@ function checkHistoryList() {
function parseHistoryCallback(list, notehistory) {
checkHistoryList();
- //sort by pinned then timestamp
- list.sort('', {
- sortFunction: function (a, b) {
- var notea = a.values();
- var noteb = b.values();
- if (notea.pinned && !noteb.pinned) {
+ //sort by pinned then timestamp
+ list.sort('', {
+ sortFunction(a, b) {
+ const notea = a.values();
+ const noteb = b.values();
+ if (notea.pinned && !noteb.pinned) {
return -1;
} else if (!notea.pinned && noteb.pinned) {
return 1;
} else {
- if (notea.timestamp > noteb.timestamp) {
- return -1;
- } else if (notea.timestamp < noteb.timestamp) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- });
+ if (notea.timestamp > noteb.timestamp) {
+ return -1;
+ } else if (notea.timestamp < noteb.timestamp) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ }
+ });
// parse filter tags
- var filtertags = [];
- for (var i = 0, l = list.items.length; i < l; i++) {
- var tags = list.items[i]._values.tags;
+ const filtertags = [];
+ for (let i = 0, l = list.items.length; i < l; i++) {
+ const tags = list.items[i]._values.tags;
if (tags && tags.length > 0) {
- for (var j = 0; j < tags.length; j++) {
+ for (let j = 0; j < tags.length; j++) {
//push info filtertags if not found
- var found = false;
- if (filtertags.indexOf(tags[j]) != -1)
+ let found = false;
+ if (filtertags.includes(tags[j]))
found = true;
if (!found)
filtertags.push(tags[j]);
@@ -169,17 +170,17 @@ function parseHistoryCallback(list, notehistory) {
}
// update items whenever list updated
-historyList.on('updated', function (e) {
- for (var i = 0, l = e.items.length; i < l; i++) {
- var item = e.items[i];
+historyList.on('updated', e => {
+ for (let i = 0, l = e.items.length; i < l; i++) {
+ const item = e.items[i];
if (item.visible()) {
- var itemEl = $(item.elm);
- var values = item._values;
- var a = itemEl.find("a");
- var pin = itemEl.find(".ui-history-pin");
- var tagsEl = itemEl.find(".tags");
+ const itemEl = $(item.elm);
+ const values = item._values;
+ const a = itemEl.find("a");
+ const pin = itemEl.find(".ui-history-pin");
+ const tagsEl = itemEl.find(".tags");
//parse link to element a
- a.attr('href', serverurl + '/' + values.id);
+ a.attr('href', `${serverurl}/${values.id}`);
//parse pinned
if (values.pinned) {
pin.addClass('active');
@@ -187,12 +188,12 @@ historyList.on('updated', function (e) {
pin.removeClass('active');
}
//parse tags
- var tags = values.tags;
+ const tags = values.tags;
if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
- var labels = [];
- for (var j = 0; j < tags.length; j++) {
+ const labels = [];
+ for (let j = 0; j < tags.length; j++) {
//push into the item label
- labels.push("
" + tags[j] + "");
+ labels.push(`
${tags[j]}`);
}
tagsEl.html(labels.join(' '));
}
@@ -206,21 +207,21 @@ historyList.on('updated', function (e) {
function historyCloseClick(e) {
e.preventDefault();
- var id = $(this).closest("a").siblings("span").html();
- var value = historyList.get('id', id)[0]._values;
+ const id = $(this).closest("a").siblings("span").html();
+ const value = historyList.get('id', id)[0]._values;
$('.ui-delete-modal-msg').text('Do you really want to delete below history?');
- $('.ui-delete-modal-item').html('
' + value.text + '
' + value.time);
+ $('.ui-delete-modal-item').html(`
${value.text}
${value.time}`);
clearHistory = false;
deleteId = id;
}
function historyPinClick(e) {
e.preventDefault();
- var $this = $(this);
- var id = $this.closest("a").siblings("span").html();
- var item = historyList.get('id', id)[0];
- var values = item._values;
- var pinned = values.pinned;
+ const $this = $(this);
+ const id = $this.closest("a").siblings("span").html();
+ const item = historyList.get('id', id)[0];
+ const values = item._values;
+ let pinned = values.pinned;
if (!values.pinned) {
pinned = true;
item._values.pinned = true;
@@ -228,10 +229,10 @@ function historyPinClick(e) {
pinned = false;
item._values.pinned = false;
}
- checkIfAuth(function () {
+ checkIfAuth(() => {
postHistoryToServer(id, {
- pinned: pinned
- }, function (err, result) {
+ pinned
+ }, (err, result) => {
if (!err) {
if (pinned)
$this.addClass('active');
@@ -239,9 +240,9 @@ function historyPinClick(e) {
$this.removeClass('active');
}
});
- }, function () {
- getHistory(function (notehistory) {
- for(var i = 0; i < notehistory.length; i++) {
+ }, () => {
+ getHistory(notehistory => {
+ for(let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id == id) {
notehistory[i].pinned = pinned;
break;
@@ -260,10 +261,10 @@ function historyPinClick(e) {
setInterval(updateItemFromNow, 60000);
function updateItemFromNow() {
- var items = $('.item').toArray();
- for (var i = 0; i < items.length; i++) {
- var item = $(items[i]);
- var timestamp = parseInt(item.find('.timestamp').text());
+ const items = $('.item').toArray();
+ for (let i = 0; i < items.length; i++) {
+ const item = $(items[i]);
+ const timestamp = parseInt(item.find('.timestamp').text());
item.find('.fromNow').text(moment(timestamp).fromNow());
}
}
@@ -272,8 +273,8 @@ var clearHistory = false;
var deleteId = null;
function deleteHistory() {
- checkIfAuth(function () {
- deleteServerHistory(deleteId, function (err, result) {
+ checkIfAuth(() => {
+ deleteServerHistory(deleteId, (err, result) => {
if (!err) {
if (clearHistory) {
historyList.clear();
@@ -287,7 +288,7 @@ function deleteHistory() {
deleteId = null;
clearHistory = false;
});
- }, function () {
+ }, () => {
if (clearHistory) {
saveHistory([]);
historyList.clear();
@@ -295,8 +296,8 @@ function deleteHistory() {
deleteId = null;
} else {
if (!deleteId) return;
- getHistory(function (notehistory) {
- var newnotehistory = removeHistory(deleteId, notehistory);
+ getHistory(notehistory => {
+ const newnotehistory = removeHistory(deleteId, notehistory);
saveHistory(newnotehistory);
historyList.remove('id', deleteId);
checkHistoryList();
@@ -308,36 +309,36 @@ function deleteHistory() {
});
}
-$(".ui-delete-modal-confirm").click(function () {
+$(".ui-delete-modal-confirm").click(() => {
deleteHistory();
});
-$(".ui-import-from-browser").click(function () {
- saveStorageHistoryToServer(function () {
+$(".ui-import-from-browser").click(() => {
+ saveStorageHistoryToServer(() => {
parseStorageToHistory(historyList, parseHistoryCallback);
});
});
-$(".ui-save-history").click(function () {
- getHistory(function (data) {
- var history = JSON.stringify(data);
- var blob = new Blob([history], {
+$(".ui-save-history").click(() => {
+ getHistory(data => {
+ const history = JSON.stringify(data);
+ const blob = new Blob([history], {
type: "application/json;charset=utf-8"
});
- saveAs(blob, 'hackmd_history_' + moment().format('YYYYMMDDHHmmss'));
+ saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`);
});
});
-$(".ui-open-history").bind("change", function (e) {
- var files = e.target.files || e.dataTransfer.files;
- var file = files[0];
- var reader = new FileReader();
- reader.onload = function () {
- var notehistory = JSON.parse(reader.result);
+$(".ui-open-history").bind("change", e => {
+ const files = e.target.files || e.dataTransfer.files;
+ const file = files[0];
+ const reader = new FileReader();
+ reader.onload = () => {
+ const notehistory = JSON.parse(reader.result);
//console.log(notehistory);
if (!reader.result) return;
- getHistory(function (data) {
- var mergedata = data.concat(notehistory);
+ getHistory(data => {
+ let mergedata = data.concat(notehistory);
mergedata = clearDuplicatedHistory(mergedata);
saveHistory(mergedata);
parseHistory(historyList, parseHistoryCallback);
@@ -347,18 +348,18 @@ $(".ui-open-history").bind("change", function (e) {
reader.readAsText(file);
});
-$(".ui-clear-history").click(function () {
+$(".ui-clear-history").click(() => {
$('.ui-delete-modal-msg').text('Do you really want to clear all history?');
$('.ui-delete-modal-item').html('There is no turning back.');
clearHistory = true;
deleteId = null;
});
-$(".ui-refresh-history").click(function () {
- var lastTags = $(".ui-use-tags").select2('val');
+$(".ui-refresh-history").click(() => {
+ const lastTags = $(".ui-use-tags").select2('val');
$(".ui-use-tags").select2('val', '');
historyList.filter();
- var lastKeyword = $('.search').val();
+ const lastKeyword = $('.search').val();
$('.search').val('');
historyList.search();
$('#history-list').slideUp('fast');
@@ -366,7 +367,7 @@ $(".ui-refresh-history").click(function () {
resetCheckAuth();
historyList.clear();
- parseHistory(historyList, function (list, notehistory) {
+ parseHistory(historyList, (list, notehistory) => {
parseHistoryCallback(list, notehistory);
$(".ui-use-tags").select2('val', lastTags);
$(".ui-use-tags").trigger('change');
@@ -378,16 +379,16 @@ $(".ui-refresh-history").click(function () {
});
});
-$(".ui-logout").click(function () {
+$(".ui-logout").click(() => {
clearLoginState();
- location.href = serverurl + '/logout';
+ location.href = `${serverurl}/logout`;
});
-var filtertags = [];
+let filtertags = [];
$(".ui-use-tags").select2({
placeholder: $(".ui-use-tags").attr('placeholder'),
multiple: true,
- data: function () {
+ data() {
return {
results: filtertags
};
@@ -397,7 +398,7 @@ $('.select2-input').css('width', 'inherit');
buildTagsFilter([]);
function buildTagsFilter(tags) {
- for (var i = 0; i < tags.length; i++)
+ for (let i = 0; i < tags.length; i++)
tags[i] = {
id: i,
text: S(tags[i]).unescapeHTML().s
@@ -405,17 +406,17 @@ function buildTagsFilter(tags) {
filtertags = tags;
}
$(".ui-use-tags").on('change', function () {
- var tags = [];
- var data = $(this).select2('data');
- for (var i = 0; i < data.length; i++)
+ const tags = [];
+ const data = $(this).select2('data');
+ for (let i = 0; i < data.length; i++)
tags.push(data[i].text);
if (tags.length > 0) {
- historyList.filter(function (item) {
- var values = item.values();
+ historyList.filter(item => {
+ const values = item.values();
if (!values.tags) return false;
- var found = false;
- for (var i = 0; i < tags.length; i++) {
- if (values.tags.indexOf(tags[i]) != -1) {
+ let found = false;
+ for (let i = 0; i < tags.length; i++) {
+ if (values.tags.includes(tags[i])) {
found = true;
break;
}
@@ -428,6 +429,6 @@ $(".ui-use-tags").on('change', function () {
checkHistoryList();
});
-$('.search').keyup(function () {
+$('.search').keyup(() => {
checkHistoryList();
});
--
cgit v1.2.3
From fce08cc164bb1ecc6b986fe6630381b630a1508c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 20:56:16 +0800
Subject: Convert history.js to es6
---
public/js/cover.js | 29 ++++----
public/js/history.js | 204 +++++++++++++++++++++++----------------------------
public/js/index.js | 13 ++--
3 files changed, 113 insertions(+), 133 deletions(-)
diff --git a/public/js/cover.js b/public/js/cover.js
index ecb385ed..677d82eb 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -11,20 +11,21 @@ import {
setloginStateChangeEvent
} from './common';
-import historyModule from './history';
-const parseStorageToHistory = historyModule.parseStorageToHistory;
-const parseHistory = historyModule.parseHistory;
-const getStorageHistory = historyModule.getStorageHistory;
-const getHistory = historyModule.getHistory;
-const saveHistory = historyModule.saveHistory;
-const removeHistory = historyModule.removeHistory;
-const postHistoryToServer = historyModule.postHistoryToServer;
-const deleteServerHistory = historyModule.deleteServerHistory;
-const parseServerToHistory = historyModule.parseServerToHistory;
-const saveStorageHistoryToServer = historyModule.saveStorageHistoryToServer;
-const clearDuplicatedHistory = historyModule.clearDuplicatedHistory;
-
-import {saveAs} from 'file-saver';
+import {
+ clearDuplicatedHistory,
+ deleteServerHistory,
+ getHistory,
+ getStorageHistory,
+ parseHistory,
+ parseServerToHistory,
+ parseStorageToHistory,
+ postHistoryToServer,
+ removeHistory,
+ saveHistory,
+ saveStorageHistoryToServer
+} from './history';
+
+import { saveAs } from 'file-saver';
import List from 'list.js';
import S from 'string';
diff --git a/public/js/history.js b/public/js/history.js
index 6972f24c..f1201683 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,10 +1,9 @@
-var store = require('store');
-var S = require('string');
-
-var common = require('./common');
-var checkIfAuth = common.checkIfAuth;
-var urlpath = common.urlpath;
-var getLoginState = common.getLoginState;
+import store from 'store';
+import S from 'string';
+import {
+ checkIfAuth,
+ urlpath
+} from './common';
window.migrateHistoryFromTempCallback = null;
@@ -12,22 +11,22 @@ migrateHistoryFromTemp();
function migrateHistoryFromTemp() {
if (url('#tempid')) {
- $.get(serverurl + '/temp', {
+ $.get(`${serverurl}/temp`, {
tempid: url('#tempid')
})
- .done(function (data) {
+ .done(data => {
if (data && data.temp) {
- getStorageHistory(function (olddata) {
+ getStorageHistory(olddata => {
if (!olddata || olddata.length == 0) {
saveHistoryToStorage(JSON.parse(data.temp));
}
});
}
})
- .always(function () {
- var hash = location.hash.split('#')[1];
+ .always(() => {
+ let hash = location.hash.split('#')[1];
hash = hash.split('&');
- for (var i = 0; i < hash.length; i++)
+ for (let i = 0; i < hash.length; i++)
if (hash[i].indexOf('tempid') == 0) {
hash.splice(i, 1);
i--;
@@ -40,12 +39,12 @@ function migrateHistoryFromTemp() {
}
}
-function saveHistory(notehistory) {
+export function saveHistory(notehistory) {
checkIfAuth(
- function () {
+ () => {
saveHistoryToServer(notehistory);
},
- function () {
+ () => {
saveHistoryToStorage(notehistory);
}
);
@@ -65,7 +64,7 @@ function saveHistoryToCookie(notehistory) {
}
function saveHistoryToServer(notehistory) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: JSON.stringify(notehistory)
});
}
@@ -75,37 +74,37 @@ function saveCookieHistoryToStorage(callback) {
callback();
}
-function saveStorageHistoryToServer(callback) {
- var data = store.get('notehistory');
+export function saveStorageHistoryToServer(callback) {
+ const data = store.get('notehistory');
if (data) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: data
})
- .done(function (data) {
+ .done(data => {
callback(data);
});
}
}
function saveCookieHistoryToServer(callback) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: Cookies.get('notehistory')
})
- .done(function (data) {
+ .done(data => {
callback(data);
});
}
-function clearDuplicatedHistory(notehistory) {
- var newnotehistory = [];
- for (var i = 0; i < notehistory.length; i++) {
- var found = false;
- for (var j = 0; j < newnotehistory.length; j++) {
- var id = notehistory[i].id.replace(/\=+$/, '');
- var newId = newnotehistory[j].id.replace(/\=+$/, '');
+export function clearDuplicatedHistory(notehistory) {
+ const newnotehistory = [];
+ for (let i = 0; i < notehistory.length; i++) {
+ let found = false;
+ for (let j = 0; j < newnotehistory.length; j++) {
+ const id = notehistory[i].id.replace(/\=+$/, '');
+ const newId = newnotehistory[j].id.replace(/\=+$/, '');
if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) {
- 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'));
+ const time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ const 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];
}
@@ -123,42 +122,42 @@ function addHistory(id, text, time, tags, pinned, notehistory) {
// only add when note id exists
if (id) {
notehistory.push({
- id: id,
- text: text,
- time: time,
- tags: tags,
- pinned: pinned
+ id,
+ text,
+ time,
+ tags,
+ pinned
});
}
return notehistory;
}
-function removeHistory(id, notehistory) {
- for (var i = 0; i < notehistory.length; i++) {
+export function removeHistory(id, notehistory) {
+ for (let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id == id) {
notehistory.splice(i, 1);
- i--;
- }
+ i -= 1;
+ }
}
return notehistory;
}
//used for inner
-function writeHistory(title, tags) {
+export function writeHistory(title, tags) {
checkIfAuth(
- function () {
+ () => {
// no need to do this anymore, this will count from server-side
// writeHistoryToServer(title, tags);
},
- function () {
+ () => {
writeHistoryToStorage(title, tags);
}
);
}
function writeHistoryToServer(title, tags) {
- $.get(serverurl + '/history')
- .done(function (data) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
try {
if (data.history) {
var notehistory = data.history;
@@ -171,10 +170,10 @@ function writeHistoryToServer(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToServer(newnotehistory);
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
@@ -188,13 +187,13 @@ function writeHistoryToCookie(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToCookie(newnotehistory);
}
function writeHistoryToStorage(title, tags) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -204,7 +203,7 @@ function writeHistoryToStorage(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToStorage(newnotehistory);
} else {
writeHistoryToCookie(title, tags);
@@ -212,32 +211,30 @@ function writeHistoryToStorage(title, tags) {
}
if (!Array.isArray) {
- Array.isArray = function(arg) {
- return Object.prototype.toString.call(arg) === '[object Array]';
- };
+ Array.isArray = arg => Object.prototype.toString.call(arg) === '[object Array]';
}
function renderHistory(title, tags) {
//console.debug(tags);
- var id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
+ const id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
return {
- id: id,
+ id,
text: title,
time: moment().valueOf(),
- tags: tags
+ tags
};
}
function generateHistory(title, tags, notehistory) {
- var info = renderHistory(title, tags);
- //keep any pinned data
- var pinned = false;
- for (var i = 0; i < notehistory.length; i++) {
- if (notehistory[i].id == info.id && notehistory[i].pinned) {
- pinned = true;
- break;
- }
- }
+ const info = renderHistory(title, tags);
+ //keep any pinned data
+ let pinned = false;
+ for (let i = 0; i < notehistory.length; i++) {
+ if (notehistory[i].id == info.id && notehistory[i].pinned) {
+ pinned = true;
+ break;
+ }
+ }
notehistory = removeHistory(info.id, notehistory);
notehistory = addHistory(info.id, info.text, info.time, info.tags, pinned, notehistory);
notehistory = clearDuplicatedHistory(notehistory);
@@ -245,25 +242,25 @@ function generateHistory(title, tags, notehistory) {
}
//used for outer
-function getHistory(callback) {
+export function getHistory(callback) {
checkIfAuth(
- function () {
+ () => {
getServerHistory(callback);
},
- function () {
+ () => {
getStorageHistory(callback);
}
);
}
function getServerHistory(callback) {
- $.get(serverurl + '/history')
- .done(function (data) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
if (data.history) {
callback(data.history);
}
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
@@ -272,9 +269,9 @@ function getCookieHistory(callback) {
callback(Cookies.getJSON('notehistory'));
}
-function getStorageHistory(callback) {
+export function getStorageHistory(callback) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -286,37 +283,37 @@ function getStorageHistory(callback) {
}
}
-function parseHistory(list, callback) {
+export function parseHistory(list, callback) {
checkIfAuth(
- function () {
+ () => {
parseServerToHistory(list, callback);
},
- function () {
+ () => {
parseStorageToHistory(list, callback);
}
);
}
-function parseServerToHistory(list, callback) {
- $.get(serverurl + '/history')
- .done(function (data) {
+export function parseServerToHistory(list, callback) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
if (data.history) {
parseToHistory(list, data.history, callback);
}
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
function parseCookieToHistory(list, callback) {
- var notehistory = Cookies.getJSON('notehistory');
+ const notehistory = Cookies.getJSON('notehistory');
parseToHistory(list, notehistory, callback);
}
-function parseStorageToHistory(list, callback) {
+export function parseStorageToHistory(list, callback) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -332,9 +329,9 @@ function parseToHistory(list, notehistory, callback) {
if (!callback) return;
else if (!list || !notehistory) callback(list, notehistory);
else if (notehistory && notehistory.length > 0) {
- for (var i = 0; i < notehistory.length; i++) {
+ for (let i = 0; i < notehistory.length; i++) {
//parse time to timestamp and fromNow
- var timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ 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');
@@ -349,42 +346,23 @@ 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) {
+export function postHistoryToServer(noteId, data, callback) {
+ $.post(`${serverurl}/history/${noteId}`, data)
+ .done(result => callback(null, result))
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
return callback(error, null);
});
}
-function deleteServerHistory(noteId, callback) {
+export function deleteServerHistory(noteId, callback) {
$.ajax({
- url: serverurl + '/history' + (noteId ? '/' + noteId : ""),
+ url: `${serverurl}/history${noteId ? '/' + noteId : ""}`,
type: 'DELETE'
})
- .done(function (result) {
- return callback(null, result);
- })
- .fail(function (xhr, status, error) {
+ .done(result => callback(null, result))
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
return callback(error, null);
});
}
-
-module.exports = {
- writeHistory: writeHistory,
- parseHistory: parseHistory,
- getStorageHistory: getStorageHistory,
- getHistory: getHistory,
- saveHistory: saveHistory,
- removeHistory: removeHistory,
- parseStorageToHistory: parseStorageToHistory,
- postHistoryToServer: postHistoryToServer,
- deleteServerHistory: deleteServerHistory,
- parseServerToHistory: parseServerToHistory,
- saveStorageHistoryToServer: saveStorageHistoryToServer,
- clearDuplicatedHistory: clearDuplicatedHistory
-}
diff --git a/public/js/index.js b/public/js/index.js
index 7406c9a2..660f73e4 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -59,12 +59,13 @@ import {
syncScrollToView
} from './syncscroll';
-var historyModule = require('./history');
-var writeHistory = historyModule.writeHistory;
-var deleteServerHistory = historyModule.deleteServerHistory;
-var getHistory = historyModule.getHistory;
-var saveHistory = historyModule.saveHistory;
-var removeHistory = historyModule.removeHistory;
+import {
+ writeHistory,
+ deleteServerHistory,
+ getHistory,
+ saveHistory,
+ removeHistory
+} from './history';
var renderer = require('./render');
var preventXSS = renderer.preventXSS;
--
cgit v1.2.3
From c2a8911b9c7872ea0d085020aa17e82162130f3d Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 22:46:38 +0800
Subject: Move config variable to lib/config
---
public/js/common.js | 25 +------------------------
public/js/lib/config/index.js | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 24 deletions(-)
create mode 100644 public/js/lib/config/index.js
diff --git a/public/js/common.js b/public/js/common.js
index 6d54b450..9a60122b 100644
--- a/public/js/common.js
+++ b/public/js/common.js
@@ -1,21 +1,4 @@
-// import config from './config';
-
-import {
- domain, // domain name
- urlpath, // sub url path, like: www.example.com/
- debug,
- GOOGLE_API_KEY,
- GOOGLE_CLIENT_ID,
- DROPBOX_APP_KEY
-} from './config';
-
-//common
-export const port = window.location.port;
-window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
-export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
-export const noteurl = `${serverurl}/${noteid}`;
-
-export const version = '0.5.0';
+import { serverurl } from './lib/config';
let checkAuth = false;
let profile = null;
@@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) {
}
export default {
- domain,
- urlpath,
- debug,
- GOOGLE_API_KEY,
- GOOGLE_CLIENT_ID,
- DROPBOX_APP_KEY,
checkAuth,
profile,
lastLoginState,
diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js
new file mode 100644
index 00000000..bffbadd9
--- /dev/null
+++ b/public/js/lib/config/index.js
@@ -0,0 +1,19 @@
+import configJson from '../../../../config.json'; // root path json config
+
+const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
+
+export const GOOGLE_API_KEY = config.google && config.google.apiKey;
+export const GOOGLE_CLIENT_ID = config.google && config.google.clientID
+export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey
+
+export const domain = config.domain;
+export const urlpath = config.urlpath;
+export const debug = config.debug;
+
+export const port = window.location.port;
+export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
+window.serverurl = serverurl;
+export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
+export const noteurl = `${serverurl}/${noteid}`;
+
+export const version = '0.5.0';
--
cgit v1.2.3
From 0fca629c34b83617b2d72e42aa0edb66fd2e71f6 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 22:51:44 +0800
Subject: Rename common.js to login.js
---
public/js/common.js | 92 -------------------------------------------
public/js/cover.js | 2 +-
public/js/extra.js | 2 +-
public/js/history.js | 8 +++-
public/js/index.js | 7 +++-
public/js/lib/common/login.js | 92 +++++++++++++++++++++++++++++++++++++++++++
6 files changed, 105 insertions(+), 98 deletions(-)
delete mode 100644 public/js/common.js
create mode 100644 public/js/lib/common/login.js
diff --git a/public/js/common.js b/public/js/common.js
deleted file mode 100644
index 9a60122b..00000000
--- a/public/js/common.js
+++ /dev/null
@@ -1,92 +0,0 @@
-import { serverurl } from './lib/config';
-
-let checkAuth = false;
-let profile = null;
-let lastLoginState = getLoginState();
-let lastUserId = getUserId();
-let loginStateChangeEvent = null;
-
-export function setloginStateChangeEvent(func) {
- loginStateChangeEvent = func;
-}
-
-export function resetCheckAuth() {
- checkAuth = false;
-}
-
-export function setLoginState(bool, id) {
- Cookies.set('loginstate', bool, {
- expires: 365
- });
- if (id) {
- Cookies.set('userid', id, {
- expires: 365
- });
- } else {
- Cookies.remove('userid');
- }
- lastLoginState = bool;
- lastUserId = id;
- checkLoginStateChanged();
-}
-
-export function checkLoginStateChanged() {
- if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
- if(loginStateChangeEvent) {
- loginStateChangeEvent();
- }
- return true;
- } else {
- return false;
- }
-}
-
-export function getLoginState() {
- const state = Cookies.get('loginstate');
- return state === "true" || state === true;
-}
-
-export function getUserId() {
- return Cookies.get('userid');
-}
-
-export function clearLoginState() {
- Cookies.remove('loginstate');
-}
-
-export function checkIfAuth(yesCallback, noCallback) {
- const cookieLoginState = getLoginState();
- if (checkLoginStateChanged())
- checkAuth = false;
- if (!checkAuth || typeof cookieLoginState == 'undefined') {
- $.get(`${serverurl}/me`)
- .done(data => {
- if (data && data.status == 'ok') {
- profile = data;
- yesCallback(profile);
- setLoginState(true, data.id);
- } else {
- noCallback();
- setLoginState(false);
- }
- })
- .fail(() => {
- noCallback();
- })
- .always(() => {
- checkAuth = true;
- });
- } else if (cookieLoginState) {
- yesCallback(profile);
- } else {
- noCallback();
- }
-}
-
-export default {
- checkAuth,
- profile,
- lastLoginState,
- lastUserId,
- loginStateChangeEvent
-};
diff --git a/public/js/cover.js b/public/js/cover.js
index 677d82eb..bc04923b 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -9,7 +9,7 @@ import {
getLoginState,
resetCheckAuth,
setloginStateChangeEvent
-} from './common';
+} from './lib/common/login';
import {
clearDuplicatedHistory,
diff --git a/public/js/extra.js b/public/js/extra.js
index 6cfb5b0a..b651d9e6 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -11,7 +11,7 @@ import PDFObject from 'pdfobject';
import S from 'string';
import { saveAs } from 'file-saver';
-require('./common');
+require('./lib/common/login');
require('../vendor/md-toc');
var Viz = require("viz.js");
diff --git a/public/js/history.js b/public/js/history.js
index f1201683..34b2cba7 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,9 +1,13 @@
import store from 'store';
import S from 'string';
+
+import {
+ checkIfAuth
+} from './lib/common/login';
+
import {
- checkIfAuth,
urlpath
-} from './common';
+} from './lib/config';
window.migrateHistoryFromTempCallback = null;
diff --git a/public/js/index.js b/public/js/index.js
index 660f73e4..3bf42ad4 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -19,7 +19,10 @@ var List = require('list.js');
import {
checkLoginStateChanged,
- setloginStateChangeEvent,
+ setloginStateChangeEvent
+} from './lib/common/login';
+
+import {
debug,
DROPBOX_APP_KEY,
GOOGLE_API_KEY,
@@ -28,7 +31,7 @@ import {
noteurl,
urlpath,
version
-} from './common';
+} from './lib/config';
import {
autoLinkify,
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
new file mode 100644
index 00000000..12cc41fc
--- /dev/null
+++ b/public/js/lib/common/login.js
@@ -0,0 +1,92 @@
+import { serverurl } from '../config';
+
+let checkAuth = false;
+let profile = null;
+let lastLoginState = getLoginState();
+let lastUserId = getUserId();
+let loginStateChangeEvent = null;
+
+export function setloginStateChangeEvent(func) {
+ loginStateChangeEvent = func;
+}
+
+export function resetCheckAuth() {
+ checkAuth = false;
+}
+
+export function setLoginState(bool, id) {
+ Cookies.set('loginstate', bool, {
+ expires: 365
+ });
+ if (id) {
+ Cookies.set('userid', id, {
+ expires: 365
+ });
+ } else {
+ Cookies.remove('userid');
+ }
+ lastLoginState = bool;
+ lastUserId = id;
+ checkLoginStateChanged();
+}
+
+export function checkLoginStateChanged() {
+ if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
+ if(loginStateChangeEvent) {
+ loginStateChangeEvent();
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+export function getLoginState() {
+ const state = Cookies.get('loginstate');
+ return state === "true" || state === true;
+}
+
+export function getUserId() {
+ return Cookies.get('userid');
+}
+
+export function clearLoginState() {
+ Cookies.remove('loginstate');
+}
+
+export function checkIfAuth(yesCallback, noCallback) {
+ const cookieLoginState = getLoginState();
+ if (checkLoginStateChanged())
+ checkAuth = false;
+ if (!checkAuth || typeof cookieLoginState == 'undefined') {
+ $.get(`${serverurl}/me`)
+ .done(data => {
+ if (data && data.status == 'ok') {
+ profile = data;
+ yesCallback(profile);
+ setLoginState(true, data.id);
+ } else {
+ noCallback();
+ setLoginState(false);
+ }
+ })
+ .fail(() => {
+ noCallback();
+ })
+ .always(() => {
+ checkAuth = true;
+ });
+ } else if (cookieLoginState) {
+ yesCallback(profile);
+ } else {
+ noCallback();
+ }
+}
+
+export default {
+ checkAuth,
+ profile,
+ lastLoginState,
+ lastUserId,
+ loginStateChangeEvent
+};
--
cgit v1.2.3
From 2408ff4ba96c929a575b34e85d5cff0a01789ca4 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 23:12:17 +0800
Subject: Add default value for config
---
public/js/lib/config/index.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js
index bffbadd9..2b73679f 100644
--- a/public/js/lib/config/index.js
+++ b/public/js/lib/config/index.js
@@ -2,13 +2,13 @@ import configJson from '../../../../config.json'; // root path json config
const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
-export const GOOGLE_API_KEY = config.google && config.google.apiKey;
-export const GOOGLE_CLIENT_ID = config.google && config.google.clientID
-export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey
+export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || '';
+export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || '';
+export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || '';
-export const domain = config.domain;
-export const urlpath = config.urlpath;
-export const debug = config.debug;
+export const domain = config.domain || ''; // domain name
+export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/
+export const debug = config.debug || false;
export const port = window.location.port;
export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
--
cgit v1.2.3
From a541569d7edbe827cae69c666079d5d1ded6790c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 23:12:27 +0800
Subject: Remove old config.js.example
---
public/js/config.js.example | 11 -----------
1 file changed, 11 deletions(-)
delete mode 100644 public/js/config.js.example
diff --git a/public/js/config.js.example b/public/js/config.js.example
deleted file mode 100644
index c5de388f..00000000
--- a/public/js/config.js.example
+++ /dev/null
@@ -1,11 +0,0 @@
-module.exports = {
- domain: '', // domain name
- urlpath: '', // sub url path, like: www.example.com/
-
- // settings
- debug: false,
-
- GOOGLE_API_KEY: '',
- GOOGLE_CLIENT_ID: '',
- DROPBOX_APP_KEY: ''
-};
--
cgit v1.2.3
From 1ed19966394b9735c348ec0116ec0e939c363ce6 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 23:37:16 +0800
Subject: Remove config.js from setup files
---
.gitignore | 1 -
bin/heroku | 2 --
bin/setup | 4 ----
3 files changed, 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index f48b3c6f..ab83c145 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,6 @@ backups/
# ignore config files
config.json
-public/js/config.js
.sequelizerc
# ignore webpack build
diff --git a/bin/heroku b/bin/heroku
index e8010038..1228b283 100755
--- a/bin/heroku
+++ b/bin/heroku
@@ -28,8 +28,6 @@ EOF
EOF
- cp public/js/config.js.example public/js/config.js
-
# build app
npm run build
fi
diff --git a/bin/setup b/bin/setup
index e24d4de7..6724b2d5 100755
--- a/bin/setup
+++ b/bin/setup
@@ -21,10 +21,6 @@ if [ ! -f config.json ]; then
cp config.json.example config.json
fi
-if [ ! -f publis/js/config.js ]; then
- cp public/js/config.js.example public/js/config.js
-fi
-
if [ ! -f .sequelizerc ]; then
cp .sequelizerc.example .sequelizerc
fi
--
cgit v1.2.3
From b4bed37d64d59a70db3f0373894cf6ac611c1630 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 14 Jan 2017 14:17:20 +0800
Subject: Add google apiKey & dropbox appKey to config.json
---
config.json.example | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/config.json.example b/config.json.example
index e5e3fc56..e980566f 100644
--- a/config.json.example
+++ b/config.json.example
@@ -45,11 +45,13 @@
},
"dropbox": {
"clientID": "change this",
- "clientSecret": "change this"
+ "clientSecret": "change this",
+ "appKey": "change this"
},
"google": {
"clientID": "change this",
- "clientSecret": "change this"
+ "clientSecret": "change this",
+ "apiKey": "change this"
},
"imgur": {
"clientID": "change this"
--
cgit v1.2.3
From 98c0cfc6a7dbf19a7996ff37968605ec946c97e1 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 14 Jan 2017 15:24:31 +0800
Subject: Update README
---
README.md | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index cc05872d..f6532d5e 100644
--- a/README.md
+++ b/README.md
@@ -97,19 +97,9 @@ Configuration files
There are some configs you need to change in the files below
```
-./config.json --- for server settings
-./public/js/config.js --- for client settings
+./config.json ----application settings
```
-Client settings `config.js`
----
-
-| variables | example values | description |
-| --------- | ------ | ----------- |
-| debug | `true` or `false` | set debug mode, show more logs |
-| domain | `localhost` | domain name |
-| urlpath | `hackmd` | sub url path, like: `www.example.com/` |
-
Environment variables (will overwrite other server configs)
---
@@ -148,7 +138,7 @@ Environment variables (will overwrite other server configs)
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
-Server settings `config.json`
+Application settings `config.json`
---
| variables | example values | description |
@@ -196,7 +186,7 @@ Third-party integration api key settings
| ------- | --------- | ----------- |
| facebook, twitter, github, gitlab, dropbox, google | environment variables or `config.json` | for signin |
| imgur | environment variables or `config.json` | for image upload |
-| google drive, dropbox | `public/js/config.js` | for export and import |
+| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
Third-party integration oauth callback urls
---
--
cgit v1.2.3
From 77994508e66bc9fa1bde547d83e50d92aa5e1d88 Mon Sep 17 00:00:00 2001
From: bananaappletw
Date: Sat, 14 Jan 2017 15:27:24 +0800
Subject: Update README.md for npm script
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 92557cf4..e2ab06a7 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ If you are upgrading HackMD from an older version, follow these steps:
1. Fully stop your old server first (important)
2. `git pull` or do whatever that updates the files
3. `npm install` to update dependencies
-4. Build front-end bundle by `npm run build:prod` (use `npm run build:dev` if you are in development)
+4. Build front-end bundle by `npm run build` (use `npm run dev` if you are in development)
5. Modify the file named `.sequelizerc`, change the value of the variable `url` with your db connection string
For example: `postgres://username:password@localhost:5432/hackmd`
6. Run `node_modules/.bin/sequelize db:migrate`, this step will migrate your db to the latest schema
--
cgit v1.2.3
From 04292240d6a589c537afb8e9838dcc0f062d0f2c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 14 Jan 2017 15:47:13 +0800
Subject: Minor style update
---
.eslintrc | 5 ++---
public/js/lib/common/login.js | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 53a6dcb0..bd14731c 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -16,7 +16,6 @@
],
"array-callback-return": "error",
"arrow-body-style": "error",
- "arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "off",
"block-spacing": "error",
@@ -123,7 +122,7 @@
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
- "no-extra-parens": "error",
+ "no-extra-parens": "warn",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implicit-coercion": "error",
@@ -195,7 +194,7 @@
"no-unneeded-ternary": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
- "no-use-before-define": "error",
+ "no-use-before-define": "warn",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
index 12cc41fc..f1a03c72 100644
--- a/public/js/lib/common/login.js
+++ b/public/js/lib/common/login.js
@@ -32,7 +32,7 @@ export function setLoginState(bool, id) {
export function checkLoginStateChanged() {
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
- if(loginStateChangeEvent) {
+ if (loginStateChangeEvent) {
loginStateChangeEvent();
}
return true;
--
cgit v1.2.3
From 0f833f099f61b93e76a5f32175580fc2c0b9dc1a Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 14 Jan 2017 19:05:54 +0800
Subject: Update server google/dropbox config check
---
lib/config.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/config.js b/lib/config.js
index 53497f1f..c0a7fffe 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -90,11 +90,11 @@ var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSE
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
clientID: process.env.HMD_DROPBOX_CLIENTID,
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
-} : config.dropbox || false;
+} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret) || false;
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
clientID: process.env.HMD_GOOGLE_CLIENTID,
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
-} : config.google || false;
+} : (config.google && config.google.clientID && config.google.clientSecret) || false;
var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email;
--
cgit v1.2.3
From a9a38c3d75b1cf467bb3b4484abfc09dcbcea107 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sun, 15 Jan 2017 11:58:00 +0800
Subject: Recover config change in 0f833f0
---
lib/config.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/config.js b/lib/config.js
index 84f6b3d7..3816017e 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -90,11 +90,11 @@ var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSE
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
clientID: process.env.HMD_DROPBOX_CLIENTID,
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
-} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret) || false;
+} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret && config.dropbox) || false;
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
clientID: process.env.HMD_GOOGLE_CLIENTID,
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
-} : (config.google && config.google.clientID && config.google.clientSecret) || false;
+} : (config.google && config.google.clientID && config.google.clientSecret && config.google) || false;
var ldap = config.ldap || (
process.env.HMD_LDAP_URL ||
process.env.HMD_LDAP_BINDDN ||
--
cgit v1.2.3
From 26d8942852f8d216d03138a6c3c1d350e6bc903e Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 21 Jan 2017 12:24:58 +0800
Subject: Revert experimental vue for now
---
.editorconfig | 4 ----
package.json | 3 ---
public/js/components/HelloWorld.vue | 21 ---------------------
public/js/cover.js | 8 --------
public/js/views/Cover.vue | 15 ---------------
public/views/index.ejs | 2 --
webpackBaseConfig.js | 8 +-------
7 files changed, 1 insertion(+), 60 deletions(-)
delete mode 100644 public/js/components/HelloWorld.vue
delete mode 100644 public/js/views/Cover.vue
diff --git a/.editorconfig b/.editorconfig
index b3e30251..619c178d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,10 +7,6 @@ indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
-[*.vue]
-indent_style = space
-indent_size = 2
-
[*.md]
trim_trailing_whitespace = false
diff --git a/package.json b/package.json
index e22f9e73..1ed81c98 100644
--- a/package.json
+++ b/package.json
@@ -116,8 +116,6 @@
"velocity-animate": "^1.4.0",
"visibilityjs": "^1.2.4",
"viz.js": "^1.4.1",
- "vue": "^2.1.6",
- "vue-loader": "^10.0.2",
"winston": "^2.3.0",
"xss": "^0.3.3"
},
@@ -164,7 +162,6 @@
"script-loader": "^0.7.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
- "vue-template-compiler": "^2.1.6",
"webpack": "^1.14.0"
}
}
diff --git a/public/js/components/HelloWorld.vue b/public/js/components/HelloWorld.vue
deleted file mode 100644
index d8e3007f..00000000
--- a/public/js/components/HelloWorld.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
- {{ message }}
-
-
-
-
-
diff --git a/public/js/cover.js b/public/js/cover.js
index 79b168d9..830564e8 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -29,14 +29,6 @@ import { saveAs } from 'file-saver';
import List from 'list.js';
import S from 'string';
-import Cover from './views/Cover';
-import Vue from 'vue';
-
-new Vue({
- el: '#cover-app',
- render: (h) => h(Cover)
-})
-
const options = {
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
item: '\
diff --git a/public/js/views/Cover.vue b/public/js/views/Cover.vue
deleted file mode 100644
index 767d087f..00000000
--- a/public/js/views/Cover.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
diff --git a/public/views/index.ejs b/public/views/index.ejs
index d258857c..b94daf5b 100644
--- a/public/views/index.ejs
+++ b/public/views/index.ejs
@@ -30,8 +30,6 @@