1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Load resources in WebView and put todos on top

This commit is contained in:
Laurent Cozic
2017-07-26 19:36:16 +01:00
parent 76914d6c28
commit f80263ab71
10 changed files with 156 additions and 43 deletions

View File

@@ -63,14 +63,14 @@ class Note extends BaseItem {
return output;
}
static sortNotes(notes, order) {
return notes.sort((a, b) => {
let r = -1;
if (a[order.orderBy] < b[order.orderBy]) r = +1;
if (order.orderByDir == 'ASC') r = -r;
return r;
});
}
// static sortNotes(notes, order) {
// return notes.sort((a, b) => {
// // let r = -1;
// // if (a[order.orderBy] < b[order.orderBy]) r = +1;
// // if (order.orderByDir == 'ASC') r = -r;
// // return r;
// });
// }
static previewFields() {
return ['id', 'title', 'body', 'is_todo', 'todo_completed', 'parent_id', 'updated_time'];
@@ -95,13 +95,13 @@ class Note extends BaseItem {
return results.length ? results[0] : null;
}
static previews(parentId, options = null) {
static async previews(parentId, options = null) {
if (!options) options = {};
if (!options.orderBy) options.orderBy = 'updated_time';
if (!options.orderByDir) options.orderByDir = 'DESC';
if (!options.order) options.order = { by: 'updated_time', dir: 'DESC' };
if (!options.conditions) options.conditions = [];
if (!options.conditionsParams) options.conditionsParams = [];
if (!options.fields) options.fields = this.previewFields();
if (!options.uncompletedTodosOnTop) options.uncompletedTodosOnTop = false;
if (parentId == Folder.conflictFolderId()) {
options.conditions.push('is_conflict = 1');
@@ -120,16 +120,47 @@ class Note extends BaseItem {
options.conditionsParams.push(pattern);
}
let hasNotes = true;
let hasTodos = true;
if (options.itemTypes && options.itemTypes.length) {
if (options.itemTypes.indexOf('note') >= 0 && options.itemTypes.indexOf('todo') >= 0) {
// Fetch everything
} else if (options.itemTypes.indexOf('note') >= 0) {
options.conditions.push('is_todo = 0');
} else if (options.itemTypes.indexOf('todo') >= 0) {
options.conditions.push('is_todo = 1');
if (options.itemTypes.indexOf('note') < 0) {
hasNotes = false;
} else if (options.itemTypes.indexOf('todo') < 0) {
hasTodos = false;
}
}
if (options.uncompletedTodosOnTop && hasTodos) {
let cond = options.conditions.slice();
cond.push('is_todo = 1');
cond.push('(todo_completed <= 0 OR todo_completed IS NULL)');
let tempOptions = Object.assign({}, options);
tempOptions.conditions = cond;
let uncompletedTodos = await this.search(tempOptions);
cond = options.conditions.slice();
if (hasNotes && hasTodos) {
cond.push('(is_todo = 0 OR (is_todo = 1 AND todo_completed > 0))');
} else {
cond.push('(is_todo = 1 AND todo_completed > 0)');
}
tempOptions = Object.assign({}, options);
tempOptions.conditions = cond;
let theRest = await this.search(tempOptions);
return uncompletedTodos.concat(theRest);
}
if (hasNotes && hasTodos) {
} else if (hasNotes) {
options.conditions.push('is_todo = 0');
} else if (hasTodos) {
options.conditions.push('is_todo = 1');
}
return this.search(options);
}

View File

@@ -44,6 +44,15 @@ class Resource extends BaseItem {
return this.fsDriver().writeBinaryFile(this.fullPath(resource), content);
}
static isResourceUrl(url) {
return url.length === 34 && url[0] === ':' && url[1] === '/';
}
static urlToId(url) {
if (!this.isResourceUrl(url)) throw new Error('Not a valid resource URL: ' + url);
return url.substr(2);
}
}
export { Resource };

View File

@@ -42,20 +42,21 @@ class Setting extends BaseModel {
this.cancelScheduleSave();
this.cache_ = [];
return this.modelSelectAll('SELECT * FROM settings').then((rows) => {
this.cache_ = rows;
this.cache_ = [];
for (let i = 0; i < this.cache_.length; i++) {
let c = this.cache_[i];
// Old keys - can be removed later
const ignore = ['clientId', 'sync.onedrive.auth', 'syncInterval', 'todoOnTop', 'todosOnTop'];
if (c.key == 'clientId') continue; // For older clients
if (c.key == 'sync.onedrive.auth') continue; // For older clients
if (c.key == 'syncInterval') continue; // For older clients
for (let i = 0; i < rows.length; i++) {
let c = rows[i];
if (ignore.indexOf(c.key) >= 0) continue;
// console.info(c.key + ' = ' + c.value);
c.value = this.formatValue(c.key, c.value);
this.cache_[i] = c;
this.cache_.push(c);
}
const keys = this.keys();
@@ -303,6 +304,7 @@ Setting.metadata_ = {
recent: _('Non-completed and recently completed ones'),
nonCompleted: _('Non-completed ones only'),
})},
'uncompletedTodosOnTop': { value: true, type: Setting.TYPE_BOOL, public: true, label: () => _('Show uncompleted todos on top of the lists') },
'trackLocation': { value: true, type: Setting.TYPE_BOOL, public: true, label: () => _('Save location with notes') },
'sync.interval': { value: 300, type: Setting.TYPE_INT, isEnum: true, public: true, label: () => _('Synchronisation interval'), options: () => {
return {