Spaces:
Runtime error
Runtime error
Update templates/company_profile.html
Browse files1 unmodified line2345567896 unmodified lines1617181920212223242526273 unmodified lines31323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868715 unmodified lines103104105484910610710810911049 unmodified lines1601611621051631641651661671101681691701711721151731741751769 unmodified lines18618718818919019119235 unmodified lines2282292301722312322332341762352362372383 unmodified lines2422432441862452462472482491912502512522532542552562572582592602612622632642652662672686 unmodified lines27527627720420527827928028128 unmodified lines31031131224031331424231531631731831932032132232332432532632732818 unmodified lines3473483493503513523533542763553563573583593603613623632822833643653663673682863693703713722903733743753763773783793803813823833843853863873883893903913923933 unmodified lines39739839930340040140240340440540640740840941041141241330541441541630841741841931031142042142242342442531742642742842943043143243343443543643743843944044132744244344444544644744844945045145245345445545623 unmodified lines4804814823574834843593604854864874884894904913664924934944954964974984995005013713723733743753763773783793803813823833843853863873883893903913923935025035045055063985075085094015105115125135145153 unmodified lines51952052141352252352452552652752842052953053153233 unmodified lines5665675684604614624634644654664675695705715725735745755765775785795804725815825835844744754765855865875885895903 unmodified lines5945955964864874885975985996006016026036044944956056066076086096106116126133 unmodified lines6176186196206216226236245126256266276286296304 unmodified lines63563663752363863964064155 unmodified lines6976986995855867007017027037047057065925935945955965975985997077087097107117127137147157167177187197207217221 unmodified line<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>6 unmodified lines rel="stylesheet" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" /> <style>
#add { display: inline-block ; margin-right: 15px !important; /* Optional: Adjust margin if needed */ }
body { background-color: transparent !important; }3 unmodified lines margin-top: 10px; margin-left: -50px; } /* Ensure the DataTable wrapper takes the full width */.dataTables_wrapper { width: 100%;}/* Ensure the DataTable wrapper takes the full width */.dataTables_wrapper { width: 100%;}
/* Style for the custom dropdown */.custom-dropdown { position: relative; display: inline-block; margin-left: 10px; /* Space between label and dropdown */}
.dropdown-button { background-color: white; color: black; padding: 5px; border: 1px solid black; border-radius: 4px; cursor: pointer; text-align: left; width: 60px; /* Adjust width as needed */}
.dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 80px; /* Adjust width as needed */ box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; border: 1px solid #ddd; top: 100%; /* Position below the button */ left: 0;}
.dropdown-content a { padding: 10px; text-decoration: none; display: block; color: #333;}
.dropdown-content a:hover { background-color: #ddd;}
.content-wrapper { background-color: transparent !important;15 unmodified lines
.table-responsive { width: 100%; width: 95%; overflow-x:none; }
.table {49 unmodified lines
th:nth-child(3), td:nth-child(3) { width: 10%; width: 20%; }
th:nth-child(4), td:nth-child(4) { width: 15%; width: 20%; }
th:nth-child(5), td:nth-child(5) { width: 20%; width: 10%; }
th:nth-child(6),9 unmodified lines td:nth-child(8) { width: 10%; }
.alert { position: relative; padding: 15px;35 unmodified lines <div class="content-header"> <div class="container-fluid"> <div class="row mb-2"> <div class="col-12"> <!-- <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> --> <input type="hidden" id="userRole" name="userRole" value={{role}}> <div class="row"> <div id="message-container" style="margin-left: 200px;width:600px;"></div>3 unmodified lines </div> <!-- Main content --> <section class="content" id="startTable" style="display: none;"> <div class="container-fluid"> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body table-container"> <table id="companyTable" class=" table table-bordered table-striped"> <div class="dataTables_wrapper"> <div class="row"> <div class="dataTables_length" > <label style="display: inline-block;margin-right:800px; margin-bottom: -40px;" >Show entries: <div class="custom-dropdown"> <button class="dropdown-button">5</button> <div class="dropdown-content"> <a href="#" data-length="5">5</a> <a href="#" data-length="10">10</a> <a href="#" data-length="50">50</a> <a href="#" data-length="100">100</a> </div> </div> </label> </div> <table id="companyTable" class="table display mb-4 dataTablesCard dataTable table-responsive-xl card-table" > <thead> <tr> <th>Sno</th>6 unmodified lines <th>Delete</th> </tr> </thead> <tbody> </tbody> </table> </div> </div>28 unmodified lines <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"> <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> <select class="form-select" 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> <div class="form-group"> <label for="domain">UserName<span class="text-danger">*</span></label> <input type="text" class="form-control" id="username" name="username" required>18 unmodified lines const company_id=sessionStorage.getItem('company_id'); console.log('Current role:', role); // Debug statement to check the role document.getElementById('userRole').value = role; const passedCompanyName = sessionStorage.getItem('company_name') document.getElementById('selectedCompany').innerText = `Company Name: ${passedCompanyName}`; $('#addModal').hide(); // Make sure this is called initially function checkForAddButton() { const addButton = document.getElementById('add');
if (addButton) { // Stop checking once the element is found clearInterval(checkInterval); if (role === 'superadmin') { console.log("insidse compamy profile super admin"); $('#startTable').show(); $('#addModal').hide(); document.getElementById('add').style.display = 'block'; $('#add').show();
} else { console.log("insidse company profile admin"); document.getElementById('add').style.display = 'none'; $('#add').hide(); const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Company Details'; viewCompany(company_id);
} } } const checkInterval = setInterval(checkForAddButton, 100); // document.querySelector('.dropdown-button').addEventListener('click', function() { const dropdownContent = document.querySelector('.dropdown-content'); dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block'; }); fetchCompanies(); }); window.addEventListener('click', function(event) { if (!event.target.matches('.dropdown-button')) { const dropdownContents = document.querySelectorAll('.dropdown-content'); dropdownContents.forEach(function(content) { content.style.display = 'none'; }); } }); window.addEventListener('pageshow', function (event) { if (event.persisted || (window.performance && window.performance.navigation.type === 2)) { window.location.reload();3 unmodified lines
$(document).ready(function () { // Initialize DataTable $('#companyTable').DataTable(); //$('#companyTable').DataTable(); $('#companyTable').DataTable({ "paging": true, "pageLength":5, "lengthChange": false, "searching": true, "ordering": true, "info": true, "autoWidth": false, "responsive": true}); // Initialize Select2 $('#llm_tools').select2({ $('select').select2({ theme: 'bootstrap4', placeholder: 'Select', allowClear: true allowClear: true, dropdownParent: $('#addModal') }); }); // Show modal function $('#add').on('click', function () { const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Add Company Details'; console.log('Modal title after setting:', modalTitle.textContent); // This should log the new title
$('#company_name').removeAttr('readonly'); $('#company_code').removeAttr('readonly'); $('#domain').removeAttr('readonly'); $('select').prop('disabled', false); $('#username').removeAttr('readonly'); $('#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'); });
$('#addModal').on('shown.bs.modal', function() { $('#companyTable').DataTable().columns.adjust().draw(); // Initialize Select2 only if not already initialized if (!$('#llm_tools').hasClass('select2-hidden-accessible')) { $('select').select2({ theme: 'bootstrap4', placeholder: 'Select LLM Tools', allowClear: true, dropdownParent: $('#addModal') }); }});
$(document).on('click', '.btn-view', function () { const companyId = $(this).data('id');23 unmodified lines deleteCompany(companyId); // Call the delete function with the company ID } });
}); // View company details function viewCompany(companyId) { // Fetch company details by IDfunction viewCompany(companyId) { const username = sessionStorage.getItem('username'); const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'View Company Details';
// Fetch company details by ID $.getJSON(`/api/getcompanydetails/${companyId}`, function (company) { // Set values and attributes for the form fields console.log("Fetched company details:", company);
// Set the company fields to readonly $('#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'); $('select').val(company.llm_tools.split(',')).trigger('change'); $('select').prop('disabled', true); $('#username').val(username).attr('readonly', 'readonly');
// Clear existing options in the dropdown $('#llm_tools').empty();
// Add the options that are present in company.llm_tools const availableOptions = { 'Database': 'Database', 'Static Documents': 'Static Documents', 'API': 'API' };
if (Array.isArray(company.llm_tools)) { company.llm_tools.forEach(tool => { if (availableOptions[tool]) { $('#llm_tools').append(new Option(availableOptions[tool], tool, true, true)); } }); }
$('#llm_tools').prop('disabled', true); // Disable the dropdown
$('#username').val(username).attr('readonly', 'readonly'); // Set username field
// Show the modal with view details only // Show the modal $('#saveupdate').hide(); $('#save').hide(); $('#addModal').modal('show'); }).fail(function () { alert("Error retrieving company details."); console.error("Error retrieving company details."); });}
// Edit company details function Editcompany(companyId) { const username=sessionStorage.getItem('username'); const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Edit Company Details';3 unmodified lines $('#company_name').removeAttr('readonly'); $('#company_code').removeAttr('readonly'); $('#domain').removeAttr('readonly'); $('#llm_tools').prop('disabled', false); $('select').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'); $('select').val(company.llm_tools.split(',')).trigger('change'); $('#username').val(username).attr('readonly', 'readonly');// Disable the select input //sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string33 unmodified lines } 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(','), username: $('#username').val() // Assuming llm_tools is a multi-select }; console.log("company_data", companyData); const llm_tools= $('#llm_tools').select2("val"); var formData = new FormData(); formData.append('company_name', $('#company_name').val()); formData.append('company_code', $('#company_code').val()); formData.append('domain', $('#domain').val()); formData.append('llm_tools',llm_tools); // Assuming llm_tools is a multi-select console.log("company_data", formData);
$.ajax({ url: `/api/putcompanydetails/${companyId}`, type: 'PUT', data: companyData, data: formData, processData: false, // Important for FormData contentType: false, success: function (response) { // alert('Company details updated successfully.'); const messageContainer = document.getElementById('message-container'); if(messageContainer) // alert('Company details updated successfully.'); const messageContainer = document.getElementById('message-container'); if (messageContainer) messageContainer.innerHTML = ` <div class='alert alert-success'> Company Data Updated successfully3 unmodified lines fetchCompanies(); }, error: function () { const messageContainer = document.getElementById('message-container'); if(messageContainer)
const messageContainer = document.getElementById('message-container'); if (messageContainer) messageContainer.innerHTML = ` <div class='alert alert-danger'> No changes have been made to update company details. <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button> </div>`; $('#addModal').modal('hide'); //alert('No changes have been made to update company details.'); $('#addModal').modal('hide'); //alert('No changes have been made to update company details.'); } }); }
function saveProfile() { const form = document.getElementById('companyForm');
3 unmodified lines 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(); const llm_tools = $('#llm_tools').select2("val"); console.log("Selected LLM Tools:", llm_tools); // console.log("llm_tools element:", document.getElementById('llm_tools')); const username=$('#username').val();
4 unmodified lines formData.append("company_name", company_name); formData.append("company_code", company_code); formData.append("domain", domain); formData.append("llm_tools", llm_tools.join(',')); formData.append("llm_tools", llm_tools); formData.append("username",username); formData.append("password",password); formData.append("role",rolesave);55 unmodified lines `<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); }); ]) });table.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 } $('#companyForm')[0].reset(); // Reset all form fields $('#llm_tools').val(null).trigger('change'); // Clear and reset the Select2 field without reinitializing}
document.querySelectorAll('.dropdown-content a').forEach(function(item) { item.addEventListener('click', function() { const length = item.getAttribute('data-length'); // Set the DataTable page length $('#companyTable').DataTable().page.len(parseInt(length)).draw(); document.querySelector('.dropdown-button').textContent = length; }); });
</script></body>templates/company_profile.html+206-86