mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-15 21:08:55 +00:00
Send SVG in shape update only when change
This commit is contained in:
parent
03e9eac55b
commit
bc613e9fd8
@ -89,10 +89,17 @@ class Shape:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Update node properties with additional elements
|
# Update node properties with additional elements
|
||||||
|
svg_changed = False
|
||||||
for prop in kwargs:
|
for prop in kwargs:
|
||||||
if getattr(self, prop) != kwargs[prop]:
|
if getattr(self, prop) != kwargs[prop]:
|
||||||
|
if prop == "svg":
|
||||||
|
# To avoid spamming client with large data we don't send the svg if the SVG didn't change
|
||||||
|
svg_changed = True
|
||||||
setattr(self, prop, kwargs[prop])
|
setattr(self, prop, kwargs[prop])
|
||||||
self._project.controller.notification.emit("shape.updated", self.__json__())
|
data = self.__json__()
|
||||||
|
if not svg_changed:
|
||||||
|
del data["svg"]
|
||||||
|
self._project.controller.notification.emit("shape.updated", data)
|
||||||
self._project.dump()
|
self._project.dump()
|
||||||
|
|
||||||
def __json__(self, topology_dump=False):
|
def __json__(self, topology_dump=False):
|
||||||
|
@ -56,7 +56,7 @@ SHAPE_OBJECT_SCHEMA = {
|
|||||||
"svg": {
|
"svg": {
|
||||||
"description": "SVG content of the shape",
|
"description": "SVG content of the shape",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"pattern": "^<.+>$"
|
"pattern": "^<(.|[\r\n])+>$"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False
|
"additionalProperties": False
|
||||||
|
@ -72,7 +72,21 @@ def test_update(shape, project, async_run, controller):
|
|||||||
controller._notification = AsyncioMagicMock()
|
controller._notification = AsyncioMagicMock()
|
||||||
project.dump = MagicMock()
|
project.dump = MagicMock()
|
||||||
|
|
||||||
async_run(shape.update(x=42))
|
async_run(shape.update(x=42, svg="<svg><rect></rect></svg>"))
|
||||||
assert shape.x == 42
|
assert shape.x == 42
|
||||||
controller._notification.emit.assert_called_with("shape.updated", shape.__json__())
|
args, kwargs = controller._notification.emit.call_args
|
||||||
|
assert args[0] == "shape.updated"
|
||||||
|
# JSON
|
||||||
|
assert args[1]["x"] == 42
|
||||||
|
assert args[1]["svg"] == "<svg><rect></rect></svg>"
|
||||||
|
|
||||||
|
async_run(shape.update(x=12, svg="<svg><rect></rect></svg>"))
|
||||||
|
assert shape.x == 12
|
||||||
|
args, kwargs = controller._notification.emit.call_args
|
||||||
|
assert args[0] == "shape.updated"
|
||||||
|
# JSON
|
||||||
|
assert args[1]["x"] == 12
|
||||||
|
# To avoid spamming client with large data we don't send the svg if the SVG didn't change
|
||||||
|
assert "svg" not in args[1]
|
||||||
|
|
||||||
assert project.dump.called
|
assert project.dump.called
|
||||||
|
Loading…
Reference in New Issue
Block a user