mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
Annotate depth for recursive hierarchies
This commit is contained in:
parent
6926b3709e
commit
50f995e7ba
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.
@ -34,8 +34,8 @@ export class DynamicTomSelect extends TomSelect {
|
|||||||
// Set the null option (if any)
|
// Set the null option (if any)
|
||||||
const nullOption = this.input.getAttribute('data-null-option');
|
const nullOption = this.input.getAttribute('data-null-option');
|
||||||
if (nullOption) {
|
if (nullOption) {
|
||||||
let valueField = user_settings.valueField || 'value';
|
let valueField = this.settings.valueField;
|
||||||
let labelField = user_settings.labelField || 'text';
|
let labelField = this.settings.labelField;
|
||||||
this.nullOption = {}
|
this.nullOption = {}
|
||||||
this.nullOption[valueField] = 'null';
|
this.nullOption[valueField] = 'null';
|
||||||
this.nullOption[labelField] = nullOption;
|
this.nullOption[labelField] = nullOption;
|
||||||
|
@ -1,6 +1,19 @@
|
|||||||
import { getElements } from '../util';
|
import { getElements } from '../util';
|
||||||
import { DynamicTomSelect } from './classes/dynamicTomSelect'
|
import { DynamicTomSelect } from './classes/dynamicTomSelect'
|
||||||
|
|
||||||
|
const VALUE_FIELD = 'id';
|
||||||
|
const LABEL_FIELD = 'display';
|
||||||
|
|
||||||
|
|
||||||
|
// Render the HTML for a dropdown option
|
||||||
|
function renderOption(data: any, escape: Function) {
|
||||||
|
// If the object has a `_depth` property, indent its display text
|
||||||
|
if (typeof data._depth === 'number' && data._depth > 0) {
|
||||||
|
return `<div>${'─'.repeat(data._depth)} ${escape(data[LABEL_FIELD])}</div>`;
|
||||||
|
}
|
||||||
|
return `<div>${escape(data[LABEL_FIELD])}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize <select> elements which are populated via a REST API call
|
// Initialize <select> elements which are populated via a REST API call
|
||||||
export function initDynamicSelects(): void {
|
export function initDynamicSelects(): void {
|
||||||
@ -8,8 +21,8 @@ export function initDynamicSelects(): void {
|
|||||||
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
||||||
new DynamicTomSelect(select, {
|
new DynamicTomSelect(select, {
|
||||||
plugins: ['clear_button'],
|
plugins: ['clear_button'],
|
||||||
valueField: 'id',
|
valueField: VALUE_FIELD,
|
||||||
labelField: 'display',
|
labelField: LABEL_FIELD,
|
||||||
searchField: [],
|
searchField: [],
|
||||||
disabledField: select.getAttribute('disabled-indicator') || undefined,
|
disabledField: select.getAttribute('disabled-indicator') || undefined,
|
||||||
copyClassesToDropdown: false,
|
copyClassesToDropdown: false,
|
||||||
@ -17,6 +30,9 @@ export function initDynamicSelects(): void {
|
|||||||
controlInput: '<input>',
|
controlInput: '<input>',
|
||||||
preload: 'focus',
|
preload: 'focus',
|
||||||
maxOptions: 100,
|
maxOptions: 100,
|
||||||
|
render: {
|
||||||
|
option: renderOption
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user