aboutsummaryrefslogtreecommitdiff
path: root/src/gui/tasks/table
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/tasks/table')
-rw-r--r--src/gui/tasks/table/menu.py8
-rw-r--r--src/gui/tasks/table/model.py20
2 files changed, 20 insertions, 8 deletions
diff --git a/src/gui/tasks/table/menu.py b/src/gui/tasks/table/menu.py
index 4366c25..f89ec92 100644
--- a/src/gui/tasks/table/menu.py
+++ b/src/gui/tasks/table/menu.py
@@ -2,7 +2,7 @@ from PyQt5 import QtWidgets
import db.tasks
import gui.tasks.modal
-from model.task import Task, TaskForm
+from model.task import Task, ValidTaskForm
def open(database, table, update_task_signal, position):
rows = set([index.row() for index in table.selectedIndexes()])
@@ -34,10 +34,10 @@ def show_update_dialog(database, parent_widget, update_task_signal, row, task):
'Modify a task',
'modify',
task,
- lambda taskForm: on_update(database, update_task_signal, row, task, taskForm))
+ lambda form: on_update(database, update_task_signal, row, task, form))
dialog.exec_()
-def on_update(database, update_task_signal, row, task: Task, taskForm: TaskForm):
- task = db.tasks.update(database.cursor(), task, taskForm)
+def on_update(database, update_task_signal, row, task: Task, form: ValidTaskForm):
+ task = db.tasks.update(database.cursor(), task, form)
update_task_signal.emit(row, task)
database.commit()
diff --git a/src/gui/tasks/table/model.py b/src/gui/tasks/table/model.py
index 90bcc4c..6b8133d 100644
--- a/src/gui/tasks/table/model.py
+++ b/src/gui/tasks/table/model.py
@@ -7,9 +7,9 @@ import math
import util.array
import util.range
-columns = 3
+columns = 4
-headers = ['Age', 'Name', 'Tag']
+headers = ['Age', 'Name', 'Duration', 'Tag']
default_sort = (0, Qt.AscendingOrder)
@@ -31,9 +31,11 @@ class TableModel(QtCore.QAbstractTableModel):
task = self._tasks[index.row()]
if index.column() == 0:
return age_since(task.created_at)
- if index.column() == 1:
+ elif index.column() == 1:
return task.name
- if index.column() == 2:
+ elif index.column() == 2:
+ return pp_duration(task.duration)
+ elif index.column() == 3:
return task.tag
else:
return QtCore.QVariant()
@@ -101,12 +103,22 @@ def age_since(timestamp):
else:
return '1m'
+def pp_duration(minutes: int):
+ if minutes >= 60 * 24:
+ return '' + str(math.floor(minutes / 60 / 24)) + 'd'
+ elif minutes >= 60:
+ return '' + str(math.floor(minutes / 60)) + 'h'
+ else:
+ return '' + str(minutes) + 'm'
+
def sort_key(task: Task, row: int):
if row == 0:
return task.created_at
elif row == 1:
return task.name.lower()
elif row == 2:
+ return task.duration
+ elif row == 3:
return task.tag.lower()
def is_reversed(row: int, order: Qt.SortOrder) -> bool: