Skip to content

Commit

Permalink
Add support for asking for meta information to client #12 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
JetamZ committed Feb 23, 2025
1 parent f114555 commit 7fc4161
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
32 changes: 21 additions & 11 deletions WebApp/scripts/dynamic_form_render.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAvailableDatabases, getMetaInformation } from './metaInformation.js';

let queryObject = {
target_databases: [],
description: "",
Expand Down Expand Up @@ -340,7 +342,8 @@ function renderGroupBy(container, step, stepIndex) {
columnsContainer.className = 'repeatable-container';
step.columns.forEach((column, columnIndex) => {
const columnRow = document.createElement('div');
columnRow.className = 'repeatable-container';
columnRow.className = 'repeatable-row';

const columnInput = document.createElement('input');
columnInput.type = 'text';
columnInput.placeholder = 'Column';
Expand Down Expand Up @@ -393,24 +396,30 @@ function renderTargetSection(container) {
queryObject.target_databases.forEach((database, databaseIndex) => {
const row = document.createElement('div');
row.className = 'repeatable-row';

const input = document.createElement('input');
input.type = 'text';
input.value = database;
input.placeholder = 'Target Database';
input.addEventListener('input', () => {
queryObject.target_databases[databaseIndex] = input.value;
// ========================== NEW ===============================
const newInput = document.createElement('select');
// let databases = getAvailableDatabases();
// console.log(databases);
let metainformation = getMetaInformation()

metainformation.available_databases.forEach(databaseName => {
const option = document.createElement('option');
option.value = databaseName;
option.textContent = databaseName;
newInput.appendChild(option);
});

newInput.addEventListener('change', () => {
queryObject.target_databasesp[databaseIndex] = newInput.value;
});
// ======================= END NEW ==============================
const removeButton = document.createElement('button');
removeButton.type = 'button';
removeButton.textContent = '-';
removeButton.onclick = () => {
queryObject.target_databases.splice(databaseIndex, 1);
renderForm();
};

row.appendChild(input);
row.appendChild(newInput);
row.appendChild(removeButton);
targetDatabasesContainer.appendChild(row);
});
Expand Down Expand Up @@ -549,4 +558,5 @@ loadButton.onclick = () => {

document.addEventListener("DOMContentLoaded", () => {
renderForm();

});
21 changes: 21 additions & 0 deletions WebApp/scripts/metaInformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let databaseInfoRouteGeneral = "http://127.0.0.1:5000/metainformation";

async function storeMetainformation() {
try {
const response = await fetch(databaseInfoRouteGeneral);
const responseJSON = await response.json();
console.log(responseJSON);
localStorage.setItem("metaInformation", JSON.stringify(responseJSON))
} catch (error) {
console.error("Error fetching metaInformation");
return []
}
}

export function getMetaInformation() {
const metaInformation = localStorage.getItem("metaInformation");
return metaInformation ? JSON.parse(metaInformation) : [];
}

// document.addEventListener("DOMContentLoaded", storeAvailableDatabases);
document.addEventListener("DOMContentLoaded", storeMetainformation);

0 comments on commit 7fc4161

Please sign in to comment.