Commit 13678f87 authored by Daniel Garcia Moreno's avatar Daniel Garcia Moreno

Merge branch 'diegogangl/timetrack-wip/comments'

parents fc8215be b3bf2964
......@@ -2,17 +2,6 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="hour">
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">2</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="minute">
<property name="upper">60</property>
<property name="step_increment">10</property>
<property name="page_increment">30</property>
</object>
<object class="GtkAdjustment" id="edit-hour-adj">
<property name="upper">24</property>
<property name="value">12</property>
......@@ -24,10 +13,24 @@
<property name="step_increment">10</property>
<property name="page_increment">30</property>
</object>
<object class="GtkAdjustment" id="hour">
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">2</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="minute">
<property name="upper">60</property>
<property name="step_increment">10</property>
<property name="page_increment">30</property>
</object>
<object class="GtkBox" id="edit-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
......@@ -52,7 +55,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
......@@ -65,7 +68,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
<child>
......@@ -102,7 +105,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
<child>
......@@ -115,7 +118,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child>
......@@ -155,7 +158,52 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<style>
<class name="comments-frame"/>
</style>
<child>
<object class="GtkTextView" id="comments">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Comments about this activity</property>
<property name="left_margin">5</property>
<property name="right_margin">5</property>
<property name="top_margin">5</property>
<property name="bottom_margin">5</property>
<property name="input_hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
<style>
<class name="comments"/>
</style>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Comments</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
</packing>
</child>
</object>
......
......@@ -539,6 +539,54 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<style>
<class name="comments-frame"/>
</style>
<child>
<object class="GtkTextView" id="current-comments">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Comments about this activity</property>
<property name="left_margin">5</property>
<property name="right_margin">5</property>
<property name="top_margin">5</property>
<property name="bottom_margin">5</property>
<property name="input_hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
<style>
<class name="comments"/>
</style>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Comments</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="current-timer">
<property name="visible">True</property>
......@@ -551,7 +599,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
</object>
......
......@@ -32,3 +32,12 @@ list row {
background-image: none;
text-shadow: none;
}
.comments-frame {
border: 1px solid @borders;
}
.activity-comment {
padding: 6px;
font-size: small;
}
......@@ -54,14 +54,16 @@ class Activity(GObject.Object):
start: datetime = datetime.now()
stop: Optional[datetime] = None
id: Optional[int] = None
comments: Optional[str] = None
def __init__(self, name="activity", start=datetime.now(),
stop=None, id=None):
stop=None, id=None, comments=None):
super().__init__()
self.name = name
self.start = start
self.stop = stop
self.id = id
self.comments = comments or ""
@property
def seconds(self):
......@@ -86,6 +88,7 @@ class ActivityWidget(Gtk.Box):
label = NotImplemented
time_label = NotImplemented
start_label = NotImplemented
comments = NotImplemented
activity = NotImplemented
activity_id = None
......@@ -118,8 +121,16 @@ class ActivityWidget(Gtk.Box):
box2.pack_start(self.start_label, True, True, 6)
self.comments = Gtk.Label(label=act.comments)
self.comments.set_xalign(0.0)
self.comments.set_line_wrap(True)
context = self.comments.get_style_context()
context.add_class("dim-label")
context.add_class("activity-comment")
self.pack_start(box2, False, False, 6)
self.add(box1)
self.add(self.comments)
self.show_all()
......
......@@ -63,11 +63,13 @@ class DB:
query = '''
UPDATE activities
SET activity = ?, start_date = ?, stop_date = ?, seconds = ?
SET activity = ?, start_date = ?, stop_date = ?, seconds = ?,
comments= ?
WHERE id = ?
'''
c.execute(query, (act.name, act.start, act.stop, act.seconds, act.id))
c.execute(query, (act.name, act.start, act.stop, act.seconds,
act.comments, act.id))
self.connection.commit()
return act.id
......@@ -91,7 +93,8 @@ class DB:
id,
activity,
start_date as "d1 [datetime]",
stop_date as "d2 [datetime]"
stop_date as "d2 [datetime]",
comments
FROM activities
WHERE id = ?
'''
......@@ -100,7 +103,8 @@ class DB:
if not rows:
return None
row = rows[0]
return Activity(id=row[0], name=row[1], start=row[2], stop=row[3])
return Activity(id=row[0], name=row[1], start=row[2], stop=row[3],
comments=row[4])
def get_last(self, limit=10, offset=0):
c = self.connection.cursor()
......@@ -110,14 +114,16 @@ class DB:
id,
activity,
start_date as "d1 [datetime]",
stop_date as "d2 [datetime]"
stop_date as "d2 [datetime]",
comments
FROM activities
ORDER BY start_date desc
LIMIT {} OFFSET {}
'''.format(limit, offset)
for row in c.execute(query):
yield Activity(id=row[0], name=row[1], start=row[2], stop=row[3])
yield Activity(id=row[0], name=row[1], start=row[2], stop=row[3],
comments=row[4])
def get_by_name(self, name, limit=10, offset=0):
c = self.connection.cursor()
......@@ -127,7 +133,8 @@ class DB:
id,
activity,
start_date as "d1 [datetime]",
stop_date as "d2 [datetime]"
stop_date as "d2 [datetime]",
comments
FROM activities
WHERE activity = ?
ORDER BY start_date desc
......@@ -135,7 +142,8 @@ class DB:
'''.format(limit, offset)
for row in c.execute(query, (name, )):
yield Activity(id=row[0], name=row[1], start=row[2], stop=row[3])
yield Activity(id=row[0], name=row[1], start=row[2], stop=row[3],
comments=row[4])
def report(self, start=None, end=None, activity=None):
c = self.connection.cursor()
......
......@@ -30,6 +30,7 @@ class EditDialog(Gtk.Dialog):
self.start_date = builder.get_object("edit-calendar")
self.start_hour = builder.get_object("edit-hour")
self.start_minute = builder.get_object("edit-minute")
self.comments = builder.get_object("comments")
self.working_hour = builder.get_object("edit-working-hour")
self.working_minute = builder.get_object("edit-working-minute")
......@@ -61,6 +62,7 @@ class EditDialog(Gtk.Dialog):
act = self.db.get(self.activity_id)
self.activity_name.set_text(act.name)
self.comments.get_buffer().set_text(act.comments)
self.start_date.set_property("day", act.start.day)
self.start_date.set_property("month", act.start.month - 1)
self.start_date.set_property("year", act.start.year)
......@@ -96,6 +98,11 @@ class EditDialog(Gtk.Dialog):
name = self.activity_name.get_text()
date = self.start_date.get_date()
comments_buf = self.comments.get_buffer()
comments_start = comments_buf.get_start_iter()
comments_end = comments_buf.get_end_iter()
comments = comments_buf.get_text(comments_start, comments_end, False)
start_h = self.start_hour.get_value()
start_m = self.start_minute.get_value()
......@@ -110,7 +117,8 @@ class EditDialog(Gtk.Dialog):
activity = Activity(id=self.activity_id,
name=name,
start=start_date,
stop=stop_date)
stop=stop_date,
comments=comments)
aid = self.db.update(activity)
activity.id = aid
......
......@@ -130,6 +130,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.current_minute = self.builder.get_object('current-minute')
self.current_day = self.builder.get_object('current-day')
self.current_timer = self.builder.get_object('current-timer')
self.current_comments = self.builder.get_object('current-comments')
self.current_name.bind_property('text', self.activity_label, 'label')
self.timer.bind_property('label', self.current_timer, 'label')
......@@ -138,6 +139,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.current_hour.connect('changed', self.change_current)
self.current_minute.connect('changed', self.change_current)
self.current_day.connect('day-selected', self.change_current)
self.current_comments.get_buffer().connect('changed', self.change_current)
def create_report(self):
self.report_stack = self.builder.get_object('report-stack')
......@@ -550,9 +552,11 @@ class MainWindow(Gtk.ApplicationWindow):
self.current_name.set_text(activity.name)
self.current_hour.set_value(activity.start.hour)
self.current_minute.set_value(activity.start.minute)
self.current_day.year = activity.start.year
self.current_day.month = activity.start.month - 1
self.current_day.day = activity.start.day
self.current_day.select_month(activity.start.month - 1,
activity.start.year)
self.current_day.select_day(activity.start.day)
self.current_comments.get_buffer().set_text(activity.comments)
def change_current(self, *args, **kwargs):
if not self.activity_id or not self.start_date:
......@@ -561,6 +565,11 @@ class MainWindow(Gtk.ApplicationWindow):
new_date = self.current_day.get_date()
name = self.current_name.get_text()
comments_buf = self.current_comments.get_buffer()
comments_start = comments_buf.get_start_iter()
comments_end = comments_buf.get_end_iter()
comments = comments_buf.get_text(comments_start, comments_end, False)
self.start_date = datetime(new_date.year,
new_date.month + 1,
new_date.day,
......@@ -569,5 +578,7 @@ class MainWindow(Gtk.ApplicationWindow):
activity = Activity(id=self.activity_id,
name=name,
start=self.start_date, stop=None)
start=self.start_date,
stop=None,
comments=comments)
self.application.db.update(activity)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment