mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-17 18:44:45 +02:00
71efff6827
* Update eslint config * Applied linter to lib * Applied eslint config to CliClient/app * Removed prettier due to https://github.com/prettier/prettier/pull/4765 * First pass on test units * Applied linter config to test units * Applied eslint config to clipper * Applied to plugin dir * Applied to root of ElectronClient * Applied on RN root * Applied on CLI root * Applied on Clipper root * Applied config to tools * test hook * test hook * test hook * Added pre-commit hook * Applied rule no-trailing-spaces * Make sure root packages are installed when installing sub-dir * Added doc
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const { BaseCommand } = require('./base-command.js');
|
|
const { app } = require('./app.js');
|
|
const { _ } = require('lib/locale.js');
|
|
const BaseModel = require('lib/BaseModel.js');
|
|
const { Database } = require('lib/database.js');
|
|
const Note = require('lib/models/Note.js');
|
|
|
|
class Command extends BaseCommand {
|
|
usage() {
|
|
return 'set <note> <name> [value]';
|
|
}
|
|
|
|
description() {
|
|
const fields = Note.fields();
|
|
const s = [];
|
|
for (let i = 0; i < fields.length; i++) {
|
|
const f = fields[i];
|
|
if (f.name === 'id') continue;
|
|
s.push(f.name + ' (' + Database.enumName('fieldType', f.type) + ')');
|
|
}
|
|
|
|
return _('Sets the property <name> of the given <note> to the given [value]. Possible properties are:\n\n%s', s.join(', '));
|
|
}
|
|
|
|
async action(args) {
|
|
let title = args['note'];
|
|
let propName = args['name'];
|
|
let propValue = args['value'];
|
|
if (!propValue) propValue = '';
|
|
|
|
let notes = await app().loadItems(BaseModel.TYPE_NOTE, title);
|
|
if (!notes.length) throw new Error(_('Cannot find "%s".', title));
|
|
|
|
for (let i = 0; i < notes.length; i++) {
|
|
this.encryptionCheck(notes[i]);
|
|
|
|
let newNote = {
|
|
id: notes[i].id,
|
|
type_: notes[i].type_,
|
|
};
|
|
newNote[propName] = propValue;
|
|
await Note.save(newNote);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Command;
|