Allow selecting note if ID matches more than one

pull/41/head
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) {
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) {
@ -89,9 +102,8 @@ class Application {
item = await ItemClass.load(pattern); // Load by id
if (item) return [item];
if (pattern.length >= 4) {
item = await ItemClass.loadByPartialId(pattern);
if (item) return [item];
if (pattern.length >= 2) {
return await ItemClass.loadByPartialId(pattern);
}
}

View File

@ -127,6 +127,37 @@ cliUtils.makeCommandArgs = function(cmd, argv) {
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) {
if (!answers) answers = [_('Y'), _('n')];
const readline = require('readline');

View File

@ -15,6 +15,13 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\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."
msgstr ""
@ -82,6 +89,17 @@ msgstr ""
msgid "Missing required argument: %s"
msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Your choice: "
msgstr ""
#, javascript-format
msgid "Invalid answer: %s"
msgstr ""
msgid "Y"
msgstr ""
@ -435,10 +453,6 @@ msgstr ""
msgid "Invalid option value: \"%s\". Possible values are: %s."
msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Synchronisation target"
msgstr ""
@ -543,15 +557,6 @@ msgstr ""
msgid "Configuration"
msgstr ""
msgid "Select date"
msgstr ""
msgid "Confirm"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Synchronise"
msgstr ""
@ -577,6 +582,9 @@ msgstr ""
msgid "Discard changes"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Delete note?"
msgstr ""
@ -586,12 +594,6 @@ msgstr ""
msgid "Delete note"
msgstr ""
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note"
msgstr ""

View File

@ -15,6 +15,14 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\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."
msgstr "Aucun carnet n'est sélectionné."
@ -84,6 +92,17 @@ msgstr ""
msgid "Missing required argument: %s"
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"
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."
msgstr "Option invalide: \"%s\". Les valeurs possibles sont : %s."
#, fuzzy, javascript-format
msgid "%s: %s"
msgstr "%s: %d/%d"
msgid "Synchronisation target"
msgstr "Cible de la synchronisation"
@ -593,17 +608,6 @@ msgstr "Etat"
msgid "Configuration"
msgstr "Configuration"
msgid "Select date"
msgstr ""
#, fuzzy
msgid "Confirm"
msgstr "Conflits"
#, fuzzy
msgid "Cancel"
msgstr "Annulation..."
msgid "Synchronise"
msgstr "Synchroniser"
@ -630,6 +634,10 @@ msgstr ""
msgid "Discard changes"
msgstr ""
#, fuzzy
msgid "Cancel"
msgstr "Annulation..."
msgid "Delete note?"
msgstr "Supprimer la note ?"
@ -639,12 +647,6 @@ msgstr "Attacher un fichier"
msgid "Delete note"
msgstr "Supprimer la note"
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note"
msgstr "Convertir en note"
@ -690,6 +692,10 @@ msgstr ""
msgid "Welcome"
msgstr "Bienvenue"
#, fuzzy
#~ msgid "Confirm"
#~ msgstr "Conflits"
#~ msgid "%s (%s)"
#~ msgstr "%s (%s)"

View File

@ -15,6 +15,13 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\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."
msgstr ""
@ -82,6 +89,17 @@ msgstr ""
msgid "Missing required argument: %s"
msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Your choice: "
msgstr ""
#, javascript-format
msgid "Invalid answer: %s"
msgstr ""
msgid "Y"
msgstr ""
@ -435,10 +453,6 @@ msgstr ""
msgid "Invalid option value: \"%s\". Possible values are: %s."
msgstr ""
#, javascript-format
msgid "%s: %s"
msgstr ""
msgid "Synchronisation target"
msgstr ""
@ -543,15 +557,6 @@ msgstr ""
msgid "Configuration"
msgstr ""
msgid "Select date"
msgstr ""
msgid "Confirm"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Synchronise"
msgstr ""
@ -577,6 +582,9 @@ msgstr ""
msgid "Discard changes"
msgstr ""
msgid "Cancel"
msgstr ""
msgid "Delete note?"
msgstr ""
@ -586,12 +594,6 @@ msgstr ""
msgid "Delete note"
msgstr ""
msgid "Edit/Clear alarm"
msgstr ""
msgid "Set an alarm"
msgstr ""
msgid "Convert to regular note"
msgstr ""

View File

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

View File

@ -1 +1 @@
320eb753be882e5509e873e2b5f624e3
fa4bd30e1ee78746aa243fa65696c869

View File

@ -110,7 +110,7 @@ class BaseModel {
}
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) {