Spaces:
Runtime error
Runtime error
Update templates/data_connectors.html
Browse files- templates/data_connectors.html +66 -93
templates/data_connectors.html
CHANGED
|
@@ -194,24 +194,26 @@
|
|
| 194 |
<div class="content-header">
|
| 195 |
<div class="container-fluid">
|
| 196 |
<div class="container mt-2">
|
| 197 |
-
<div class="form-group left-align">
|
| 198 |
<label for="company" class="mr-1" style="margin-left:-60px;margin-top:-1px;">Company Name <span class="text-danger">*</span></label>
|
| 199 |
<select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;margin-bottom:-35px" required>
|
| 200 |
<option value="" selected>Select</option>
|
| 201 |
</select>
|
| 202 |
-
</div>
|
| 203 |
<div class="row">
|
| 204 |
<div id="message-container" style="padding:10px 10px;margin-left: 150px;width:500px;margin-bottom:-20px; margin-top: -30px;"></div>
|
| 205 |
</div>
|
| 206 |
</div>
|
| 207 |
</div>
|
| 208 |
</div>
|
|
|
|
| 209 |
<form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
|
| 210 |
-
method="post"
|
| 211 |
<div class="form-group">
|
| 212 |
<!-- <label for="company_id">company_id</label>--->
|
| 213 |
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
| 214 |
</div>
|
|
|
|
| 215 |
<div class="row">
|
| 216 |
<div class="col-md-3">
|
| 217 |
<div class="form-group">
|
|
@@ -338,58 +340,45 @@
|
|
| 338 |
{%include 'footer.html'%}
|
| 339 |
</footer>
|
| 340 |
<script>
|
| 341 |
-
|
| 342 |
-
// const selectedDatabaseType =this.value;
|
| 343 |
-
// if (selectedDatabaseType) {
|
| 344 |
-
// fetchDatabaseDetails(selectedDatabaseType);
|
| 345 |
-
// }
|
| 346 |
-
// });
|
| 347 |
-
|
| 348 |
-
// async function fetchDatabaseDetails(databaseType) {
|
| 349 |
-
// try {
|
| 350 |
-
// const response = await fetch(`/api/get_database_details?database_type=${encodeURIComponent(databaseType)}`);
|
| 351 |
-
// if (!response.ok) {
|
| 352 |
-
// throw new Error('Network response was not ok');
|
| 353 |
-
// }
|
| 354 |
-
// const connectorsData= await response.json();
|
| 355 |
-
// //document.getElementById('server').value = connectorsData.server;
|
| 356 |
-
// // document.getElementById('port').value = connectorsData.port;
|
| 357 |
-
// // document.getElementById('databaseName').value = connectorsData.database_name;
|
| 358 |
-
// // document.getElementById('username').value = connectorsData.username;
|
| 359 |
-
// // document.getElementById('password').value = connectorsData.password;
|
| 360 |
-
// // document.getElementById('selectedTables').value = connectorsData.dbtablename;
|
| 361 |
-
// //updateFormFields(data);
|
| 362 |
-
// } catch (error) {
|
| 363 |
-
// console.error('Error fetching database details:', error);
|
| 364 |
-
// }
|
| 365 |
-
// }
|
| 366 |
document.addEventListener('DOMContentLoaded', function () {
|
| 367 |
-
fetchCompanies();
|
| 368 |
-
const companySelect = document.getElementById('company');
|
| 369 |
-
const databaseconnectorForm = document.getElementById('databaseconnectorForm');
|
| 370 |
-
database.addEventListener('change', async function () {
|
| 371 |
-
|
| 372 |
-
});
|
| 373 |
-
companySelect.addEventListener('change', async function () {
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
try {
|
| 392 |
-
const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${
|
| 393 |
if (!connectorsResponse.ok) {
|
| 394 |
throw new Error('data connector Network response was not ok');
|
| 395 |
}
|
|
@@ -411,7 +400,7 @@
|
|
| 411 |
document.getElementById('port').value = " ";
|
| 412 |
document.getElementById('databaseName').value = " ";
|
| 413 |
document.getElementById('username').value = " ";
|
| 414 |
-
document.getElementById('password').value = "
|
| 415 |
document.getElementById('selectedTables').value = " ";
|
| 416 |
console.error('Error fetching data from data connectors:', error);
|
| 417 |
("Company name does not exist. Please fill in the details.");
|
|
@@ -429,16 +418,17 @@
|
|
| 429 |
console.log(`Company ID does not exist, you can create and save data: ${data.company_id}`);
|
| 430 |
databaseconnectorForm.style.display = 'none';
|
| 431 |
}
|
|
|
|
| 432 |
|
| 433 |
-
|
| 434 |
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
});
|
| 442 |
|
| 443 |
// document.getElementById("connectBtn").addEventListener("click", function (event) {
|
| 444 |
// var database = document.getElementById("database").value;
|
|
@@ -469,7 +459,7 @@
|
|
| 469 |
});
|
| 470 |
$("#selectedTables").val(currentText);
|
| 471 |
});
|
| 472 |
-
|
| 473 |
var database = document.getElementById("database").value;
|
| 474 |
var server = document.getElementById("server").value;
|
| 475 |
var port = document.getElementById("port").value;
|
|
@@ -547,7 +537,7 @@ function updateTablesDropdown(schemaTables, selectedSchema) {
|
|
| 547 |
}
|
| 548 |
}
|
| 549 |
|
| 550 |
-
|
| 551 |
event.preventDefault(); // Prevent the default form submission
|
| 552 |
|
| 553 |
// Set the password value
|
|
@@ -555,8 +545,13 @@ function updateTablesDropdown(schemaTables, selectedSchema) {
|
|
| 555 |
|
| 556 |
const form = document.getElementById('databaseconnectorForm');
|
| 557 |
const formData = new FormData(form);
|
| 558 |
-
|
| 559 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
const response = await fetch(form.action, {
|
| 561 |
method: "POST",
|
| 562 |
body: formData
|
|
@@ -577,7 +572,7 @@ function updateTablesDropdown(schemaTables, selectedSchema) {
|
|
| 577 |
messageContainer.innerHTML = `
|
| 578 |
<div class='alert ${messageType}'>
|
| 579 |
${data.msg}
|
| 580 |
-
<button class='close'
|
| 581 |
</div>`;
|
| 582 |
}
|
| 583 |
}
|
|
@@ -588,15 +583,15 @@ function updateTablesDropdown(schemaTables, selectedSchema) {
|
|
| 588 |
if (messageContainer) {
|
| 589 |
messageContainer.innerHTML = `
|
| 590 |
<div class='alert alert-danger'>
|
| 591 |
-
An error occurred while saving data.
|
| 592 |
-
<button class='close' onclick='dismissMessage()'>OK</button>
|
| 593 |
</div>`;
|
| 594 |
}
|
| 595 |
}
|
| 596 |
});
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
const messageContainer = document.getElementById('message-container');
|
| 601 |
if (messageContainer) {
|
| 602 |
messageContainer.innerHTML = '';
|
|
@@ -610,29 +605,7 @@ function updateTablesDropdown(schemaTables, selectedSchema) {
|
|
| 610 |
document.getElementById('username').value = " ";
|
| 611 |
document.getElementById('password').value = " ";
|
| 612 |
}
|
| 613 |
-
|
| 614 |
-
try {
|
| 615 |
-
const response = await fetch('/api/companies');
|
| 616 |
-
if (!response.ok) {
|
| 617 |
-
throw new Error('Network response was not ok');
|
| 618 |
-
}
|
| 619 |
-
const data = await response.json();
|
| 620 |
-
displayCompanies(data.companies);
|
| 621 |
-
} catch (error) {
|
| 622 |
-
console.error('Error fetching companies:', error);
|
| 623 |
-
}
|
| 624 |
-
}
|
| 625 |
-
|
| 626 |
-
function displayCompanies(companies) {
|
| 627 |
-
const companySelect = document.getElementById('company');
|
| 628 |
-
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
|
| 629 |
-
companies.forEach(company => {
|
| 630 |
-
const option = document.createElement('option');
|
| 631 |
-
option.value = company.name;
|
| 632 |
-
option.textContent = company.name;
|
| 633 |
-
companySelect.appendChild(option);
|
| 634 |
-
});
|
| 635 |
-
}
|
| 636 |
|
| 637 |
function setMultiSelectValues(selectElement, values) {
|
| 638 |
// Ensure values is an array
|
|
|
|
| 194 |
<div class="content-header">
|
| 195 |
<div class="container-fluid">
|
| 196 |
<div class="container mt-2">
|
| 197 |
+
<!-- <div class="form-group left-align">
|
| 198 |
<label for="company" class="mr-1" style="margin-left:-60px;margin-top:-1px;">Company Name <span class="text-danger">*</span></label>
|
| 199 |
<select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;margin-bottom:-35px" required>
|
| 200 |
<option value="" selected>Select</option>
|
| 201 |
</select>
|
| 202 |
+
</div> -->
|
| 203 |
<div class="row">
|
| 204 |
<div id="message-container" style="padding:10px 10px;margin-left: 150px;width:500px;margin-bottom:-20px; margin-top: -30px;"></div>
|
| 205 |
</div>
|
| 206 |
</div>
|
| 207 |
</div>
|
| 208 |
</div>
|
| 209 |
+
|
| 210 |
<form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
|
| 211 |
+
method="post" >
|
| 212 |
<div class="form-group">
|
| 213 |
<!-- <label for="company_id">company_id</label>--->
|
| 214 |
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
| 215 |
</div>
|
| 216 |
+
<h4 id="selectedCompany" style="margin-left: 300px;margin-bottom: 50px;margin-top: -50px;"></h4>
|
| 217 |
<div class="row">
|
| 218 |
<div class="col-md-3">
|
| 219 |
<div class="form-group">
|
|
|
|
| 340 |
{%include 'footer.html'%}
|
| 341 |
</footer>
|
| 342 |
<script>
|
| 343 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
document.addEventListener('DOMContentLoaded', function () {
|
| 345 |
+
// fetchCompanies();
|
| 346 |
+
// const companySelect = document.getElementById('company');
|
| 347 |
+
// const databaseconnectorForm = document.getElementById('databaseconnectorForm');
|
| 348 |
+
// database.addEventListener('change', async function () {
|
| 349 |
+
// $("#message-container").empty();
|
| 350 |
+
// });
|
| 351 |
+
// companySelect.addEventListener('change', async function () {
|
| 352 |
+
// $("#message-container").empty();
|
| 353 |
+
// const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
|
| 354 |
+
// console.log(`Selected Company Name: ${selectedCompanyName}`);
|
| 355 |
+
|
| 356 |
+
// if (selectedCompanyName !== "Select") {
|
| 357 |
+
// $("#schema-table-section").hide();
|
| 358 |
+
// try {
|
| 359 |
+
// const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
|
| 360 |
+
// if (!response.ok) {
|
| 361 |
+
// throw new Error('Network response was not ok');
|
| 362 |
+
// }
|
| 363 |
+
// const data = await response.json();
|
| 364 |
+
// console.log(`Company ID: ${data.company_id}`);
|
| 365 |
+
// const companyId = data.company_id;
|
| 366 |
+
// document.getElementById('company_id').value = companyId;
|
| 367 |
+
var table = $('#databaseconnecorsform').show();
|
| 368 |
+
const role = sessionStorage.getItem('userRole');
|
| 369 |
+
const passedCompanyName=sessionStorage.getItem('company_name')
|
| 370 |
+
document.getElementById('selectedCompany').innerText = `Company name: ${passedCompanyName}`;
|
| 371 |
+
console.log('Current role:', role); // Debug statement to check the role
|
| 372 |
+
const storecompany_id=sessionStorage.getItem('company_id');
|
| 373 |
+
document.getElementById("company_id").value=storecompany_id;
|
| 374 |
+
|
| 375 |
+
data_get_from_db(storecompany_id,passedCompanyName);
|
| 376 |
+
});
|
| 377 |
+
async function data_get_from_db(storecompany_id,selectedCompanyName) {
|
| 378 |
+
|
| 379 |
+
if (storecompany_id) {
|
| 380 |
try {
|
| 381 |
+
const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${storecompany_id}&company_name=${selectedCompanyName}`);
|
| 382 |
if (!connectorsResponse.ok) {
|
| 383 |
throw new Error('data connector Network response was not ok');
|
| 384 |
}
|
|
|
|
| 400 |
document.getElementById('port').value = " ";
|
| 401 |
document.getElementById('databaseName').value = " ";
|
| 402 |
document.getElementById('username').value = " ";
|
| 403 |
+
document.getElementById('password').value = "";
|
| 404 |
document.getElementById('selectedTables').value = " ";
|
| 405 |
console.error('Error fetching data from data connectors:', error);
|
| 406 |
("Company name does not exist. Please fill in the details.");
|
|
|
|
| 418 |
console.log(`Company ID does not exist, you can create and save data: ${data.company_id}`);
|
| 419 |
databaseconnectorForm.style.display = 'none';
|
| 420 |
}
|
| 421 |
+
}
|
| 422 |
|
| 423 |
+
// } catch (error) {
|
| 424 |
|
| 425 |
+
// console.error('Error fetching company ID or data connectors:', error);
|
| 426 |
+
// databaseconnectorForm.style.display = 'none';
|
| 427 |
+
// }
|
| 428 |
+
// } else {
|
| 429 |
+
// databaseconnectorForm.style.display = 'none';
|
| 430 |
+
// }
|
| 431 |
+
// });
|
| 432 |
|
| 433 |
// document.getElementById("connectBtn").addEventListener("click", function (event) {
|
| 434 |
// var database = document.getElementById("database").value;
|
|
|
|
| 459 |
});
|
| 460 |
$("#selectedTables").val(currentText);
|
| 461 |
});
|
| 462 |
+
document.getElementById("connectBtn").addEventListener("click", function (event) {
|
| 463 |
var database = document.getElementById("database").value;
|
| 464 |
var server = document.getElementById("server").value;
|
| 465 |
var port = document.getElementById("port").value;
|
|
|
|
| 537 |
}
|
| 538 |
}
|
| 539 |
|
| 540 |
+
document.getElementById("saveBtn").addEventListener("click", async function (event) {
|
| 541 |
event.preventDefault(); // Prevent the default form submission
|
| 542 |
|
| 543 |
// Set the password value
|
|
|
|
| 545 |
|
| 546 |
const form = document.getElementById('databaseconnectorForm');
|
| 547 |
const formData = new FormData(form);
|
| 548 |
+
formData.append("company_id", document.getElementById('company_id').value);
|
| 549 |
try {
|
| 550 |
+
console.log("inside save",formData);
|
| 551 |
+
console.log("comaonyid", document.getElementById('company_id').value);
|
| 552 |
+
for (const [key, value] of formData.entries()) {
|
| 553 |
+
console.log(`${key}: ${value}`);
|
| 554 |
+
}
|
| 555 |
const response = await fetch(form.action, {
|
| 556 |
method: "POST",
|
| 557 |
body: formData
|
|
|
|
| 572 |
messageContainer.innerHTML = `
|
| 573 |
<div class='alert ${messageType}'>
|
| 574 |
${data.msg}
|
| 575 |
+
<button class='close'style='font-size:medium;margin-top:6px;'onclick='dismissMessage()'>OK</button>
|
| 576 |
</div>`;
|
| 577 |
}
|
| 578 |
}
|
|
|
|
| 583 |
if (messageContainer) {
|
| 584 |
messageContainer.innerHTML = `
|
| 585 |
<div class='alert alert-danger'>
|
| 586 |
+
An error occurred while saving data in database.
|
| 587 |
+
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
| 588 |
</div>`;
|
| 589 |
}
|
| 590 |
}
|
| 591 |
});
|
| 592 |
|
| 593 |
+
|
| 594 |
+
function dismissMessage() {
|
| 595 |
const messageContainer = document.getElementById('message-container');
|
| 596 |
if (messageContainer) {
|
| 597 |
messageContainer.innerHTML = '';
|
|
|
|
| 605 |
document.getElementById('username').value = " ";
|
| 606 |
document.getElementById('password').value = " ";
|
| 607 |
}
|
| 608 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
|
| 610 |
function setMultiSelectValues(selectElement, values) {
|
| 611 |
// Ensure values is an array
|