Spaces:
Runtime error
Runtime error
Upload 5 files
Browse filesFiles changed (5)
- templates/API_connectors.htmlAdded+461
- templates/company_profile.htmlAdded+521
- templates/data_connectors.htmlAdded+662
- templates/knowledgebase.htmlAdded+667
- templates/prompt_template.htmlAdded+459
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461<!DOCTYPE html>
<html>
<head>
<title>API Connectors</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Include AdminLTE CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1/dist/css/adminlte.min.css">
<!-- Include DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<style>
.form-group {
margin-top: -10px;
}
.card {
padding: 0;
margin-top: -15px;
margin-left: -40px;
}
.header-row {
display: flex;
justify-content: space-between;
align-items: center;
}
.table-container {
width: 100%;
overflow-x: auto;
}
.wrapper {
display: flex;
flex-direction: column;
height: 100vh;
}
.content-wrapper {
flex: 1;
overflow-y: auto;
}
.content-header {
padding: 5px;
}
th,
td {
white-space: nowrap;
}
th:nth-child(1),
td:nth-child(1) {
/* Sno column */
width: 5%;
}
div.dataTables_wrapper div.dataTables_length select{
width: 60px;
display: inline-block;
}
th:nth-child(2),
td:nth-child(2) {
/* API Name column */
width: 20%;
}
th:nth-child(3),
td:nth-child(3) {
/* API Endpoint column */
width: 40%;
}
th:nth-child(4),
td:nth-child(4) {
/* Auth/Bearer token column */
width: 5%;
}
th:nth-child(5),
td:nth-child(5) {
/* View column */
width: 5%;
}
th:nth-child(6),
td:nth-child(6) {
/* View column */
width: 5%;
}
.reduced-width {
width: 25%;
}
div.dataTables_wrapper div.dataTables_length select{
width: 60px;
display: inline-block;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<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: 5px;">Company Name <span class="text-danger">*</span></label>
<select type="text" id="company" name="company" class="form-control"style="width: 20%;margin-left:-60px;" required>
<option value="" selected>Select</option>
</select>
<div class="col-12 d-flex justify-content-end mb-3">
<button class="btn btn-primary" style="margin-top: -40px;margin-right: -25px;position: fixed;" id="add">Add</button>
</div>
</div>
<div class="row">
<div id="message-container" style="margin-left: 150px; width: auto;"></div>
</div>
</div>
</div>
</div>
<section class="content" id="contentSection" style="display: none;">
<div class="container-fluid">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
</div>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body table-container">
<table id="apiTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sno</th>
<th>API Name</th>
<th>API Endpoint</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<!-- <tr>
<td>1</td>
<td>Warehouse</td>
<td>http://193.203.162.39:9090/nxt-wms/userWarehouse/fetchWarehouseForUserId
</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>2</td>
<td>customer</td>
<td>http://193.203.162.39:9090/nxt-wms/userCustomer/fetchCustomerForUserId
</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>3</td>
<td>SKU</td>
<td>http://193.203.162.39:9090/nxt-wms/sku/autoComplete?</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>4</td>
<td>ASN</td>
<td>http://193.203.162.39:9090/nxt-wms/trnHeader</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr> -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
aria-hidden="true">
<div class="modal-dialog" style="margin-top: -10px;" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">Add API Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" data-backdrop="static" data-keyboard="false">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<form id="documentForm">
<div class="form-group">
<label for="APIName">API Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="APIName" name="APIName" required>
</div>
<div class="form-group">
<label for="APIEndpoint">API Endpoint <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="APIEndpoint" name="APIEndpoint" required>
</div>
<div class="form-group">
<label for="Auth_Bearer">Auth/Bearer token <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="Auth_Bearer" name="Auth_Bearer" required>
</div>
<div class="form-group">
<label for="Inputjson">Input parameter <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="Inputjson" name="Inputjson" required>
</div>
<div class="form-group">
<label for="OutputJson">Output Json <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="OutputJson" name="OutputJson" required>
</div>
<div class="form-group">
<label for="Description">Description <span class="text-danger">*</span></label>
<textarea class="form-control" id="Description" name="Description" rows="3"
required></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> -->
<button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
{%include 'footer.html'%}
<!-- Include DataTables JS and your custom script -->
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function () {
// Show modal function
$('#add').on('click', function () {
clearFormFields();
$('#message-container').empty(); // Clear the message container
$('#addModal').modal('show');
});
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
$('#addModal').modal('hide');
});
// $('#apiTable').DataTable({
// autoWidth: false
// });
});
document.addEventListener("DOMContentLoaded", function () {
// clearFormFields();
fetchCompanies();
const companySelect = document.getElementById('company');
const documentForm = document.getElementById('documentForm');
const table = $('#apiTable').DataTable();
// Initialize DataTable at the start
companySelect.addEventListener('change', async function () {
$("#message-container").empty();
const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
console.log(`Selected Company Name: ${selectedCompanyName}`);
if (selectedCompanyName !== "Select") {
try {
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
if (!response.ok) {
contentSection.style.display = 'none';
("Company id does not exist for this company name does not exist. Please fill in the details.");
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = "<div class='alert alert-danger'>Document details do not exist for this company. Please fill in the details.</div>";
}
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log('data returned', data);
console.log(`Company ID: ${data.company_id}`);
const companyId = data.company_id;
document.getElementById('company_id').value = companyId;
if (companyId) {
try {
const Response = await fetch(`/api/get_api_connectors?company_id=${companyId}&company_name=${selectedCompanyName}`);
const connectorsResponse = await Response.json();
console.log("api connector data table after connecting to table", connectorsResponse);
table.clear();
if (!Array.isArray(connectorsResponse)) {
throw new TypeError('Expected an array of companies');
displayErrorMessage("Data do not exist for this company. Please fill in the details by clicking add button.");
contentSection.style.display = 'none';
} else {
connectorsResponse.forEach((company, index) => {
table.row.add([
index + 1,
company.APIName,
company.APIEndpoint,
"<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye' fa-eye'></i></a>",
"<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
"<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
]).draw(false);
});
contentSection.style.display = 'block';
}
} catch (error) {
console.error('Error fetching company documents:', error);
//displayEmptyTable();
displayErrorMessage("Data do not exist for this company. Please fill in the details by clicking add button.");
contentSection.style.display = 'none';
}
}
else {
// displayEmptyTable();
displayErrorMessage("Document details2 for knowledge do not exist for this company. Please fill in the details.");
}
} catch (error) {
console.error('No details for this company ID or data documents:', error);
// displayEmptyTable();
displayErrorMessage("Document details3 do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
}
} else {
table.clear().draw();
document.getElementById('contentSection').style.display = 'none';
// Optionally, you might want to clear the form fields as well
clearFormFields();
}
});
function displayErrorMessage(message) {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = `<div class='alert alert-danger'>${message}</div>`;
}
}
});
function save_file() {
const form = document.getElementById('documentForm');
// Check if the form is valid
if (!form.checkValidity()) {
// If the form is invalid, show validation messages and stop the submission
form.reportValidity();
return;
}
const company_id = $('#company_id').val();
const APIName = $('#APIName').val();
const APIEndpoint = $('#APIEndpoint').val();
const Auth_Bearer = $('#Auth_Bearer').val();
const Inputjson = $('#Inputjson').val();
const OutputJson = $('#OutputJson').val();
const Description = $('#Description').val();
const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
const dele = "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
var formData = new FormData($('#documentForm')[0]);
formData.append("company_id", company_id),
formData.append("api_name", APIName),
formData.append("api_endpoint", APIEndpoint),
formData.append("auth_bearer", Auth_Bearer),
formData.append("input_json", Inputjson),
formData.append("output_json", OutputJson),
formData.append("description", Description)
//const formData = new FormData();
fetch('/api/save_api_details', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
var table = $('#apiTable').DataTable();
var rowCount = table.rows().count();
table.row.add([
rowCount + 1,
APIName,
APIEndpoint,
Auth_Bearer,
Inputjson,
OutputJson,
Description,
view,
edit,
dele
]).draw(false);
alert('Document saved successfully');
$('#addModal').modal('hide');
document.getElementById('contentSection').style.display = 'block'; // Show the table section
})
.catch(error => console.error('Error:', error));
}
async function fetchCompanies() {
try {
const response = await fetch('/api/companies');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
displayCompanies(data.companies);
} catch (error) {
console.error('Error fetching companies:', error);
}
}
function displayCompanies(companies) {
const companySelect = document.getElementById('company');
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
companies.forEach(company => {
const option = document.createElement('option');
option.value = company.name;
option.textContent = company.name;
companySelect.appendChild(option);
});
}
function clearFormFields() {
document.getElementById('APIName').value = "";
document.getElementById('APIEndpoint').value = "";
document.getElementById('Auth_Bearer').value = "";
document.getElementById('Inputjson').value = "";
document.getElementById('OutputJson').value = "";
document.getElementById('Description').value = "";
}
</script>
</body>
</html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Company Profile</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Include AdminLTE CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1/dist/css/adminlte.min.css">
<!-- Include DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/@ttskch/select2-bootstrap4-theme@1.4.0/dist/select2-bootstrap4.min.css"
rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<style>
body {
background-color: transparent !important;
}
.card {
padding: 0;
margin-top: 10px;
margin-left: -40px;
}
.content-wrapper {
background-color: transparent !important;
text-align: center;
}
.wrapper {
background-color: transparent !important;
}
.modal-content {
background-color: #fff;
}
h1 {
text-align: center;
margin-bottom: 30px;
}
.table-responsive {
width: 100%;
overflow-x: auto;
}
.table {
width: 100%;
}
.text-wrap {
white-space: normal !important;
word-break: break-word;
}
div.dataTables_wrapper div.dataTables_length select {
width: 60px;
display: inline-block;
}
.center-align {
padding-top: 20px;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.reduced-width {
width: 50%;
}
th,
td {
white-space: nowrap;
}
.select2-container--bootstrap4 {
z-index: 1050;
/* Higher than the modal's z-index */
}
.select2-container--open {
z-index: 1060;
/* Ensure the dropdown is above the modal */
}
th:nth-child(1),
td:nth-child(1) {
width: 5%;
}
th:nth-child(2),
td:nth-child(2) {
width: 20%;
}
th:nth-child(3),
td:nth-child(3) {
width: 20%;
}
th:nth-child(4),
td:nth-child(4) {
width: 20%;
}
th:nth-child(5),
td:nth-child(5) {
width: 20%;
}
th:nth-child(6),
td:nth-child(6) {
width: 15%;
}
th:nth-child(7),
td:nth-child(7) {
width: 20%;
}
.alert {
position: relative;
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
.close2 {
position: absolute;
bottom: 10px;
right: 10px;
border: none;
background: none;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-12">
<div class="col-12 d-flex justify-content-end mb-3">
<button class="btn btn-primary" style="margin-bottom:-30px;position:fixed"
id="add">Add</button>
</div>
</div>
<div class="row">
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
</div>
</div>
</div>
</div>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body table-container">
<table id="companyTable"
class="custom-select-lm table table-bordered table-striped">
<thead>
<tr>
<th>Sno</th>
<th>Company Name</th>
<th>Company code</th>
<th>Domain</th>
<th>LLM Tools</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">Add Company Profile</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" data-backdrop="static" data-keyboard="false">×</span>
</button>
</div>
<div class="modal-body">
<form id="companyForm">
<div class="form-group">
<label for="companyName">Company Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="company_name" name="company_name" required>
</div>
<div class="form-group">
<label for="companyCode">Company Code<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="company_code" name="company_code" required>
</div>
<div class="form-group">
<label for="domain">Domain<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="domain" name="domain" required>
</div>
<div class="form-group">
<label for="llm_tools">LLM Tools<span class="text-danger">*</span></label>
<select class="form-control" id="llm_tools" name="llm_tools" multiple required>
<option value="Database">Database</option>
<option value="Static Documents">Static Documents</option>
<option value="API">API</option>
</select>
<div class="invalid-feedback">
Please select at least one LLM tool.
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
<button type="button" id="save" onclick="saveProfile()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
{%include 'footer.html'%}
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const role = sessionStorage.getItem('userRole');
console.log('Current role:', role); // Debug statement to check the role
if (role === 'admin') {
document.getElementById('add').style.display = 'block';
} else {
document.getElementById('add').style.display = 'none';
}
fetchCompanies();
});
window.addEventListener('pageshow', function (event) {
if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
window.location.reload();
}
});
$(document).ready(function () {
// Initialize DataTable
$('#companyTable').DataTable();
// Initialize Select2
$('#llm_tools').select2({
theme: 'bootstrap4',
placeholder: 'Select',
allowClear: true
});
// Show modal function
$('#add').on('click', function () {
$('#addModal').modal('show');
$('#save').show();
$('#saveupdate').hide();
clearmodal();
$('#save').prop('disabled', false); // Disable the "Save" button when the modal opens
});
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
$('#addModal').modal('hide');
});
$(document).on('click', '.btn-view', function () {
const companyId = $(this).data('id');
console.log("company_id in view", companyId);
viewCompany(companyId);
});
// Edit company details
$(document).on('click', '.btn-edit', function () {
const companyId = $(this).data('id');
console.log("company_id in edit", companyId);
editCompany(companyId);
});
// Delete company
$(document).on('click', '.btn-delete', function () {
const companyId = $(this).data('id'); // Get the company ID from the da
console.log("company_id in delete", companyId);
if (confirm("Are you sure you want to delete this company?")) {
deleteCompany(companyId); // Call the delete function with the company ID
}
});
});
// View company details
function viewCompany(companyId) {
// Fetch company details by ID
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
// alert(`Company Name: ${company.company_name}\nCompany Code: ${company.company_code}\nDomain: ${company.domain}\nLLM Tools: ${company.llm_tools}`);
$('#company_name').val(company.company_name).attr('readonly', 'readonly');
$('#company_code').val(company.company_code).attr('readonly', 'readonly');
$('#domain').val(company.domain).attr('readonly', 'readonly');
$('#llm_tools').val(company.llm_tools.split(',')).trigger('change');
$('#llm_tools').prop('disabled', true); // Disable the select input
// Open the modal for editing
$('#save').hide();// Disable the "Save" button when the modal opens
$('#addModal').modal('show');
}).fail(function () {
alert("Error retrieving company details.");
});
}
// Edit company details
function editCompany(companyId) {
// Fetch company details by ID
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
$('#company_name').removeAttr('readonly');
$('#company_code').removeAttr('readonly');
$('#domain').removeAttr('readonly');
$('#llm_tools').prop('disabled', false);
$('#save').hide();
$('#saveupdate').show();
// Populate the form with the company's details
$('#company_name').val(company.company_name);
$('#company_code').val(company.company_code);
$('#domain').val(company.domain);
$('#llm_tools').val(company.llm_tools.split(',')).trigger('change');
// Open the modal for editing
$('#addModal').modal('show');
// Update the save button to save the edited company
$('#saveupdate').off('click').on('click', function () {
saveupdate(companyId); // Pass the company ID for updating
});
}).fail(function () {
alert("Error retrieving company details.");
});
}
// Delete company
function deleteCompany(companyId) {
console.log("company_id deleted", companyId);
$.ajax({
type: "DELETE",
url: `/api/delcompanydetails/${companyId}`,
success: function () {
// alert("Company deleted successfully.");
const messageContainer = document.getElementById('message-container');
if (messageContainer)
messageContainer.innerHTML = `
<div class='alert alert-success'>
Company deleted successfully.
<button class='close' onclick='dismissMessage()'>OK</button>
</div>`;
fetchCompanies(); // Refresh the table
},
error: function (xhr) {
alert("Error deleting company: " + xhr.responseJSON.detail);
}
});
}
function saveupdate(companyId) {
console.log("company_id", companyId);
var companyData = {
company_name: $('#company_name').val(),
company_code: $('#company_code').val(),
domain: $('#domain').val(),
llm_tools: $('#llm_tools').val().join(',') // Assuming llm_tools is a multi-select
};
console.log("company_data", companyData);
$.ajax({
url: `/api/putcompanydetails/${companyId}`,
type: 'PUT',
data: companyData,
success: function (response) {
alert('Company details updated successfully.');
$('#addModal').modal('hide'); // Close the modal after saving
fetchCompanies();
},
error: function () {
alert('Failed to update company details.');
}
});
}
function saveProfile() {
const form = document.getElementById('companyForm');
// Check if the form is valid
if (!form.checkValidity()) {
// If the form is invalid, show validation messages and stop the submission
form.reportValidity();
return;
}
// Gather form data
const company_name = document.getElementById('company_name').value;
const company_code = document.getElementById('company_code').value;
const domain = document.getElementById('domain').value;
const llm_tools = $('#llm_tools').val(); // Get selected values from Select2
// Prepare FormData
let formData = new FormData();
formData.append("company_name", company_name);
formData.append("company_code", company_code);
formData.append("domain", domain);
formData.append("llm_tools", llm_tools.join(','));
$.ajax({
type: "POST",
url: "/submit_company_profile",
data: formData,
processData: false,
contentType: false,
success: function (response) {
// alert("Data saved successfully"); // Show success message
const messageContainer = document.getElementById('message-container');
if (messageContainer)
messageContainer.innerHTML = `
<div class='alert alert-success'>
Data saved successfully
<button class='close' onclick='dismissMessage()'>OK</button>
</div>`;
fetchCompanies(); // Refresh table data
// Clear the form and close the modal
// $('#companyForm')[0].reset();
$('#addModal').modal('hide');
},
error: function (xhr) {
alert("An error occurred: " + xhr.responseJSON.detail); // Show error message
}
});
}
function dismissMessage() {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = '';
}
}
async function fetchCompanies() {
try {
console.log("Fetching companies...");
const response = await fetch(`/api/companydetails`);
const companies = await response.json();
console.log(companies); // Inspect the data here
if (!Array.isArray(companies)) {
throw new TypeError('Expected an array of companies');
}
const table = $('#companyTable').DataTable();
table.clear(); // Clear existing table data
companies.forEach((company, index) => {
table.row.add([
index + 1,
company.company_name,
company.company_code,
company.domain,
company.llm_tools, // Join array of tools into a string
`<a href='#' class='btn btn-info btn-sm'onclick='viewCompany(${company.company_id})'><i class='fas fa-eye'></i></a>`,
`<a href='#' class='btn btn-warning btn-sm'onclick='editCompany(${company.company_id})'><i class='fas fa-edit'></i></a>`,
`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
]).draw(false);
});
} catch (error) {
console.error('Error fetching companies:', error);
}
}
function clearmodal() {
$('#companyForm')[0].reset(); // Reset all form fields
$('#llm_tools').val(null).trigger('change'); // Clear and reset the Select2 field
$('#llm_tools').select2({
theme: 'bootstrap4',
placeholder: 'Select',
allowClear: true
}); // Reinitialize Select2
}
</script>
</body>
</html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662<!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/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1/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" />
<style>
html,
body {
height: 90%;
margin: 0;
display: flex;
flex-direction: column;
}
body {
display: inline-flex;
flex-direction: column;
min-height: 90%;
}
.main-content {
flex: 1;
display: inline-flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding: 30px;
}
/* .container {
margin-top: 50px;
margin-left: 320px;
max-width: 800px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
position: relative;
z-index: 1;
} */
.form-group {
margin-bottom: 20px;
}
.form-group label {
font-weight: bold;
margin-top: -10px;
margin-left:-22px;
display: block;
}
.form-group input,
.form-group select,
.form-group textarea {
width: 90%;
margin-left:-22px;
padding: 2px;
border: 1px solid #ccc;
border-radius: 4px;
}
.btn-primary {
margin-right: 10px;
color: white;
font-size: 16px;
font-weight: bold;
}
/* .btn-container {
text-align: center;
margin-top: 20px;
margin-bottom: 10px;
} */
.btn-primary {
margin-right: 10px;
color: white;
font-size: 16px;
font-weight: bold;
}
.btn-container {
text-align: center;
margin-top: 30px;
margin-left: 20px;
margin-right: 0px;
margin-bottom: 10px;
/* color: white; */
}
.btn-container1 {
text-align: center;
margin-top: 50px;
margin-left: 30px;
margin-right: 30px;
margin-bottom: 10px;
color: white;
}
/* #selectedTables,
#labelselected {
display: none;
} */
.btn-primary:focus,
.btn-primary:active {
color: white;
background-color: #007bff;
border-color: #007bff;
box-shadow: none;
}
#saveBtn1 {
margin: 0 auto;
}
/* footer {
position: relative;
margin-top: auto;
width: 100%;
color: black;
text-align: right;
padding-right: 245px;
padding-top: 20px;
background-color: #f8f9fa;
border: none !important;
}
*/
.small-select {
margin-top: 5px;
width: 200px;
/* Adjust the width as needed */
}
.custom-dropdown {
width: 250px;
/* Adjust the width as needed */
}
/* Ensure the new row aligns with the previous row */
#schema-table-section {
margin-left: -20px; /* Adjust this if you need spacing between rows */
padding-top: 5px; /* Adjust padding if needed */
}
.alert {
position: relative;
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
.close {
position: absolute;
bottom: 10px;
right: 10px;
border: none;
background: none;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<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:10px" required>
<option value="" selected>Select</option>
</select>
</div>
<div class="row">
<div id="message-container" style="padding:20px;margin-left: 150px;width:500px;"></div>
</div>
</div>
</div>
</div>
<form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
method="post" style="display:none;">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="database">Database Type<span class="text-danger">*</span></label>
<select type="text" 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-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-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-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-3">
<div class="form-group">
<label for="userame">UserName <span class="text-danger">*</span></label>
<input type="text" id="username" name="username" class="form-control" required>
</div>
</div>
<div class="col-md-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-6">
<div class="form-group d-flex justify-content-between">
<div class="form-group btn-container">
<button type="button" id="connectBtn" class="btn btn-primary">Connect</button>
<button type="reset" class="btn btn-primary">Clear</button>
</div>
</div>
</div>
</div>
<div id="schema-table-section" style="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">
<div class="form-group1">
<label for="tableschema" style="margin-left: 30px;margin-right: 30px;">Select Tables <span
class="text-danger">*</span></label>
<div class="dropdown custom-dropdown">
<button class="btn btn-secondary dropdown-toggle"
style="margin-left: 30px;margin-right: 0px;" type="button" id="tablesDropdown"
data-bs-toggle="dropdown" aria-expanded="false">
Select Tables
</button>
<ul class="dropdown-menu" aria-labelledby="tablesDropdown">
<li>
<select type="text" id="tableschema" name="tableschema" class="form-control"
multiple required>
<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 class="col-md-3">
<div class="btn-container1">
<button type="button" id="saveBtn" class="btn btn-primary">Save</button>
</div>
</div>
</div>
<div class="row">-->
<div class="col-md-3">
<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></textarea>
</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>
</div>
</div>
</form>
</div>
</div>
</div>
<footer class="footer">
{%include 'footer.html'%}
</footer>
<script>
// document.getElementById('database').addEventListener('change', function () {
// const selectedDatabaseType =this.value;
// if (selectedDatabaseType) {
// fetchDatabaseDetails(selectedDatabaseType);
// }
// });
// async function fetchDatabaseDetails(databaseType) {
// try {
// const response = await fetch(`/api/get_database_details?database_type=${encodeURIComponent(databaseType)}`);
// if (!response.ok) {
// throw new Error('Network response was not ok');
// }
// const connectorsData= await response.json();
// //document.getElementById('server').value = connectorsData.server;
// // 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;
// //updateFormFields(data);
// } catch (error) {
// console.error('Error fetching database details:', error);
// }
// }
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;
if (companyId) {
try {
const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${companyId}&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) {
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.");
}
})
.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);
});
}
}
// $("#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("saveBtn").addEventListener("click", function (event) {
// var tables = Array.from(document.getElementById("tableschema").selectedOptions).map(option => option.value);
// if (tables.length === 0) {
// alert("Please select at least one table.");
// return;
// }
// var selectedTables = document.getElementById("selectedTables");
// selectedTables.value = tables.join(", ");
// selectedTables.style.display = "block";
// document.getElementById("labelselected").style.display = "block";
// document.getElementById("saveBtn1").style.display = "block";
// });
document.getElementById("saveBtn").addEventListener("click", async function (event) {
//event.preventDefault(); // Prevent default form submission
const form = document.getElementById('databaseconnectorForm');
const formData = new FormData(form);
console.log("formdatat",formData);
try {
const response = await fetch(form.action, {
method: form.method,
body: formData
});
console.log('Response:', response);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const result = await response.json();
// // Optionally, handle the response from the server
if (result.success) {
// alert('Data saved successfully');
const messageContainer = document.getElementById('message-container');
if(messageContainer)
messageContainer.innerHTML = `
<div class='alert alert-success'>
Data saved successfully
<button class='close' onclick='dismissMessage()'>OK</button>
</div>`;
}
} catch (error) {
console.error('Error saving data:', error);
alert('An error occurred while saving data');
}
});
});
function dismissMessage() {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = '';
}
}
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 = " ";
}
async function fetchCompanies() {
try {
const response = await fetch('/api/companies');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
displayCompanies(data.companies);
} catch (error) {
console.error('Error fetching companies:', error);
}
}
function displayCompanies(companies) {
const companySelect = document.getElementById('company');
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
companies.forEach(company => {
const option = document.createElement('option');
option.value = company.name;
option.textContent = company.name;
companySelect.appendChild(option);
});
}
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>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667<!DOCTYPE html>
<html>
<head>
<title>Knowledge Base</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Include AdminLTE CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1/dist/css/adminlte.min.css">
<!-- Include DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
<!-- Include AdminLTE JS -->
<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.1/dist/js/adminlte.min.js"></script>
<!-- Include DataTables JS -->
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<style>
body {
background-color: transparent !important;
}
.content-wrapper{
flex: 1;
overflow-y: auto;
}
.wrapper {
display: flex;
flex-direction: column;
height: 100vh;
}
.modal-content {
background-color: #fff;
}
.content-header {
padding: 1rem;
}
h1 {
text-align: center;
margin-bottom: 30px;
}
.card {
padding: 0;
margin-top: -15px;
margin-left: -40px;
}
.table-responsive {
width: 100%;
overflow-x: auto;
/*overflow-y: scroll;*/
/* Allows horizontal scrolling if necessary */
}
.table,
.table-bordered {
width: 100%;
border-collapse: collapse;
margin-right: 7.5px;
}
.text-wrap {
white-space: normal !important;
word-break: break-word;
}
div.dataTables_wrapper div.dataTables_length select{
width: 60px;
display: inline-block;
}
th {
white-space: nowrap;
}
th:nth-child(1),
td:nth-child(1) {
/* Sno column */
width: 2%;
}
th:nth-child(2),
td:nth-child(2) {
/* Document Name column */
width: auto;
}
th:nth-child(3),
td:nth-child(3) {
/* Document Description column */
width: auto;
}
th:nth-child(4),
td:nth-child(4) {
/* Document Version column */
width: 20%;
}
th:nth-child(5),
td:nth-child(5) {
/* VectorDB Flag column */
width: auto;
}
th:nth-child(6),
td:nth-child(6) {
/* View column */
width: 10%;
}
th:nth-child(7),
td:nth-child(7) {
/* Edit column */
width: 10%;
}
th:nth-child(8),
td:nth-child(8) {
/* Delete column */
width: auto;
}
.alert {
position: relative;
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
.close {
position: absolute;
bottom: 10px;
right: 10px;
border: none;
background: none;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<div class="main-header" style="border-bottom: none;">
<div class="container mt-2">
<div class="form-group left-align" >
<label for="company" class="mr-1" style="margin-left:-40px; margin-top: 12px;">Company Name <span class="text-danger">*</span></label>
<select type="text" id="company" name="company" class="form-control" style="width:20%;margin-left:-40px;"required>
<option value="" selected>Select</option>
</select>
<div class="col-12 d-flex justify-content-end mb-3">
<button class="btn btn-primary" style="margin-top:-40px;margin-right: -10px;position: fixed;"
id="add" data-action="add">Add</button>
</div>
</div>
</div>
<div class="row">
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
</div>
<section class="content" id="contentSection" style="display: none;">
<div class="container-fluid">
<div>
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div id="message-container">
<div class="card-body table-container">
<table id="knowledgeTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sno</th>
<th>Document Name</th>
<th>Document Description</th>
<th>Document Version</th>
<th>VectorDB Flag</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
<!-- <th style="display:none;">Company ID</th> -->
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">Add Document Details</h5>
<button type="button" class="btn-close" data-dismiss="modal" >
<span aria-hidden="true" data-backdrop="static" data-keyboard="false"></span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<form id="documentForm">
<div class="form-group">
<label for="uploadFile">Upload File<span class="text-danger">*</span></label>
<span id="file-name"></span>
<input type="hidden" id="file_name" name="file_name" class="form-control" required>
<input type="file" class="form-control-file" id="uploadFile" name="uploadFile" required
accept=".pdf,.doc,.docx">
<small class="form-text text-muted">Accepted formats: .pdf, .doc, .docx</small>
</div>
<div class="form-group">
<label for="documentName">Document Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="documentName" name="documentName" required>
</div>
<div class="form-group">
<label for="documentDescription">Document Description<span
class="text-danger">*</span></label>
<textarea class="form-control" id="documentDescription" name="documentDescription"
rows="3" required></textarea>
</div>
<div class="form-group">
<label for="department">Department<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="department" name="department" required>
</div>
<div class="form-group">
<label for="version">Version<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="version" name="version" required>
</div>
<div class="form-group">
<label for="lastUpdated">Last Updated<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="lastUpdated" name="lastUpdated" required>
</div>
</form>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> -->
<button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
<button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
{%include 'footer.html'%}
<!-- JavaScript to handle modal display -->
<script>
document.addEventListener("DOMContentLoaded", function () {
now = new Date().toISOString().replace('T', ' ').substr(0, 19);
document.getElementById('lastUpdated').value = now;
const inputs = document.querySelectorAll("#documentForm input, textarea");
inputs.forEach((input, index) => {
input.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
moveToNextInput(inputs, index);
}
});
});
function moveToNextInput(inputs, currentIndex) {
const nextInput = inputs[currentIndex + 1];
if (nextInput) {
nextInput.focus();
} else {
// Optionally, submit the form or trigger the save button
document.getElementById("save").focus();
}
}
// $(document).on('click', '.btn-view', function () {
// const companyId = $(this).data('id');
// console.log("company_id in view",companyId);
// viewCompany(companyId);
// });
// // Edit company details
// $(document).on('click', '.btn-edit', function () {
// const companyId = $(this).data('id');
// console.log("company_id in edit",companyId);
// editCompany(companyId);
// });
// // Delete company
// $(document).on('click', '.btn-delete', function () {
// const kid = $(this).data('id'); // Get the company ID from the da
// console.log("company_id in delete",kid);
// if (confirm("Are you sure you want to delete this company?")) {
// deleteCompany(kid); // Call the delete function with the company ID
// }
// });
fetchCompanies();
const companySelect = document.getElementById('company');
const documentForm = document.getElementById('documentForm');
const table = $('#knowledgeTable').DataTable(); // Initialize DataTable at the start
companySelect.addEventListener('change', async function () {
$("#message-container").empty();
const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
console.log(`Selected Company Name: ${selectedCompanyName}`);
if (selectedCompanyName !== "Select") {
try {
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
if (!response.ok) {
contentSection.style.display = 'none';
displayErrorMessage("Document details do not exist for this company. Please fill in the details.");
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log('data returned', data);
const companyId = data.company_id;
document.getElementById('company_id').value = companyId;
if (companyId) {
try {
const Response = await fetch(`/api/document_upload?company_id=${companyId}&company_name=${selectedCompanyName}`);
const connectorsResponse = await Response.json();
console.log("knowledge data table after connecting to table", connectorsResponse);
table.clear();
if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
//displayEmptyTable();
displayErrorMessage("Document details do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
} else {
connectorsResponse.forEach((company, index) => {
table.row.add([
index + 1,
company.document_name,
company.document_desc,
company.version,
company.vectorDBflag,
`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
//`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`,
`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,
company.row_id
// "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>",
// "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
// "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
]).draw(false);
});
contentSection.style.display = 'block';
}
} catch (error) {
console.error('Error fetching company documents:', error);
//displayEmptyTable();
displayErrorMessage("Document details1 do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
}
} else {
// displayEmptyTable();
displayErrorMessage("Document details2 for knowledge do not exist for this company. Please fill in the details.");
}
} catch (error) {
console.error('No details for this company ID or data documents:', error);
// displayEmptyTable();
displayErrorMessage("Document details3 do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
}
} else {
table.clear().draw();
document.getElementById('contentSection').style.display = 'none';
clearFormFields();
}
});
function displayErrorMessage(message) {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = `<div class='alert alert-danger'>${message}</div>`;
}
}
});
function clearFormFields() {
document.getElementById('file-name').textContent=""
document.getElementById('uploadFile').value = "";
document.getElementById('documentName').value = "";
document.getElementById('documentDescription').value = "";
document.getElementById('department').value = "";
document.getElementById('version').value = "";
//document.getElementById('lastUpdated').value = "";
}
$(document).ready(function () {
// Show modal function
$('#add').on('click', function () {
const modalTitle = document.getElementById('addModalLabel');
modalTitle.textContent = 'Add Document Details';
$('#uploadFile').show();
$('#saveupdate').hide();
clearFormFields();
$('#message-container').empty(); // Clear the message container
$('#addModal').modal('show');
});
$('.modal-footer .btn-secondary, .modal-header .btn-close').on('click', function () {
$('#addModal').modal('hide');
});
$('#KnowledgeTable').DataTable({
autoWidth: false
});
});
function viewCompany(button) {
var companyId = $(button).data('kid-id');
const modalTitle = document.getElementById('addModalLabel');
modalTitle.textContent = 'View Document Details';
$.getJSON(`/api/getknowledgebase/${companyId}`, function (company) {
$('#uploadFile').hide();
$('#file-name').text(company.file_path).attr('readonly','readonly');
$('#documentName').val(company.document_name).attr('readonly', 'readonly');
$('#documentDescription').val(company.document_desc).attr('readonly', 'readonly');
$('#department').val(company.department).attr('readonly', 'readonly');
$('#version').val(company.version).attr('readonly', 'readonly');
//$('#lastUpdated').val(company.last_updated).attr('readonly', 'readonly');
var lastUpdated = company.last_updated;
$('#lastUpdated').val(lastUpdated).attr('readonly', 'readonly');
$('#save').hide();// Disable the "Save" button when the modal opens
$('#addModal').modal('show');
}).fail(function () {
alert("Error retrieving company details.");
});
}
// Edit company details
function editCompany(button) {
var companyId = $(button).data('kid-id');
const modalTitle = document.getElementById('addModalLabel');
modalTitle.textContent = 'Edit Document Details';
// Fetch company details by ID
$.getJSON(`/api/getknowledgebase/${companyId}`, function (company) {
$('#uploadFile').hide();
$('#file-name').text(company.file_path).attr('readonly','readonly');
$('#documentName').removeAttr('readonly');
$('#documentDescription').removeAttr('readonly');
$('#department').removeAttr('readonly');
$('#version').removeAttr('readonly');
$('#lastUpdated').removeAttr('readonly');
// $('#vectorDBflag').removeAttr('readonly');
$('#company_id').removeAttr('readonly');
$('#save').hide();
$('#saveupdate').show();
// Populate the form with the company's details
$('#uploadFile').hide();
$('#file_name').val(company.file_path);
$('#file-name').val(company.file_path);
$('#documentName').val(company.document_name);
$('#documentDescription').val(company.document_desc);
$('#department').val(company.department);
$('#version').val(company.version);
$('#lastUpdated').val(company.last_updated);
$('#company_id').val(company.company_id);
$('#addModal').modal('show');
$('saveupdate').show();
// Update the save button to save the edited company
$('#saveupdate').off('click').on('click', function () {
saveupdate(companyId); // Pass the company ID for updating
});
}).fail(function () {
alert("Error retrieving company details.");
});
}
// Delete company
function deleteCompany(button) {
var companyId = $(button).data('kid-id');
console.log("k_id deleted",companyId);
$.ajax({
type: "DELETE",
url: `/api/delknowledgebase/${companyId}`,
success: function () {
var table = $('#knowledgeTable').DataTable();
table.row($(button).closest('tr')).remove().draw();
alert("Company deleted successfully.");
fetchCompanies(); // Refresh the table
},
error: function (xhr) {
alert("Error deleting company: " + xhr.responseJSON.detail);
}
});
}
function saveupdate(companyId) {
console.log("k_id", companyId);
var fileInput = document.getElementById('uploadFile'); // Assuming an input element for file upload
// var filePath = $('#file-name').text();
// console.log("k_id path", filePath);
var formData = new FormData();
formData.append('company_id', $('#company_id').val());
formData.append('file_name', $('#file_name').val());
formData.append('uploadFile', fileInput.files[0]); // Assuming a file input for upload
formData.append('documentName', $('#documentName').val());
formData.append('documentDescription', $('#documentDescription').val());
formData.append('department', $('#department').val());
formData.append('version', $('#version').val());
formData.append('vectorDBFlag', "NO");
formData.append('lastUpdated', $('#lastUpdated').val());
$.ajax({
url: `/api/putknowledgebase/${companyId}`,
type: 'PUT',
data: formData,
processData: false, // Required for FormData
contentType: false, // Required for FormData
success: function (response) {
alert('Knowledgebase details updated successfully.');
$('#addModal').modal('hide'); // Close the modal after saving
fetchCompanies();
},
error: function () {
alert('Failed to update company details.');
}
});
}
function save_file() {
const form = document.getElementById('documentForm');
// Check if the form is valid
if (!form.checkValidity()) {
// If the form is invalid, show validation messages and stop the submission
form.reportValidity();
return;
}
const uploadFile = document.getElementById("uploadFile").files[0];
const documentName = document.getElementById("documentName").value;
const documentDescription = document.getElementById("documentDescription").value;
const department = document.getElementById("department").value;
const version = document.getElementById("version").value;
const lastUpdated = document.getElementById("lastUpdated").value;
const company_id = document.getElementById("company_id").value;
//const formData = new FormData();
var formData = new FormData($('#documentForm')[0]);
const vectorDBFlag = "NO"; // Example value
const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
const dele= "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
formData.append("uploadFile", uploadFile);
formData.append("documentName", documentName);
formData.append("documentDescription", documentDescription);
formData.append("department", department);
formData.append("version", version);
formData.append("lastUpdated", lastUpdated);
formData.append("vectorDBflag", vectorDBFlag);
formData.append("company_id", company_id);
fetch('/upload_document', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
var table = $('#knowledgeTable').DataTable();
var rowCount = table.rows().count();
table.row.add([
rowCount + 1,
documentName,
documentDescription,
version,
vectorDBFlag,
view,
edit,
dele
]).draw(false);
const messageContainer = document.getElementById('message-container');
if(messageContainer)
messageContainer.innerHTML = `
<div class='alert alert-success'>
Data saved successfully
<button class='close' onclick='dismissMessage()'>OK</button>
</div>`;
// alert('Document saved successfully');
$('#addModal').modal('hide');
document.getElementById('contentSection').style.display = 'block'; // Show the table section
})
.catch(error => console.error('Error:', error));
}
function dismissMessage() {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = '';
}
}
async function fetchCompanies() {
try {
const response = await fetch('/api/companies');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
displayCompanies(data.companies);
} catch (error) {
console.error('Error fetching companies:', error);
}
}
function displayCompanies(companies) {
const companySelect = document.getElementById('company');
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
companies.forEach(company => {
const option = document.createElement('option');
option.value = company.name;
option.textContent = company.name;
companySelect.appendChild(option);
});
}
</script>
</body>
</html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459<!DOCTYPE html>
<html>
<head>
<title>Prompt Template</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Include AdminLTE CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/admin-lte@3.1/dist/css/adminlte.min.css">
<!-- Include DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<style>
.header-row {
display: flex;
justify-content: space-between;
align-items: center;
}
.card {
padding: 0;
margin-top: -15px;
margin-left: -40px;
}
.table-container {
width: 100%;
overflow-x: auto;
}
.wrapper {
display: flex;
flex-direction: column;
height: 100vh;
}
.content-wrapper {
flex: 1;
overflow-y: auto;
}
.content-header {
padding: 5px;
}
div.dataTables_wrapper div.dataTables_length select{
width: 60px;
display: inline-block;
}
th,
td {
white-space: nowrap;
}
th:nth-child(1),
td:nth-child(1) {
/* Sno column */
width: 1%;
}
th:nth-child(2),
td:nth-child(2) {
/* API Name column */
width: 20%;
}
th:nth-child(3),
td:nth-child(3) {
/* API Endpoint column */
width: 45%;
}
th:nth-child(4),
td:nth-child(4) {
/* view column*/
width: 5%;
}
th:nth-child(5),
td:nth-child(5) {
/* view column*/
width: 5%;
}
th:nth-child(6),
td:nth-child(6) {
/* view column*/
width: 5%;
}
.reduced-width {
width: 25%;
}
.viewButton {
size: 2px;
}
div.dataTables_wrapper div.dataTables_length select{
width: 60px;
display: inline-block;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<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:-11px;">Company Name <span class="text-danger">*</span></label>
<select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;" required>
<option value="" selected>Select</option>
</select>
<div class="col-12 d-flex justify-content-end mb-2">
<button class="btn btn-primary" style="margin-top:-40px;margin-right: -25px;position: fixed;" id="add">Add</button>
<!-- <button class="btn btn-primary" style="margin-top: 20px;" id="add">Add</button> -->
</div>
</div>
<div class="row">
<div id="message-container" style="margin-left: 150px;width:auto;"></div>
</div>
</div>
</div>
</div>
<section class="content" id="contentSection" style="display: none;">
<div class="container-fluid">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
</div>
<!-- Main content-->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body table-container">
<table id="promptTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sno</th>
<th>Datasource</th>
<th>Sample Prompt</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<!-- <tr>
<td>1</td>
<td>API</td>
<td>What are the details of ASN24080200002?</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>2</td>
<td>API</td>
<td>What is the expected receiving date of ASN24080200002</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>3</td>
<td>Document</td>
<td>Explain Pre-Receiving Yard Management</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>4</td>
<td>Document</td>
<td>Can you explain the process of unloading a vehicle in more detail?</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>5</td>
<td>Visual Analysis</td>
<td>I want to analyze item name and quantity in a bar chart in warehouse Allcargo Logistics</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>6</td>
<td>Visual Analysis</td>
<td>Can you generate a pie chart with item names and quantities in warehouse Allcargo Logistics</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>7</td>
<td>Database</td>
<td>What are the active warehouses available</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
<tr>
<td>8</td>
<td>Database</td>
<td>What are the warehouses available</td>
<td><button class="btn btn-primary viewButton">View</button></td>
</tr>
-->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">Add Prompt</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
<span aria-hidden="true" data-backdrop="static" data-keyboard="false">×</span>
</div>
<div class="modal-body">
<div class="form-group">
<!-- <label for="company_id">company_id</label>--->
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
</div>
<form id="addPromptForm">
<div class="form-group">
<label for="scenario">Scenario <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="scenario" name="scenario" required>
</div>
<div class="form-group">
<label for="prompt">Sample Prompt <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="prompt" name="sampleprompt" required>
</div>
<div class="form-group">
<label for="comments">Comments <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="comments" name="comments" required>
</div>
</form>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> -->
<button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
{%include 'footer.html'%}
<!-- Include DataTables JS and your custom script -->
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function () {
$('#add').on('click', function () {
clearFormFields();
$('#message-container').empty(); // Clear the message container
$('#addModal').modal('show');
});
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
$('#addModal').modal('hide');
});
});
document.addEventListener("DOMContentLoaded", function () {
// clearFormFields();
fetchCompanies();
const companySelect = document.getElementById('company');
const addPromptForm = document.getElementById('addPromptForm');
const table = $('#promptTable').DataTable();
// Initialize DataTable at the start
companySelect.addEventListener('change', async function () {
$("#message-container").empty();
const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
console.log(`Selected Company Name: ${selectedCompanyName}`);
if (selectedCompanyName !== "Select") {
try {
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
if (!response.ok) {
contentSection.style.display = 'none';
("company id does not exist for name does not exist. Please fill in the details.");
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = "<div class='alert alert-danger'>Document details do not exist for this company. Please fill in the details.</div>";
}
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log('data returned', data);
console.log(`Company ID: ${data.company_id}`);
const companyId = data.company_id;
document.getElementById('company_id').value = companyId;
if (companyId) {
try {
const Response = await fetch(`/api/get_prompt_templates?company_id=${companyId}&company_name=${selectedCompanyName}`);
const connectorsResponse = await Response.json();
console.log("prompt template data table after connecting to table", connectorsResponse);
table.clear();
if (!Array.isArray(connectorsResponse)) {
throw new TypeError('Expected an array of companies');
displayErrorMessage("template details do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
} else {
connectorsResponse.forEach((company, index) => {
table.row.add([
index + 1,
company.scenario,
company.prompt,
"<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye' fa-eye'></i></a>",
"<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
"<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
]).draw(false);
});
contentSection.style.display = 'block';
}
} catch (error) {
console.error('Error fetching company documents:', error);
//displayEmptyTable();
displayErrorMessage("Prompt template do not exist for this company. Please fill in the details by clicking add button.");
contentSection.style.display = 'none';
}
}
else {
// displayEmptyTable();
displayErrorMessage("Company id do not exist for this company. Please fill in the details by clicking add button.");
}
} catch (error) {
console.error('No details for this company ID or data documents:', error);
// displayEmptyTable();
displayErrorMessage("Document details3 do not exist for this company. Please fill in the details.");
contentSection.style.display = 'none';
}
} else {
table.clear().draw();
document.getElementById('contentSection').style.display = 'none';
// Optionally, you might want to clear the form fields as well
clearFormFields();
}
});
function displayErrorMessage(message) {
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
messageContainer.innerHTML = `<div class='alert alert-danger'>${message}</div>`;
}
}
});
function save_file() {
const form = document.getElementById('addPromptForm');
// Check if the form is valid
if (!form.checkValidity()) {
// If the form is invalid, show validation messages and stop the submission
form.reportValidity();
return;
}
const company_id = $('#company_id').val();
const scenario = $('#scenario').val();
const prompt = $('#prompt').val();
const comments = $('#comments').val();
const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
const dele = "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
var formData = new FormData($('#addPromptForm')[0]);
formData.append("company_id", company_id),
formData.append("scenario", scenario),
formData.append("prompt", prompt),
formData.append("comments", comments),
//const formData = new FormData();
fetch('/api/save_prompt_details', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
var table = $('#promptTable').DataTable();
var rowCount = table.rows().count();
table.row.add([
rowCount + 1,
scenario,
prompt,
view,
edit,
dele
]).draw(false);
alert('Document saved successfully');
$('#addModal').modal('hide');
document.getElementById('contentSection').style.display = 'block'; // Show the table section
})
.catch(error => console.error('Error:', error));
}
async function fetchCompanies() {
try {
const response = await fetch('/api/companies');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
displayCompanies(data.companies);
} catch (error) {
console.error('Error fetching companies:', error);
}
}
function displayCompanies(companies) {
const companySelect = document.getElementById('company');
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
companies.forEach(company => {
const option = document.createElement('option');
option.value = company.name;
option.textContent = company.name;
companySelect.appendChild(option);
});
}
function clearFormFields() {
document.getElementById('scenario').value = "";
document.getElementById('prompt').value = "";
document.getElementById('comments').value = "";
}
</script>
</body>
</html>templates/API_connectors.htmlAdded+461
templates/company_profile.htmlAdded+521
templates/data_connectors.htmlAdded+662
templates/knowledgebase.htmlAdded+667
templates/prompt_template.htmlAdded+459