Spaces:
Sleeping
Sleeping
File size: 29,639 Bytes
294253d c7525e3 294253d e0981df c7525e3 294253d c7525e3 04b105c c7525e3 294253d c7525e3 294253d c7525e3 294253d c7525e3 294253d c7525e3 294253d c7525e3 294253d c7525e3 294253d 04b105c c7525e3 294253d 04b105c c7525e3 04b105c c7525e3 04b105c c7525e3 04b105c c7525e3 294253d 04b105c c7525e3 294253d 04b105c c7525e3 294253d 04b105c c7525e3 294253d c7525e3 04b105c c7525e3 04b105c c7525e3 04b105c c7525e3 294253d 04b105c 294253d 04b105c c7525e3 04b105c c7525e3 04b105c e0981df 294253d e0981df 294253d e0981df c7525e3 e0981df ba95f6e c7525e3 e0981df c7525e3 294253d c7525e3 294253d c7525e3 294253d c7525e3 e0981df c7525e3 294253d c7525e3 294253d c7525e3 e0981df 294253d c7525e3 294253d e0981df c7525e3 294253d e0981df 294253d e0981df c7525e3 e0981df 294253d e0981df 294253d e0981df 294253d e0981df 294253d e0981df 294253d 04b105c e0981df 294253d c7525e3 294253d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Connectors</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<link rel="stylesheet" href="/static/css/data_connectors.css">
</head>
<style>
</style>
<body>
{% include 'sidepane.html' %}
<div class="wrapper" style="z-index: 0 !important;">
<div class="main-header" style="border-bottom: none;">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="container mt-2">
<!-- <div class="form-group left-align">
<label for="company" class="mr-1" style="margin-left:-60px;margin-top:-1px;">Company Name <span class="text-danger">*</span></label>
<select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;margin-bottom:-35px" required>
<option value="" selected>Select</option>
</select>
</div> -->
<div class="row">
<div id="message-container"
style="padding:10px 10px;margin-left: 150px;width:500px;margin-bottom:-20px; margin-top: -30px;">
</div>
</div>
</div>
</div>
</div>
<form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
method="post">
<div class="container-fluid main" id="main">
<div class="form-group">
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<h4 id="selectedCompany" class="text-center mb-4"></h4>
<div class="row">
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="database">Database Type <span class="text-danger">*</span></label>
<select id="database" name="database" class="form-control" required>
<option value="" selected>Select</option>
<option value="Postgres">Postgres</option>
<option value="mysql">MySQL</option>
</select>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="server">Server IP <span class="text-danger">*</span></label>
<input type="text" id="server" name="server" class="form-control" required>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="port">Port <span class="text-danger">*</span></label>
<input type="text" id="port" name="port" class="form-control" required>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="databaseName">Database Name <span class="text-danger">*</span></label>
<input type="text" id="databaseName" name="databaseName" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="username">UserName <span class="text-danger">*</span></label>
<input type="text" id="username" name="username" class="form-control" required>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<div class="form-group">
<label for="password">Password <span class="text-danger">*</span></label>
<input type="password" id="password" name="password" class="form-control" required>
</div>
</div>
<div class="col-md-12 col-lg-6 d-flex justify-content-center align-items-center mb-3 "
id="btnbox">
<div class="btn-container">
<button type="button" id="connectBtn" class="btn btn-primary me-2">Connect</button>
<button type="reset" class="btn btn-secondary">Clear</button>
</div>
</div>
</div>
</div>
<!-- Table -->
<div class="container-fluid table-container" style="display: none;" id="table">
<div class="row">
<div class="col-12">
<div class="card shadow p-4">
<h1 class="text-center fs-4" id="tablename">Selected Tables</h1>
<div class="table-responsive">
<table id="adminlte-table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sno</th>
<th>Table Name</th>
<th>Schema Name</th>
</tr>
</thead>
<tbody id="table-body">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="schema-table-section" style="margin-left: 30px; width: 100%; height: 530px; display: none;">
<div class="row">
<div class="col-md-3">
<div class="form-group1">
<label for="schemas">Select Schemas <span class="text-danger">*</span></label>
<select type="text" id="schemas" name="schemas" class="form-control" required>
<option value="" selected>Select</option>
<option value="schema1">Lookup</option>
<option value="schema2">Public</option>
<option value="schema3" selected>tenant_default</option>
</select>
</div>
</div>
<div class="col-md-3" style="position: absolute; right: 15%;">
<div class="form-group1">
<label for="selectedTables" id="labelselected">Selected Tables</label>
<textarea type="text" id="selectedTables" name="selectedTables" class="form-control"
rows="4" readonly
style="height: 310px !important; width: 330px !important;"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3" style="margin-top: 50px;margin-left: -100px;">
<div class="form-group">
<!-- Label with better spacing -->
<label for="tableschema" class="form-label" style="margin-top: 0px; width: 200%;">
Available Tables <span class="text-danger">*</span>
</label>
<!-- Dropdown container -->
<div class="dropdown custom-dropdown" style="margin-top: -35px;">
<!-- Dropdown menu with form styling -->
<ul class="dropdown-menu p-3 w-100" aria-labelledby="tablesDropdown"
style="max-height: 200px; overflow-y: auto;">
<li>
<!-- Multiple select dropdown with custom styles -->
<select id="tableschema" name="tableschema" class="form-select" multiple
required
style="height: 150px; width: 240px; border-radius: .375rem; box-shadow: 0 1px 2px rgba(0,0,0,.1);margin-left: 10px;padding: 5px;">
<option value="customer_master">Customer Master</option>
<option value="efs_company_master">EFS Company Master</option>
<option value="efs_group_company_master">EFS Group Company Master
</option>
<option value="efs_region_master">EFS Region Master</option>
<option value="party_address_detail">Party Address Detail</option>
<option value="wms_warehouse_master">WMS Warehouse Master</option>
</select>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-md-3" style="margin-top: 250px;">
<div class="btn-container1">
<button type="button" id="saveBtn" class="btn btn-primary"
style="width: 600px; margin-top: 10px;">Save</button>
</div>
</div>
</div>
<!-- <div class="col-md-3">
<div class="form-group">
<div class="btn-container1">
<button type="submit" id="saveBtn" class="btn btn-primary">Save</button>
</div>
</div>
</div> -->
</form>
</div>
</div>
</div>
<footer class="footer">
{%include 'footer.html'%}
</footer>
<!-- Include jQuery, DataTables, and AdminLTE Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/admin-lte/dist/js/adminlte.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// fetchCompanies();
// const companySelect = document.getElementById('company');
// const databaseconnectorForm = document.getElementById('databaseconnectorForm');
// database.addEventListener('change', async function () {
// $("#message-container").empty();
// });
// companySelect.addEventListener('change', async function () {
// $("#message-container").empty();
// const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
// console.log(`Selected Company Name: ${selectedCompanyName}`);
// if (selectedCompanyName !== "Select") {
// $("#schema-table-section").hide();
// try {
// const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
// if (!response.ok) {
// throw new Error('Network response was not ok');
// }
// const data = await response.json();
// console.log(`Company ID: ${data.company_id}`);
// const companyId = data.company_id;
// document.getElementById('company_id').value = companyId;
var table = $('#databaseconnecorsform').show();
const role = sessionStorage.getItem('userRole');
const passedCompanyName = sessionStorage.getItem('company_name')
document.getElementById('selectedCompany').innerText = `Company Name: ${passedCompanyName}`;
console.log('Current role:', role); // Debug statement to check the role
const storecompany_id = sessionStorage.getItem('company_id');
document.getElementById("company_id").value = storecompany_id;
data_get_from_db(storecompany_id, passedCompanyName);
});
async function data_get_from_db(storecompany_id, selectedCompanyName) {
if (storecompany_id) {
try {
const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${storecompany_id}&company_name=${selectedCompanyName}`);
if (!connectorsResponse.ok) {
throw new Error('data connector Network response was not ok');
}
const connectorsData = await connectorsResponse.json();
//setMultiSelectValues(document.getElementById('database'), connectorsData.databasetype); // Ensure this is an array
//setMultiSelectValues(document.getElementById('databaseName'), connectorsData.database_name); // Ensure this is an array
document.getElementById('database').value = connectorsData.databasetype;
document.getElementById('server').value = connectorsData.serverip; // document.getElementById('server').value = connectorsData.serverip;
document.getElementById('port').value = connectorsData.port;
document.getElementById('databaseName').value = connectorsData.database_name;
document.getElementById('username').value = connectorsData.username;
document.getElementById('password').value = connectorsData.password;
document.getElementById('selectedTables').value = connectorsData.dbtablename;
databaseconnectorForm.style.display = 'block';
} catch (error) {
document.getElementById('database').value = " ";
document.getElementById('server').value = " ";
document.getElementById('port').value = " ";
document.getElementById('databaseName').value = " ";
document.getElementById('username').value = " ";
document.getElementById('password').value = "";
document.getElementById('selectedTables').value = " ";
console.error('Error fetching data from data connectors:', error);
("Company name does not exist. Please fill in the details.");
// Optionally, you can insert a message into the DOM
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = "<div class='alert alert-danger'>Database details does not exist for this Company name.. Please fill in the details.</div>";
}
databaseconnectorForm.style.display = 'block';
}
} else {
console.log(`Company ID does not exist, you can create and save data: ${data.company_id}`);
databaseconnectorForm.style.display = 'none';
}
}
// } catch (error) {
// console.error('Error fetching company ID or data connectors:', error);
// databaseconnectorForm.style.display = 'none';
// }
// } else {
// databaseconnectorForm.style.display = 'none';
// }
// });
// document.getElementById("connectBtn").addEventListener("click", function (event) {
// var database = document.getElementById("database").value;
// var server = document.getElementById("server").value;
// var port = document.getElementById("port").value;
// var databaseName = document.getElementById("databaseName").value;
// var username = document.getElementById("username").value;
// var password = document.getElementById("password").value;
// if (!database || !server || !port || !databaseName || !username || !password) {
// alert("Please fill in all required fields.");
// return;
// }
// document.getElementById("schema-table-section").style.display = "block";
// });
$("#tableschema").change(function () {
var selectedTables = $(this).val();
var currentText = $("#selectedTables").val();
selectedTables.forEach(function (table) {
if (!currentText.includes(table)) {
if (currentText.length > 1) {
currentText += ", " + table;
} else {
currentText = table;
}
}
});
$("#selectedTables").val(currentText);
});
document.getElementById("connectBtn").addEventListener("click", function (event) {
var database = document.getElementById("database").value;
var server = document.getElementById("server").value;
var port = document.getElementById("port").value;
var databaseName = document.getElementById("databaseName").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value || "";
if (!database || !server || !port || !databaseName || !username) {
alert("Please fill in all required fields.");
return;
}
// document.getElementById("schema-table-section").style.display = "block";
fetch("/api/connect", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
database_type: database,
server: server,
port: port,
databaseName: databaseName,
username: username,
password: password
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById("schema-table-section").style.display = "block";
document.getElementById("main").style.display = "none"
document.getElementById("table").style.display = "none"
populateSchemaDropdown(data.schemas);
// Set default selection for tables
if (data.schemas.length > 0) {
updateTablesDropdown(data.schema_tables, data.schemas[0]);
schemas.addEventListener("change", function (event) {
var selectedSchema = event.target.value;
updateTablesDropdown(data.schema_tables, selectedSchema);
});
}
} else {
alert("Failed to connect to the database. Please check your credentials.");
document.getElementById("schema-table-section").style.display = "none";
}
})
.catch(error => {
console.error("Error:", error);
alert("An error occurred while connecting to the database.");
});
});
function populateSchemaDropdown(schemas) {
var schemaSelect = document.getElementById("schemas");
schemaSelect.innerHTML = ""; // Clear any existing options
schemas.forEach(function (schema) {
var option = document.createElement("option");
option.value = schema;
option.textContent = schema;
schemaSelect.appendChild(option);
});
}
function updateTablesDropdown(schemaTables, selectedSchema) {
var tableSchemaSelect = document.getElementById("tableschema");
tableSchemaSelect.innerHTML = ""; // Clear any existing options
if (schemaTables[selectedSchema]) {
schemaTables[selectedSchema].forEach(function (table) {
var option = document.createElement("option");
option.value = table;
option.textContent = table;
tableSchemaSelect.appendChild(option);
});
}
}
document.getElementById("saveBtn").addEventListener("click", async function (event) {
event.preventDefault(); // Prevent the default form submission
// Get values from form fields
const schemaname = document.getElementById("schemas") ? document.getElementById("schemas").value : null;
const tablename = document.getElementById('selectedTables') ? document.getElementById('selectedTables').value : null;
const companyId = document.getElementById('company_id') ? document.getElementById('company_id').value : null;
// Validate required fields
if (!tablename) {
alert('Table name is required');
return;
}
if (!companyId) {
alert('Company ID is required');
return;
}
// Save the table name to localStorage
window.localStorage.setItem("tablename", tablename);
// Retrieve table names from localStorage and process
const tableNames = localStorage.getItem("tablename"); // Retrieve the string
if (tableNames) {
const tableArray = tableNames.split(','); // Split the string into an array
tableArray.forEach((table) => console.error(table.trim())); // Print each table name
} else {
console.error("No table names found in localStorage.");
}
const form = document.getElementById('databaseconnectorForm');
const formData = new FormData(form);
// Append additional data to the formData
formData.append("company_id", companyId);
try {
console.log("inside save", formData);
console.log("company_id", companyId);
// Log form data for debugging
for (const [key, value] of formData.entries()) {
console.error(`${key}: ${value}`);
}
// Send data to the server
const response = await fetch(form.action, {
method: "POST",
body: formData
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log("result", data);
const messageContainer = document.getElementById('message-container');
if (data.created) {
if (messageContainer) {
dismissMessage()
}
// If there are table names in localStorage, display them in the table
const schemaName = schemaname ? schemaname : 'N/A'; // Default to 'N/A' if schema is null
const tableNames = localStorage.getItem("tablename");
const tableBody = document.getElementById("table-body");
if (tableNames) {
const tableArray = tableNames.split(',');
let serialNumber = tableBody.rows.length + 1;
tableArray.forEach((table, index) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${serialNumber++}</td>
<td>${table.trim()}</td>
<td>${schemaName}</td>
`;
tableBody.appendChild(row);
});
} else {
console.error("No table names found in localStorage.");
}
// Initialize DataTable only if it's not already initialized
$(document).ready(function () {
if (!$.fn.dataTable.isDataTable('#adminlte-table')) {
$("#adminlte-table").DataTable({
responsive: true,
autoWidth: false,
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
pageLength: 5,
lengthMenu: [5, 10, 15, 20],
language: {
paginate: {
previous: "<button class='btn1'>Previous</button>",
next: "<button class='btn1'>Next</button>",
}
}
});
}
});
}
} catch (error) {
console.error('Error saving data:', error);
}
});
function dismissMessage() {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = '';
document.getElementById("main").style.display = "block"
document.getElementById("table").style.display = "block"
document.getElementById("schema-table-section").style.display = "none"
}
}
function handleError() {
document.getElementById('database').value = " ";
document.getElementById('server').value = " ";
document.getElementById('port').value = " ";
document.getElementById('databaseName').value = " ";
document.getElementById('username').value = " ";
document.getElementById('password').value = " ";
}
function setMultiSelectValues(selectElement, values) {
// Ensure values is an array
if (!Array.isArray(values)) {
values = [values];
}
Array.from(selectElement.options).forEach(option => {
option.selected = values.includes(option.value);
});
}
</script>
</body>
</html> |