1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-20 11:28:40 +02:00

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-11-05 23:55:01 +00:00
let shared = {};
shared.renderFolders = function(props, renderItem) {
let items = [];
for (let i = 0; i < props.folders.length; i++) {
let folder = props.folders[i];
2018-03-09 17:49:35 +00:00
items.push(renderItem(folder, props.selectedFolderId == folder.id && props.notesParentType == "Folder"));
2017-11-05 23:55:01 +00:00
}
return items;
2018-03-09 17:49:35 +00:00
};
2017-11-05 23:55:01 +00:00
shared.renderTags = function(props, renderItem) {
let tags = props.tags.slice();
2018-03-09 17:49:35 +00:00
tags.sort((a, b) => {
return a.title < b.title ? -1 : +1;
});
2017-11-05 23:55:01 +00:00
let tagItems = [];
for (let i = 0; i < tags.length; i++) {
const tag = tags[i];
2018-03-09 17:49:35 +00:00
tagItems.push(renderItem(tag, props.selectedTagId == tag.id && props.notesParentType == "Tag"));
2017-11-05 23:55:01 +00:00
}
return tagItems;
2018-03-09 17:49:35 +00:00
};
2017-11-05 23:55:01 +00:00
2017-11-17 18:57:27 +00:00
shared.renderSearches = function(props, renderItem) {
let searches = props.searches.slice();
let searchItems = [];
for (let i = 0; i < searches.length; i++) {
const search = searches[i];
2018-03-09 17:49:35 +00:00
searchItems.push(renderItem(search, props.selectedSearchId == search.id && props.notesParentType == "Search"));
2017-11-17 18:57:27 +00:00
}
return searchItems;
2018-03-09 17:49:35 +00:00
};
2017-11-17 18:57:27 +00:00
2017-11-06 21:11:15 +00:00
shared.synchronize_press = async function(comp) {
2018-03-09 17:49:35 +00:00
const Setting = require("lib/models/Setting.js");
const { reg } = require("lib/registry.js");
2017-11-06 21:11:15 +00:00
2018-03-09 17:49:35 +00:00
const action = comp.props.syncStarted ? "cancel" : "start";
2017-11-06 21:11:15 +00:00
2018-01-25 19:01:14 +00:00
if (!reg.syncTarget().isAuthenticated()) {
if (reg.syncTarget().authRouteName()) {
comp.props.dispatch({
2018-03-09 17:49:35 +00:00
type: "NAV_GO",
2018-01-25 19:01:14 +00:00
routeName: reg.syncTarget().authRouteName(),
});
2018-03-09 17:49:35 +00:00
return "auth";
2018-01-25 19:01:14 +00:00
}
2018-03-09 17:49:35 +00:00
reg.logger().info("Not authentified with sync target - please check your credential.");
return "error";
2017-11-06 21:11:15 +00:00
}
let sync = null;
try {
sync = await reg.syncTarget().synchronizer();
2017-11-06 21:11:15 +00:00
} catch (error) {
2018-03-09 17:49:35 +00:00
reg.logger().info("Could not acquire synchroniser:");
2017-11-06 21:11:15 +00:00
reg.logger().info(error);
2018-03-09 17:49:35 +00:00
return "error";
2017-11-06 21:11:15 +00:00
}
2018-03-09 17:49:35 +00:00
if (action == "cancel") {
2017-11-06 21:11:15 +00:00
sync.cancel();
2018-03-09 17:49:35 +00:00
return "cancel";
2017-11-06 21:11:15 +00:00
} else {
reg.scheduleSync(0);
2018-03-09 17:49:35 +00:00
return "sync";
2017-11-06 21:11:15 +00:00
}
2018-03-09 17:49:35 +00:00
};
2017-11-06 21:11:15 +00:00
2018-03-09 17:49:35 +00:00
module.exports = shared;