1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Allow selecting note if ID matches more than one

This commit is contained in:
Laurent Cozic 2017-09-10 18:32:04 +01:00
parent 8e54404d28
commit 7cc26a4fe4
8 changed files with 119 additions and 66 deletions

View File

@ -60,7 +60,20 @@ class Application {
async loadItem(type, pattern, options = null) { async loadItem(type, pattern, options = null) {
let output = await this.loadItems(type, pattern, options); let output = await this.loadItems(type, pattern, options);
return output.length ? output[0] : null;
if (output.length > 1) {
let answers = { 0: _('[Cancel]') };
for (let i = 0; i < output.length; i++) {
answers[i + 1] = output[i].title;
}
let msg = _('More than one item match "%s". Please select one:', pattern);
const response = await cliUtils.promptMcq(msg, answers);
if (!response) return null;
return output[response - 1];
} else {
return output.length ? output[0] : null;
}
} }
async loadItems(type, pattern, options = null) { async loadItems(type, pattern, options = null) {
@ -89,9 +102,8 @@ class Application {
item = await ItemClass.load(pattern); // Load by id item = await ItemClass.load(pattern); // Load by id
if (item) return [item]; if (item) return [item];
if (pattern.length >= 4) { if (pattern.length >= 2) {
item = await ItemClass.loadByPartialId(pattern); return await ItemClass.loadByPartialId(pattern);
if (item) return [item];
} }
} }

View File

@ -127,6 +127,37 @@ cliUtils.makeCommandArgs = function(cmd, argv) {
return output; return output;
} }
cliUtils.promptMcq = function(message, answers) {
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
message += "\n\n";
for (let n in answers) {
if (!answers.hasOwnProperty(n)) continue;
message += _('%s: %s', n, answers[n]) + "\n";
}
message += "\n";
message += _('Your choice: ');
return new Promise((resolve, reject) => {
rl.question(message, (answer) => {
rl.close();
if (!(answer in answers)) {
reject(new Error(_('Invalid answer: %s', answer)));
return;
}
resolve(answer);
});
});
}
cliUtils.promptConfirm = function(message, answers = null) { cliUtils.promptConfirm = function(message, answers = null) {
if (!answers) answers = [_('Y'), _('n')]; if (!answers) answers = [_('Y'), _('n')];
const readline = require('readline'); const readline = require('readline');

View File

@ -15,6 +15,13 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
msgid "[Cancel]"
msgstr ""
#, javascript-format
msgid "More than one item match \"%s\". Please select one:"
msgstr ""
msgid "No notebook selected." msgid "No notebook selected."
msgstr "" msgstr ""
@ -82,6 +89,17 @@ msgstr ""
msgid "Missing required argument: %s" msgid "Missing required argument: %s"
msgstr "" msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Your choice: "
msgstr ""
#, javascript-format
msgid "Invalid answer: %s"
msgstr ""
msgid "Y" msgid "Y"
msgstr "" msgstr ""
@ -435,10 +453,6 @@ msgstr ""
msgid "Invalid option value: \"%s\". Possible values are: %s." msgid "Invalid option value: \"%s\". Possible values are: %s."
msgstr "" msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Synchronisation target" msgid "Synchronisation target"
msgstr "" msgstr ""
@ -543,15 +557,6 @@ msgstr ""
msgid "Configuration" msgid "Configuration"
msgstr "" msgstr ""
msgid "Select date"
msgstr ""
msgid "Confirm"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Synchronise" msgid "Synchronise"
msgstr "" msgstr ""
@ -577,6 +582,9 @@ msgstr ""
msgid "Discard changes" msgid "Discard changes"
msgstr "" msgstr ""
msgid "Cancel"
msgstr ""
msgid "Delete note?" msgid "Delete note?"
msgstr "" msgstr ""
@ -586,12 +594,6 @@ msgstr ""
msgid "Delete note" msgid "Delete note"
msgstr "" msgstr ""
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note" msgid "Convert to regular note"
msgstr "" msgstr ""

View File

@ -15,6 +15,14 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.3\n" "X-Generator: Poedit 2.0.3\n"
#, fuzzy
msgid "[Cancel]"
msgstr "Annulation..."
#, javascript-format
msgid "More than one item match \"%s\". Please select one:"
msgstr ""
msgid "No notebook selected." msgid "No notebook selected."
msgstr "Aucun carnet n'est sélectionné." msgstr "Aucun carnet n'est sélectionné."
@ -84,6 +92,17 @@ msgstr ""
msgid "Missing required argument: %s" msgid "Missing required argument: %s"
msgstr "" msgstr ""
#, fuzzy, javascript-format
msgid "%s: %s"
msgstr "%s: %d/%d"
msgid "Your choice: "
msgstr ""
#, fuzzy, javascript-format
msgid "Invalid answer: %s"
msgstr "Commande invalide : \"%s\""
msgid "Y" msgid "Y"
msgstr "" msgstr ""
@ -483,10 +502,6 @@ msgstr "Impossible de déplacer la note vers le carnet \"%s\""
msgid "Invalid option value: \"%s\". Possible values are: %s." msgid "Invalid option value: \"%s\". Possible values are: %s."
msgstr "Option invalide: \"%s\". Les valeurs possibles sont : %s." msgstr "Option invalide: \"%s\". Les valeurs possibles sont : %s."
#, fuzzy, javascript-format
msgid "%s: %s"
msgstr "%s: %d/%d"
msgid "Synchronisation target" msgid "Synchronisation target"
msgstr "Cible de la synchronisation" msgstr "Cible de la synchronisation"
@ -593,17 +608,6 @@ msgstr "Etat"
msgid "Configuration" msgid "Configuration"
msgstr "Configuration" msgstr "Configuration"
msgid "Select date"
msgstr ""
#, fuzzy
msgid "Confirm"
msgstr "Conflits"
#, fuzzy
msgid "Cancel"
msgstr "Annulation..."
msgid "Synchronise" msgid "Synchronise"
msgstr "Synchroniser" msgstr "Synchroniser"
@ -630,6 +634,10 @@ msgstr ""
msgid "Discard changes" msgid "Discard changes"
msgstr "" msgstr ""
#, fuzzy
msgid "Cancel"
msgstr "Annulation..."
msgid "Delete note?" msgid "Delete note?"
msgstr "Supprimer la note ?" msgstr "Supprimer la note ?"
@ -639,12 +647,6 @@ msgstr "Attacher un fichier"
msgid "Delete note" msgid "Delete note"
msgstr "Supprimer la note" msgstr "Supprimer la note"
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note" msgid "Convert to regular note"
msgstr "Convertir en note" msgstr "Convertir en note"
@ -690,6 +692,10 @@ msgstr ""
msgid "Welcome" msgid "Welcome"
msgstr "Bienvenue" msgstr "Bienvenue"
#, fuzzy
#~ msgid "Confirm"
#~ msgstr "Conflits"
#~ msgid "%s (%s)" #~ msgid "%s (%s)"
#~ msgstr "%s (%s)" #~ msgstr "%s (%s)"

View File

@ -15,6 +15,13 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
msgid "[Cancel]"
msgstr ""
#, javascript-format
msgid "More than one item match \"%s\". Please select one:"
msgstr ""
msgid "No notebook selected." msgid "No notebook selected."
msgstr "" msgstr ""
@ -82,6 +89,17 @@ msgstr ""
msgid "Missing required argument: %s" msgid "Missing required argument: %s"
msgstr "" msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Your choice: "
msgstr ""
#, javascript-format
msgid "Invalid answer: %s"
msgstr ""
msgid "Y" msgid "Y"
msgstr "" msgstr ""
@ -435,10 +453,6 @@ msgstr ""
msgid "Invalid option value: \"%s\". Possible values are: %s." msgid "Invalid option value: \"%s\". Possible values are: %s."
msgstr "" msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Synchronisation target" msgid "Synchronisation target"
msgstr "" msgstr ""
@ -543,15 +557,6 @@ msgstr ""
msgid "Configuration" msgid "Configuration"
msgstr "" msgstr ""
msgid "Select date"
msgstr ""
msgid "Confirm"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Synchronise" msgid "Synchronise"
msgstr "" msgstr ""
@ -577,6 +582,9 @@ msgstr ""
msgid "Discard changes" msgid "Discard changes"
msgstr "" msgstr ""
msgid "Cancel"
msgstr ""
msgid "Delete note?" msgid "Delete note?"
msgstr "" msgstr ""
@ -586,12 +594,6 @@ msgstr ""
msgid "Delete note" msgid "Delete note"
msgstr "" msgstr ""
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note" msgid "Convert to regular note"
msgstr "" msgstr ""

View File

@ -7,7 +7,7 @@
"url": "https://github.com/laurent22/joplin" "url": "https://github.com/laurent22/joplin"
}, },
"url": "git://github.com/laurent22/joplin.git", "url": "git://github.com/laurent22/joplin.git",
"version": "0.9.17", "version": "0.9.18",
"bin": { "bin": {
"joplin": "./main.js" "joplin": "./main.js"
}, },

View File

@ -1 +1 @@
320eb753be882e5509e873e2b5f624e3 fa4bd30e1ee78746aa243fa65696c869

View File

@ -110,7 +110,7 @@ class BaseModel {
} }
static loadByPartialId(partialId) { static loadByPartialId(partialId) {
return this.modelSelectOne('SELECT * FROM `' + this.tableName() + '` WHERE `id` LIKE ?', [partialId + '%']); return this.modelSelectAll('SELECT * FROM `' + this.tableName() + '` WHERE `id` LIKE ?', [partialId + '%']);
} }
static applySqlOptions(options, sql, params = null) { static applySqlOptions(options, sql, params = null) {