You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-02 22:49:09 +02:00
First pass at linting lib dir
This commit is contained in:
@@ -3,14 +3,14 @@ const SyncTargetRegistry = require('lib/SyncTargetRegistry');
|
||||
const ObjectUtils = require('lib/ObjectUtils');
|
||||
const { _ } = require('lib/locale.js');
|
||||
|
||||
const shared = {}
|
||||
const shared = {};
|
||||
|
||||
shared.init = function(comp) {
|
||||
if (!comp.state) comp.state = {};
|
||||
comp.state.checkSyncConfigResult = null;
|
||||
comp.state.settings = {};
|
||||
comp.state.changedSettingKeys = [];
|
||||
}
|
||||
};
|
||||
|
||||
shared.checkSyncConfig = async function(comp, settings) {
|
||||
const syncTargetId = settings['sync.target'];
|
||||
@@ -19,7 +19,7 @@ shared.checkSyncConfig = async function(comp, settings) {
|
||||
comp.setState({ checkSyncConfigResult: 'checking' });
|
||||
const result = await SyncTargetClass.checkConfig(ObjectUtils.convertValuesToFunctions(options));
|
||||
comp.setState({ checkSyncConfigResult: result });
|
||||
}
|
||||
};
|
||||
|
||||
shared.checkSyncConfigMessages = function(comp) {
|
||||
const result = comp.state.checkSyncConfigResult;
|
||||
@@ -35,7 +35,7 @@ shared.checkSyncConfigMessages = function(comp) {
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
shared.updateSettingValue = function(comp, key, value) {
|
||||
const settings = Object.assign({}, comp.state.settings);
|
||||
@@ -47,18 +47,18 @@ shared.updateSettingValue = function(comp, key, value) {
|
||||
settings: settings,
|
||||
changedSettingKeys: changedSettingKeys,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
shared.saveSettings = function(comp) {
|
||||
for (let key in comp.state.settings) {
|
||||
if (!comp.state.settings.hasOwnProperty(key)) continue;
|
||||
if (comp.state.changedSettingKeys.indexOf(key) < 0) continue;
|
||||
console.info("Saving", key, comp.state.settings[key]);
|
||||
console.info('Saving', key, comp.state.settings[key]);
|
||||
Setting.setValue(key, comp.state.settings[key]);
|
||||
}
|
||||
|
||||
comp.setState({ changedSettingKeys: [] });
|
||||
}
|
||||
};
|
||||
|
||||
shared.settingsToComponents = function(comp, device, settings) {
|
||||
const keys = Setting.keys(true, device);
|
||||
@@ -76,8 +76,8 @@ shared.settingsToComponents = function(comp, device, settings) {
|
||||
settingComps.push(settingComp);
|
||||
}
|
||||
|
||||
return settingComps
|
||||
}
|
||||
return settingComps;
|
||||
};
|
||||
|
||||
shared.settingsToComponents2 = function(comp, device, settings) {
|
||||
const keys = Setting.keys(true, device);
|
||||
@@ -103,7 +103,7 @@ shared.settingsToComponents2 = function(comp, device, settings) {
|
||||
sectionComps.push(sectionComp);
|
||||
}
|
||||
|
||||
return sectionComps
|
||||
}
|
||||
return sectionComps;
|
||||
};
|
||||
|
||||
module.exports = shared;
|
||||
module.exports = shared;
|
||||
|
||||
@@ -5,7 +5,6 @@ const { _ } = require('lib/locale.js');
|
||||
const Setting = require('lib/models/Setting');
|
||||
|
||||
class Shared {
|
||||
|
||||
constructor(comp, showInfoMessageBox, showErrorMessageBox) {
|
||||
this.comp_ = comp;
|
||||
|
||||
@@ -20,13 +19,13 @@ class Shared {
|
||||
this.loginUrl_click = () => {
|
||||
if (!this.comp_.state.loginUrl) return;
|
||||
shim.openUrl(this.comp_.state.loginUrl);
|
||||
}
|
||||
};
|
||||
|
||||
this.authCodeInput_change = (event) => {
|
||||
this.authCodeInput_change = event => {
|
||||
this.comp_.setState({
|
||||
authCode: typeof event === 'object' ? event.target.value : event
|
||||
authCode: typeof event === 'object' ? event.target.value : event,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.submit_click = async () => {
|
||||
this.comp_.setState({ checkingAuthToken: true });
|
||||
@@ -45,7 +44,7 @@ class Shared {
|
||||
} finally {
|
||||
this.comp_.setState({ checkingAuthToken: false });
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
syncTargetId() {
|
||||
@@ -67,7 +66,6 @@ class Shared {
|
||||
loginUrl: api.loginUrl(),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Shared;
|
||||
module.exports = Shared;
|
||||
|
||||
@@ -18,15 +18,18 @@ shared.constructor = function(comp) {
|
||||
comp.isMounted_ = false;
|
||||
|
||||
comp.refreshStatsIID_ = null;
|
||||
}
|
||||
};
|
||||
|
||||
shared.initState = function(comp, props) {
|
||||
comp.setState({
|
||||
masterKeys: props.masterKeys,
|
||||
passwords: props.passwords ? props.passwords : {},
|
||||
}, () => {
|
||||
comp.checkPasswords();
|
||||
});
|
||||
comp.setState(
|
||||
{
|
||||
masterKeys: props.masterKeys,
|
||||
passwords: props.passwords ? props.passwords : {},
|
||||
},
|
||||
() => {
|
||||
comp.checkPasswords();
|
||||
}
|
||||
);
|
||||
|
||||
comp.refreshStats();
|
||||
|
||||
@@ -43,12 +46,12 @@ shared.initState = function(comp, props) {
|
||||
}
|
||||
comp.refreshStats();
|
||||
}, 3000);
|
||||
}
|
||||
};
|
||||
|
||||
shared.refreshStats = async function(comp) {
|
||||
const stats = await BaseItem.encryptedItemsStats();
|
||||
comp.setState({ stats: stats });
|
||||
}
|
||||
};
|
||||
|
||||
shared.checkPasswords = async function(comp) {
|
||||
const passwordChecks = Object.assign({}, comp.state.passwordChecks);
|
||||
@@ -59,14 +62,14 @@ shared.checkPasswords = async function(comp) {
|
||||
passwordChecks[mk.id] = ok;
|
||||
}
|
||||
comp.setState({ passwordChecks: passwordChecks });
|
||||
}
|
||||
};
|
||||
|
||||
shared.decryptedStatText = function(comp) {
|
||||
const stats = comp.state.stats;
|
||||
const doneCount = stats.encrypted !== null ? (stats.total - stats.encrypted) : '-';
|
||||
const doneCount = stats.encrypted !== null ? stats.total - stats.encrypted : '-';
|
||||
const totalCount = stats.total !== null ? stats.total : '-';
|
||||
return _('Decrypted items: %s / %s', doneCount, totalCount);
|
||||
}
|
||||
};
|
||||
|
||||
shared.onSavePasswordClick = function(comp, mk) {
|
||||
const password = comp.state.passwords[mk.id];
|
||||
@@ -77,12 +80,12 @@ shared.onSavePasswordClick = function(comp, mk) {
|
||||
}
|
||||
|
||||
comp.checkPasswords();
|
||||
}
|
||||
};
|
||||
|
||||
shared.onPasswordChange = function(comp, mk, password) {
|
||||
const passwords = comp.state.passwords;
|
||||
passwords[mk.id] = password;
|
||||
comp.setState({ passwords: passwords });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = shared;
|
||||
module.exports = shared;
|
||||
|
||||
@@ -17,12 +17,16 @@ const saveNoteMutex_ = new Mutex();
|
||||
shared.noteExists = async function(noteId) {
|
||||
const existingNote = await Note.load(noteId);
|
||||
return !!existingNote;
|
||||
}
|
||||
};
|
||||
|
||||
shared.saveNoteButton_press = async function(comp, folderId = null, options = null) {
|
||||
options = Object.assign({}, {
|
||||
autoTitle: true,
|
||||
}, options);
|
||||
options = Object.assign(
|
||||
{},
|
||||
{
|
||||
autoTitle: true,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
const releaseMutex = await saveNoteMutex_.acquire();
|
||||
|
||||
@@ -55,7 +59,7 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
|
||||
if (saveOptions.fields && saveOptions.fields.indexOf('title') < 0) saveOptions.fields.push('title');
|
||||
}
|
||||
|
||||
const savedNote = ('fields' in saveOptions) && !saveOptions.fields.length ? Object.assign({}, note) : await Note.save(note, saveOptions);
|
||||
const savedNote = 'fields' in saveOptions && !saveOptions.fields.length ? Object.assign({}, note) : await Note.save(note, saveOptions);
|
||||
|
||||
const stateNote = comp.state.note;
|
||||
|
||||
@@ -91,7 +95,7 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
|
||||
// await shared.refreshAttachedResources(comp, newState.note.body);
|
||||
|
||||
if (isNew) {
|
||||
Note.updateGeolocation(note.id).then((geoNote) => {
|
||||
Note.updateGeolocation(note.id).then(geoNote => {
|
||||
const stateNote = comp.state.note;
|
||||
if (!stateNote || !geoNote) return;
|
||||
if (stateNote.id !== geoNote.id) return; // Another note has been loaded while geoloc was being retrieved
|
||||
@@ -103,7 +107,7 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
|
||||
longitude: geoNote.longitude,
|
||||
latitude: geoNote.latitude,
|
||||
altitude: geoNote.altitude,
|
||||
}
|
||||
};
|
||||
|
||||
const modNote = Object.assign({}, stateNote, geoInfo);
|
||||
const modLastSavedNote = Object.assign({}, comp.state.lastSavedNote, geoInfo);
|
||||
@@ -122,7 +126,7 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
|
||||
}
|
||||
|
||||
releaseMutex();
|
||||
}
|
||||
};
|
||||
|
||||
shared.saveOneProperty = async function(comp, name, value) {
|
||||
let note = Object.assign({}, comp.state.note);
|
||||
@@ -145,25 +149,25 @@ shared.saveOneProperty = async function(comp, name, value) {
|
||||
});
|
||||
} else {
|
||||
note[name] = value;
|
||||
comp.setState({ note: note });
|
||||
comp.setState({ note: note });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shared.noteComponent_change = function(comp, propName, propValue) {
|
||||
let newState = {}
|
||||
let newState = {};
|
||||
|
||||
let note = Object.assign({}, comp.state.note);
|
||||
note[propName] = propValue;
|
||||
newState.note = note;
|
||||
|
||||
comp.setState(newState);
|
||||
}
|
||||
};
|
||||
|
||||
let resourceCache_ = {};
|
||||
|
||||
shared.clearResourceCache = function() {
|
||||
resourceCache_ = {};
|
||||
}
|
||||
};
|
||||
|
||||
shared.attachedResources = async function(noteBody) {
|
||||
if (!noteBody) return {};
|
||||
@@ -172,7 +176,7 @@ shared.attachedResources = async function(noteBody) {
|
||||
const output = {};
|
||||
for (let i = 0; i < resourceIds.length; i++) {
|
||||
const id = resourceIds[i];
|
||||
|
||||
|
||||
if (resourceCache_[id]) {
|
||||
output[id] = resourceCache_[id];
|
||||
} else {
|
||||
@@ -190,14 +194,14 @@ shared.attachedResources = async function(noteBody) {
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
shared.isModified = function(comp) {
|
||||
if (!comp.state.note || !comp.state.lastSavedNote) return false;
|
||||
let diff = BaseModel.diffObjects(comp.state.lastSavedNote, comp.state.note);
|
||||
delete diff.type_;
|
||||
return !!Object.getOwnPropertyNames(diff).length;
|
||||
}
|
||||
};
|
||||
|
||||
shared.initState = async function(comp) {
|
||||
let note = null;
|
||||
@@ -226,13 +230,13 @@ shared.initState = async function(comp) {
|
||||
}
|
||||
|
||||
comp.lastLoadedNoteId_ = note ? note.id : null;
|
||||
}
|
||||
};
|
||||
|
||||
shared.toggleIsTodo_onPress = function(comp) {
|
||||
let newNote = Note.toggleIsTodo(comp.state.note);
|
||||
let newState = { note: newNote };
|
||||
comp.setState(newState);
|
||||
}
|
||||
};
|
||||
|
||||
shared.toggleCheckbox = function(ipcMessage, noteBody) {
|
||||
let newBody = noteBody.split('\n');
|
||||
@@ -264,24 +268,24 @@ shared.toggleCheckbox = function(ipcMessage, noteBody) {
|
||||
|
||||
if (!isCrossLine) {
|
||||
line = line.replace(/- \[ \] /, '- [x] ');
|
||||
} else {
|
||||
} else {
|
||||
line = line.replace(/- \[x\] /i, '- [ ] ');
|
||||
}
|
||||
|
||||
newBody[lineIndex] = line;
|
||||
return newBody.join('\n')
|
||||
}
|
||||
return newBody.join('\n');
|
||||
};
|
||||
|
||||
shared.installResourceHandling = function(refreshResourceHandler) {
|
||||
ResourceFetcher.instance().on('downloadComplete', refreshResourceHandler);
|
||||
ResourceFetcher.instance().on('downloadStarted', refreshResourceHandler);
|
||||
DecryptionWorker.instance().on('resourceDecrypted', refreshResourceHandler);
|
||||
}
|
||||
};
|
||||
|
||||
shared.uninstallResourceHandling = function(refreshResourceHandler) {
|
||||
ResourceFetcher.instance().off('downloadComplete', refreshResourceHandler);
|
||||
ResourceFetcher.instance().off('downloadStarted', refreshResourceHandler);
|
||||
DecryptionWorker.instance().off('resourceDecrypted', refreshResourceHandler);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = shared;
|
||||
|
||||
@@ -30,6 +30,6 @@ const reduxSharedMiddleware = async function(store, next, action) {
|
||||
items: await Tag.allWithNotes(),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = reduxSharedMiddleware;
|
||||
module.exports = reduxSharedMiddleware;
|
||||
|
||||
@@ -49,11 +49,13 @@ function renderFoldersRecursive_(props, renderItem, items, parentId, depth, orde
|
||||
|
||||
shared.renderFolders = function(props, renderItem) {
|
||||
return renderFoldersRecursive_(props, renderItem, [], '', 0, []);
|
||||
}
|
||||
};
|
||||
|
||||
shared.renderTags = function(props, renderItem) {
|
||||
let tags = props.tags.slice();
|
||||
tags.sort((a, b) => { return a.title < b.title ? -1 : +1; });
|
||||
tags.sort((a, b) => {
|
||||
return a.title < b.title ? -1 : +1;
|
||||
});
|
||||
let tagItems = [];
|
||||
const order = [];
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
@@ -65,7 +67,7 @@ shared.renderTags = function(props, renderItem) {
|
||||
items: tagItems,
|
||||
order: order,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// shared.renderSearches = function(props, renderItem) {
|
||||
// let searches = props.searches.slice();
|
||||
@@ -88,7 +90,7 @@ shared.synchronize_press = async function(comp) {
|
||||
|
||||
const action = comp.props.syncStarted ? 'cancel' : 'start';
|
||||
|
||||
if (!await reg.syncTarget().isAuthenticated()) {
|
||||
if (!(await reg.syncTarget().isAuthenticated())) {
|
||||
if (reg.syncTarget().authRouteName()) {
|
||||
comp.props.dispatch({
|
||||
type: 'NAV_GO',
|
||||
@@ -117,6 +119,6 @@ shared.synchronize_press = async function(comp) {
|
||||
reg.scheduleSync(0);
|
||||
return 'sync';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = shared;
|
||||
module.exports = shared;
|
||||
|
||||
Reference in New Issue
Block a user