|
| 1 | +/** |
| 2 | + * Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Creates a SAS Content Job Object |
| 6 | + * |
| 7 | + * @param {Object} sasContentJobObject - Contains the definition of the SAS Content Job Object |
| 8 | + * @param {String} paneID - The shorthand of the page which will contain the object |
| 9 | + * @param {Object} scjInterfaceText - Contains all of the static language interface for the SAS Content Job Object |
| 10 | + * @returns a SAS Content Job object |
| 11 | + */ |
| 12 | +async function addSASContentJobObject(sasContentJobObject, paneID, scjInterfaceText) { |
| 13 | + let sasContentJobContainer = document.createElement('div'); |
| 14 | + sasContentJobContainer.setAttribute('id', `${paneID}-obj-${sasContentJobObject?.id}`); |
| 15 | + |
| 16 | + let sasContentGroup = document.createElement('sas-content-group'); |
| 17 | + sasContentGroup.id = `${paneID}-obj-${sasContentJobObject?.id}-cg`; |
| 18 | + sasContentGroup.className = 'col-12'; |
| 19 | + sasContentGroup.setAttribute('url', window.VIYA); |
| 20 | + sasContentGroup.initialFilterValue = { |
| 21 | + queryModeFilter: "or(eq(contentType,'jobDefinition'),eq(contentType,'folder'))" |
| 22 | + }; |
| 23 | + // Check if the a folder filter has been specified |
| 24 | + if (sasContentJobObject?.folderFilter?.length > 0) { |
| 25 | + let folderFilter = { |
| 26 | + "type": "folderUri", |
| 27 | + "value": sasContentJobObject?.folderFilter |
| 28 | + }; |
| 29 | + sasContentGroup.initialNavigationValue = { |
| 30 | + location: folderFilter, |
| 31 | + locationContextPath: [folderFilter], |
| 32 | + locations: [folderFilter] |
| 33 | + }; |
| 34 | + } else { |
| 35 | + let sasContentIdentifier = { |
| 36 | + type: "persistentLocation", |
| 37 | + value: "root" |
| 38 | + }; |
| 39 | + sasContentGroup.initialNavigationValue = { |
| 40 | + location: sasContentIdentifier, |
| 41 | + locationContextPath: [sasContentIdentifier], |
| 42 | + locations: [sasContentIdentifier] |
| 43 | + }; |
| 44 | + } |
| 45 | + // Job Header |
| 46 | + let sasContentJobName = document.createElement('h3'); |
| 47 | + let sasJobContainer = document.createElement('div'); |
| 48 | + sasJobContainer.style.height = '75vh'; |
| 49 | + let sasJob = document.createElement('iframe'); |
| 50 | + |
| 51 | + let sasContentArea = document.createElement('sas-content-area'); |
| 52 | + sasContentArea.id = `${paneID}-obj-${sasContentJobObject?.id}-ca`; |
| 53 | + //sasContentArea.style.height = '30vh'; |
| 54 | + sasContentArea.setAttribute('url', window.VIYA); |
| 55 | + sasContentArea.setAttribute('selection-mode', 'single'); |
| 56 | + sasContentArea.setAttribute('initial-selection-index', 0); |
| 57 | + sasContentArea.onSelect = async (value) => { |
| 58 | + console.log(value); |
| 59 | + if (value && value.length > 0 && value[0]?.resource?.type?.sasType === 'jobDefinition') { |
| 60 | + const job = value[0]; |
| 61 | + const jobExecutionUrl = await contentSdkComponents.getSASJobExecutionUrl(job.resource.id, window.VIYA); |
| 62 | + if (jobExecutionUrl) { |
| 63 | + if (sasContentJobObject?.jobName === 1) { |
| 64 | + sasContentJobName.innerText = job.name; |
| 65 | + } |
| 66 | + sasJobContainer.style.display = 'block'; |
| 67 | + sasJob.src = jobExecutionUrl; |
| 68 | + } else { |
| 69 | + if (sasContentJobObject?.jobName === 1) { |
| 70 | + sasContentJobName.innerText = scjInterfaceText?.noJobSelectedText; |
| 71 | + } |
| 72 | + sasJobContainer.style.display = 'none'; |
| 73 | + sasJob.src = 'about:blank'; |
| 74 | + } |
| 75 | + } else { |
| 76 | + if (sasContentJobObject?.jobName === 1) { |
| 77 | + sasContentJobName.innerText = scjInterfaceText?.noJobSelectedText; |
| 78 | + } |
| 79 | + sasJobContainer.style.display = 'none'; |
| 80 | + sasJob.src = 'about:blank'; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + sasContentGroup.appendChild(sasContentArea); |
| 85 | + |
| 86 | + // Job display |
| 87 | + if (sasContentJobObject?.jobName === 1) { |
| 88 | + sasContentJobName.id = `${paneID}-obj-${sasContentJobObject?.id}-jn`; |
| 89 | + console.log(scjInterfaceText); |
| 90 | + sasContentJobName.innerText = scjInterfaceText?.noJobSelectedText; |
| 91 | + sasContentGroup.appendChild(sasContentJobName); |
| 92 | + } |
| 93 | + sasJob.id = `${paneID}-obj-${sasContentJobObject?.id}-sj`; |
| 94 | + sasJob.src = 'about:blank'; |
| 95 | + sasJob.style.overflow = 'hidden'; |
| 96 | + sasJob.style.border = '0'; |
| 97 | + sasJob.style.height = '70vh'; |
| 98 | + sasJob.style.width = '70vh'; |
| 99 | + sasJobContainer.appendChild(sasJob); |
| 100 | + sasContentGroup.appendChild(sasJobContainer); |
| 101 | + |
| 102 | + sasContentJobContainer.appendChild(sasContentGroup); |
| 103 | + |
| 104 | + return sasContentJobContainer; |
| 105 | +} |
0 commit comments