1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

use getNetboxData utility function in job handling

This commit is contained in:
checktheroads
2021-04-21 10:40:37 -07:00
parent a55316aef9
commit 024f3962b2
3 changed files with 7 additions and 11 deletions

View File

@ -145,6 +145,6 @@ var t;!function(i,o){"function"==typeof t&&t.amd?t(["outlayer/outlayer","get-siz
},{"cookie":"PEEL"}],"UEe5":[function(require,module,exports) { },{"cookie":"PEEL"}],"UEe5":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createToast=u,exports.initBootstrap=f;var t=require("bootstrap"),e=r(require("masonry-layout")),n=require("./util");function r(t){return t&&t.__esModule?t:{default:t}}function a(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,a=function(){};return{s:a,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},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 i,l=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return l=t.done,t},e:function(t){c=!0,i=t},f:function(){try{l||null==n.return||n.return()}finally{if(c)throw i}}}}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(){var t,r=a((0,n.getElements)(".masonry"));try{for(r.s();!(t=r.n()).done;){var o=t.value;new e.default(o,{itemSelector:".masonry-item",percentPosition:!0})}}catch(i){r.e(i)}finally{r.f()}}function c(){var e,r=a((0,n.getElements)('[data-bs-toggle="tooltip"]'));try{for(r.s();!(e=r.n()).done;){var o=e.value;new t.Tooltip(o,{container:"body",boundary:"window"})}}catch(i){r.e(i)}finally{r.f()}}function s(){var e,r=a((0,n.getElements)('[data-bs-toggle="modal"]'));try{for(r.s();!(e=r.n()).done;){var o=e.value;new t.Modal(o)}}catch(i){r.e(i)}finally{r.f()}}function u(e,n,r,a){var o="bi-exclamation-triangle-fill";switch(e){case"warning":o="bi-exclamation-triangle-fill";case"success":o="bi-check-circle-fill";case"info":o="bi-info-circle-fill";case"danger":o="bi-exclamation-triangle-fill"}var i=document.createElement("div");i.setAttribute("class","toast-container position-fixed bottom-0 end-0 m-3");var l=document.createElement("div");l.setAttribute("class","toast bg-".concat(e)),l.setAttribute("role","alert"),l.setAttribute("aria-live","assertive"),l.setAttribute("aria-atomic","true");var c=document.createElement("div");c.setAttribute("class","toast-header bg-".concat(e," text-body"));var s=document.createElement("i");s.setAttribute("class","bi ".concat(o));var u=document.createElement("strong");u.setAttribute("class","me-auto ms-1"),u.innerText=n;var d=document.createElement("button");d.setAttribute("type","button"),d.setAttribute("class","btn-close"),d.setAttribute("data-bs-dismiss","toast"),d.setAttribute("aria-label","Close");var f=document.createElement("div");if(f.setAttribute("class","toast-body"),c.appendChild(s),c.appendChild(u),void 0!==a){var b=document.createElement("small");b.setAttribute("class","text-muted"),c.appendChild(b)}return c.appendChild(d),f.innerText=r.trim(),l.appendChild(c),l.appendChild(f),i.appendChild(l),document.body.appendChild(i),new t.Toast(l)}function d(){var e=location.hash;if(e&&e.match(/^\#tab_.+$/)){var r,o=e.replace("tab_",""),i=a((0,n.getElements)('ul.nav.nav-tabs .nav-link[data-bs-target="'.concat(o,'"]')));try{for(i.s();!(r=i.n()).done;){var l=r.value;new t.Tab(l).show()}}catch(c){i.e(c)}finally{i.f()}}}function f(){for(var t=0,e=[c,s,l,d];t<e.length;t++){(0,e[t])()}} "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createToast=u,exports.initBootstrap=f;var t=require("bootstrap"),e=r(require("masonry-layout")),n=require("./util");function r(t){return t&&t.__esModule?t:{default:t}}function a(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,a=function(){};return{s:a,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},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 i,l=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return l=t.done,t},e:function(t){c=!0,i=t},f:function(){try{l||null==n.return||n.return()}finally{if(c)throw i}}}}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(){var t,r=a((0,n.getElements)(".masonry"));try{for(r.s();!(t=r.n()).done;){var o=t.value;new e.default(o,{itemSelector:".masonry-item",percentPosition:!0})}}catch(i){r.e(i)}finally{r.f()}}function c(){var e,r=a((0,n.getElements)('[data-bs-toggle="tooltip"]'));try{for(r.s();!(e=r.n()).done;){var o=e.value;new t.Tooltip(o,{container:"body",boundary:"window"})}}catch(i){r.e(i)}finally{r.f()}}function s(){var e,r=a((0,n.getElements)('[data-bs-toggle="modal"]'));try{for(r.s();!(e=r.n()).done;){var o=e.value;new t.Modal(o)}}catch(i){r.e(i)}finally{r.f()}}function u(e,n,r,a){var o="bi-exclamation-triangle-fill";switch(e){case"warning":o="bi-exclamation-triangle-fill";case"success":o="bi-check-circle-fill";case"info":o="bi-info-circle-fill";case"danger":o="bi-exclamation-triangle-fill"}var i=document.createElement("div");i.setAttribute("class","toast-container position-fixed bottom-0 end-0 m-3");var l=document.createElement("div");l.setAttribute("class","toast bg-".concat(e)),l.setAttribute("role","alert"),l.setAttribute("aria-live","assertive"),l.setAttribute("aria-atomic","true");var c=document.createElement("div");c.setAttribute("class","toast-header bg-".concat(e," text-body"));var s=document.createElement("i");s.setAttribute("class","bi ".concat(o));var u=document.createElement("strong");u.setAttribute("class","me-auto ms-1"),u.innerText=n;var d=document.createElement("button");d.setAttribute("type","button"),d.setAttribute("class","btn-close"),d.setAttribute("data-bs-dismiss","toast"),d.setAttribute("aria-label","Close");var f=document.createElement("div");if(f.setAttribute("class","toast-body"),c.appendChild(s),c.appendChild(u),void 0!==a){var b=document.createElement("small");b.setAttribute("class","text-muted"),c.appendChild(b)}return c.appendChild(d),f.innerText=r.trim(),l.appendChild(c),l.appendChild(f),i.appendChild(l),document.body.appendChild(i),new t.Toast(l)}function d(){var e=location.hash;if(e&&e.match(/^\#tab_.+$/)){var r,o=e.replace("tab_",""),i=a((0,n.getElements)('ul.nav.nav-tabs .nav-link[data-bs-target="'.concat(o,'"]')));try{for(i.s();!(r=i.n()).done;){var l=r.value;new t.Tab(l).show()}}catch(c){i.e(c)}finally{i.f()}}}function f(){for(var t=0,e=[c,s,l,d];t<e.length;t++){(0,e[t])()}}
},{"bootstrap":"xqrD","masonry-layout":"l7pb","./util":"BHXf"}],"txP6":[function(require,module,exports) { },{"bootstrap":"xqrD","masonry-layout":"l7pb","./util":"BHXf"}],"txP6":[function(require,module,exports) {
"use strict";var e=require("./bs"),t=require("./util");function r(e,t,r,n,a,u,o){try{var i=e[u](o),c=i.value}catch(s){return void r(s)}i.done?t(c):Promise.resolve(c).then(n,a)}function n(e){return function(){var t=this,n=arguments;return new Promise(function(a,u){var o=e.apply(t,n);function i(e){r(o,a,u,i,c,"next",e)}function c(e){r(o,a,u,i,c,"throw",e)}i(void 0)})}}var a=1e3;function u(e){return new Promise(function(t){return setTimeout(t,e)})}function o(){var e=null,t=!1,r=document.getElementById("jobId");null!==r&&r.getAttribute("data-value")&&(e=r.getAttribute("data-value"));var n=document.getElementById("jobComplete");return null!==n&&"None"!==n.getAttribute("data-value")&&(t=!0),{id:e,complete:t}}function i(e){var t=document.querySelector("#pending-result-label > span.badge");if(null!==t){var r="secondary";switch(e.value){case"failed":r="danger";case"running":r="warning";case"completed":r="success"}t.setAttribute("class","badge bg-".concat(r)),t.innerText=e.label}}function c(e){return s.apply(this,arguments)}function s(){return(s=n(regeneratorRuntime.mark(function r(n){var o;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,(0,t.apiGetBase)("/api/extras/job-results/".concat(n,"/"));case 2:if(o=r.sent,!(0,t.hasError)(o)){r.next=9;break}return(0,e.createToast)("danger","Error",o.error).show(),r.abrupt("return");case 9:if(i(o.status),!["completed","failed","errored"].includes(o.status.value)){r.next=15;break}return location.reload(),r.abrupt("return");case 15:return a<1e4&&(a+=1e3),r.next=18,Promise.all([c(n),u(a)]);case 18:case"end":return r.stop()}},r)}))).apply(this,arguments)}function l(){var e=o(),t=e.id,r=e.complete;null===t||r||Promise.resolve(c(t))}"loading"!==document.readyState?l():document.addEventListener("DOMContentLoaded",l); "use strict";var e=require("./bs"),t=require("./util");function r(e,t,r,n,a,o,u){try{var i=e[o](u),s=i.value}catch(c){return void r(c)}i.done?t(s):Promise.resolve(s).then(n,a)}function n(e){return function(){var t=this,n=arguments;return new Promise(function(a,o){var u=e.apply(t,n);function i(e){r(u,a,o,i,s,"next",e)}function s(e){r(u,a,o,i,s,"throw",e)}i(void 0)})}}var a=1e3;function o(e){return new Promise(function(t){return setTimeout(t,e)})}function u(){var e=!1,r=(0,t.getNetboxData)("data-job-id"),n=(0,t.getNetboxData)("data-job-complete");return"string"==typeof n&&"none"!==n.toLowerCase()&&(e=!0),{id:r,complete:e}}function i(e){var t=document.querySelector("#pending-result-label > span.badge");if(null!==t){var r="secondary";switch(e.value){case"failed":r="danger";case"running":r="warning";case"completed":r="success"}t.setAttribute("class","badge bg-".concat(r)),t.innerText=e.label}}function s(e){return c.apply(this,arguments)}function c(){return(c=n(regeneratorRuntime.mark(function r(n){var u;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,(0,t.apiGetBase)("/api/extras/job-results/".concat(n,"/"));case 2:if(u=r.sent,!(0,t.hasError)(u)){r.next=9;break}return(0,e.createToast)("danger","Error",u.error).show(),r.abrupt("return");case 9:if(i(u.status),!["completed","failed","errored"].includes(u.status.value)){r.next=15;break}return location.reload(),r.abrupt("return");case 15:return a<1e4&&(a+=1e3),r.next=18,Promise.all([s(n),o(a)]);case 18:case"end":return r.stop()}},r)}))).apply(this,arguments)}function l(){var e=u(),t=e.id,r=e.complete;null===t||r||Promise.resolve(s(t))}"loading"!==document.readyState?l():document.addEventListener("DOMContentLoaded",l);
},{"./bs":"UEe5","./util":"BHXf"}]},{},["txP6"], null) },{"./bs":"UEe5","./util":"BHXf"}]},{},["txP6"], null)
//# sourceMappingURL=/static/jobs.js.map //# sourceMappingURL=/static/jobs.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
import { createToast } from './bs'; import { createToast } from './bs';
import { apiGetBase, hasError } from './util'; import { apiGetBase, hasError, getNetboxData } from './util';
let timeout: number = 1000; let timeout: number = 1000;
@ -21,19 +21,14 @@ function asyncTimeout(ms: number) {
* JavaScript. * JavaScript.
*/ */
function getJobInfo(): JobInfo { function getJobInfo(): JobInfo {
let id: Nullable<string> = null;
let complete = false; let complete = false;
// Determine the Job ID, if present. const id = getNetboxData('data-job-id');
const jobIdElement = document.getElementById('jobId'); const jobComplete = getNetboxData('data-job-complete');
if (jobIdElement !== null && jobIdElement.getAttribute('data-value')) {
id = jobIdElement.getAttribute('data-value');
}
// Determine the job completion status, if present. If the job is not complete, the value will be // Determine the job completion status, if present. If the job is not complete, the value will be
// "None". Otherwise, it will be a stringified date. // "None". Otherwise, it will be a stringified date.
const jobCompleteElement = document.getElementById('jobComplete'); if (typeof jobComplete === 'string' && jobComplete.toLowerCase() !== 'none') {
if (jobCompleteElement !== null && jobCompleteElement.getAttribute('data-value') !== 'None') {
complete = true; complete = true;
} }
return { id, complete }; return { id, complete };
@ -91,6 +86,7 @@ async function checkJobStatus(id: string) {
function initJobs() { function initJobs() {
const { id, complete } = getJobInfo(); const { id, complete } = getJobInfo();
if (id !== null && !complete) { if (id !== null && !complete) {
// If there is a job ID and it is not completed, check for the job's status. // If there is a job ID and it is not completed, check for the job's status.
Promise.resolve(checkJobStatus(id)); Promise.resolve(checkJobStatus(id));