Redmind_GPT_API / templates /company_profile.html
lakshmivairamani's picture
Upload 14 files
6952a04 verified
raw
history blame
12.1 kB
<!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/[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">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/@ttskch/[email protected]/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;
}
.content-wrapper {
background-color: transparent !important;
text-align: center;
}
.table-container{
margin-top: 0px !important;
}
.wrapper {
background-color: transparent !important;
}
.modal-content {
background-color: #fff;
}
h1 {
text-align: center;
margin-bottom: 30px;
}
.card-body {
padding: 0;
margin: 0;
}
.table-responsive {
width: 100%;
overflow-x: auto;
}
.table {
width: 100%;
}
.text-wrap {
white-space: normal !important;
word-break: break-word;
}
.center-align {
padding-top: 20px;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.reduced-width {
width: 50%;
}
th,
td {
white-space: nowrap;
}
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%;
}
</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" id="add">Add</button>
</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="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">&times;</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="save" onclick="saveProfile()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
<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/[email protected]/dist/js/select2.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
fetchCompanies();
});
$(document).ready(function () {
// Initialize DataTable
$('#companyTable').DataTable();
// Show modal function
$('#add').on('click', function () {
$('#addModal').modal('show');
});
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
$('#addModal').modal('hide');
});
// Initialize Select2
$('#llm_tools').select2({
theme: 'bootstrap4',
placeholder: 'Select',
allowClear: true
});
});
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
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
}
});
}
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'><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);
});
} catch (error) {
console.error('Error fetching companies:', error);
}
}
</script>
</body>
</html>