|
@@ -8,11 +8,12 @@ import { DynamicParamsMap } from './dynamicParams';
|
|
|
import { isStaticParams, isOption } from './types';
|
|
import { isStaticParams, isOption } from './types';
|
|
|
import {
|
|
import {
|
|
|
hasMore,
|
|
hasMore,
|
|
|
- isTruthy,
|
|
|
|
|
hasError,
|
|
hasError,
|
|
|
- getElement,
|
|
|
|
|
|
|
+ isTruthy,
|
|
|
getApiData,
|
|
getApiData,
|
|
|
|
|
+ getElement,
|
|
|
isApiError,
|
|
isApiError,
|
|
|
|
|
+ replaceAll,
|
|
|
createElement,
|
|
createElement,
|
|
|
uniqueByProperty,
|
|
uniqueByProperty,
|
|
|
findFirstAdjacent,
|
|
findFirstAdjacent,
|
|
@@ -461,7 +462,7 @@ export class APISelect {
|
|
|
// Set any primitive k/v pairs as data attributes on each option.
|
|
// Set any primitive k/v pairs as data attributes on each option.
|
|
|
for (const [k, v] of Object.entries(result)) {
|
|
for (const [k, v] of Object.entries(result)) {
|
|
|
if (!['id', 'slug'].includes(k) && ['string', 'number', 'boolean'].includes(typeof v)) {
|
|
if (!['id', 'slug'].includes(k) && ['string', 'number', 'boolean'].includes(typeof v)) {
|
|
|
- const key = k.replace(/_/g, '-');
|
|
|
|
|
|
|
+ const key = replaceAll(k, '_', '-');
|
|
|
data[key] = String(v);
|
|
data[key] = String(v);
|
|
|
}
|
|
}
|
|
|
// Set option to disabled if the result contains a matching key and is truthy.
|
|
// Set option to disabled if the result contains a matching key and is truthy.
|
|
@@ -659,7 +660,7 @@ export class APISelect {
|
|
|
for (const [key, value] of this.pathValues.entries()) {
|
|
for (const [key, value] of this.pathValues.entries()) {
|
|
|
for (const result of this.url.matchAll(new RegExp(`({{${key}}})`, 'g'))) {
|
|
for (const result of this.url.matchAll(new RegExp(`({{${key}}})`, 'g'))) {
|
|
|
if (isTruthy(value)) {
|
|
if (isTruthy(value)) {
|
|
|
- url = url.replace(result[1], value.toString());
|
|
|
|
|
|
|
+ url = replaceAll(url, result[1], value.toString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -741,7 +742,7 @@ export class APISelect {
|
|
|
* @param id DOM ID of the other element.
|
|
* @param id DOM ID of the other element.
|
|
|
*/
|
|
*/
|
|
|
private updatePathValues(id: string): void {
|
|
private updatePathValues(id: string): void {
|
|
|
- const key = id.replace(/^id_/gi, '');
|
|
|
|
|
|
|
+ const key = replaceAll(id, /^id_/i, '');
|
|
|
const element = getElement<HTMLSelectElement>(`id_${key}`);
|
|
const element = getElement<HTMLSelectElement>(`id_${key}`);
|
|
|
if (element !== null) {
|
|
if (element !== null) {
|
|
|
// If this element's URL contains Django template tags ({{), replace the template tag
|
|
// If this element's URL contains Django template tags ({{), replace the template tag
|
|
@@ -919,16 +920,18 @@ export class APISelect {
|
|
|
style.setAttribute('data-netbox', id);
|
|
style.setAttribute('data-netbox', id);
|
|
|
|
|
|
|
|
// Scope the CSS to apply both the list item and the selected item.
|
|
// Scope the CSS to apply both the list item and the selected item.
|
|
|
- style.innerHTML = `
|
|
|
|
|
|
|
+ style.innerHTML = replaceAll(
|
|
|
|
|
+ `
|
|
|
div.ss-values div.ss-value[data-id="${id}"],
|
|
div.ss-values div.ss-value[data-id="${id}"],
|
|
|
div.ss-list div.ss-option:not(.ss-disabled)[data-id="${id}"]
|
|
div.ss-list div.ss-option:not(.ss-disabled)[data-id="${id}"]
|
|
|
{
|
|
{
|
|
|
background-color: ${bg} !important;
|
|
background-color: ${bg} !important;
|
|
|
color: ${fg} !important;
|
|
color: ${fg} !important;
|
|
|
}
|
|
}
|
|
|
- `
|
|
|
|
|
- .replace(/\n/g, '')
|
|
|
|
|
- .trim();
|
|
|
|
|
|
|
+ `,
|
|
|
|
|
+ '\n',
|
|
|
|
|
+ '',
|
|
|
|
|
+ ).trim();
|
|
|
|
|
|
|
|
// Add the style element to the DOM.
|
|
// Add the style element to the DOM.
|
|
|
document.head.appendChild(style);
|
|
document.head.appendChild(style);
|