mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
use getNetboxData utility function in job handling
This commit is contained in:
parent
a55316aef9
commit
024f3962b2
BIN
netbox/project-static/dist/jobs.js
vendored
BIN
netbox/project-static/dist/jobs.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/jobs.js.map
vendored
BIN
netbox/project-static/dist/jobs.js.map
vendored
Binary file not shown.
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user