예제 #1
0
    def __init__(self):
        super(EffortWindow, self).__init__()
        self.ui = Ui_effortWindow()
        self.ui.setupUi(self)
        self.tbl = self.ui.effortTableWidget

        self.monkeys = []
        self.efforts = {}

        self.ui.queryButton.clicked.connect(self._query_btn_clicked)
        self.tbl.cellClicked.connect(self._cell_clicked)
예제 #2
0
class EffortWindow(QWidget):

    # noinspection PyUnresolvedReferences
    def __init__(self):
        super(EffortWindow, self).__init__()
        self.ui = Ui_effortWindow()
        self.ui.setupUi(self)
        self.tbl = self.ui.effortTableWidget

        self.monkeys = []
        self.efforts = {}

        self.ui.queryButton.clicked.connect(self._query_btn_clicked)
        self.tbl.cellClicked.connect(self._cell_clicked)

    def load(self):
        self._load_default_time_frame()
        self._query_btn_clicked()

    def _load_default_time_frame(self):
        first_month = Monkey.current()
        last_month = Monkey.last_month(first_month, 6)
        self.ui.firstMonthEdit.setText(first_month)
        self.ui.lastMonthEdit.setText(last_month)

    def _query_btn_clicked(self):
        from models import Effort
        interval = TimeInterval(
            first_month=Monkey.unslash(self.ui.firstMonthEdit.text()),
            last_month=Monkey.unslash(self.ui.lastMonthEdit.text())
        )
        self.monkeys, self.efforts = Effort.get(interval)
        self._load_table()

    def _load_table(self):
        from PyQt5.QtCore import Qt
        tbl = self.ui.effortTableWidget
        tbl.clear()
        if not self.efforts:
            return
        tbl.setRowCount(len(self.efforts))
        tbl.setColumnCount(len(self.monkeys) + 2)
        lbls = ['Employee', 'FTE'] + list(map(Monkey.prettify, self.monkeys))
        tbl.setHorizontalHeaderLabels(lbls)
        tbl.verticalHeader().hide()
        tbl.resizeColumnsToContents()
        tbl.setColumnWidth(0, 180)
        tbl.setFixedWidth(tbl.horizontalHeader().length() + 40)

        for row, emp in enumerate(sorted(self.efforts.keys())):
            tbl.setItem(row, 0, QTableWidgetItem(emp))
            item = QTableWidgetItem(str(self.efforts[emp].fte))
            item.setTextAlignment(Qt.AlignRight)
            tbl.setItem(row, 1, item)
            for col, monkey in enumerate(self.monkeys):
                item = QTableWidgetItem(str(self.efforts[emp].totals[monkey]))
                item.setTextAlignment(Qt.AlignRight)
                tbl.setItem(row, col + 2, item)

    def _cell_clicked(self, row, col):
        if col == 0:
            self._employee_clicked(row)
        elif col == 1:
            return
        else:
            self._monkey_clicked(row, col)

    def _employee_clicked(self, row):
        from models import Dataset
        emp_name = self.tbl.item(row, 0).text()
        emp = Dataset.employees[emp_name]
        emp.set_assignments()

        from views import AssignmentDialog
        assignment_dialog = AssignmentDialog(emp)
        assignment_dialog.exec_()

    def _monkey_clicked(self, row, col):
        employee = self.tbl.item(row, 0).text()
        monkey = self.monkeys[col - 2]
        hdr = '%s\n%s' % (employee, Monkey.prettify(monkey))
        lines = []
        total = 0
        for asn in self.efforts[employee].assignments:
            interval = TimeInterval(
                first_month=asn.first_month,
                last_month=asn.last_month
            )
            asn_monkeys = Monkey.monkey_list(interval)
            if monkey in asn_monkeys:
                lines.append('%s: %d' % (asn.project_name, asn.effort))
                total += asn.effort
        msg = hdr + '\n\n' + '\n'.join(lines) + ('\n\nTotal: %d' % total)
        QMessageBox.information(QMessageBox(), 'Effort Breakdown', msg)