Получить вывод из Alteryx API Query - PullRequest
0 голосов
/ 01 октября 2019

Я пытался настроить приложение javascrip, способное запускать и отображать результаты аналитического приложения Alteryx, размещенного на моем сервере. Идея заключается в том, чтобы встроить его в сервер Tableau.

У меня есть кое-что настроенное, что позволяет запускать приложение из пользовательского ввода и отображать его статус. Но получить результат работы немного сложнее, и я не могу разобраться с этим. Кажется, я должен использовать функцию getOutputFileURL (), чтобы получить то, что я хочу, но я действительно не уверен, как мне это настроить. Я пытался создать функцию getOutputs (), строка 54, но она ничего мне не дает.

Кто-нибудь, у кого был подобный опыт, не возражал бы мне помочь? Спасибо

'''`// Importing the modules & the keys
// polyfilling the extensions browser
import "babel-polyfill";
import keys from "./keys";
import Gallery from "alteryx-subscription-api";
import tableauJS from "./tableau";

// Grab the Run Button
const btn = document.getElementById("btn");
// Grab the input box
const input = document.getElementById("peopleSearch");
// Grab the message box
const inputValue = document.getElementById("message");
// Grab the spinner gif
const loading = document.getElementById("spinner");
// Grab the status paragraph
const statusInfo = document.getElementById("status");
// Grab the output div
const dataPrint = document.getElementById("dataOutput");

// load into the gallery based on the values specified in the keys file
const createGallery = () => {
  const gallery = new Gallery(keys.apilocation, keys.apikey, keys.apisecret);
  return gallery;
};

async function jobs(jobId) {
  const response = await createGallery().getJob(jobId);
  const data = await response.json();

  if (data.status !== "Completed") {
    // if workflow hasn't been completed, keep checking the jobID for its status
    jobs(jobId);
    if (inputValue.style.display == "block") {
      inputValue.style.display = "none";
    }
    loading.style.display = "inline";
    // if error please report
  } else if (data.status === "Error") {
    console.error(data.status);
    const status = data.status;
    statusInfo.innerHTML = status;
  } else {
    // if finished display completed message
    loading.style.display = "none";
    const status = data.status;
    statusInfo.innerHTML = status;
    statusInfo.style.display = "inline";
    // after 4 seconds remove the input and refresh the DS
    removeElement();
  }
}

// gets output from the job
async function getOutputs(jobId) {
  const response = await createGallery().getJob(jobId);
  const data = await response.json();
  console.log(data);
  for (var i = 0; i < data.length; i++) {
    var url = galleryOutput.getOutputFileURL(jobId, data.id, "Raw");
    dataPrint.innerHTML == url;
    dataPrint.style.display = "inline";
  }
  }

// on click of buton run the workflow/app specified in the keys file
async function runWorkflow(appId, dataArray) {
  const response = await createGallery().executeWorkflow(appId, dataArray);
  const data = await response.json();
  console.log(data);
  // check if the job is running and if finished
  jobs(data.id);
  getOutputs(data.id);
}


// If you click run, first check if search input has been specified, then it grabs the appID from the keys file
btn.addEventListener("click", () => {
  const peopleSearch = input.value;
  const appId = keys.appId;
  if (!peopleSearch) {
    inputValue.style.display = "block";
  } else {
    inputValue.style.display = "none";
    statusInfo.style.display = "none";
    const dataArray = [
      {
        name: "Text Box (414)",
        value: peopleSearch
      }
    ];
    runWorkflow(appId, dataArray);
  }
});

//removes the messages and the search input after 4 seconds and refresh the data source
function removeElement() {
  setTimeout(() => {
    if ((statusInfo.style.display = "inline")) {
      statusInfo.style.display = "none";
      input.value = "";
      tableauJS.refreshDS();
    }
  }, 6000);
}
`
...