diff --git a/netbox/project-static/dist/config.js b/netbox/project-static/dist/config.js new file mode 100644 index 000000000..a1a0c35c6 Binary files /dev/null and b/netbox/project-static/dist/config.js differ diff --git a/netbox/project-static/dist/config.js.map b/netbox/project-static/dist/config.js.map new file mode 100644 index 000000000..969e1bb2e Binary files /dev/null and b/netbox/project-static/dist/config.js.map differ diff --git a/netbox/project-static/dist/jobs.js b/netbox/project-static/dist/jobs.js index b8c7f5ff4..c463bc18b 100644 Binary files a/netbox/project-static/dist/jobs.js and b/netbox/project-static/dist/jobs.js differ diff --git a/netbox/project-static/dist/jobs.js.map b/netbox/project-static/dist/jobs.js.map index 04a41deb9..d4046b543 100644 Binary files a/netbox/project-static/dist/jobs.js.map and b/netbox/project-static/dist/jobs.js.map differ diff --git a/netbox/project-static/dist/lldp.js b/netbox/project-static/dist/lldp.js index 755f90066..55e0f651d 100644 Binary files a/netbox/project-static/dist/lldp.js and b/netbox/project-static/dist/lldp.js differ diff --git a/netbox/project-static/dist/lldp.js.map b/netbox/project-static/dist/lldp.js.map index 1611e8e65..6f2bcd677 100644 Binary files a/netbox/project-static/dist/lldp.js.map and b/netbox/project-static/dist/lldp.js.map differ diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 1cceceffa..08ffda791 100644 Binary files a/netbox/project-static/dist/netbox.js and b/netbox/project-static/dist/netbox.js differ diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index dc3c355f7..e4d567239 100644 Binary files a/netbox/project-static/dist/netbox.js.map and b/netbox/project-static/dist/netbox.js.map differ diff --git a/netbox/project-static/package.json b/netbox/project-static/package.json index fb3d43f02..555b5da99 100644 --- a/netbox/project-static/package.json +++ b/netbox/project-static/package.json @@ -5,7 +5,7 @@ "license": "Apache2", "scripts": { "bundle:css": "parcel build --public-url /static -o netbox.css main.scss && parcel build --public-url /static -o rack_elevation.css rack_elevation.scss", - "bundle:js": "parcel build --public-url /static -o netbox.js src/index.ts && parcel build --public-url /static -o jobs.js src/jobs.ts && parcel build --public-url /static -o lldp.js src/lldp.ts", + "bundle:js": "parcel build --public-url /static -o netbox.js src/index.ts && parcel build --public-url /static -o jobs.js src/jobs.ts && parcel build --public-url /static -o lldp.js src/device/lldp.ts && parcel build --public-url /static -o config.js src/device/config.ts", "bundle": "yarn bundle:css && yarn bundle:js" }, "dependencies": { diff --git a/netbox/project-static/src/device/config.ts b/netbox/project-static/src/device/config.ts new file mode 100644 index 000000000..e64793c41 --- /dev/null +++ b/netbox/project-static/src/device/config.ts @@ -0,0 +1,41 @@ +import { createToast } from '../toast'; +import { apiGetBase, getNetboxData, hasError, toggleLoader } from '../util'; + +/** + * Initialize device config elements. + */ +function initConfig() { + toggleLoader('show'); + const url = getNetboxData('data-object-url'); + + if (url !== null) { + apiGetBase(url) + .then(data => { + if (hasError(data)) { + createToast('danger', 'Error Fetching Device Config', data.error).show(); + } else { + const configTypes = [ + 'running', + 'startup', + 'candidate', + ] as (keyof DeviceConfig['get_config'])[]; + + for (const configType of configTypes) { + const element = document.getElementById(`${configType}_config`); + if (element !== null) { + element.innerHTML = data.get_config[configType]; + } + } + } + }) + .finally(() => { + toggleLoader('hide'); + }); + } +} + +if (document.readyState !== 'loading') { + initConfig(); +} else { + document.addEventListener('DOMContentLoaded', initConfig); +} diff --git a/netbox/project-static/src/lldp.ts b/netbox/project-static/src/device/lldp.ts similarity index 85% rename from netbox/project-static/src/lldp.ts rename to netbox/project-static/src/device/lldp.ts index f005f4637..3f1b802c7 100644 --- a/netbox/project-static/src/lldp.ts +++ b/netbox/project-static/src/device/lldp.ts @@ -1,19 +1,5 @@ -import { createToast } from './toast'; -import { getNetboxData, apiGetBase, hasError, isTruthy } from './util'; - -/** - * Toggle visibility of card loader. - */ -function toggleLoader(action: 'show' | 'hide') { - const spinnerContainer = document.querySelector('div.card-overlay'); - if (spinnerContainer !== null) { - if (action === 'show') { - spinnerContainer.classList.remove('d-none'); - } else { - spinnerContainer.classList.add('d-none'); - } - } -} +import { createToast } from '../toast'; +import { getNetboxData, apiGetBase, hasError, isTruthy, toggleLoader } from '../util'; /** * Get an attribute from a row's cell. diff --git a/netbox/project-static/src/global.d.ts b/netbox/project-static/src/global.d.ts index 11f3c7db1..3fb669adf 100644 --- a/netbox/project-static/src/global.d.ts +++ b/netbox/project-static/src/global.d.ts @@ -113,6 +113,14 @@ type LLDPNeighborDetail = { get_lldp_neighbors_detail: { [interface: string]: LLDPInterface[] }; }; +type DeviceConfig = { + get_config: { + candidate: string; + running: string; + startup: string; + }; +}; + interface ObjectWithGroup extends APIObjectBase { group: Nullable; } diff --git a/netbox/project-static/src/util.ts b/netbox/project-static/src/util.ts index 1317afab7..20bb3dacd 100644 --- a/netbox/project-static/src/util.ts +++ b/netbox/project-static/src/util.ts @@ -172,3 +172,17 @@ export function getNetboxData(key: string): string | null { } return null; } + +/** + * Toggle visibility of card loader. + */ +export function toggleLoader(action: 'show' | 'hide') { + const spinnerContainer = document.querySelector('div.card-overlay'); + if (spinnerContainer !== null) { + if (action === 'show') { + spinnerContainer.classList.remove('d-none'); + } else { + spinnerContainer.classList.add('d-none'); + } + } +} diff --git a/netbox/templates/dcim/device/config.html b/netbox/templates/dcim/device/config.html index e8ca0da10..f13755ec9 100644 --- a/netbox/templates/dcim/device/config.html +++ b/netbox/templates/dcim/device/config.html @@ -3,50 +3,43 @@ {% block title %}{{ object }} - Config{% endblock %} +{% block head %} + +{% endblock %} + {% block content %} - {% include 'inc/ajax_loader.html' %} -
-
-
-
Device Configuration
-
- -
-
-

-                        
-
-

-                        
-
-

-                        
+
+
+
+
+
+ Loading... +
+
+
Device Configuration
+
+ +
+
+

+                    
+
+

+                    
+
+

                     
+
{% endblock %} -{% block javascript %} - +{% block data %} + {% endblock %} diff --git a/netbox/templates/dcim/device/lldp_neighbors.html b/netbox/templates/dcim/device/lldp_neighbors.html index 515de6755..b3b2eeae8 100644 --- a/netbox/templates/dcim/device/lldp_neighbors.html +++ b/netbox/templates/dcim/device/lldp_neighbors.html @@ -16,7 +16,6 @@
LLDP Neighbors
- {% comment %}
{% endcomment %}