You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Got tags working and fixed sync issue
This commit is contained in:
@@ -238,7 +238,11 @@ class BaseModel {
|
||||
}
|
||||
|
||||
if (!o.user_created_time && this.hasField('user_created_time')) {
|
||||
o.user_created_time = timeNow;
|
||||
o.user_created_time = o.created_time ? o.created_time : timeNow;
|
||||
}
|
||||
|
||||
if (!o.user_updated_time && this.hasField('user_updated_time')) {
|
||||
o.user_updated_time = o.updated_time ? o.updated_time : timeNow;
|
||||
}
|
||||
|
||||
query = Database.insertQuery(this.tableName(), o);
|
||||
|
||||
@@ -193,6 +193,14 @@ class JoplinDatabase extends Database {
|
||||
// 1. Add the new version number to the existingDatabaseVersions array
|
||||
// 2. Add the upgrade logic to the "switch (targetVersion)" statement below
|
||||
|
||||
// IMPORTANT:
|
||||
//
|
||||
// Whenever adding a new database property, some additional logic might be needed
|
||||
// in the synchronizer to handle this property. For example, when adding a property
|
||||
// that should have a default value, existing remote items will not have this
|
||||
// default value and thus might cause problems. In that case, the default value
|
||||
// must be set in the synchronizer too.
|
||||
|
||||
const existingDatabaseVersions = [0, 1, 2, 3, 4, 5];
|
||||
|
||||
let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion);
|
||||
|
||||
@@ -43,10 +43,17 @@ class Tag extends BaseItem {
|
||||
let hasIt = await this.hasNote(tagId, noteId);
|
||||
if (hasIt) return;
|
||||
|
||||
return NoteTag.save({
|
||||
const output = await NoteTag.save({
|
||||
tag_id: tagId,
|
||||
note_id: noteId,
|
||||
});
|
||||
|
||||
this.dispatch({
|
||||
type: 'TAGS_UPDATE_ONE',
|
||||
tag: await Tag.load(tagId),
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static async removeNote(tagId, noteId) {
|
||||
@@ -54,6 +61,11 @@ class Tag extends BaseItem {
|
||||
for (let i = 0; i < noteTags.length; i++) {
|
||||
await NoteTag.delete(noteTags[i].id);
|
||||
}
|
||||
|
||||
this.dispatch({
|
||||
type: 'TAGS_UPDATE_ONE',
|
||||
tag: await Tag.load(tagId),
|
||||
});
|
||||
}
|
||||
|
||||
static async hasNote(tagId, noteId) {
|
||||
@@ -61,6 +73,20 @@ class Tag extends BaseItem {
|
||||
return !!r;
|
||||
}
|
||||
|
||||
static async allWithNotes() {
|
||||
return await Tag.modelSelectAll('SELECT * FROM tags WHERE id IN (SELECT DISTINCT tag_id FROM note_tags)');
|
||||
}
|
||||
|
||||
static async save(o, options = null) {
|
||||
return super.save(o, options).then((tag) => {
|
||||
this.dispatch({
|
||||
type: 'TAGS_UPDATE_ONE',
|
||||
tag: tag,
|
||||
});
|
||||
return tag;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Tag };
|
||||
@@ -37,6 +37,33 @@ function historyCanGoBackTo(route) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function updateOneTagOrFolder(state, action) {
|
||||
let newItems = action.type === 'TAGS_UPDATE_ONE' ? state.tags.splice(0) : state.folders.splice(0);
|
||||
let item = action.type === 'TAGS_UPDATE_ONE' ? action.tag : action.folder;
|
||||
|
||||
var found = false;
|
||||
for (let i = 0; i < newItems.length; i++) {
|
||||
let n = newItems[i];
|
||||
if (n.id == item.id) {
|
||||
newItems[i] = Object.assign(newItems[i], item);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) newItems.push(item);
|
||||
|
||||
let newState = Object.assign({}, state);
|
||||
|
||||
if (action.type === 'TAGS_UPDATE_ONE') {
|
||||
newState.tags = newItems;
|
||||
} else {
|
||||
newState.folders = newItems;
|
||||
}
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
const reducer = (state = defaultState, action) => {
|
||||
let newState = state;
|
||||
let historyGoingBack = false;
|
||||
@@ -128,6 +155,7 @@ const reducer = (state = defaultState, action) => {
|
||||
|
||||
newState = Object.assign({}, state);
|
||||
newState.selectedFolderId = action.folderId;
|
||||
newState.notesParentType = 'Folder';
|
||||
break;
|
||||
|
||||
case 'SETTINGS_UPDATE_ALL':
|
||||
@@ -231,23 +259,52 @@ const reducer = (state = defaultState, action) => {
|
||||
newState.tags = action.tags;
|
||||
break;
|
||||
|
||||
case 'FOLDERS_UPDATE_ONE':
|
||||
|
||||
var newFolders = state.folders.splice(0);
|
||||
var found = false;
|
||||
for (let i = 0; i < newFolders.length; i++) {
|
||||
let n = newFolders[i];
|
||||
if (n.id == action.folder.id) {
|
||||
newFolders[i] = Object.assign(newFolders[i], action.folder);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) newFolders.push(action.folder);
|
||||
case 'TAGS_SELECT':
|
||||
|
||||
newState = Object.assign({}, state);
|
||||
newState.folders = newFolders;
|
||||
newState.selectedTagId = action.tagId;
|
||||
newState.notesParentType = 'Tag';
|
||||
break;
|
||||
|
||||
case 'TAGS_UPDATE_ONE':
|
||||
|
||||
newState = updateOneTagOrFolder(state, action);
|
||||
|
||||
// var newTags = state.tags.splice(0);
|
||||
// var found = false;
|
||||
// for (let i = 0; i < newTags.length; i++) {
|
||||
// let n = newTags[i];
|
||||
// if (n.id == action.tag.id) {
|
||||
// newTags[i] = Object.assign(newTags[i], action.tag);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!found) newTags.push(action.tag);
|
||||
|
||||
// newState = Object.assign({}, state);
|
||||
// newState.tags = newTags;
|
||||
break;
|
||||
|
||||
case 'FOLDERS_UPDATE_ONE':
|
||||
|
||||
newState = updateOneTagOrFolder(state, action);
|
||||
// var newFolders = state.folders.splice(0);
|
||||
// var found = false;
|
||||
// for (let i = 0; i < newFolders.length; i++) {
|
||||
// let n = newFolders[i];
|
||||
// if (n.id == action.folder.id) {
|
||||
// newFolders[i] = Object.assign(newFolders[i], action.folder);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!found) newFolders.push(action.folder);
|
||||
|
||||
// newState = Object.assign({}, state);
|
||||
// newState.folders = newFolders;
|
||||
break;
|
||||
|
||||
case 'FOLDER_DELETE':
|
||||
|
||||
@@ -413,7 +413,6 @@ class Synchronizer {
|
||||
let newContent = Object.assign({}, content);
|
||||
let options = {
|
||||
autoTimestamp: false,
|
||||
applyMetadataChanges: true,
|
||||
nextQueries: BaseItem.updateSyncTimeQueries(syncTargetId, newContent, time.unixMs()),
|
||||
};
|
||||
if (action == 'createLocal') options.isNew = true;
|
||||
@@ -424,6 +423,9 @@ class Synchronizer {
|
||||
await this.api().get(remoteResourceContentPath, { path: localResourceContentPath, target: 'file' });
|
||||
}
|
||||
|
||||
if (!newContent.user_updated_time) newContent.user_updated_time = newContent.updated_time;
|
||||
if (!newContent.user_created_time) newContent.user_created_time = newContent.created_time;
|
||||
|
||||
await ItemClass.save(newContent, options);
|
||||
|
||||
} else if (action == 'deleteLocal') {
|
||||
|
||||
Reference in New Issue
Block a user