Spaces:
Sleeping
Sleeping
| <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 ; | |
| } | |
| .wrapper { | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| } | |
| .content-wrapper { | |
| flex: 1; | |
| overflow-y: auto; | |
| } | |
| .modal-content { | |
| background-color: #fff; | |
| } | |
| .content-header { | |
| padding: 1rem; | |
| } | |
| h1 { | |
| text-align: center; | |
| margin-bottom: 30px; | |
| } | |
| .card-body { | |
| padding: 0; | |
| margin: 0; | |
| } | |
| .table-responsive { | |
| width: 100%; | |
| overflow-x: auto; | |
| /*overflow-y: scroll;*/ | |
| /* Allows horizontal scrolling if necessary */ | |
| } | |
| .table { | |
| width: 100%; | |
| border-collapse: collapse; | |
| } | |
| /* .table { | |
| table-layout: fixed; | |
| width: 100%; | |
| } */ | |
| .text-wrap { | |
| white-space: normal ; | |
| word-break: break-word; | |
| } | |
| .center-align { | |
| padding-top: 20px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| width: 100%; | |
| } | |
| .reduced-width { | |
| width: 25%; | |
| /* Adjust the percentage as needed */ | |
| } | |
| th | |
| { | |
| white-space: nowrap; | |
| } | |
| th:nth-child(1), | |
| td:nth-child(1) { | |
| /* Sno column */ | |
| width: 5%; | |
| } | |
| 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: 10%; | |
| } | |
| th:nth-child(6), | |
| td:nth-child(6) { | |
| /* View column */ | |
| width: 10%; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| {% include 'sidepane.html' %} | |
| <div class="wrapper"> | |
| <div class="content-wrapper"> | |
| <div class="content-header"> | |
| <div class="container-fluid"> | |
| <div class="container mt-2"> | |
| <div class="form-group center-align"> | |
| <label for="company" class="mr-2">Company Name <span class="text-danger">*</span></label> | |
| <select type="text" id="company" name="company" class="form-control reduced-width" required> | |
| <option value="" selected>Select</option> | |
| </select> | |
| <div class="col-8 d-flex justify-content-end mb-3"> | |
| <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: 200px;"></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 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> | |
| </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" 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="uploadFile">Upload File<span class="text-danger">*</span></label> | |
| <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="save" onclick="save_file()" class="btn btn-primary">Save</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- JavaScript to handle modal display --> | |
| <script> | |
| document.addEventListener("DOMContentLoaded", function () { | |
| now = new Date().toISOString().substr(0, 10); | |
| 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(); | |
| } | |
| } | |
| 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'><i class='fas fa-eye'></i></a>", | |
| ]).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 displayEmptyTable() { | |
| // table.clear().draw(); | |
| // contentSection.style.display = 'block'; // Ensure the table section is visible even if empty | |
| // } | |
| }); | |
| function clearFormFields() { | |
| 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 () { | |
| 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 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>"; | |
| 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 | |
| ]).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); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |