From 5ff47492472a4193f3895ebed7383b42bc575ffb375b3b51d100de0f699bacc7 Mon Sep 17 00:00:00 2001 From: linuxero Date: Fri, 14 Feb 2025 12:05:45 +0100 Subject: [PATCH] Employee/Applicant GUI and DB --- Gui/AddApplicant.qml | 40 +++++++++++++---- Gui/ApplicantNationalInsurance.qml | 52 +++++++++++++++++++++ Gui/ApplicantPersonalData.qml | 19 +++++++- Gui/CustomersTable.qml | 9 ++-- Gui/EmployeeDetails.qml | 2 +- Gui/EmployeesTable.qml | 72 +++++++++++++++++++++++------- Gui/main.qml | 1 + lib/DB/BusinessModel.py | 3 +- lib/DB/EmployeeDAO.py | 14 ++---- lib/DB/EmployeeModel.py | 39 +++++++++++----- 10 files changed, 199 insertions(+), 52 deletions(-) diff --git a/Gui/AddApplicant.qml b/Gui/AddApplicant.qml index 142275f..c8ab042 100644 --- a/Gui/AddApplicant.qml +++ b/Gui/AddApplicant.qml @@ -8,6 +8,9 @@ ColumnLayout { id: colPar anchors.fill: parent + Layout.fillWidth: true + Layout.fillHeight: true + implicitWidth: parent.width Label { Layout.alignment: Qt.AlignHCenter | Qt.AlignTop @@ -29,7 +32,7 @@ ColumnLayout { Layout.fillWidth: true id: radio - Layout.columnSpan: 2 + //Layout.columnSpan: 2 RadioButton { checked: true @@ -40,15 +43,30 @@ ColumnLayout text: qsTr("Mitarbeiter") } } + + // ScrollView + // { + // Layout.fillHeight: true + // Layout.fillWidth: true + // implicitWidth: parent.width + + // ColumnLayout + // { + // anchors.fill: parent + // //implicitWidth: parent.width + // //width: parent.width + // //height: parent.height RowLayout { Layout.fillWidth: true + //implicitWidth: parent.width spacing: 50 Frame { Layout.alignment: Qt.AlignTop Layout.fillWidth: true + //implicitWidth: parent.width ApplicantPersonalData { id: personalData @@ -64,7 +82,7 @@ ColumnLayout ColumnLayout { Layout.alignment: Qt.AlignTop - width: parent.width + implicitWidth: parent.width ApplicantBankData { @@ -84,9 +102,14 @@ ColumnLayout } } - RowLayout + Item { Layout.fillHeight: true + } + + RowLayout + { + Layout.fillWidth: true Layout.alignment: Qt.AlignRight Button { @@ -105,7 +128,7 @@ ColumnLayout { // Ein Bewerber new_applicant = JsLib.parseForm(personalData) - employee_model.addEmployee(new_applicant, false) + employee_model.addEmployee(new_applicant, true) // appLoader.source = "EmployeeTable.qml" // console.log(JSON.stringify (new_applicant)) } @@ -114,7 +137,7 @@ ColumnLayout // Ein Mitarbeiter // console.log(personalData, bankAccount, nationalInsurance, applicantVarious) new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious) - employee_model.addEmployee(new_applicant, true) + employee_model.addEmployee(new_applicant, false) // var new_contact = JsLib.addApplicant(addContactLayout) // contact_model.addContact(new_contact) // console.log(JSON.stringify (new_applicant)) @@ -122,10 +145,9 @@ ColumnLayout } } } - Item - { - Layout.fillHeight: true - } +// } +// } // ScrollView + function checkFields() { if(radio.children[1].checked) diff --git a/Gui/ApplicantNationalInsurance.qml b/Gui/ApplicantNationalInsurance.qml index c2e79ce..5cad9d0 100644 --- a/Gui/ApplicantNationalInsurance.qml +++ b/Gui/ApplicantNationalInsurance.qml @@ -114,6 +114,19 @@ GridLayout property string name: "idexpiry" id: idexpiry Layout.fillWidth: true + validator: RegularExpressionValidator + { + regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ + } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = idexpiry.length + var bd = idexpiry.text + if (len === 2 || len === 5) idexpiry.text = bd + "." + } + } } Label { @@ -137,6 +150,19 @@ GridLayout property string name: "idissued" id: idissued Layout.fillWidth: true + validator: RegularExpressionValidator + { + regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ + } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = idissued.length + var bd = idissued.text + if (len === 2 || len === 5) idissued.text = bd + "." + } + } } CheckBox { @@ -191,6 +217,19 @@ GridLayout id: residenceissued visible: residencetype.checked Layout.fillWidth: true + validator: RegularExpressionValidator + { + regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ + } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = residenceissued.length + var bd = residenceissued.text + if (len === 2 || len === 5) residenceissued.text = bd + "." + } + } } Label { @@ -204,6 +243,19 @@ GridLayout id: residenceexpiry visible: residencetype.checked Layout.fillWidth: true + validator: RegularExpressionValidator + { + regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ + } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = residenceexpiry.length + var bd = residenceexpiry.text + if (len === 2 || len === 5) residenceexpiry.text = bd + "." + } + } } } diff --git a/Gui/ApplicantPersonalData.qml b/Gui/ApplicantPersonalData.qml index df19d65..6a944a3 100644 --- a/Gui/ApplicantPersonalData.qml +++ b/Gui/ApplicantPersonalData.qml @@ -6,7 +6,6 @@ GridLayout { id: personalData columns: 4 - Label { text: qsTr("Anrede") @@ -336,6 +335,15 @@ GridLayout { regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = contractstart.length + var bd = contractstart.text + if (len === 2 || len === 5) contractstart.text = bd + "." + } + } } Label { @@ -356,6 +364,15 @@ GridLayout { regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ } + Keys.onPressed: (event)=> + { + if (event.key !== Qt.Key_Backspace) + { + var len = contractend.length + var bd = contractend.text + if (len === 2 || len === 5) contractend.text = bd + "." + } + } } Label { diff --git a/Gui/CustomersTable.qml b/Gui/CustomersTable.qml index 3746ced..af7d8fc 100644 --- a/Gui/CustomersTable.qml +++ b/Gui/CustomersTable.qml @@ -101,16 +101,17 @@ Item id: customerTable Layout.fillHeight: true Layout.fillWidth: true - ScrollBar.vertical: ScrollBar - { - policy: customerTable.contentHeight > customerTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff - } columnSpacing: 1 rowSpacing: 2 model: business_model alternatingRows: true resizableColumns: true selectionBehavior: TableView.SelectRows + ScrollBar.vertical: ScrollBar + { + policy: customerTable.contentHeight > customerTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff + } + selectionModel: ItemSelectionModel { id: selModel diff --git a/Gui/EmployeeDetails.qml b/Gui/EmployeeDetails.qml index fe1b8ba..c310f7d 100644 --- a/Gui/EmployeeDetails.qml +++ b/Gui/EmployeeDetails.qml @@ -22,6 +22,6 @@ Item Component.onCompleted: { - business_model.onRowClicked(selectedEmployee) + employee_model.onRowClicked(selectedEmployee) } } diff --git a/Gui/EmployeesTable.qml b/Gui/EmployeesTable.qml index e96b34c..7acfef7 100644 --- a/Gui/EmployeesTable.qml +++ b/Gui/EmployeesTable.qml @@ -23,6 +23,16 @@ Item onClicked: appLoader.source = "AddApplicant.qml" } + ButtonGroup + { + id: criterion + // buttons: criterion.children + onClicked: + { + viewEmployees(criterion.checkedButton.text) + } + } + ColumnLayout { anchors @@ -32,50 +42,74 @@ Item bottom: parent.bottom left: parent.left right: parent.right - } RowLayout { + //id: criterion RadioButton { - + //id: showAll checked: true text: qsTr("Alle") + ButtonGroup.group: criterion + //onClicked: viewEmployees(showAll) } RadioButton { - + //id: showApplicant text: qsTr("Bewerber") + ButtonGroup.group: criterion + //onClicked: viewEmployees(showApplicant) } RadioButton { - + //id: showEmployee text: qsTr("Mitarbeiter") + ButtonGroup.group: criterion + //onClicked: viewEmployees(showEmployee) } - RadioButton + CheckBox { - + id: showProcessed text: qsTr("Erledigt") + onClicked: viewEmployees(criterion.checkedButton.text) } - RadioButton + CheckBox { - + id: showFired text: qsTr("Ausgeschieden") + onClicked: viewEmployees(criterion.checkedButton.text) } } HorizontalHeaderView { - id: horizontalHeader + id: employeeTableHeader Layout.fillWidth: true syncView: appliEmpTable implicitHeight: 40 - visible: false movableColumns: true //@disable-check M16 - + delegate: Rectangle + { + color: addEmployeeBtn.palette.alternateBase + border.color: palette.base + implicitHeight: 40 + Layout.fillWidth: true + implicitWidth: 1 + Text + { + text: model.display + elide: Text.ElideRight + width: parent.width + height: parent.height + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + color: palette.text + } + } } TableView @@ -85,6 +119,8 @@ Item Layout.fillWidth: true columnSpacing: 1 rowSpacing: 2 + alternatingRows: true + resizableColumns: true model: employee_model selectionBehavior: TableView.SelectRows @@ -104,13 +140,13 @@ Item { required property bool selected required property bool current - //implicitWidth: 200 + implicitWidth: appliEmpTable.width / appliEmpTable.columns implicitHeight: 25 color: selected - ? palette.highlight //palette.highlight - : (objectTable.alternatingRows && row % 2 !== 0 - ? palette.base // palette.base - : palette.alternateBase) //palette.alternateBase) + ? addEmployeeBtn.palette.highlight //palette.highlight + : (appliEmpTable.alternatingRows && row % 2 !== 0 + ? addEmployeeBtn.palette.base // palette.base + : addEmployeeBtn.palette.alternateBase) //palette.alternateBase) Text { @@ -152,5 +188,9 @@ Item } } + function viewEmployees(criterion) + { + employee_model.viewCriterion(criterion, showProcessed.checked, showFired.checked) + } Component.onCompleted: employeesStack.pop() } diff --git a/Gui/main.qml b/Gui/main.qml index bd3f55e..2e85370 100644 --- a/Gui/main.qml +++ b/Gui/main.qml @@ -44,6 +44,7 @@ ApplicationWindow Loader { id: appLoader + anchors { left: parent.left diff --git a/lib/DB/BusinessModel.py b/lib/DB/BusinessModel.py index 3cd908d..36b188d 100644 --- a/lib/DB/BusinessModel.py +++ b/lib/DB/BusinessModel.py @@ -105,7 +105,7 @@ class BusinessModel(QAbstractTableModel): def columnCount(self, parent= QModelIndex()): return len(self.__visible_columns) - 1 - def data(self, index, role= Qt.DisplayRole): + def data(self, index, role = Qt.DisplayRole): if role == Qt.DisplayRole: row = self.__data[index.row()] return row[index.column() + 1] @@ -132,6 +132,7 @@ class BusinessModel(QAbstractTableModel): @Slot(int) def onRowClicked(self, row): + #print(self.__data) #print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}") if not self.__business_dict['business'] or self.__data[row][0] != self.__business_dict['business']['id']: self.__business = self.__business_dao.getOneBusiness(self.__data[row][0], self.__key) diff --git a/lib/DB/EmployeeDAO.py b/lib/DB/EmployeeDAO.py index 263ddeb..b38335c 100644 --- a/lib/DB/EmployeeDAO.py +++ b/lib/DB/EmployeeDAO.py @@ -17,16 +17,10 @@ class EmployeeDAO(QObject): if self.__con: self.__cur = self.__con.cursor() - def getEmployees(self, enc_key, criterion = "Alle", appli_emp = 0, processed = False): - ''' - appli_emp: - 0 = applicants and employees - 1 = applicants only - 2 = employees only - ''' + def getEmployees(self, enc_key, criterion = "Alle", processed = False, fired = False): try: if self.__cur: - self.__cur.callproc("getEmployeesView", (appli_emp, processed, criterion, enc_key, )) + self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, enc_key, )) self.__all_cols = [desc[0] for desc in self.__cur.description] return self.__cur.fetchall(), self.__all_cols else: @@ -45,10 +39,10 @@ class EmployeeDAO(QObject): except mariadb.Error as e: print(str(e)) - def addEmployee(self, data, enc_key, employee = False): + def addEmployee(self, data, enc_key, applicant = True): try: if self.__cur: - self.__cur.callproc("addApplicant", (json.dumps(data), employee, enc_key,)) + self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,)) self.__con.commit() self.newEmployeeAdded.emit() diff --git a/lib/DB/EmployeeModel.py b/lib/DB/EmployeeModel.py index 696b47b..7620773 100644 --- a/lib/DB/EmployeeModel.py +++ b/lib/DB/EmployeeModel.py @@ -21,21 +21,22 @@ class EmployeeModel(QAbstractTableModel): self.__getData() @Slot(dict, bool) - def addEmployee(self, new_employee, employee = False): - print(new_employee) - self.__employee_dao.addEmployee(new_employee, self.__key, employee) + def addEmployee(self, new_employee, applicant = True): + new_employee['worklicense'] = int(new_employee['worklicense']) + new_employee['residencetype'] = int(new_employee['residencetype']) + self.__employee_dao.addEmployee(new_employee, self.__key, applicant) @Slot(str) - def viewCriterion(self, criterion): - self.__getData(criterion) + def viewCriterion(self, criterion, processed = False, fired = False): + self.__getData(criterion, processed, fired) @Slot() def __refreshView(self): self.__getData() - def __getData(self, criterion = "Alle", processed = False): + def __getData(self, criterion = "Alle", processed = False, fired = False): self.beginResetModel() - rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, 0, processed) + rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, processed, fired) self.__data = rows self.endResetModel() @@ -45,14 +46,32 @@ class EmployeeModel(QAbstractTableModel): def columnCount(self, parent= QModelIndex()): return len(self.__visible_columns) - 2 + @Slot(str, bool, bool) + def viewCriterion(self, criterion, processed, fired): + self.__getData(criterion, processed, fired) + def data(self, index, role= Qt.DisplayRole): if role == Qt.DisplayRole: row = self.__data[index.row()] - return row[index.column() + 2] + tr = row[index.column() + 2] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8") + #print(f"Data: {tr}") + # return row[index.column() + 2] + return tr return None - def headerData(self, section, orientation, role= Qt.DisplayRole): - if orientation == Qt.Horizontal and role ==Qt.DisplayRole: + def headerData(self, section, orientation, role = Qt.DisplayRole): + if orientation == Qt.Horizontal and role == Qt.DisplayRole: self.__col_name = self.__visible_columns[section + 2] return self.__col_name return super().headerData(section, orientation, role) + + @Slot(int) + def onRowClicked(self, row): + #print(self.__data) + print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}") + #if not self.__employee_dict['employee'] or self.__data[row][0] != self.__employee_dict['employee']['id']: + #self.__employee = self.__employee_dao.getEmployee(self.__data[row][0], self.__key) + #print(self.__business) + #self.__getEmployeeInfo() + # self.__getContactInfo() + # print(self.__business_dict)