mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import { BaseCommand } from './base-command.js';
|
|
import { app } from './app.js';
|
|
import { _ } from 'lib/locale.js';
|
|
import { BaseModel } from 'lib/base-model.js';
|
|
import { Folder } from 'lib/models/folder.js';
|
|
import { Note } from 'lib/models/note.js';
|
|
import { autocompleteItems } from './autocomplete.js';
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
usage() {
|
|
return 'mv <pattern> <notebook>';
|
|
}
|
|
|
|
description() {
|
|
return 'Moves the notes matching <pattern> to <notebook>.';
|
|
}
|
|
|
|
autocomplete() {
|
|
return { data: autocompleteItems };
|
|
}
|
|
|
|
async action(args) {
|
|
const pattern = args['pattern'];
|
|
|
|
const folder = await Folder.loadByField('title', args['notebook']);
|
|
if (!folder) throw new Error(_('No notebook "%s"', args['notebook']));
|
|
|
|
const notes = await app().loadItems(BaseModel.TYPE_NOTE, pattern);
|
|
if (!notes.length) throw new Error(_('No note matches this pattern: "%s"', pattern));
|
|
|
|
for (let i = 0; i < notes.length; i++) {
|
|
await Note.save({ id: notes[i].id, parent_id: folder.id });
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Command; |