Skip to content

Commit

Permalink
feat(package/calendar): complete todos WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 19, 2019
1 parent 1a3dab0 commit 602aa69
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 26 deletions.
7 changes: 4 additions & 3 deletions packages/calendar/data/answers/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
"Good luck! The following have been added to your \"%list%\" list:<br><br><ul>%result%</ul>"
],
"todos_uncompleted": [
"I uncompleted \"%todo%\" from your \"%list%\" list."
"I uncompleted the following from your \"%list%\" list:<br><br><ul>%result%</ul>",
"The following have been uncompleted from your \"%list%\" list:<br><br><ul>%result%</ul>"
],
"todos_completed": [
"I completed \"%todo%\" from your \"%list%\" list, keep going!",
"Well done! I completed \"%todo%\" from your \"%list%\" list."
"Keep going! I completed the following from your \"%list%\" list:<br><br><ul>%result%</ul>",
"Well done! The following have been completed from your \"%list%\" list:<br><br><ul>%result%</ul>"
]
}
}
7 changes: 4 additions & 3 deletions packages/calendar/data/answers/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
"Bonne chance ! Ce qui suit vient d'être ajouté à votre liste \"%list%\" :<br><br><ul>%result%</ul>"
],
"todos_uncompleted": [
"J'ai décompléter l'élément \"%todo%\" de votre liste \"%list%\"."
"J'ai décomplété ceci de votre liste \"%list%\" :<br><br><ul>%result%</ul>",
"Ce qui suit vient d'être décomplété de votre liste \"%list%\" :<br><br><ul>%result%</ul>"
],
"todos_completed": [
"J'ai complété l'élément \"%todo%\" de votre liste \"%list%\", continue ainsi !",
"Bien joué ! J'ai complété l'élément \"%todo%\" de votre liste \"%list%\"."
"Continue ainsi ! J'ai complété ceci de votre liste \"%list%\" :<br><br><ul>%result%</ul>",
"Bien joué ! Ce qui suit vient d'être complété de votre liste \"%list%\" :<br><br><ul>%result%</ul>"
]
}
}
10 changes: 10 additions & 0 deletions packages/calendar/data/expressions/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
"type": "between",
"from": "add",
"to": "to"
},
{
"type": "between",
"from": "add",
"to": "and"
},
{
"type": "between",
"from": "and",
"to": "to"
}
]
},
Expand Down
88 changes: 68 additions & 20 deletions packages/calendar/todolist.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ def add_todos(string, entities):
if not listname:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))

# Verify the list exists
if lists.count(List.name == listname) == 0:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': listname }))

# Verify todos have been provided
if len(todos) == 0:
return utils.output('end', 'todos_not_provided', utils.translate('todos_not_provided'))
Expand All @@ -171,21 +167,79 @@ def add_todos(string, entities):
todos[i] = todo
result += utils.translate('list_todo_element', { 'todo': todo['name'] })

# Add todos to the to-do list
lists.update({
'todos': todos + existing_todos,
'updated_at': int(time())
}, List.name == listname)
# Verify the list exists
if lists.count(List.name == listname) == 0:
# Create the to-do list
lists.insert({
'name': listname,
'todos': todos,
'created_at': timestamp,
'updated_at': timestamp
})
else:
# Add todos to the to-do list
lists.update({
'todos': todos + existing_todos,
'updated_at': int(time())
}, List.name == listname)

return utils.output('end', 'todos_added', utils.translate('todos_added', {
'list': listname,
'result': result
}))

def view_todos(string, entities):
"""WIP"""
def complete_todos(string, entities):
"""Complete todos"""

# TODO
# List name
listname = ''

# Todos
todos = []

# Find entities
for item in entities:
if item['entity'] == 'list':
listname = item['sourceText'].lower()
elif item['entity'] == 'todos':
# Split todos into array and trim start/end-whitespaces
todos = [chunk.strip() for chunk in item['sourceText'].lower().split(',')]

# Verify if a list name has been provided
if not listname:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))

# Verify the list exists
if lists.count(List.name == listname) == 0:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': listname }))

# Verify todos have been provided
if len(todos) == 0:
return utils.output('end', 'todos_not_provided', utils.translate('todos_not_provided'))

result = ''
updated_todos = []
db_todos = lists.get(List.name == listname)['todos']

# # Verify same word in todo. Allow to not give the exact same todo (e.g. 1kg of rice = rice)
# if db_todo['name'].find(todo) != -1:

# result += utils.translate('list_todo_element', { 'todo': db_todo['name'] })

# Complete todos
# lists.update({
# 'todos': updated_todos,
# 'updated_at': int(time())
# }, List.name == listname)

# return utils.output('end', 'todos_completed', utils.translate('todos_completed', {
# 'list': listname,
# 'result': result
# }))

# 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

def uncomplete_todos(string, entities):
"""WIP"""
Expand All @@ -199,14 +253,8 @@ def uncomplete_todos(string, entities):
'todo': 'todo 1'
}))

def complete_todos(string, entities):
def view_todos(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
# TODO

return utils.output('end', 'todo_completed', utils.translate('todo_completed', {
'list': 'fake',
'todo': 'todo 1'
}))

0 comments on commit 602aa69

Please sign in to comment.