Spaces:
Runtime error
Runtime error
| <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/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | |
| <!-- Include AdminLTE CSS --> | |
| <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/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> |