migrate interface filtering to typescript

This commit is contained in:
checktheroads
2021-04-17 18:16:13 -07:00
parent c035af5409
commit a8cad28da7
4 changed files with 50 additions and 5 deletions

View File

@@ -878,11 +878,11 @@ var t;!function(e,n){"object"==typeof exports&&"object"==typeof module?module.ex
},{}],"8XnJ":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.initClipboard=u;var t=e(require("clipboard")),r=require("./util");function e(t){return t&&t.__esModule?t:{default:t}}function n(t,r){var e;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(e=o(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,l=!1;return{s:function(){e=t[Symbol.iterator]()},n:function(){var t=e.next();return a=t.done,t},e:function(t){l=!0,u=t},f:function(){try{a||null==e.return||e.return()}finally{if(l)throw u}}}}function o(t,r){if(t){if("string"==typeof t)return i(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(t,r):void 0}}function i(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function u(){var e,o=n((0,r.getElements)("a.copy-token","button.copy-secret"));try{for(o.s();!(e=o.n()).done;){var i=e.value;new t.default(i)}}catch(u){o.e(u)}finally{o.f()}}
},{"clipboard":"iNgO","./util":"BHXf"}],"uQ9J":[function(require,module,exports) {
"use strict";function e(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=t(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var o=0,l=function(){};return{s:l,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:l}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw a}}}}function t(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function r(e){var t,n;return null!==(t=null==e?void 0:null===(n=e.dataset)||void 0===n?void 0:n.searchValue)&&void 0!==t&&t}function o(){var t=document.getElementById("object-type-selector"),n=document.getElementById("selected-value"),o=document.getElementById("search-obj-type"),l="";if(null!==t){var a,i=e(t.querySelectorAll("li > button.dropdown-item"));try{var u=function(){var e=a.value;if(null!==e){e.addEventListener("click",function(t){if(r(t.target)){var a,i=t.target.dataset.searchValue;""!==i&&l!==i?(l=i,n.innerHTML=null!==(a=e.textContent)&&void 0!==a?a:"Error",o.value=i):(l="",o.innerHTML="All Objects",o.value="")}})}};for(i.s();!(a=i.n()).done;)u()}catch(c){i.e(c)}finally{i.f()}}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.initSearchBar=o;
},{}],"NEpu":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.initSearchBar=a,exports.initInterfaceFilter=l;var e=require("./util");function t(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=n(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l,i=!0,u=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return i=e.done,e},e:function(e){u=!0,l=e},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw l}}}}function n(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e){var t,n;return null!==(t=null==e?void 0:null===(n=e.dataset)||void 0===n?void 0:n.searchValue)&&void 0!==t&&t}function a(){var e=document.getElementById("object-type-selector"),n=document.getElementById("selected-value"),r=document.getElementById("search-obj-type"),a="";if(null!==e){var l,i=t(e.querySelectorAll("li > button.dropdown-item"));try{var u=function(){var e=l.value;if(null!==e){e.addEventListener("click",function(t){if(o(t.target)){var l,i=t.target.dataset.searchValue;""!==i&&a!==i?(a=i,n.innerHTML=null!==(l=e.textContent)&&void 0!==l?l:"Error",r.value=i):(a="",r.innerHTML="All Objects",r.value="")}})}};for(i.s();!(l=i.n()).done;)u()}catch(c){i.e(c)}finally{i.f()}}}function l(){var n,r=t((0,e.getElements)("input.interface-filter"));try{for(r.s();!(n=r.n()).done;){function o(n){var r,o=n.target,a=new RegExp(o.value),l=t((0,e.getElements)("table > tbody > tr"));try{for(l.s();!(r=l.n()).done;){var i=r.value,u=i.getAttribute("data-name"),c=i.querySelector('input[type="checkbox"][name="pk"]');null!==c&&(c.checked=!1),"string"==typeof u&&(a.test(u)?i.classList.contains("d-none")&&i.classList.remove("d-none"):i.classList.add("d-none"))}}catch(f){l.e(f)}finally{l.f()}}n.value.addEventListener("keyup",o)}}catch(a){r.e(a)}finally{r.f()}}
},{"./util":"BHXf"}],"NEpu":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.initGenerateKeyPair=c,exports.initLockUnlock=l,exports.initGetSessionKey=u;var e=require("bootstrap"),t=require("./util"),n=require("./toast");function r(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=o(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c,i=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){l=!0,c=e},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw c}}}}function o(e,t){if(e){if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,t):void 0}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(){var e=document.getElementById("new_keypair_modal"),r=document.getElementById("use_new_pubkey");if(null!==e&&null!==r){var o=e.querySelector("textarea#new_pubkey"),a=e.querySelector("textarea#new_privkey");e.addEventListener("shown.bs.modal",function(){for(var e=0,r=[o,a];e<r.length;e++){var c=r[e];null!==c&&c.setAttribute("readonly","")}(0,t.apiGetBase)("/api/secrets/generate-rsa-key-pair").then(function(e){if((0,t.hasError)(e))(0,n.createToast)("danger","Error",e.error).show();else{var r=e.private_key,c=e.public_key;null!==o&&null!==a&&(o.value=c,a.value=r)}})}),r.addEventListener("click",function(){var e=document.getElementById("id_public_key");null!==o&&(e.value=o.value,e.innerText=o.value)})}}function i(e,t){var n=document.querySelector("button.unlock-secret[secret-id='".concat(e,"']")),r=document.querySelector("button.lock-secret[secret-id='".concat(e,"']")),o=document.querySelector("button.copy-secret[secret-id='".concat(e,"']"));null!==n&&("unlock"===t&&n.classList.add("d-none"),"lock"===t&&n.classList.remove("d-none")),null!==r&&("unlock"===t&&r.classList.remove("d-none"),"lock"===t&&r.classList.add("d-none")),null!==o&&("unlock"===t&&o.classList.remove("d-none"),"lock"===t&&o.classList.add("d-none"))}function l(){var o=document.getElementById("privkey_modal");if(null!==o){var a,c=new e.Modal(o),l=r((0,t.getElements)("button.unlock-secret"));try{var s=function(){var e=a.value;e.addEventListener("click",function(){return r=e.getAttribute("secret-id"),o=document.getElementById("secret_".concat(r)),void("string"==typeof r&&""!==r&&(0,t.apiGetBase)("/api/secrets/secrets/".concat(r)).then(function(e){if((0,t.hasError)(e))e.error.toLowerCase().includes("invalid session key")?c.show():(0,n.createToast)("danger","Error",e.error).show();else{var a=e.plaintext;null!==o&&null!==a?(o.innerText=a,i(r,"unlock")):c.show()}}));var r,o})};for(l.s();!(a=l.n()).done;)s()}catch(v){l.e(v)}finally{l.f()}var u,d=r((0,t.getElements)("button.lock-secret"));try{var f=function(){var e=u.value;e.addEventListener("click",function(){return function(e){if("string"==typeof e&&""!==e){var t=document.getElementById("secret_".concat(e));null!==t&&(t.innerText="********"),i(e,"lock")}}(e.getAttribute("secret-id"))})};for(d.s();!(u=d.n()).done;)f()}catch(v){d.e(v)}finally{d.f()}}}function s(e){(0,t.apiPostForm)("/api/secrets/get-session-key/",{private_key:e}).then(function(e){if((0,t.hasError)(e)){var r=e.error;(0,t.isApiError)(e)&&(r+="\n".concat(e.exception)),(0,n.createToast)("danger","Failed to Retrieve Session Key",r).show()}else{(0,n.createToast)("success","Session Key Received","You may now unlock secrets.").show()}})}function u(){var e,n=r((0,t.getElements)("#request_session_key"));try{for(n.s();!(e=n.n()).done;){function o(){var e,n=r((0,t.getElements)("#user_privkey"));try{for(n.s();!(e=n.n()).done;){var o=e.value;s(o.value),o.value=""}}catch(a){n.e(a)}finally{n.f()}}e.value.addEventListener("click",o)}}catch(a){n.e(a)}finally{n.f()}}
},{"bootstrap":"xqrD","./util":"BHXf","./toast":"JH4Y"}],"oZ9N":[function(require,module,exports) {
"use strict";var e=require("bootstrap"),t=d(require("masonry-layout")),n=require("./select"),r=require("./dateSelector"),o=require("./toast"),i=require("./forms"),a=require("./buttons"),l=require("./clipboard"),u=require("./search"),c=require("./secrets"),s=require("./util");function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=m(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw i}}}}function m(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var v=[u.initSearchBar,b,S,n.initApiSelect,n.initStaticSelect,r.initDateSelector,i.initSpeedSelector,n.initColorSelect,a.initRackElevation,l.initClipboard,c.initGenerateKeyPair,c.initLockUnlock,c.initGetSessionKey];function g(){if(null!==document){var t,n=f((0,s.getElements)('[data-bs-toggle="tooltip"]'));try{for(n.s();!(t=n.n()).done;){var r=t.value;new e.Tooltip(r,{container:"body",boundary:"window"})}}catch(c){n.e(c)}finally{n.f()}var a,l=f((0,s.getElements)('[data-bs-toggle="modal"]'));try{for(l.s();!(a=l.n()).done;){var u=a.value;new e.Modal(u)}}catch(c){l.e(c)}finally{l.f()}(0,o.initMessageToasts)(),(0,i.initForms)()}}function b(){if(null!==document){var e,n=f((0,s.getElements)(".masonry"));try{for(n.s();!(e=n.n()).done;){var r=e.value;new t.default(r,{itemSelector:".masonry-item",percentPosition:!0})}}catch(o){n.e(o)}finally{n.f()}}}function p(e,t){return e.replace(/[^\-\.\w\s]/g,"").replace(/^[\s\.]+|[\s\.]+$/g,"").replace(/[\-\.\s]+/g,"-").toLowerCase().substring(0,t)}function S(){var e=document.getElementById("id_slug"),t=document.getElementById("reslug");if(null!==e&&null!==t){var n=e.getAttribute("slug-source"),r=document.getElementById("id_".concat(n));if(null!==r){var o=e.getAttribute("maxlength"),i=50;o&&(i=Number(o)),r.addEventListener("blur",function(){e.value=p(r.value,i)}),t.addEventListener("click",function(){e.value=p(r.value,i)})}else console.error("Unable to find field for slug field.")}}"loading"!==document.readyState?g():document.addEventListener("DOMContentLoaded",g);for(var h=0,w=v;h<w.length;h++){var q=w[h];q()}
"use strict";var e=require("bootstrap"),t=f(require("masonry-layout")),n=require("./select"),r=require("./dateSelector"),i=require("./toast"),o=require("./forms"),a=require("./buttons"),l=require("./clipboard"),u=require("./search"),c=require("./secrets"),s=require("./util");function f(e){return e&&e.__esModule?e:{default:e}}function d(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=m(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}function m(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var v=[u.initSearchBar,b,S,n.initApiSelect,n.initStaticSelect,r.initDateSelector,o.initSpeedSelector,n.initColorSelect,a.initRackElevation,l.initClipboard,c.initGenerateKeyPair,c.initLockUnlock,c.initGetSessionKey,u.initInterfaceFilter];function g(){if(null!==document){var t,n=d((0,s.getElements)('[data-bs-toggle="tooltip"]'));try{for(n.s();!(t=n.n()).done;){var r=t.value;new e.Tooltip(r,{container:"body",boundary:"window"})}}catch(c){n.e(c)}finally{n.f()}var a,l=d((0,s.getElements)('[data-bs-toggle="modal"]'));try{for(l.s();!(a=l.n()).done;){var u=a.value;new e.Modal(u)}}catch(c){l.e(c)}finally{l.f()}(0,i.initMessageToasts)(),(0,o.initForms)()}}function b(){if(null!==document){var e,n=d((0,s.getElements)(".masonry"));try{for(n.s();!(e=n.n()).done;){var r=e.value;new t.default(r,{itemSelector:".masonry-item",percentPosition:!0})}}catch(i){n.e(i)}finally{n.f()}}}function p(e,t){return e.replace(/[^\-\.\w\s]/g,"").replace(/^[\s\.]+|[\s\.]+$/g,"").replace(/[\-\.\s]+/g,"-").toLowerCase().substring(0,t)}function S(){var e=document.getElementById("id_slug"),t=document.getElementById("reslug");if(null!==e&&null!==t){var n=e.getAttribute("slug-source"),r=document.getElementById("id_".concat(n));if(null!==r){var i=e.getAttribute("maxlength"),o=50;i&&(o=Number(i)),r.addEventListener("blur",function(){e.value=p(r.value,o)}),t.addEventListener("click",function(){e.value=p(r.value,o)})}else console.error("Unable to find field for slug field.")}}"loading"!==document.readyState?g():document.addEventListener("DOMContentLoaded",g);for(var h=0,w=v;h<w.length;h++){var q=w[h];q()}
},{"bootstrap":"xqrD","masonry-layout":"l7pb","./select":"lv+U","./dateSelector":"mp96","./toast":"JH4Y","./forms":"Okbr","./buttons":"EcbZ","./clipboard":"8XnJ","./search":"uQ9J","./secrets":"NEpu","./util":"BHXf"}],"7QCb":[function(require,module,exports) {
"use strict";require("babel-polyfill"),require("@popperjs/core"),require("bootstrap"),require("./netbox");
},{"babel-polyfill":"wllv","@popperjs/core":"vePw","bootstrap":"xqrD","./netbox":"oZ9N"}]},{},["7QCb"], null)

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ import { initMessageToasts } from './toast';
import { initSpeedSelector, initForms } from './forms';
import { initRackElevation } from './buttons';
import { initClipboard } from './clipboard';
import { initSearchBar } from './search';
import { initSearchBar, initInterfaceFilter } from './search';
import { initGenerateKeyPair, initLockUnlock, initGetSessionKey } from './secrets';
import { getElements } from './util';
@@ -24,6 +24,7 @@ const INITIALIZERS = [
initGenerateKeyPair,
initLockUnlock,
initGetSessionKey,
initInterfaceFilter,
] as (() => void)[];
/**

View File

@@ -1,3 +1,5 @@
import { getElements } from './util';
interface SearchFilterButton extends EventTarget {
dataset: { searchValue: string };
}
@@ -35,3 +37,45 @@ export function initSearchBar() {
}
}
}
/**
* Initialize Interface Table Filter Elements.
*/
export function initInterfaceFilter() {
for (const element of getElements<HTMLInputElement>('input.interface-filter')) {
/**
* Filter on-page table by input text.
*/
function handleInput(event: Event) {
const target = event.target as HTMLInputElement;
// Create a regex pattern from the input search text to match against.
const filter = new RegExp(target.value);
// Each row represents an interface and its attributes.
for (const row of getElements<HTMLTableRowElement>('table > tbody > tr')) {
// The data-name attribute's value contains the interface name.
const name = row.getAttribute('data-name');
// Find the row's checkbox and deselect it, so that it is not accidentally included in form
// submissions.
const checkBox = row.querySelector<HTMLInputElement>('input[type="checkbox"][name="pk"]');
if (checkBox !== null) {
checkBox.checked = false;
}
if (typeof name === 'string') {
if (filter.test(name)) {
// If this row matches the search pattern, but is already hidden, unhide it.
if (row.classList.contains('d-none')) {
row.classList.remove('d-none');
}
} else {
// If this row doesn't match the search pattern, hide it.
row.classList.add('d-none');
}
}
}
}
element.addEventListener('keyup', handleInput);
}
}