diff options
author | Joris | 2020-05-31 13:59:35 +0200 |
---|---|---|
committer | Joris | 2020-05-31 13:59:35 +0200 |
commit | 0f1610333324d58acafee8c0fa9d9c9bc293b219 (patch) | |
tree | 302c37dd3751e9fe2e50ab656d56253bfd2d55fc /src/gui/tasks/dialog.py | |
parent | 8a6e10d401eea8db0947f8c4b309b8a6256f9748 (diff) |
Use defined tags for tasks
Diffstat (limited to 'src/gui/tasks/dialog.py')
-rw-r--r-- | src/gui/tasks/dialog.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/gui/tasks/dialog.py b/src/gui/tasks/dialog.py index 2e0d8d4..a28ecb0 100644 --- a/src/gui/tasks/dialog.py +++ b/src/gui/tasks/dialog.py @@ -1,46 +1,47 @@ from PyQt5 import QtCore, QtWidgets +from typing import List +from model.tag import Tag from model.task import Task, ValidTaskForm - +import database +import db.task_tags import db.tasks import gui.tasks.form.widget +import service.tasks -def add(database, parent_widget, add_task_signal): +def add(parent_widget, add_task_signal): - def on_add(form: ValidTaskForm): - task = db.tasks.insert(database.cursor(), form) - database.commit() - add_task_signal.emit(task) + def on_add(task_form: ValidTaskForm): + task = service.tasks.create(database.cursor(), task_form) + add_task_signal.emit(task, task_form.tags) - return widget(parent_widget, 'Add a task', 'add', None, on_add) + return widget(parent_widget, 'Add a task', 'add', None, [], on_add) -def update(database, parent_widget, update_task_signal, row, task): +def update(parent_widget, update_task_signal, row: int, task: Task, tags: List[int]): - def on_update(form: ValidTaskForm): - updated_task = db.tasks.update(database.cursor(), task, form) - update_task_signal.emit(row, updated_task) - database.commit() + def on_update(task_form: ValidTaskForm): + updated_task = service.tasks.update(database.cursor(), task, task_form) + update_task_signal.emit(row, updated_task, task_form.tags) - return widget(parent_widget, 'Modify a task', 'modify', task, on_update) + return widget(parent_widget, 'Modify a task', 'modify', task, tags, on_update) -def show_delete(database, table, rows): +def show_delete(parent, rows: List[int], on_delete): confirm = QtWidgets.QMessageBox.question( - table, + parent, 'Task deletion', 'Do you really want to delete the selected tasks ?', QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes) if confirm == QtWidgets.QMessageBox.Yes: - db.tasks.delete(database.cursor(), table.model().row_ids(rows)) - database.commit() - table.model().delete_tasks(rows) + on_delete() def widget( parent: QtWidgets.QWidget, title: str, action_title: str, task: Task, + tags: List[int], on_validated): dialog = QtWidgets.QDialog(parent) @@ -58,6 +59,7 @@ def widget( parent = dialog, action_title = action_title, task = task, + tags = tags, on_validated = on_dialog_validated, on_cancel = lambda: dialog.reject())) |