Commit 58428edb authored by Lysander Trischler's avatar Lysander Trischler
Browse files

Add event descriptions in WebSocket support

parent 9d426488
......@@ -50,4 +50,3 @@ https://stackoverflow.com/questions/3363190/qt-qtableview-how-to-have-a-checkbox
Websocket
* camelCase-Bezeichner
* Aktion-/Dienstbeschreibungen
......@@ -510,6 +510,7 @@ class Event(isobeef.core.Object):
# all signals are documented in the class docstring above
eventChanged = signal()
nameChanged = signal()
descriptionChanged = signal()
timeOfDayChanged = signal()
custodianAdded = signal(Custodian)
custodianRemoved = signal(Custodian)
......@@ -548,6 +549,7 @@ class Event(isobeef.core.Object):
"""
self.description = description
self.descriptionChanged.emit()
self.eventChanged.emit()
......
......@@ -24,6 +24,7 @@ class WebSocketSupport(QObject):
self.dayEventAddedSlots = {}
self.dayEventRemovedSlots = {}
self.eventNameChangedSlots = {}
self._eventDescriptionChangedSlots = {}
self.eventTimeOfDayChangedSlots = {}
self.eventCustodianAddedSlots = {}
self.eventCustodianRemovedSlots = {}
......@@ -37,6 +38,7 @@ class WebSocketSupport(QObject):
self.dayEventAddedSlots = {}
self.dayEventRemovedSlots = {}
self.eventNameChangedSlots = {}
self._eventDescriptionChangedSlots = {}
self.eventTimeOfDayChangedSlots = {}
self.eventCustodianAddedSlots = {}
self.eventCustodianRemovedSlots = {}
......@@ -97,6 +99,10 @@ class WebSocketSupport(QObject):
event.nameChanged.disconnect(nameChangedSlot)
self.eventNameChangedSlots = {}
for event, descriptionChangedSlot in self._eventDescriptionChangedSlots.items():
event.descriptionChanged.disconnect(descriptionChangedSlot)
self._eventDescriptionChangedSlots = {}
for event, timeOfDayChangedSlot in self.eventTimeOfDayChangedSlots.items():
event.timeOfDayChanged.disconnect(timeOfDayChangedSlot)
self.eventTimeOfDayChangedSlots = {}
......@@ -131,6 +137,16 @@ class WebSocketSupport(QObject):
self.eventNameChangedSlots[event] = nameChangedSlot
event.nameChanged.connect(nameChangedSlot)
def descriptionChanged(event):
def handler():
self.send('PUT', '/api/v1/events/%s' % self.eventIDs[event],
{u'description': unicode(event.description) if event.description is not None else None})
return handler
descriptionChangedSlot = descriptionChanged(event)
self._eventDescriptionChangedSlots[event] = descriptionChangedSlot
event.descriptionChanged.connect(descriptionChangedSlot)
def timeOfDayChanged(event):
def handler():
self.send('PUT', '/api/v1/events/%s' % self.eventIDs[event],
......@@ -158,6 +174,7 @@ class WebSocketSupport(QObject):
def _disconnectEvent(self, event):
event.nameChanged.disconnect(self.eventNameChangedSlots.pop(event))
event.descriptionChanged.disconnect(self._eventDescriptionChangedSlots.pop(event))
event.timeOfDayChanged.disconnect(self.eventTimeOfDayChangedSlots.pop(event))
event.custodianAdded.disconnect(self.eventCustodianAddedSlots.pop(event))
event.custodianRemoved.disconnect(self.eventCustodianRemovedSlots.pop(event))
......@@ -207,6 +224,7 @@ class WebSocketSupport(QObject):
u'time_of_day': self.timeOfDayIDs[event.timeOfDay] if event.timeOfDay is not None else None,
u'type': u'service' if isinstance(event, Service) else u'action',
u'name': unicode(event.name) if event.name is not None else None,
u'description': unicode(event.description) if event.description is not None else None,
u'custodians': [self.custodianIDs[c] for c in event.custodians]}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment