From 2041be14dbc01640a61de96d1982cc20cd05a8b3 Mon Sep 17 00:00:00 2001 From: Louistiti Date: Sun, 19 May 2019 12:42:46 +0800 Subject: [PATCH] feat(package/calendar): rename a list in the To-Do List module --- packages/calendar/data/answers/en.json | 11 ++-- packages/calendar/data/answers/fr.json | 11 ++-- packages/calendar/data/expressions/en.json | 38 +++++++++++++ packages/calendar/todolist.py | 63 +++++++++++++++++----- 4 files changed, 105 insertions(+), 18 deletions(-) diff --git a/packages/calendar/data/answers/en.json b/packages/calendar/data/answers/en.json index 31a37d6c..b5df73f6 100644 --- a/packages/calendar/data/answers/en.json +++ b/packages/calendar/data/answers/en.json @@ -7,6 +7,14 @@ "Please provide me a list name.", "Please provide the name of the list you wish to create." ], + "new_or_old_list_name_not_provided": [ + "Please make sure you provide the list name to rename and its new list name.", + "Please provide the list name to rename and its new list name." + ], + "list_does_not_exists": [ + "Sorry I can't because the \"%list%\" does not exist.", + "I cannot do that because the \"%list%\" does not exist." + ], "list_already_exists": [ "You already have a list named \"%list%\"." ], @@ -21,9 +29,6 @@ ], "todo_completed": [ "I completed \"%todo%\" from your \"%list%\" list, congrats!" - ], - "todo_archived": [ - "I archived \"%todo%\" from your \"%list%\" list." ] } } diff --git a/packages/calendar/data/answers/fr.json b/packages/calendar/data/answers/fr.json index fbdba37d..7e349a34 100644 --- a/packages/calendar/data/answers/fr.json +++ b/packages/calendar/data/answers/fr.json @@ -7,6 +7,14 @@ "Merci de me fournir un nom de liste.", "Merci de fournir le nom de la liste que vous souhaitez créer." ], + "new_or_old_list_name_not_provided": [ + "Merci de vous assurer d'avoir fourni le nom de la liste à renommer et son nouveau nom.", + "Merci de fournir le nom de la liste à renommer ainsi que son nouveau nom." + ], + "list_does_not_exists": [ + "Désolé je ne peux pas car la liste \"%list%\" n'éxiste pas.", + "Je ne peux pas parce que la liste \"%list%\" n'éxiste pas." + ], "list_already_exists": [ "Vous avez déjà une liste nommée \"%list%\"." ], @@ -21,9 +29,6 @@ ], "todo_completed": [ "J'ai complété la tâche \"%todo%\" de votre liste \"%list%\", bravo !" - ], - "todo_archived": [ - "J'ai archivé la tâche \"%todo%\" de votre liste \"%list%\"." ] } } diff --git a/packages/calendar/data/expressions/en.json b/packages/calendar/data/expressions/en.json index 7b890558..91375d62 100644 --- a/packages/calendar/data/expressions/en.json +++ b/packages/calendar/data/expressions/en.json @@ -38,6 +38,44 @@ "expressions": [ "Rename the list to list", "Rename my list to list" + ], + "entities": [ + { + "type": "trim", + "name": "old_list", + "conditions": [ + { + "type": "between", + "from": "the", + "to": "list" + }, + { + "type": "between", + "from": "a", + "to": "list" + }, + { + "type": "between", + "from": "an", + "to": "list" + }, + { + "type": "between", + "from": "my", + "to": "list" + } + ] + }, + { + "type": "trim", + "name": "new_list", + "conditions": [ + { + "type": "after", + "from": "to" + } + ] + } ] }, "delete_list": { diff --git a/packages/calendar/todolist.py b/packages/calendar/todolist.py index 3654e599..388b29d4 100644 --- a/packages/calendar/todolist.py +++ b/packages/calendar/todolist.py @@ -33,21 +33,59 @@ def create_list(string, entities): if lists.count(List.name == listname) > 0: return utils.output('end', 'list_already_exists', utils.translate('list_already_exists', { 'list': listname })) + timestamp = int(time()) # Create the new to-do list lists.insert({ 'name': listname, 'todos': [], - 'created_at': int(time()) + 'created_at': timestamp, + 'updated_at': timestamp }) return utils.output('end', 'list_created', utils.translate('list_created', { 'list': listname })) +def view_lists(string, entities): + """View to-do lists""" + + # TODO + def rename_list(string, entities): - """WIP""" + """Rename a to-do list""" + + # Old list name + old_listname = '' + + # New list name + new_listname = '' + + # Find entities + for item in entities: + if item['entity'] == 'old_list': + old_listname = item['sourceText'] + elif item['entity'] == 'new_list': + new_listname = item['sourceText'] + + # Verify if an old and new list name have been provided + if not old_listname or not new_listname: + return utils.output('end', 'new_or_old_list_name_not_provided', utils.translate('new_or_old_list_name_not_provided')) + + # Verify if the old list exists + if lists.count(List.name == old_listname) == 0: + return utils.output('end', 'list_does_not_exists', utils.translate('list_does_not_exists', { 'list': old_listname })) + + # Verify if the new list name already exists + if lists.count(List.name == new_listname) > 0: + return utils.output('end', 'list_already_exists', utils.translate('list_already_exists', { 'list': new_listname })) + + # Rename the to-do list + lists.update({ + 'name': new_listname, + 'updated_at': int(time()) + }, List.name == old_listname) return utils.output('end', 'list_renamed', utils.translate('list_renamed', { - 'old_list': 'fake', - 'new_list': 'new' + 'old_list': old_listname, + 'new_list': new_listname })) def delete_list(string, entities): @@ -63,18 +101,19 @@ def add_todo(string, entities): 'todo': 'todo 1' })) +def view_todos(string, entities): + """WIP""" + + # TODO + def complete_todo(string, entities): """WIP""" + # Complete potatoes from my list + # TODO: look in all lists first, if several then ask to specify from which list + # Complete potatoes from the shopping list + return utils.output('end', 'todo_completed', utils.translate('todo_completed', { 'list': 'fake', 'todo': 'todo 1' })) - -def archive_todo(string, entities): - """WIP""" - - return utils.output('end', 'todo_archived', utils.translate('todo_archived', { - 'list': 'fake', - 'todo': 'todo 1' - }))