Merge branch 'main' into schnacke

merge main
This commit is contained in:
2025-03-12 10:25:38 +01:00
23 changed files with 275 additions and 63 deletions

1
.gitignore vendored
View File

@@ -228,3 +228,4 @@ cython_debug/
rc_*.py rc_*.py
.DS_STORE

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

14
.idea/discord.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="APPLICATION" />
<option name="description" value="" />
<option name="applicationTheme" value="default" />
<option name="iconsTheme" value="default" />
<option name="button1Title" value="" />
<option name="button1Url" value="" />
<option name="button2Title" value="" />
<option name="button2Url" value="" />
<option name="customApplicationId" value="" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (pyqcrm)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pyqcrm)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pyqcrm.iml" filepath="$PROJECT_DIR$/.idea/pyqcrm.iml" />
</modules>
</component>
</project>

10
.idea/pyqcrm.iml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12 (pyqcrm)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

45
.idea/watcherTasks.xml generated Normal file
View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="true">
<option name="arguments" value="-o rc_qml.py qml.qrc" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="qml" />
<option name="immediateSync" value="true" />
<option name="name" value="qml.qrc" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="$PROJECT_DIR$/.venv/bin/pyside6-rcc" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="$PROJECT_DIR$" />
<envs />
</TaskOptions>
<TaskOptions isEnabled="true">
<option name="arguments" value="-o rc_pyqcrm.py pyqcrm.qrc" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="qml" />
<option name="immediateSync" value="true" />
<option name="name" value="pyqcrm.qrc" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="$PROJECT_DIR$/.venv/bin/pyside6-rcc" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="$PROJECT_DIR$" />
<envs />
</TaskOptions>
</component>
</project>

View File

@@ -114,6 +114,7 @@ GridLayout
from: 1 from: 1
to: 100 to: 100
value: 1 value: 1
editable: true
} }
Label Label
@@ -130,6 +131,7 @@ GridLayout
from: 1 from: 1
to: 100 to: 100
value: 1 value: 1
editable: true
} }
// New grid row // New grid row
@@ -185,13 +187,11 @@ GridLayout
text: qsTr("Besonderheiten") text: qsTr("Besonderheiten")
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }
ComboBox TextField
{ {
property string name: "remarks" property string name: "remarks"
id: remarks id: remarks
Layout.fillWidth: true Layout.fillWidth: true
editable: false
textRole: "display"
} }
//// New grid row //// New grid row

View File

@@ -8,6 +8,7 @@ import "../js/qmldict.js" as JsLib
ColumnLayout ColumnLayout
{ {
property var new_object: null property var new_object: null
property alias checkAddContact: checkAddContact
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
spacing: 15 spacing: 15
@@ -74,18 +75,7 @@ ColumnLayout
new_object = JsLib.parseForm(newObject) new_object = JsLib.parseForm(newObject)
new_object['lift'] = new_object['lift'] === 'Ja' ? 1 : 0 new_object['lift'] = new_object['lift'] === 'Ja' ? 1 : 0
new_object['mezzanin'] = new_object['mezzanin'] === 'Ja' ? 1 : 0 new_object['mezzanin'] = new_object['mezzanin'] === 'Ja' ? 1 : 0
if (!checkAddContact.checked) object_model.addObject(new_object)
{
var list = []
object_model.addObject(new_object, list, false)
}
else
{
var new_objecto = addObjectLayout.getForm()
object_model.addObject(new_object, new_objecto, true)
}
} }
} }
} }
@@ -98,6 +88,7 @@ ColumnLayout
Component.onCompleted: Component.onCompleted:
{ {
object_model.objectAdded.connect(onObjectAdded) object_model.objectAdded.connect(onObjectAdded)
contact_model.objectContactAdded.connect(onObjectContact)
} }
// Connections // Connections
@@ -112,11 +103,27 @@ ColumnLayout
// } // }
// } // }
function onObjectAdded(added) function onObjectAdded(added, oid)
{ {
if (!added) if (!added)
console.log(qsTr("Fehler beim Objekt-Anlegen!")) console.log(qsTr("Fehler beim Objekt-Anlegen!"))
appLoader.source = "ObjectTable.qml" if (checkAddContact.checked && oid)
{
var new_objecto = addObjectLayout.getForm()
contact_model.addObjectContact(new_objecto, oid)
}
else appLoader.source = "ObjectTable.qml"
}
function onObjectContact(added)
{
if (!added)
console.log(qsTr("Fehler beim Objekt-Kontakt-Anlegen!"))
else
{
//object_model.viewCriterion("Alle")
appLoader.source = "ObjectTable.qml"
}
} }
function checkFields() function checkFields()

View File

@@ -5,7 +5,11 @@ import QtQuick.Layouts
GridLayout GridLayout
{ {
// property alias firstStart: firstStartGrid property alias dbHost: dbHost
property alias dbPort: dbPort
property alias dbName: dbName
property alias dbUserName: dbUserName
property alias dbPassword: dbPassword
id: dbGrid id: dbGrid
columns: 2 columns: 2
columnSpacing: 5 columnSpacing: 5
@@ -102,4 +106,17 @@ GridLayout
{ {
Layout.fillHeight: true Layout.fillHeight: true
} }
Component.onCompleted:
{
var db = config.getDbConf()
if (Object.keys(db).length)
{
dbHost.text = db['DB_HOST']
dbPort.text = db['DB_PORT']
dbName.text = db['DB_NAME']
dbUserName.text = db['DB_USER']
dbPassword.text = db['DB_PASS']
}
}
} }

View File

@@ -53,6 +53,7 @@ Item
font.pixelSize: 89 font.pixelSize: 89
font.bold: true font.bold: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
color: "yellow"
} }
Item Item

View File

@@ -9,17 +9,17 @@ GridLayout
Layout.fillWidth: true Layout.fillWidth: true
Label Label
{ {
text: qsTr("Kontaktdaten") text: qsTr("Position")
Layout.alignment: Qt.AlignRight | Qt.AlignTop Layout.alignment: Qt.AlignRight | Qt.AlignTop
} }
ComboBox ComboBox
{ {
//property string name: "contacttype" //property string name: "contacttype"
id: contacttype id: posizion
Layout.fillWidth: true Layout.fillWidth: true
editable: false editable: false
model: [qsTr("Beirat"), qsTr("Hausmeister")] model: [qsTr("Beirat"), qsTr("Hausmeister"), qsTr("Hausbewohner"), qsTr("Sonstiges")]
} }
Label Label
@@ -30,7 +30,7 @@ GridLayout
ComboBox ComboBox
{ {
id: title id: title
model: [qsTr("Herr"), qsTr("Frau"), qsTr("keine Angabe")] model: [qsTr("Herr"), qsTr("Frau"), qsTr("Keine Angabe")]
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -88,18 +88,18 @@ GridLayout
} }
Label // Label
{ // {
text: qsTr("Position") // text: qsTr("Position")
Layout.alignment: Qt.AlignRight // Layout.alignment: Qt.AlignRight
} // }
TextField // TextField
{ // {
id: posizion // id: posizion
Layout.fillWidth: true // Layout.fillWidth: true
placeholderText: "Pflichtfeld" // placeholderText: "Pflichtfeld"
placeholderTextColor: "red" // placeholderTextColor: "red"
} // }
RowLayout RowLayout
{ {
@@ -140,23 +140,22 @@ GridLayout
{ {
id: addContact id: addContact
text: qsTr("Hinzufügen") text: qsTr("Hinzufügen")
enabled: firstname.text.trim() && lastname.text.trim() && (phonenumber.text.trim() || mobile.text.trim()) && posizion.text.trim() && (contacts === null || Object.keys(contacts).length < 3) enabled: firstname.text.trim() && lastname.text.trim() && (phonenumber.text.trim() || mobile.text.trim()) && (contacts === null || Object.keys(contacts).length < 3)
onClicked: onClicked:
{ {
var num_contacts = 0 var num_contacts = 0
if (contacts !== null && contacts !== undefined) num_contacts = Object.keys(contacts).length if (contacts !== null && contacts !== undefined) num_contacts = Object.keys(contacts).length
else contacts = [] else contacts = []
if (num_contacts < 3 && firstname.text.trim() !== "" && lastname.text.trim() !== "" && (phonenumber.text.trim() !== "" || mobile.text.trim() !== "") && posizion.text.trim() !== "") if (num_contacts < 3 && firstname.text.trim() !== "" && lastname.text.trim() !== "" && (phonenumber.text.trim() !== "" || mobile.text.trim() !== ""))
{ {
contacts[num_contacts] = {} contacts[num_contacts] = {}
contacts[num_contacts]["title"] = title.currentText contacts[num_contacts]["title"] = title.currentText
contacts[num_contacts]["ctype"] = contacttype.currentText contacts[num_contacts]["position"] = posizion.currentText
contacts[num_contacts]["fname"] = firstname.text.trim() contacts[num_contacts]["fname"] = firstname.text.trim()
contacts[num_contacts]["lname"] = lastname.text.trim() contacts[num_contacts]["lname"] = lastname.text.trim()
contacts[num_contacts]["phone"] = phonenumber.text.trim() contacts[num_contacts]["phone"] = phonenumber.text.trim()
contacts[num_contacts]["mobile"] = mobile.text.trim() contacts[num_contacts]["mobile"] = mobile.text.trim()
contacts[num_contacts]["position"] = posizion.text.trim() contactModel.append({name: title.currentText + " " + firstname.text.trim() + " " + lastname.text.trim(), phone: phonenumber.text.trim(), mobile: mobile.text.trim(), posizion: posizion.currentText})
contactModel.append({name: title.currentText + " " + firstname.text.trim() + " " + lastname.text.trim(), phone: phonenumber.text.trim(), mobile: mobile.text.trim(), posizion: posizion.text.trim(), cdata: contacttype.currentText})
if (checkFields()) if (checkFields())
{ {
saveBtn.enabled = true saveBtn.enabled = true
@@ -165,7 +164,8 @@ GridLayout
lastname.text = "" lastname.text = ""
phonenumber.text = "" phonenumber.text = ""
mobile.text = "" mobile.text = ""
posizion.text = "" posizion.currentIndex = 0
title.currentIndex = 0
removeContact.enabled = true removeContact.enabled = true
checkFields() checkFields()
@@ -286,7 +286,7 @@ GridLayout
// header: headline // header: headline
highlight: Rectangle { color: "slategray"; radius: 3} highlight: Rectangle { color: "slategray"; radius: 3}
highlightFollowsCurrentItem: false highlightFollowsCurrentItem: false
//focus: true //focus: true test
onActiveFocusChanged: if(!focus) currentIndex = -1 onActiveFocusChanged: if(!focus) currentIndex = -1
delegate: Item delegate: Item
{ {

View File

@@ -142,5 +142,15 @@ Item
// object_model.viewCriterion(criterion.text) // object_model.viewCriterion(criterion.text)
// } // }
Component.onCompleted: objectsStack.pop() Component.onCompleted:
{
contact_model.objectContactAdded.connect(onObjectContactAdded)
objectsStack.pop()
}
function onObjectContactAdded(added)
{
console.log(added)
if (added) object_model.viewCriterion("")
}
} }

View File

@@ -112,7 +112,7 @@ Item
switch (confContainer.currentIndex) switch (confContainer.currentIndex)
{ {
case 1: case 1:
console.log("Need to update DB paramenters") updateDbConf()
break break
case 2: case 2:
@@ -128,6 +128,23 @@ Item
} }
} }
function updateDbConf()
{
var db = {}
db['database'] = {}
db['database']['DB_HOST'] = dbConf.dbHost.text.trim()
db['database']['DB_PORT'] = dbConf.dbPort.text.trim()
db['database']['DB_NAME'] = dbConf.dbName.text.trim()
db['database']['DB_USER'] = dbConf.dbUserName.text.trim()
db['database']['DB_PASS'] = dbConf.dbPassword.text.trim()
if (db['database']['DB_HOST'] === '' || db['database']['DB_PORT'] === '' ||
db['database']['DB_NAME'] === '' || db['database']['DB_USER'] === '' ||
db['database']['DB_PASS'] === '');
else config.saveDbConf(company)
}
function updateCompanyInfo() function updateCompanyInfo()
{ {
var company = {} var company = {}

View File

@@ -6,6 +6,7 @@ import QtCore
ApplicationWindow ApplicationWindow
{ {
//property alias appLoader: appLoader
id: appWindow id: appWindow
width: Screen.width * .75 width: Screen.width * .75
height: Screen.height * .85 height: Screen.height * .85
@@ -150,6 +151,15 @@ ApplicationWindow
} }
} }
onWindowStateChanged: (windowState) =>
{
if (windowState !== Qt.WindowMinimized)
{
systray.setVisible(false)
appWindow.show()
}
}
onClosing: (close) => onClosing: (close) =>
{ {
if (false) if (false)

View File

@@ -243,6 +243,19 @@ class ConfigLoader(QObject):
self.__saveData(filename, password, conf_file) self.__saveData(filename, password, conf_file)
@Slot(dict)
def saveDbConf(self, db = None):
self.__config.update(db)
self.__saveConfig()
@Slot(result = dict)
def getDbConf(self):
try:
return self.__config['database']
except KeyError as ex:
print(f"Missing database configuration: {ex}")
return None
@Slot(dict) @Slot(dict)
def saveCompanyInfo(self, company = None): def saveCompanyInfo(self, company = None):
self.__config.update(company) self.__config.update(company)

View File

@@ -1,10 +1,14 @@
from .DbManager import DbManager from .DbManager import DbManager
from PySide6.QtCore import QObject, Signal
import json import json
import mariadb import mariadb
class ContactDAO: class ContactDAO(QObject):
newObjectContactAdded = Signal(bool)
def __init__(self): def __init__(self):
super().__init__()
#print(f"*** File: {__file__}, __init__()") #print(f"*** File: {__file__}, __init__()")
self.__con = DbManager().getConnection() self.__con = DbManager().getConnection()
if self.__con: if self.__con:
@@ -18,18 +22,28 @@ class ContactDAO:
if self.__cur: if self.__cur:
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),)) self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
self.__con.commit() self.__con.commit()
self.__cur.callproc("getLastInsertId")
contact_id = self.__cur.fetchone()
self.__cur.callproc("logger",(contact_id[0], "INSERT", "addContactPerson: New Contact added",)) self.__cur.callproc("logger",(contact_id[0], "INSERT", "addContactPerson: New Contact added",))
self.__con.commit() self.__con.commit()
return contact_id[0]
else:
return None
except mariadb.Error as e: except mariadb.Error as e:
print("MDB: " + str(e)) print("MDB: " + str(e))
except Exception as e: except Exception as e:
print("PYT: " + str(e)) print("PYT: " + str(e))
def addObjectContact(self, contact, objectid, enc_key):
try:
if self.__cur:
self.__cur.callproc("addObjectContact", (enc_key, json.dumps(contact), objectid,))
self.__con.commit()
self.__cur.callproc("logObjectContact")
self.__con.commit()
self.newObjectContactAdded.emit(True)
except mariadb.Error as e:
print("MDB (addObjectContact): " + str(e))
self.newObjectContactAdded.emit(False)
except Exception as e:
print("PYT: " + str(e))
self.newObjectContactAdded.emit(False)
def getContact(self, contact_id, enc_key = None): def getContact(self, contact_id, enc_key = None):
try: try:
if self.__cur: if self.__cur:

View File

@@ -5,6 +5,7 @@ import logging
class ContactModel(QObject): class ContactModel(QObject):
contactIdReady = Signal(int) contactIdReady = Signal(int)
objectContactAdded = Signal(bool)
__contact = None __contact = None
__contact_dict = {'contact':{}} __contact_dict = {'contact':{}}
@@ -15,6 +16,8 @@ class ContactModel(QObject):
#self.logger = logging.getLogger() #self.logger = logging.getLogger()
self.__conf = ConfigLoader().getConfig() self.__conf = ConfigLoader().getConfig()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__contact_dao = ContactDAO()
self.__contact_dao.newObjectContactAdded.connect(self.objectContactAdded)
self.__data = self.__getData() self.__data = self.__getData()
def getContacts(self): def getContacts(self):
@@ -31,6 +34,11 @@ class ContactModel(QObject):
i = ContactDAO().addContact(contact, self.__key) i = ContactDAO().addContact(contact, self.__key)
self.contactIdReady.emit(i) self.contactIdReady.emit(i)
@Slot(dict, int)
def addObjectContact(self, contact, objectid):
ContactDAO().addObjectContact(contact, objectid, self.__key)
#self.contactIdReady.emit(i)
def __getContact(self, contact): def __getContact(self, contact):
self.__contact = ContactDAO().getContact(contact, self.__key) self.__contact = ContactDAO().getContact(contact, self.__key)
self.__getContactInfo() self.__getContactInfo()

View File

@@ -6,7 +6,7 @@ from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
class ObjectDAO(QObject): class ObjectDAO(QObject):
newObjectAdded = Signal(bool) newObjectAdded = Signal(bool, int)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@@ -15,12 +15,17 @@ class ObjectDAO(QObject):
if self.__con: if self.__con:
self.__cur = self.__con.cursor() self.__cur = self.__con.cursor()
def addObject(self, new_object, new_objcontact, enc_key): def addObject(self, new_object):
try: try:
if self.__cur: if self.__cur:
self.__cur.callproc("addObject", (json.dumps(new_object), json.dumps(new_objcontact), enc_key,)) self.__cur.callproc("addObject", (json.dumps(new_object),))
self.__con.commit() self.__con.commit()
self.newObjectAdded.emit(True) self.__cur.callproc("getLastInsertId")
object_id = self.__cur.fetchone()
self.newObjectAdded.emit(True, object_id[0])
return object_id[0]
else:
return None
except mariadb.Error as e: except mariadb.Error as e:
self.newObjectAdded.emit(False) self.newObjectAdded.emit(False)
print(str(e)) print(str(e))

View File

@@ -6,7 +6,7 @@ import re
import json import json
class ObjectModel(QAbstractTableModel): class ObjectModel(QAbstractTableModel):
objectAdded = Signal(bool) objectAdded = Signal(bool, int)
__data = None __data = None
__object_dao = None __object_dao = None
@@ -27,13 +27,11 @@ class ObjectModel(QAbstractTableModel):
self.__object_dao.newObjectAdded.connect(self.objectAdded) self.__object_dao.newObjectAdded.connect(self.objectAdded)
self.__getData() self.__getData()
@Slot(dict, list, bool) @Slot(dict)
def addObject(self, new_object, new_objcontact = None, new_contact = False): def addObject(self, new_object):
#print(new_object) #print(new_object)
print(new_objcontact) o = self.__object_dao.addObject(new_object)
#self.__object_dao.addObject(new_object, new_objcontact, self.__key)
# @Slot(str) # @Slot(str)
# def viewCriterion(self, criterion, processed = False, fired = False): # def viewCriterion(self, criterion, processed = False, fired = False):
@@ -57,15 +55,16 @@ class ObjectModel(QAbstractTableModel):
@Slot(str) @Slot(str)
def viewCriterion(self, criterion): def viewCriterion(self, criterion):
print(f"Criterion: {criterion}")
self.__getData(criterion) self.__getData(criterion)
def data(self, index, role= Qt.DisplayRole): def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
row = self.__data[index.row()] row = self.__data[index.row()]
applicant_col = index.column() + self.__col_skip object_col = index.column() + self.__col_skip
tr = row[applicant_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8") tr = row[object_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
#print(f"Data: {tr}") if object_col > 4 and tr:
# return row[index.column() + 2] tr = re.sub("Keine Angabe ","", tr)
return tr return tr
return None return None