diff --git a/src/ui/userInterface.py b/src/ui/userInterface.py index f43dc32..57793cb 100644 --- a/src/ui/userInterface.py +++ b/src/ui/userInterface.py @@ -13,7 +13,6 @@ from omegaconf import OmegaConf from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6.QtCore import QDate, QThread from PyQt6.QtGui import QRegularExpressionValidator -import yaml from src import Icon from src.backend import ( @@ -126,6 +125,7 @@ class Ui(Ui_Semesterapparat): # Actions self.actionEinstellungen.triggered.connect(self.open_settings) + Icon("settings", self.actionEinstellungen) self.actionDokumentation.triggered.connect(self.open_documentation) Icon("offAction", self.actionBeenden) self.actionBeenden.triggered.connect(self.quit) @@ -525,7 +525,7 @@ class Ui(Ui_Semesterapparat): try: self.elsa_statistics.removeTab(1) except: - pass + self.logger.log_debug("No tab to remove") self.elsa_table.setRowCount(0) elsa_apparats = self.db.getElsaApparats() elsa_apparats = natsorted(elsa_apparats, key=lambda x: x[2], reverse=True) @@ -1627,7 +1627,7 @@ class Ui(Ui_Semesterapparat): if self.check_send_mail.isChecked(): self.contact_prof( - apparat=appd.appnr, mail="Information zum Semesterapparat" + apparat=appd.appnr, mail="Information zum Semesterapparat", location="" ) if clear_fields: self.__clear_fields() @@ -1712,8 +1712,14 @@ class Ui(Ui_Semesterapparat): remind_action = menu.addAction("Erinnerung") menu.addAction(extend_action) menu.addActions([contact_action, delete_action, remind_action]) + # convert point to row and column + row = self.tableWidget_apparate.rowAt(position.y()) + column = self.tableWidget_apparate.columnAt(position.x()) + pos = (str(row), str(column)) + ic(pos) extend_action.triggered.connect(self.extend_apparat) - delete_action.triggered.connect(self.delete_apparat) + delete_action.triggered.connect(lambda: self.delete_apparat(pos)) + # pass pos to contact_prof contact_action.triggered.connect(self.contact_prof) remind_action.triggered.connect(self.reminder) menu.exec(self.tableWidget_apparate.mapToGlobal(position)) @@ -1858,7 +1864,7 @@ class Ui(Ui_Semesterapparat): if state == 1: self.db.deleteBook(book_id) self.update_app_media_list() - self.contact_prof(mail="deleted") + self.contact_prof(mail="deleted", location="") pass else: # get all selected rows @@ -1903,8 +1909,46 @@ class Ui(Ui_Semesterapparat): else: return - def contact_prof(self, apparat=None, mail=""): + def __get_table_data_field(self, table, row, column): + ic(row, column) + row = int(row) + return table.item(row, column).text() + + def __contact_dialog(self, apparat, location: tuple | str, mail=None, pid=""): + ic(location, pid) + + active_apparat_id = ( + self.drpdwn_app_nr.currentText() if apparat is None else apparat + ) + print(active_apparat_id) + + profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ") + profname = f"{profname[1]} {profname[0]}" + # get the row of the clicked cell + prof_id = self.db.getProfId(pid) + if profname == "Name Kein": + profname = pid + + profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}" + if prof_id: + pmail = self.db.getSpecificProfData(prof_id, ["mail"]) + else: + pmail = self.prof_mail.text() + # create a new thread to show the mail interface and send the mail + print("showing mail dialog") + self.mail_thread = Mail_Dialog( + app_id=active_apparat_id, + prof_name=pid, + prof_mail=pmail, + app_name=self.app_name.text(), + app_subject=self.app_fach.currentText(), + default_mail=mail if mail != "" else "Information zum Semesterapparat", + ) + self.mail_thread.show() + + def contact_prof(self, location="", apparat=None, mail="", pid=""): print(apparat) + print("location", location) if self.active_apparat == "": if apparat is False: self.confirm_popup( @@ -1912,35 +1956,18 @@ class Ui(Ui_Semesterapparat): ) return else: - # TODO: stuff - pass + self.__contact_dialog(apparat, location, mail, pid=pid) else: - if apparat: - active_apparat_id = apparat - else: - active_apparat_id = self.drpdwn_app_nr.currentText() - print(active_apparat_id) - profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ") - profname = f"{profname[1]} {profname[0]}" - prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) - pmail = self.db.getSpecificProfData(prof_id, ["mail"]) - # create a new thread to show the mail interface and send the mail - self.mail_thread = Mail_Dialog( - app_id=active_apparat_id, - prof_name=profname, - prof_mail=pmail, - app_name=self.app_name.text(), - app_subject=self.app_fach.currentText(), - ) - self.mail_thread.show() + self.__contact_dialog(apparat, mail=mail, pid=pid, location=location) - def delete_apparat(self): + def delete_apparat(self, position): selected_apparat_id = self.tableWidget_apparate.item( self.tableWidget_apparate.currentRow(), 0 ).text() message = f"Soll der Apparat {selected_apparat_id} wirklich gelöscht werden?" - state = self.confirm_popup(message) + state = self.confirm_popup(message, title="Löschen?") print(state) + pid = self.__get_table_data_field(self.tableWidget_apparate, position[0], 2) if state == 1: self.db.deleteApparat(selected_apparat_id, generateSemesterByDate()) # delete the corresponding entry from self.apparats @@ -1953,7 +1980,7 @@ class Ui(Ui_Semesterapparat): # remove the row from the table self.tableWidget_apparate.removeRow(self.tableWidget_apparate.currentRow()) # send mail to prof - self.contact_prof(mail="deleted", apparat=selected_apparat_id) + self.contact_prof(mail="deleted", apparat=selected_apparat_id, pid=pid) # if state==QtWidgets.QDialog.DialogCode.Accepted: # self.db.delete_apparat(selected_apparat_id) # pass