Redmind_GPT_API / templates /dashboard.html
Redmind's picture
Update templates/dashboard.html
7284c69 verified
raw
history blame
10.8 kB
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<!-- AdminLTE CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/3.1.0/css/adminlte.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.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: 100%;
margin: 0;
display: flex;
flex-direction: column;
}
.wrapper {
flex: 1; /* This allows the content to grow and push the footer down */
padding: 10px;
margin-left: -35px;
}
</style>
</head>
<body>
{% include 'sidepane.html' %}
<div class="wrapper">
<section class="main-header" style="border-bottom: none;border-top: none;">
<div class="container-fluid">
<div id="company-block" class="form-group left-align" style="display: none;">
<label for="company" class="ml-3" style="display: inline-block; margin-right: 10px;">Select the Company Name
to view the details <span class="text-danger">*</span>
</label>
<select type="text" id="company" name="company" class="ml-3 form-control"
style="display: inline-block; width: 20%;" required>
<option value="" selected>Select</option>
</select>
</div>
<div class="row">
<div class="col-lg-4 col-6">
<div class="small-box bg-info">
<div class="inner margin-left:10px;">
<h3 id="knowledgeBaseCount">{{table_count_of_each_table.knowledge_base}}</h3>
<h4>KnowledgeBase</h4>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
</div>
</div>
<div class="col-lg-4 col-6">
<div class="small-box bg-success">
<div class="inner">
<h3 id="dataConnectorsCount">{{table_count_of_each_table.data_connectors}}</h3>
<h4>Data connectors</h4>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
</div>
</div>
</div>
<div class="col-lg-4 col-6">
<div class="small-box bg-warning">
<div class="inner">
<h3 id="apiConnectorsCount">{{table_count_of_each_table.api_connectors}}</h3>
<h4>API Connectors</h4>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
</div>
</div>
<div class="col-lg-4 col-6">
<div class="small-box bg-warning">
<div class="inner">
<h3 id="promptTemplatesCount">{{table_count_of_each_table.prompt_templates}}</h3>
<h4>Prompt_Templates</h4>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<input type="hidden" id="userRole" name="userRole" value={{role}}>
<input type="hidden" id="company_id" name="company_id" value={{company_id}}>
<input type="hidden" id="username" name="username" value={{username}}>
<input type="hidden" id="company_name" name="company_name" value={{company_name}}>
<footer>
{% include 'footer.html' %}
</footer>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
window.addEventListener('pageshow', function (event) {
if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
window.location.reload();
}
});
document.addEventListener('DOMContentLoaded', function () {
var role1 = document.getElementById("userRole").value;
var company_id1 = document.getElementById("company_id").value;
var company_name1=document.getElementById("company_name").value;
var username1=document.getElementById("username").value;
console.log("companyid in dasshboard",username1);
sessionStorage.setItem('userRole', role1);
// sessionStorage.setItem('siderole',role1);
// sessionStorage.setItem('sidecompanyId',company_id1);
sessionStorage.setItem('company_id', company_id1);
sessionStorage.setItem('company_name',company_name1);
sessionStorage.setItem('username',username1);
if (!role1) {
var roleFromInput = sessionStorage.getItem('userRole');
sessionStorage.setItem('userRole', roleFromInput);
console.log("Role set in sessionStorage:", roleFromInput);
} else {
sessionStorage.setItem('userRole', role1);
console.log("Retrieved user role from input:", role1); // Debugging
}
if (role1 === "superadmin") {
document.getElementById('company-block').style.display = 'block';
fetchCompanies();
}
});
document.getElementById('company').addEventListener('change', async function () {
const selectedCompany = this.value;
sessionStorage.setItem("company_name",selectedCompany);
if (selectedCompany!== "Select") {
try {
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompany)}`);
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;
sessionStorage.setItem("company_id",companyId);
console.log("company id for superadmin", company_id);
//document.getElementById('company_id').value = companyId;
if (companyId) {
try {
const countResponse = await fetch(`/api/company_record_count/${companyId}`);
if (!countResponse.ok) {
throw new Error('Network response was not ok');
}
const countData = await countResponse.json();
console.log('Count data:', countData); // Log the response data
updateRecordCounts(countData.table_counts);
} catch (error) {
console.error('Error fetching record counts:', error);
}
} else {
clearRecordCounts();
}
} catch (error) {
console.error('No details for this company ID or data documents:', error);
// displayEmptyTable();
displayErrorMessage("company details do not exist for this company.");
}
}
});
function updateRecordCounts(counts) {
// Update the counts displayed in the dashboard
document.getElementById('knowledgeBaseCount').textContent = counts.knowledge_base || 0;
document.getElementById('dataConnectorsCount').textContent = counts.data_connectors || 0;
document.getElementById('apiConnectorsCount').textContent = counts.api_connectors || 0;
document.getElementById('promptTemplatesCount').textContent = counts.prompt_templates || 0;
}
function clearRecordCounts() {
document.getElementById('knowledgeBaseCount').textContent = 0;
document.getElementById('dataConnectorsCount').textContent = 0;
document.getElementById('apiConnectorsCount').textContent = 0;
document.getElementById('promptTemplatesCount').textContent = 0;
}
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>