1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Return the svg field in shape API

Ref #498
This commit is contained in:
Julien Duponchelle 2016-06-21 12:19:12 +02:00
parent 51dbe59e99
commit 4f78efa0c8
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 33 additions and 10 deletions

View File

@ -24,8 +24,8 @@ class Shape:
Shape are visual element not used by the network emulation. Like Shape are visual element not used by the network emulation. Like
text, images, rectangle... They are pure SVG elements. text, images, rectangle... They are pure SVG elements.
""" """
def __init__(self, project, shape_id=None, svg=None, x=0, y=0, z=0): def __init__(self, project, shape_id=None, svg="<svg></svg>", x=0, y=0, z=0):
self.svg = "<svg></svg>" self.svg = svg
self._project = project self._project = project
if shape_id is None: if shape_id is None:
self._id = str(uuid.uuid4()) self._id = str(uuid.uuid4())
@ -74,9 +74,9 @@ class Shape:
@asyncio.coroutine @asyncio.coroutine
def update(self, **kwargs): def update(self, **kwargs):
""" """
Update the node on the compute server Update the shape
:param kwargs: Node properties :param kwargs: Shape properties
""" """
# Update node properties with additional elements # Update node properties with additional elements
@ -96,6 +96,7 @@ class Shape:
"x": self._x, "x": self._x,
"y": self._y, "y": self._y,
"z": self._z, "z": self._z,
"svg": self._svg
} }
return { return {
"project_id": self._project.id, "project_id": self._project.id,
@ -103,6 +104,7 @@ class Shape:
"x": self._x, "x": self._x,
"y": self._y, "y": self._y,
"z": self._z, "z": self._z,
"svg": self._svg
} }
def __repr__(self): def __repr__(self):

View File

@ -26,7 +26,7 @@ in futur GNS3 versions.
<table border="1"> <table border="1">
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>ID</td> <th>ID</th>
<th>Compute</th> <th>Compute</th>
<th>Console</th> <th>Console</th>
</tr> </tr>
@ -43,9 +43,9 @@ in futur GNS3 versions.
<h2>Links</h2> <h2>Links</h2>
<table border="1"> <table border="1">
<tr> <tr>
<th>ID</td> <th>ID</th>
<th>Capture</td> <th>Capture</th>
<th>PCAP</td> <th>PCAP</th>
</tr> </tr>
{% for link in project.links.values() %} {% for link in project.links.values() %}
<tr> <tr>
@ -56,6 +56,25 @@ in futur GNS3 versions.
{% endfor %} {% endfor %}
</table> </table>
<h2>Shapes</h2>
<table border="1">
<tr>
<th>ID</th>
<th>Position</th>
<th>Content</th>
</tr>
{% for shape in project.shapes.values() %}
<tr>
<td>{{shape.id}}</td>
<td>{{shape.x}}, {{shape.y}}, {{shape.z}}</td>
<td>{{shape.svg}}</td>
</tr>
{% endfor %}
</table>
<h2>Notifications</h2> <h2>Notifications</h2>
<div id="notifications"> <div id="notifications">
</div> </div>

View File

@ -54,13 +54,15 @@ def test_json(project):
"project_id": project.id, "project_id": project.id,
"x": i.x, "x": i.x,
"y": i.y, "y": i.y,
"z": i.z "z": i.z,
"svg": i.svg
} }
assert i.__json__(topology_dump=True) == { assert i.__json__(topology_dump=True) == {
"shape_id": i.id, "shape_id": i.id,
"x": i.x, "x": i.x,
"y": i.y, "y": i.y,
"z": i.z "z": i.z,
"svg": i.svg
} }