diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py
index e5a17bfa9..e0f24cfe7 100644
--- a/netbox/extras/api/serializers.py
+++ b/netbox/extras/api/serializers.py
@@ -5,10 +5,14 @@ from extras.models import Graph
class GraphSerializer(serializers.ModelSerializer):
embed_url = serializers.SerializerMethodField()
+ embed_link = serializers.SerializerMethodField()
class Meta:
model = Graph
- fields = ['name', 'embed_url', 'link']
+ fields = ['name', 'embed_url', 'embed_link']
def get_embed_url(self, obj):
return obj.embed_url(self.context['graphed_object'])
+
+ def get_embed_link(self, obj):
+ return obj.embed_link(self.context['graphed_object'])
diff --git a/netbox/extras/models.py b/netbox/extras/models.py
index 7c1ed0913..229debfd6 100644
--- a/netbox/extras/models.py
+++ b/netbox/extras/models.py
@@ -56,6 +56,12 @@ class Graph(models.Model):
template = Template(self.source)
return template.render(Context({'obj': obj}))
+ def embed_link(self, obj):
+ if self.link is None:
+ return ''
+ template = Template(self.link)
+ return template.render(Context({'obj': obj}))
+
class ExportTemplate(models.Model):
content_type = models.ForeignKey(ContentType, limit_choices_to={'model__in': EXPORTTEMPLATE_MODELS})
diff --git a/netbox/project-static/js/graphs.js b/netbox/project-static/js/graphs.js
new file mode 100644
index 000000000..4405c2903
--- /dev/null
+++ b/netbox/project-static/js/graphs.js
@@ -0,0 +1,26 @@
+$('#graphs_modal').on('show.bs.modal', function (event) {
+ var button = $(event.relatedTarget);
+ var obj = button.data('obj');
+ var url = button.data('url');
+ var modal_title = $(this).find('.modal-title');
+ var modal_body = $(this).find('.modal-body');
+ modal_title.text(obj);
+ modal_body.empty();
+ $.ajax({
+ url: url,
+ dataType: 'json',
+ success: function(json) {
+ $.each(json, function(i, graph) {
+ // Build in a 500ms delay per graph to avoid hammering the server
+ setTimeout(function() {
+ modal_body.append('
' + graph.name + '
');
+ if (graph.embed_link) {
+ modal_body.append('
');
+ } else {
+ modal_body.append('
');
+ }
+ }, i*500);
+ })
+ }
+ });
+});
diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html
index 1261cfcc2..18658f593 100644
--- a/netbox/templates/dcim/device.html
+++ b/netbox/templates/dcim/device.html
@@ -396,32 +396,7 @@ $(".powerport-toggle").click(function() {
$(".interface-toggle").click(function() {
return toggleConnection($(this), "/api/dcim/interface-connections/");
});
-$('#graphs_modal').on('show.bs.modal', function (event) {
- var button = $(event.relatedTarget);
- var iface = button.data('interface');
- var iface_id = button.data('id');
- var modal_title = $(this).find('.modal-title');
- var modal_body = $(this).find('.modal-body');
- modal_title.text('{{ device.name }} - ' + iface);
- modal_body.empty();
- $.ajax({
- url: "/api/dcim/interfaces/" + iface_id + "/graphs/",
- dataType: 'json',
- success: function(json) {
- $.each(json, function(i, graph) {
- // Build in a 500ms delay per graph to avoid hammering the server
- setTimeout(function() {
- modal_body.append('' + graph.name + '
');
- if (graph.link) {
- modal_body.append('
');
- } else {
- modal_body.append('
');
- }
- }, i*500);
- })
- }
- });
-});
+
{% endblock %}
diff --git a/netbox/templates/dcim/inc/_interface.html b/netbox/templates/dcim/inc/_interface.html
index 9be170f0b..84af875e4 100644
--- a/netbox/templates/dcim/inc/_interface.html
+++ b/netbox/templates/dcim/inc/_interface.html
@@ -25,7 +25,7 @@
{% endif %}
{% if iface.circuit or iface.connection %}
- |