mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 05:21:55 -06:00
migrate connection toggle to typescript
This commit is contained in:
parent
8737e9824f
commit
7d07631f12
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -1,9 +1,10 @@
|
|||||||
import { isTruthy, getElements } from './util';
|
import { createToast } from './toast';
|
||||||
|
import { isTruthy, getElements, apiPatch, hasError } from './util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add onClick callback for toggling rack elevation images.
|
* Add onClick callback for toggling rack elevation images.
|
||||||
*/
|
*/
|
||||||
export function initRackElevation() {
|
function initRackElevation() {
|
||||||
for (const button of getElements('button.toggle-images')) {
|
for (const button of getElements('button.toggle-images')) {
|
||||||
/**
|
/**
|
||||||
* Toggle the visibility of device images and update the toggle button style.
|
* Toggle the visibility of device images and update the toggle button style.
|
||||||
@ -40,3 +41,58 @@ export function initRackElevation() {
|
|||||||
button.addEventListener('click', handleClick);
|
button.addEventListener('click', handleClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the toggle button is clicked, swap the connection status via the API and toggle CSS
|
||||||
|
* classes to reflect the connection status.
|
||||||
|
*
|
||||||
|
* @param element Connection Toggle Button Element
|
||||||
|
*/
|
||||||
|
function toggleConnection(element: HTMLButtonElement) {
|
||||||
|
const id = element.getAttribute('data');
|
||||||
|
const connected = element.classList.contains('connected');
|
||||||
|
const status = connected ? 'planned' : 'connected';
|
||||||
|
|
||||||
|
if (isTruthy(id)) {
|
||||||
|
apiPatch(`/api/dcim/cables/${id}/`, { status }).then(res => {
|
||||||
|
if (hasError(res)) {
|
||||||
|
// If the API responds with an error, show it to the user.
|
||||||
|
createToast('danger', 'Error', res.error).show();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Get the button's row to change its styles.
|
||||||
|
const row = element.parentElement?.parentElement as HTMLTableRowElement;
|
||||||
|
// Get the button's icon to change its CSS class.
|
||||||
|
const icon = element.querySelector('i.mdi, span.mdi') as HTMLSpanElement;
|
||||||
|
if (connected) {
|
||||||
|
row.classList.remove('success');
|
||||||
|
row.classList.add('info');
|
||||||
|
element.classList.remove('connected', 'btn-warning');
|
||||||
|
element.title = 'Mark Installed';
|
||||||
|
icon.classList.remove('mdi-lan-disconnect');
|
||||||
|
icon.classList.add('mdi-lan-connect');
|
||||||
|
} else {
|
||||||
|
row.classList.remove('info');
|
||||||
|
row.classList.add('success');
|
||||||
|
element.classList.remove('btn-success');
|
||||||
|
element.classList.add('connected', 'btn-warning');
|
||||||
|
element.title = 'Mark Installed';
|
||||||
|
icon.classList.remove('mdi-lan-connect');
|
||||||
|
icon.classList.add('mdi-lan-disconnect');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initConnectionToggle() {
|
||||||
|
for (const element of getElements<HTMLButtonElement>('button.cable-toggle')) {
|
||||||
|
element.addEventListener('click', () => toggleConnection(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initButtons() {
|
||||||
|
for (const func of [initRackElevation, initConnectionToggle]) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,10 +4,11 @@ import { initApiSelect, initStaticSelect, initColorSelect } from './select';
|
|||||||
import { initDateSelector } from './dateSelector';
|
import { initDateSelector } from './dateSelector';
|
||||||
import { initMessageToasts } from './toast';
|
import { initMessageToasts } from './toast';
|
||||||
import { initSpeedSelector, initForms } from './forms';
|
import { initSpeedSelector, initForms } from './forms';
|
||||||
import { initRackElevation } from './buttons';
|
import { initButtons } from './buttons';
|
||||||
import { initClipboard } from './clipboard';
|
import { initClipboard } from './clipboard';
|
||||||
import { initSearchBar, initInterfaceFilter } from './search';
|
import { initSearchBar, initInterfaceFilter } from './search';
|
||||||
import { initGenerateKeyPair, initLockUnlock, initGetSessionKey } from './secrets';
|
import { initGenerateKeyPair, initLockUnlock, initGetSessionKey } from './secrets';
|
||||||
|
import { initTabs } from './tabs';
|
||||||
import { initTableConfig } from './tableConfig';
|
import { initTableConfig } from './tableConfig';
|
||||||
import { getElements } from './util';
|
import { getElements } from './util';
|
||||||
|
|
||||||
@ -20,13 +21,14 @@ const INITIALIZERS = [
|
|||||||
initDateSelector,
|
initDateSelector,
|
||||||
initSpeedSelector,
|
initSpeedSelector,
|
||||||
initColorSelect,
|
initColorSelect,
|
||||||
initRackElevation,
|
initButtons,
|
||||||
initClipboard,
|
initClipboard,
|
||||||
initGenerateKeyPair,
|
initGenerateKeyPair,
|
||||||
initLockUnlock,
|
initLockUnlock,
|
||||||
initGetSessionKey,
|
initGetSessionKey,
|
||||||
initInterfaceFilter,
|
initInterfaceFilter,
|
||||||
initTableConfig,
|
initTableConfig,
|
||||||
|
initTabs,
|
||||||
] as (() => void)[];
|
] as (() => void)[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=consoleport_table.paginator page=consoleport_table.page %}
|
{% include 'inc/paginator.html' with paginator=consoleport_table.paginator page=consoleport_table.page %}
|
||||||
{% table_config_form consoleport_table %}
|
{% table_config_form consoleport_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=consoleserverport_table.paginator page=consoleserverport_table.page %}
|
{% include 'inc/paginator.html' with paginator=consoleserverport_table.paginator page=consoleserverport_table.page %}
|
||||||
{% table_config_form consoleserverport_table %}
|
{% table_config_form consoleserverport_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=frontport_table.paginator page=frontport_table.page %}
|
{% include 'inc/paginator.html' with paginator=frontport_table.paginator page=frontport_table.page %}
|
||||||
{% table_config_form frontport_table %}
|
{% table_config_form frontport_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5>Interfaces</h5>
|
<h5 class="d-inline">Interfaces</h5>
|
||||||
<div class="float-end col-md-2 noprint">
|
<div class="float-end col-md-2 noprint">
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
<input type="text" class="form-control interface-filter" placeholder="Filter" title="Filter text (regular expressions supported)" />
|
<input type="text" class="form-control interface-filter" placeholder="Filter" title="Filter text (regular expressions supported)" />
|
||||||
@ -52,7 +52,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=interface_table.paginator page=interface_table.page %}
|
{% include 'inc/paginator.html' with paginator=interface_table.paginator page=interface_table.page %}
|
||||||
{% table_config_form interface_table %}
|
{% table_config_form interface_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=poweroutlet_table.paginator page=poweroutlet_table.page %}
|
{% include 'inc/paginator.html' with paginator=poweroutlet_table.paginator page=poweroutlet_table.page %}
|
||||||
{% table_config_form poweroutlet_table %}
|
{% table_config_form poweroutlet_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=powerport_table.paginator page=powerport_table.page %}
|
{% include 'inc/paginator.html' with paginator=powerport_table.paginator page=powerport_table.page %}
|
||||||
{% table_config_form powerport_table %}
|
{% table_config_form powerport_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -49,7 +49,3 @@
|
|||||||
{% include 'inc/paginator.html' with paginator=rearport_table.paginator page=rearport_table.page %}
|
{% include 'inc/paginator.html' with paginator=rearport_table.paginator page=rearport_table.page %}
|
||||||
{% table_config_form rearport_table %}
|
{% table_config_form rearport_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
{% if perms.dcim.change_cable %}
|
{% if perms.dcim.change_cable %}
|
||||||
{% if cable.status == 'connected' %}
|
{% if cable.status == 'connected' %}
|
||||||
<a href="#" class="btn btn-warning btn-sm cable-toggle connected" title="Mark Planned" data="{{ cable.pk }}">
|
<button type="button" class="btn btn-warning btn-sm cable-toggle connected" title="Mark Planned" data="{{ cable.pk }}">
|
||||||
<i class="mdi mdi-lan-disconnect" aria-hidden="true"></i>
|
<i class="mdi mdi-lan-disconnect" aria-hidden="true"></i>
|
||||||
</a>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="#" class="btn btn-success btn-sm cable-toggle" title="Mark Installed" data="{{ cable.pk }}">
|
<button type="button" class="btn btn-success btn-sm cable-toggle" title="Mark Installed" data="{{ cable.pk }}">
|
||||||
<i class="mdi mdi-lan-connect" aria-hidden="true"></i>
|
<i class="mdi mdi-lan-connect" aria-hidden="true"></i>
|
||||||
</a>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -48,7 +48,3 @@
|
|||||||
</form>
|
</form>
|
||||||
{% table_config_form interface_table %}
|
{% table_config_form interface_table %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script src="{% static 'js/connection_toggles.js' %}?v{{ settings.VERSION }}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user