99 lines
3.6 KiB
Python
99 lines
3.6 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
from gi.repository import Gtk
|
|
|
|
from .view import View
|
|
from yms import gtkutils, combobox, treeview
|
|
from yms.model import project
|
|
|
|
class ProjectsView(View):
|
|
|
|
def __init__(self, context):
|
|
super().__init__(context, _("Projects"), "projects.ui")
|
|
self.context = context
|
|
|
|
self.project = project.Project(context.db) # current record
|
|
self.newrecord = False
|
|
|
|
self.lst_projects = Gtk.ListStore(int, str, str, int, str, str)
|
|
sql = (
|
|
"SELECT projid, projname, startdate, duration, projstate, remarks "
|
|
"FROM project "
|
|
"WHERE vid=%s "
|
|
"ORDER BY projid"
|
|
)
|
|
self.db.dcur.execute(sql, (context.vessel.vid,))
|
|
for row in self.db.dcur.fetchall():
|
|
data = (
|
|
row['projid'],
|
|
row['projname'],
|
|
self.format_date(row['startdate']),
|
|
row['duration'],
|
|
row['projstate'],
|
|
row['remarks']
|
|
)
|
|
self.lst_projects.append(data)
|
|
|
|
treeview.add_column(self.tree['projects'], _('ID'), 0)
|
|
treeview.add_column(self.tree['projects'], _('Name'), 1)
|
|
treeview.add_column(self.tree['projects'], _('Start date'), 2)
|
|
treeview.add_column(self.tree['projects'], _('Duration'), 3)
|
|
treeview.add_column(self.tree['projects'], _('Status'), 4)
|
|
treeview.add_column(self.tree['projects'], _('Remarks'), 5)
|
|
self.tree['projects'].set_model(self.lst_projects)
|
|
|
|
self.dd_user = context.lookup.user()
|
|
self.dd_state = self.context.lookup.enum('project.projstate')
|
|
|
|
# buttons on list page
|
|
def on_but_new_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['proj_edit'])
|
|
|
|
def on_but_edit_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['proj_edit'])
|
|
|
|
def on_but_detail_clicked(self, widget):
|
|
projid = treeview.get_value(self.tree['projects'], 0)
|
|
if not projid:
|
|
return
|
|
self.project.load(projid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['proj_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
def on_tvw_projects_row_activated(self, widget, path, column):
|
|
projid = treeview.get_value(widget, 0)
|
|
self.project.load(projid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['proj_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
# buttons on detail page
|
|
# edit2 uses edit callback
|
|
def on_but_close_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['projects'])
|
|
|
|
def on_but_delete_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['projects'])
|
|
|
|
# buttons on edit page
|
|
def on_but_save_clicked(self, widget):
|
|
pass
|
|
|
|
def on_but_cancel_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['projects'])
|
|
|
|
def display_record(self):
|
|
self.label['name'].set_text(self.project.projname)
|
|
self.label['responsible'].set_text(self.dd_user[self.project.responsible])
|
|
self.label['date_start'].set_text(self.format_date(self.project.startdate))
|
|
self.label['duration'].set_text(self.format_int(self.project.duration, suffix="Days"))
|
|
self.label['costs_plan'].set_text(self.format_float(self.project.costs_plan, 2, suffix="€"))
|
|
self.label['costs_final'].set_text(self.format_float(self.project.costs_final, 2, suffix="€"))
|
|
self.label['status'].set_text(self.project.projstate)
|
|
self.label['remarks'].set_text(self.project.remarks or '')
|
|
|
|
def edit_record(self):
|
|
pass
|