Spaces:
Runtime error
Runtime error
Update templates/API_connectors.html
Browse files123459 unmodified lines151617181920212223242521 unmodified lines474849505152533 unmodified lines5758596061626364656617 unmodified lines8485868788893 unmodified lines939495969798991001011021031 unmodified line1051061071081091101111121131141151161171181191201211222 unmodified lines1251261271281291301 unmodified line13213313413513613797 unmodified lines2352362372382392402415 unmodified lines24724824925025125214 unmodified lines2672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623631 unmodified line3653663673683693703713723733743753763773783793804 unmodified lines3853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155161 unmodified line5185195205215225235246 unmodified lines53153253353453553653711 unmodified lines54955055155255355455555655714 unmodified lines5725735745755765775785795805815823 unmodified lines5865875885895905915925934 unmodified lines5985996006016026036046056066076086096106116126136146156166176186196206216226236246256263 unmodified lines630631632633634635636<!DOCTYPE html><html><head><title>API Connectors</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>9 unmodified lines.form-group {margin-top: -10px;}.card {padding: 0;margin-top: -15px;margin-left: -40px;}.header-row {display: flex;justify-content: space-between;21 unmodified linespadding: 5px;}th,td {white-space: nowrap;}3 unmodified lines/* Sno column */width: 5%;}div.dataTables_wrapper div.dataTables_length select{width: 60px;display: inline-block;}th:nth-child(2),td:nth-child(2) {/* API Name column */17 unmodified lines/* View column */width: 5%;}th:nth-child(6),td:nth-child(6) {/* View column */3 unmodified lines.reduced-width {width: 25%;}div.dataTables_wrapper div.dataTables_length select{width: 60px;display: inline-block;}</style></head>1 unmodified line{% 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: 5px;">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-3"><button class="btn btn-primary" style="margin-top: -40px;margin-right: -25px;position: fixed;" id="add">Add</button></div></div><div class="row">2 unmodified lines</div></div></div><section class="content" id="contentSection" style="display: none;"><div class="container-fluid"><div class="form-group">1 unmodified line<input type="hidden" id="company_id" name="company_id" class="form-control" required></div></div><!-- Main content --><section class="content"><div class="container-fluid">97 unmodified lines</div><div class="modal-footer"><!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> --><button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button><button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button></div></div>5 unmodified lines<!-- 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 () {// Show modal function14 unmodified lines// });});document.addEventListener("DOMContentLoaded", function () {// clearFormFields();fetchCompanies();const companySelect = document.getElementById('company');const documentForm = document.getElementById('documentForm');const table = $('#apiTable').DataTable();// Initialize DataTable at the startcompanySelect.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 this company name does not exist. Please fill in the details.");const messageContainer = document.getElementById('message-container');if (messageContainer) {messageContainer.innerHTML = "<div class='alert alert-danger'>API 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_api_connectors?company_id=${companyId}&company_name=${selectedCompanyName}`);const connectorsResponse = await Response.json();console.log("api connector data table after connecting to table", connectorsResponse);table.clear();if (!Array.isArray(connectorsResponse)) {throw new TypeError('Expected an array of companies');displayErrorMessage("Data do not exist for this company. Please fill in the details by clicking add button.");contentSection.style.display = 'none';} else {connectorsResponse.forEach((company, index) => {table.row.add([index + 1,company.APIName,company.APIEndpoint,`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,// "<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("Data do not exist for this company. Please fill in the details by clicking add button.");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';// Optionally, you might want to clear the form fields as wellclearFormFields();}});function displayErrorMessage(message) {const messageContainer = document.getElementById('message-container');if (messageContainer) {1 unmodified line}}});function viewCompany(button) {var companyId = $(button).data('kid-id');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'View API Details';$.getJSON(`/api/viewapiconnectors/${companyId}`, function (company) {$('#APIName').val(company.api_name).attr('readonly','readonly');$('#APIEndpoint').val(company.api_endpoint).attr('readonly', 'readonly');$('#Auth_Bearer') .val(company.auth_token).attr('readonly', 'readonly') ;$('#Inputjson').val(company.input_param).attr('readonly', 'readonly');$('#OutputJson').val(company.output_json).attr('readonly', 'readonly');$('#Description').val(company.description).attr('readonly', 'readonly');4 unmodified linesalert("Error retrieving API details.");});}// Edit knowledge base detailsfunction editCompany(button) {var companyId = $(button).data('kid-id');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Edit API Details';// Fetch company details by ID$.getJSON(`/api/viewapiconnectors/${companyId}`, function (company) {$('#APIName').val(company.api_name);$('#APIEndpoint').val(company.api_endpoint);$('#Auth_Bearer') .val(company.auth_token);$('#Inputjson').val(company.input_param);$('#OutputJson').val(company.output_json);$('#Description').val(company.description);// Show/hide appropriate elements$('#uploadFile').show(); // Hide the file upload field$('#save').hide(); // Hide the default save button$('#saveupdate').show(); // Show the update button// Ensure fields are editable$('#APIName').removeAttr('readonly');$('#APIEndpoint').removeAttr('readonly');$('#Auth_Bearer').removeAttr('readonly');$('#Inputjson').removeAttr('readonly');$('#OutputJson').removeAttr('readonly');$('#Description').removeAttr('readonly');// Show the modal$('#addModal').modal('show');// Set up the click event for the update button$('#saveupdate').off('click').on('click', function () {saveupdate(companyId); // Pass the company ID for updating});}).fail(function () {alert("Error in retrieving API details.");});}function saveupdate(companyId, filename) {const formData = new FormData();const company_id=document.getElementById("company_id").value;formData.append("company_id", $('#company_id').val());formData.append("APIName", $('#APIName').val());formData.append("APIEndpoint", $('#APIEndpoint').val());formData.append("Auth_Bearer", $('#Auth_Bearer').val());formData.append("Inputjson", $('#Inputjson').val());formData.append("OutputJson", $('#OutputJson').val());formData.append("Description", $('#Description').val());console.log("company_id to table refresh",company_id)const messageContainer = document.getElementById('message-container');$.ajax({url: `/api/editapiconnectors/${companyId}`,type: 'PUT',data: formData,processData: false, // Required for FormDatacontentType: false, // Required for FormDatasuccess: function (response) {// alert('Knowledgebase details updated successfully.');if(messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>API Data Updated successfully<button class='close' onclick='dismissMessage()'>OK</button></div>`;$('#addModal').modal('hide'); // Close the modal after savingfetchUpdatedDocuments(company_id);},error: function () {alert('Form has no changes to update knowledge base details.');}});}function dismissMessage() {const messageContainer = document.getElementById('message-container');if (messageContainer) {messageContainer.innerHTML = '';}}async function fetchUpdatedDocuments(company_id) {console.log("company_id:", company_id);var table = $('#apiTable').DataTable();try {const response = await fetch(`/api/api_updatetable?company_id=${company_id}`);const connectorsResponse = await response.json();console.log("Fetched connectorsResponse:", connectorsResponse);table.clear(); // Clear existing data in the tableif (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {displayErrorMessage("Knowledgebase 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.api_name,company.api_endpoint,`<a href='#' class='btn btn-info btn-sm' data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)'><i class='fas fa-eye'></i></a>`,`<a href='#' class='btn btn-warning btn-sm' data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,company.row_id]);});table.draw(false); // Draw the table with the new datacontentSection.style.display = 'block';}} catch (error) {console.error("Error fetching updated documents:", error);displayErrorMessage("There was an error fetching the updated documents.");}}// Delete companyfunction deleteCompany(button) {var companyId = $(button).data('kid-id');console.log("k_id deleted",companyId);$.ajax({type: "DELETE",url: `/api/deleteapi/${companyId}`,1 unmodified linevar table = $('#apiTable').DataTable();table.row($(button).closest('tr')).remove().draw();const messageContainer = document.getElementById('message-container');if(messageContainer)messageContainer.innerHTML = `<div class='alert alert-danger'>API Data Deleted successfully6 unmodified linesalert("Error deleting company: " + xhr.responseJSON.detail);}});}function save_file() {const form = document.getElementById('documentForm');11 unmodified linesconst Inputjson = $('#Inputjson').val();const OutputJson = $('#OutputJson').val();const Description = $('#Description').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($('#documentForm')[0]);14 unmodified linesif (!response.ok) {throw new Error('Network response was not ok');}return response.text();}).then(data => {var table = $('#apiTable').DataTable();var rowCount = table.rows().count();table.row.add([rowCount + 1,APIName,3 unmodified linesdele]).draw(false);// alert('Document saved successfully');if(messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>API Data saved successfully4 unmodified lines}).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 dropdowncompanies.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 = "";3 unmodified linesdocument.getElementById('Description').value = "";}</script></body>1234569 unmodified lines1617181920212223242526272821 unmodified lines505152535455563 unmodified lines60616263646566676869707117 unmodified lines899091929394953 unmodified lines991001011021031041051061071081091 unmodified line1111121131141151161171181191201211221231241251261272 unmodified lines1301311321331341351361 unmodified line13813914014114214314414597 unmodified lines2432442452462472482495 unmodified lines25525625725825926026126214 unmodified lines2772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103111 unmodified line3133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783794 unmodified lines3843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155161 unmodified line5185195205215225235246 unmodified lines53153253353453553653711 unmodified lines54955055155255355414 unmodified lines5695705715725735745755765775785795805815825833 unmodified lines5875885895905915925935944 unmodified lines5996006016026036046056063 unmodified lines610611612613614615616<!DOCTYPE html><html><head><title>API Connectors</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>9 unmodified lines.form-group {margin-top: -10px;}.card {padding: 0;margin-top: -15px;margin-left: -40px;}.header-row {display: flex;justify-content: space-between;21 unmodified linespadding: 5px;}th,td {white-space: nowrap;}3 unmodified lines/* Sno column */width: 5%;}div.dataTables_wrapper div.dataTables_length select {width: 60px;display: inline-block;}th:nth-child(2),td:nth-child(2) {/* API Name column */17 unmodified lines/* View column */width: 5%;}th:nth-child(6),td:nth-child(6) {/* View column */3 unmodified lines.reduced-width {width: 25%;}div.dataTables_wrapper div.dataTables_length select {width: 60px;display: inline-block;}</style></head>1 unmodified line{% 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"id="company-select"><h4 id="selectedCompany" style="margin-left: 300px;"></h4><div class="col-12 d-flex justify-content-end mb-3"><button class="btn btn-primary"style="margin-top: -40px;margin-right: -25px;position: fixed;" id="add">Add</button></div></div><div class="row">2 unmodified lines</div></div></div><h3 id="company_name" style="margin-left: 400px;">{{company_name}}</h3><section class="content" id="contentSection" style="display: none;"><div class="container-fluid"><div class="form-group">1 unmodified line<input type="hidden" id="company_id" name="company_id" class="form-control" required></div></div><!-- Main content --><section class="content"><div class="container-fluid">97 unmodified lines</div><div class="modal-footer"><!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> --><button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button><button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button></div></div>5 unmodified lines<!-- 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 () {// Show modal function14 unmodified lines// });});var table = $('#apiTable').DataTable();const role = sessionStorage.getItem('userRole');console.log('Current role:', role); // Debug statement to check the roleconst company_name=sessionStorage.getItem('company_name');console.log("company_name",company_name);// document.getElementById('company_name').textContent = company_name;const passedCompanyName = sessionStorage.getItem('company_name')document.getElementById('selectedCompany').innerText = `Company name: ${passedCompanyName}`;const company_id = sessionStorage.getItem('company_id');document.getElementById("company_id").value = company_id;data_get_from_db(company_id);const companySelect = document.getElementById('company');const documentForm = document.getElementById('documentForm');function moveToNextInput(inputs, currentIndex) {const nextInput = inputs[currentIndex + 1];if (nextInput) {nextInput.focus();} else {// Optionally, submit the form or trigger the save buttondocument.getElementById("save").focus();}}function displayErrorMessage(message) {const messageContainer = document.getElementById('message-container');if (messageContainer) {1 unmodified line}}async function data_get_from_db(companyId) {if (companyId) {try {console.log('comp_id',companyId)const Response = await fetch(`/api/get_api_connectors?company_id=${companyId}`);console.log("responce from api :==> ", Response)const connectorsResponse = await Response.json();console.log("knowledge data table after connecting to table", connectorsResponse);console.log("api connector data table after connecting to table", connectorsResponse);const table = $('#apiTable').DataTable(); // Initialize DataTable at the starttable.clear();if (!Array.isArray(connectorsResponse)) {throw new TypeError('Expected an array of companies');displayErrorMessage("Data do not exist for this company. Please fill in the details by clicking add button.");contentSection.style.display = 'none';} else {connectorsResponse.forEach((company, index) => {table.row.add([index + 1,company.APIName,company.APIEndpoint,`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,]).draw(false);});contentSection.style.display = 'block';}} catch (error) {console.error('Error fetching company documents:', error);//displayEmptyTable();displayErrorMessage("Data do not exist for this company. Please fill in the details by clicking add button.");contentSection.style.display = 'none';}}else {// displayEmptyTable();displayErrorMessage("Document details2 for knowledge do not exist for this company. Please fill in the details.");}}function viewCompany(button) {var companyId = $(button).data('kid-id');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'View API Details';if(companyId){$.getJSON(`/api/viewapiconnectors/${companyId}`, function (company) {$('#APIName').val(company.api_name).attr('readonly', 'readonly');$('#APIEndpoint').val(company.api_endpoint).attr('readonly', 'readonly');$('#Auth_Bearer').val(company.auth_token).attr('readonly', 'readonly');$('#Inputjson').val(company.input_param).attr('readonly', 'readonly');$('#OutputJson').val(company.output_json).attr('readonly', 'readonly');$('#Description').val(company.description).attr('readonly', 'readonly');4 unmodified linesalert("Error retrieving API details.");});}}// Edit knowledge base detailsfunction editCompany(button) {var companyId = $(button).data('kid-id');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Edit API Details';if(companyId){// Fetch company details by ID$.getJSON(`/api/viewapiconnectors/${companyId}`, function (company) {$('#APIName').val(company.api_name);$('#APIEndpoint').val(company.api_endpoint);$('#Auth_Bearer').val(company.auth_token);$('#Inputjson').val(company.input_param);$('#OutputJson').val(company.output_json);$('#Description').val(company.description);// Show/hide appropriate elements$('#uploadFile').show(); // Hide the file upload field$('#save').hide(); // Hide the default save button$('#saveupdate').show(); // Show the update button// Ensure fields are editable$('#APIName').removeAttr('readonly');$('#APIEndpoint').removeAttr('readonly');$('#Auth_Bearer').removeAttr('readonly');$('#Inputjson').removeAttr('readonly');$('#OutputJson').removeAttr('readonly');$('#Description').removeAttr('readonly');// Show the modal$('#addModal').modal('show');// Set up the click event for the update button$('#saveupdate').off('click').on('click', function () {saveupdate(companyId); // Pass the company ID for updating});}).fail(function () {alert("Error in retrieving API details.");});}}function saveupdate(companyId, filename) {const formData = new FormData();const company_id = document.getElementById("company_id").value;formData.append("company_id", $('#company_id').val());formData.append("APIName", $('#APIName').val());formData.append("APIEndpoint", $('#APIEndpoint').val());formData.append("Auth_Bearer", $('#Auth_Bearer').val());formData.append("Inputjson", $('#Inputjson').val());formData.append("OutputJson", $('#OutputJson').val());formData.append("Description", $('#Description').val());console.log("company_id to table refresh", company_id)const messageContainer = document.getElementById('message-container');$.ajax({url: `/api/editapiconnectors/${companyId}`,type: 'PUT',data: formData,processData: false, // Required for FormDatacontentType: false, // Required for FormDatasuccess: function (response) {// alert('Knowledgebase details updated successfully.');if (messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>API Data Updated successfully<button class='close' onclick='dismissMessage()'>OK</button></div>`;$('#addModal').modal('hide'); // Close the modal after savingfetchUpdatedDocuments(company_id);},error: function () {alert('Form has no changes to update knowledge base details.');}});}function dismissMessage() {const messageContainer = document.getElementById('message-container');if (messageContainer) {messageContainer.innerHTML = '';}}async function fetchUpdatedDocuments(company_id) {console.log("company_id:", company_id);var table = $('#apiTable').DataTable();try {const response = await fetch(`/api/api_updatetable?company_id=${company_id}`);const connectorsResponse = await response.json();console.log("Fetched connectorsResponse:", connectorsResponse);table.clear(); // Clear existing data in the tableif (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {displayErrorMessage("Knowledgebase 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.api_name,company.api_endpoint,`<a href='#' class='btn btn-info btn-sm' data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)'><i class='fas fa-eye'></i></a>`,`<a href='#' class='btn btn-warning btn-sm' data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,company.row_id]);});table.draw(false); // Draw the table with the new datacontentSection.style.display = 'block';}} catch (error) {console.error("Error fetching updated documents:", error);displayErrorMessage("There was an error fetching the updated documents.");}}// Delete companyfunction deleteCompany(button) {var companyId = $(button).data('kid-id');console.log("k_id deleted", companyId);$.ajax({type: "DELETE",url: `/api/deleteapi/${companyId}`,1 unmodified linevar table = $('#apiTable').DataTable();table.row($(button).closest('tr')).remove().draw();const messageContainer = document.getElementById('message-container');if (messageContainer)messageContainer.innerHTML = `<div class='alert alert-danger'>API Data Deleted successfully6 unmodified linesalert("Error deleting company: " + xhr.responseJSON.detail);}});}function save_file() {const form = document.getElementById('documentForm');11 unmodified linesconst Inputjson = $('#Inputjson').val();const OutputJson = $('#OutputJson').val();const Description = $('#Description').val();var formData = new FormData($('#documentForm')[0]);14 unmodified linesif (!response.ok) {throw new Error('Network response was not ok');}return response.json();}).then(data => {row_id = data.row_id;var table = $('#apiTable').DataTable();var rowCount = table.rows().count();const view = `<a href='#' class='btn btn-info btn-sm'data-kid-id='${row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`;const edit = `<a href='#' class='btn btn-warning btn-sm'data-kid-id='${row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`;const dele = `<a href='#' class='btn btn-danger btn-sm' data-kid-id='${row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`;table.row.add([rowCount + 1,APIName,3 unmodified linesdele]).draw(false);// alert('Document saved successfully');if (messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>API Data saved successfully4 unmodified lines}).catch(error => console.error('Error:', error));}function clearFormFields() {document.getElementById('APIName').value = "";document.getElementById('APIEndpoint').value = "";3 unmodified linesdocument.getElementById('Description').value = "";}</script></body>
templates/API_connectors.html+223-243