fixed auth, added save-coords

This commit is contained in:
Mattijs Vanhaverbeke committed 2020-05-14 22:20:01 +02:00
1 parent a1d155fdbc
commit 5e53066ba7
12 files changed
+99 -41

No files matched your search

@@ -1 +1 @@
var graph=null,container=null,csrftoken=null,nodes=new vis.DataSet,edges=new vis.DataSet,options={interaction:{hover:!0,hoverConnectedEdges:!0,multiselect:!0},nodes:{shape:"image",brokenImage:"/static/netbox_topology_views/img/role-unknown.png",size:35,font:{multi:"md",face:"helvetica"}},edges:{length:100,width:2,font:{face:"helvetica"}},physics:{solver:"forceAtlas2Based"}};function iniPlotboxIndex(){document.addEventListener("DOMContentLoaded",function(){container=document.getElementById("visgraph"),csrftoken=jQuery("[name=csrfmiddlewaretoken]").val(),startLoadSearchBar(),handleButtonPress()},!1)}function startLoadSearchBar(){$("#device-roles").select2({allowClear:!0,placeholder:"---------",theme:"bootstrap",multiple:!0,ajax:{url:"/api/dcim/device-roles/?brief=true",dataType:"json",type:"GET",data:function(e){return{term:e.term}},processResults:function(e){return{results:$.map(e.results,function(e){return{text:e.name,id:e.id}})}}}}),$("#sites").select2({allowClear:!0,placeholder:"---------",theme:"bootstrap",multiple:!0,ajax:{url:"/api/dcim/sites/?brief=true",dataType:"json",type:"GET",data:function(e){return{term:e.term}},processResults:function(e){return{results:$.map(e.results,function(e){return{text:e.name,id:e.id}})}}}});var n=$("#device-roles");$.ajax({type:"GET",url:"/api/plugins/topology-views/preselectdeviceroles/"}).then(function(e){$.each(e.results,function(e,t){var a=new Option(t.name,t.id,!0,!0);n.append(a).trigger("change"),n.trigger({type:"select2:select",params:{data:t}})})})}function handleButtonPress(){$("#search-form").submit(function(e){$("#status").html('<span class="badge badge-pill badge-info">Loading data</span>'),e.preventDefault();var t=$("#name").val(),a=$("#device-roles").val(),n=$("#sites").val();$.ajax({type:"POST",url:"/api/plugins/topology-views/search/search/",data:JSON.stringify({name:t,devicerole:a,sites:n}),headers:{"X-CSRFToken":csrftoken},contentType:"application/json; charset=utf-8",dataType:"json",success:function(e){$("#status").html('<span class="badge badge-pill badge-info">Drawing network</span>'),graph=null,nodes=new vis.DataSet,edges=new vis.DataSet,graph=new vis.Network(container,{nodes:nodes,edges:edges},options),$.each(e.nodes,function(e,t){nodes.add(t)}),$.each(e.edges,function(e,t){edges.add(t)}),graph.fit(),graph.on("afterDrawing",function(){$("#status").html('<span class="badge badge-pill badge-success">Ready</span>')}),graph.on("dragEnd",function(e){dragged=this.getPositions(e.nodes),$.each(dragged,function(e,t){$("#coordstatus").html(""),$("#checkSaveCoordinates").is(":checked")&&(nodes.update({id:e,physics:!1}),$.ajax({url:"/api/save_coords",type:"POST",dataType:"json",headers:{"X-CSRFToken":csrftoken},contentType:"application/json; charset=utf-8",data:JSON.stringify({node_id:e,x:t.x,y:t.y}),error:function(e){$("#coordstatus").html('<span class="badge badge-pill badge-warning">Failed to update coordinates</span>')},success:function(e){$("#coordstatus").html('<span class="badge badge-pill badge-success">Updated coordinates</span>'),$.ajax({url:"/api/reload_devices",type:"GET",headers:{"X-CSRFToken":csrftoken},success:function(e){}})}}))})})},error:function(e){$("#status").html('<span class="badge badge-pill badge-warning">Something went wrong</span>')}})})}
var graph=null,container=null,csrftoken=null,nodes=new vis.DataSet,edges=new vis.DataSet,options={interaction:{hover:!0,hoverConnectedEdges:!0,multiselect:!0},nodes:{shape:"image",brokenImage:"../../static/netbox_topology_views/img/role-unknown.png",size:35,font:{multi:"md",face:"helvetica"}},edges:{length:100,width:2,font:{face:"helvetica"}},physics:{solver:"forceAtlas2Based"}};function iniPlotboxIndex(){document.addEventListener("DOMContentLoaded",function(){container=document.getElementById("visgraph"),csrftoken=jQuery("[name=csrfmiddlewaretoken]").val(),startLoadSearchBar(),handleButtonPress()},!1)}function startLoadSearchBar(){$("#device-roles").select2({allowClear:!0,placeholder:"---------",theme:"bootstrap",multiple:!0,ajax:{url:"../../api/dcim/device-roles/?brief=true",dataType:"json",type:"GET",data:function(e){return{term:e.term}},processResults:function(e){return{results:$.map(e.results,function(e){return{text:e.name,id:e.id}})}}}}),$("#sites").select2({allowClear:!0,placeholder:"---------",theme:"bootstrap",multiple:!0,ajax:{url:"../../api/dcim/sites/?brief=true",dataType:"json",type:"GET",data:function(e){return{term:e.term}},processResults:function(e){return{results:$.map(e.results,function(e){return{text:e.name,id:e.id}})}}}});var n=$("#device-roles");$.ajax({type:"GET",url:"../../api/plugins/topology-views/preselectdeviceroles/"}).then(function(e){$.each(e.results,function(e,t){var a=new Option(t.name,t.id,!0,!0);n.append(a).trigger("change"),n.trigger({type:"select2:select",params:{data:t}})})})}function handleButtonPress(){$("#search-form").submit(function(e){$("#status").html('<span class="label label-info">Loading data</span>'),e.preventDefault();var t=$("#name").val(),a=$("#device-roles").val(),n=$("#sites").val();$.ajax({type:"POST",url:"../../api/plugins/topology-views/search/search/",data:JSON.stringify({name:t,devicerole:a,sites:n}),headers:{"X-CSRFToken":csrftoken},contentType:"application/json; charset=utf-8",dataType:"json",success:function(e){$("#status").html('<span class="label label-info">Drawing network</span>'),graph=null,nodes=new vis.DataSet,edges=new vis.DataSet,graph=new vis.Network(container,{nodes:nodes,edges:edges},options),$.each(e.nodes,function(e,t){nodes.add(t)}),$.each(e.edges,function(e,t){edges.add(t)}),graph.fit(),graph.on("afterDrawing",function(){$("#status").html('<span class="label label-success">Ready</span>')}),graph.on("dragEnd",function(e){dragged=this.getPositions(e.nodes),$.each(dragged,function(e,t){$("#coordstatus").html(""),$("#checkSaveCoordinates").is(":checked")&&(nodes.update({id:e,physics:!1}),$.ajax({url:"../../api/plugins/topology-views/save-coords/save_coords/",type:"POST",dataType:"json",headers:{"X-CSRFToken":csrftoken},contentType:"application/json; charset=utf-8",data:JSON.stringify({node_id:e,x:t.x,y:t.y}),error:function(e){$("#coordstatus").html('<span class="label label-warning">Failed to update coordinates</span>')},success:function(e){$("#coordstatus").html('<span class="label label-success">Updated coordinates</span>')}}))})})},error:function(e){$("#status").html('<span class="label label-warning">Something went wrong</span>')}})})}
@@ -1 +1 @@
!function(t,g){"object"==typeof exports&&"undefined"!=typeof module?g(exports):"function"==typeof define&&define.amd?define(["exports"],g):g((t=t||self).vis=t.vis||{})}(this,function(t){"use strict";var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,g){return t(g={exports:{}},g.exports),g.exports}function A(t){return t&&t.default||t}function I(t){return t&&t.Math==Math&&t}function a(t){try{return!!t()}catch(t){return!0}}function y(t,g){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:g}}function C(t){return k.call(t).slice(8,-1)}function o(t){if(null==t)throw TypeError("Can't call method on "+t);return t}function r(t){return O(o(t))}function d(t){return"object"==typeof t?null!==t:"function"==typeof t}function i(t,g){if(!d(t))return t;var e,A;if(g&&"function"==typeof(e=t.toString)&&!d(A=e.call(t)))return A;if("function"==typeof(e=t.valueOf)&&!d(A=e.call(t)))return A;if(!g&&"function"==typeof(e=t.toString)&&!d(A=e.call(t)))return A;throw TypeError("Can't convert object to primitive value")}function f(t,g){return N.call(t,g)}function n(t){return Z?E.createElement(t):{}}function s(t,g){var e=S[R(t)];return e==L||e!=F&&("function"==typeof g?a(g):!!g)}function l(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}function m(A,I,t){if(l(A),void 0===I)return A;switch(t){case 0:return function(){return A.call(I)};case 1:return function(t){return A.call(I,t)};case 2:return function(t,g){return A.call(I,t,g)};case 3:return function(t,g,e){return A.call(I,t,g,e)}}return function(){return A.apply(I,arguments)}}function c(t){if(!d(t))throw TypeError(String(t)+" is not an object");return t}function p(A){function t(t,g,e){if(this instanceof A){switch(arguments.length){case 0:return new A;case 1:return new A(t);case 2:return new A(t,g)}return new A(t,g,e)}return A.apply(this,arguments)}return t.prototype=A.prototype,t}function b(t,g){var e,A,I,C,i,n,o,r,s=t.target,a=t.global,d=t.stat,l=t.proto,c=a?v:d?v[s]:(v[s]||{}).prototype,h=a?Y:Y[s]||(Y[s]={}),u=h.prototype;for(I in g)e=!Q(a?I:s+(d?".":"#")+I,t.forced)&&c&&f(c,I),i=h[I],e&&(n=t.noTargetGet?(r=P(c,I))&&r.value:c[I]),C=e&&n?n:g[I],e&&typeof i==typeof C||(o=t.bind&&e?m(C,v):t.wrap&&e?p(C):l&&"function"==typeof C?m(Function.call,C):C,(t.sham||C&&C.sham||i&&i.sham)&&j(o,"sham",!0),h[I]=o,l&&(f(Y,A=s+"Prototype")||j(Y,A,{}),Y[A][I]=C,t.real&&u&&!u[I]&&j(u,I,C)))}var v=I("object"==typeof globalThis&&globalThis)||I("object"==typeof window&&window)||I("object"==typeof self&&self)||I("object"==typeof g&&g)||Function("return this")(),h=!a(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}),u={}.propertyIsEnumerable,w=Object.getOwnPropertyDescriptor,x={f:w&&!u.call({1:2},1)?function(t){var g=w(this,t);return!!g&&g.enumerable}:u},k={}.toString,D="".split,O=a(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return"String"==C(t)?D.call(t,""):Object(t)}:Object,N={}.hasOwnProperty,E=v.document,Z=d(E)&&d(E.createElement),M=!h&&!a(function(){return 7!=Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}),T=Object.getOwnPropertyDescriptor,G={f:h?T:function(t,g){if(t=r(t),g=i(g,!0),M)try{return T(t,g)}catch(t){}if(f(t,g))return y(!x.f.call(t,g),t[g])}},B=/#|\.prototype\./,R=s.normalize=function(t){return String(t).replace(B,".").toLowerCase()},S=s.data={},F=s.NATIVE="N",L=s.POLYFILL="P",Q=s,Y={},W=Object.defineProperty,z={f:h?W:function(t,g,e){if(c(t),g=i(g,!0),c(e),M)try{return W(t,g,e)}catch(t){}if("get"in e||"set"in e)throw TypeError("Accessors not supported");return"value"in e&&(t[g]=e.value),t}},j=h?function(t,g,e){return z.f(t,g,y(1,e))}:function(t,g,e){return t[g]=e,t},P=G.f,V=[].slice,X={},U=Function.bind||function(g){var e=l(this),A=V.call(arguments,1),I=function(){var t=A.concat(V.call(arguments));return this instanceof I?function(t,g,e){if(!(g in X)){for(var A=[],I=0;I<g;I++)A[I]="a["+I+"]";X[g]=Function("C,a","return new C("+A.join(",")+")")}return X[g](t,e)}(e,t.length,t):e.apply(g,t)};return d(e.prototype)&&(I.prototype=e.prototype),I};b({target:"Function",proto:!0},{bind:U});function _(t){return Y[t+"Prototype"]}var H=_("Function").bind,J=Function.prototype,K=function(t){var g=t.bind;return t===J||t instanceof Function&&g===J.bind?H:g};function q(t,g,e,A){t.beginPath(),t.arc(g,e,A,0,2*Math.PI,!1),t.closePath()}function $(t,g,e,A,I,C){var i=Math.PI/180;A-2*C<0&&(C=A/2),I-2*C<0&&(C=I/2),t.beginPath(),t.moveTo(g+C,e),t.lineTo(g+A-C,e),t.arc(g+A-C,e+C,C,270*i,360*i,!1),t.lineTo(g+A,e+I-C),t.arc(g+A-C,e+I-C,C,0,90*i,!1),t.lineTo(g+C,e+I),t.arc(g+C,e+I-C,C,90*i,180*i,!1),t.lineTo(g,e+C),t.arc(g+C,e+C,C,180*i,270*i,!1),t.closePath()}function tt(t,g,e,A,I){var C=A/2*.5522848,i=I/2*.5522848,n=g+A,o=e+I,r=g+A/2,s=e+I/2;t.beginPath(),t.moveTo(g,s),t.bezierCurveTo(g,s-i,r-C,e,r,e),t.bezierCurveTo(r+C,e,n,s-i,n,s),t.bezierCurveTo(n,s+i,r+C,o,r,o),t.bezierCurveTo(r-C,o,Line truncated
!function(t,g){"object"==typeof exports&&"undefined"!=typeof module?g(exports):"function"==typeof define&&define.amd?define(["exports"],g):g((t=t||self).vis=t.vis||{})}(this,function(t){"use strict";var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,g){return t(g={exports:{}},g.exports),g.exports}function A(t){return t&&t.default||t}function I(t){return t&&t.Math==Math&&t}function a(t){try{return!!t()}catch(t){return!0}}function v(t,g){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:g}}function C(t){return k.call(t).slice(8,-1)}function o(t){if(null==t)throw TypeError("Can't call method on "+t);return t}function r(t){return O(o(t))}function d(t){return"object"==typeof t?null!==t:"function"==typeof t}function i(t,g){if(!d(t))return t;var e,A;if(g&&"function"==typeof(e=t.toString)&&!d(A=e.call(t)))return A;if("function"==typeof(e=t.valueOf)&&!d(A=e.call(t)))return A;if(!g&&"function"==typeof(e=t.toString)&&!d(A=e.call(t)))return A;throw TypeError("Can't convert object to primitive value")}function p(t,g){return N.call(t,g)}function n(t){return Z?E.createElement(t):{}}function s(t,g){var e=S[R(t)];return e==L||e!=F&&("function"==typeof g?a(g):!!g)}function l(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}function y(A,I,t){if(l(A),void 0===I)return A;switch(t){case 0:return function(){return A.call(I)};case 1:return function(t){return A.call(I,t)};case 2:return function(t,g){return A.call(I,t,g)};case 3:return function(t,g,e){return A.call(I,t,g,e)}}return function(){return A.apply(I,arguments)}}function c(t){if(!d(t))throw TypeError(String(t)+" is not an object");return t}function f(A){function t(t,g,e){if(this instanceof A){switch(arguments.length){case 0:return new A;case 1:return new A(t);case 2:return new A(t,g)}return new A(t,g,e)}return A.apply(this,arguments)}return t.prototype=A.prototype,t}function m(t,g){var e,A,I,C,i,n,o,r,s=t.target,a=t.global,d=t.stat,l=t.proto,c=a?b:d?b[s]:(b[s]||{}).prototype,h=a?Y:Y[s]||(Y[s]={}),u=h.prototype;for(I in g)e=!Q(a?I:s+(d?".":"#")+I,t.forced)&&c&&p(c,I),i=h[I],e&&(n=t.noTargetGet?(r=P(c,I))&&r.value:c[I]),C=e&&n?n:g[I],e&&typeof i==typeof C||(o=t.bind&&e?y(C,b):t.wrap&&e?f(C):l&&"function"==typeof C?y(Function.call,C):C,(t.sham||C&&C.sham||i&&i.sham)&&j(o,"sham",!0),h[I]=o,l&&(p(Y,A=s+"Prototype")||j(Y,A,{}),Y[A][I]=C,t.real&&u&&!u[I]&&j(u,I,C)))}var b=I("object"==typeof globalThis&&globalThis)||I("object"==typeof window&&window)||I("object"==typeof self&&self)||I("object"==typeof g&&g)||Function("return this")(),h=!a(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}),u={}.propertyIsEnumerable,w=Object.getOwnPropertyDescriptor,x={f:w&&!u.call({1:2},1)?function(t){var g=w(this,t);return!!g&&g.enumerable}:u},k={}.toString,D="".split,O=a(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return"String"==C(t)?D.call(t,""):Object(t)}:Object,N={}.hasOwnProperty,E=b.document,Z=d(E)&&d(E.createElement),M=!h&&!a(function(){return 7!=Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}),T=Object.getOwnPropertyDescriptor,G={f:h?T:function(t,g){if(t=r(t),g=i(g,!0),M)try{return T(t,g)}catch(t){}if(p(t,g))return v(!x.f.call(t,g),t[g])}},B=/#|\.prototype\./,R=s.normalize=function(t){return String(t).replace(B,".").toLowerCase()},S=s.data={},F=s.NATIVE="N",L=s.POLYFILL="P",Q=s,Y={},W=Object.defineProperty,z={f:h?W:function(t,g,e){if(c(t),g=i(g,!0),c(e),M)try{return W(t,g,e)}catch(t){}if("get"in e||"set"in e)throw TypeError("Accessors not supported");return"value"in e&&(t[g]=e.value),t}},j=h?function(t,g,e){return z.f(t,g,v(1,e))}:function(t,g,e){return t[g]=e,t},P=G.f,V=[].slice,X={},U=Function.bind||function(g){var e=l(this),A=V.call(arguments,1),I=function(){var t=A.concat(V.call(arguments));return this instanceof I?function(t,g,e){if(!(g in X)){for(var A=[],I=0;I<g;I++)A[I]="a["+I+"]";X[g]=Function("C,a","return new C("+A.join(",")+")")}return X[g](t,e)}(e,t.length,t):e.apply(g,t)};return d(e.prototype)&&(I.prototype=e.prototype),I};m({target:"Function",proto:!0},{bind:U});function _(t){return Y[t+"Prototype"]}var H=_("Function").bind,J=Function.prototype,K=function(t){var g=t.bind;return t===J||t instanceof Function&&g===J.bind?H:g};function q(t,g,e,A){t.beginPath(),t.arc(g,e,A,0,2*Math.PI,!1),t.closePath()}function $(t,g,e,A,I,C){var i=Math.PI/180;A-2*C<0&&(C=A/2),I-2*C<0&&(C=I/2),t.beginPath(),t.moveTo(g+C,e),t.lineTo(g+A-C,e),t.arc(g+A-C,e+C,C,270*i,360*i,!1),t.lineTo(g+A,e+I-C),t.arc(g+A-C,e+I-C,C,0,90*i,!1),t.lineTo(g+C,e+I),t.arc(g+C,e+I-C,C,90*i,180*i,!1),t.lineTo(g,e+C),t.arc(g+C,e+C,C,180*i,270*i,!1),t.closePath()}function tt(t,g,e,A,I){var C=A/2*.5522848,i=I/2*.5522848,n=g+A,o=e+I,r=g+A/2,s=e+I/2;t.beginPath(),t.moveTo(g,s),t.bezierCurveTo(g,s-i,r-C,e,r,e),t.bezierCurveTo(r+C,e,n,s-i,n,s),t.bezierCurveTo(n,s+i,r+C,o,r,o),t.bezierCurveTo(r-C,o,Line truncated