mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-04 16:51:29 +02:00
Contacts and domains prepared for high load; patches
This commit is contained in:
parent
46cebdf3c6
commit
56ff89a37c
10 changed files with 161 additions and 102 deletions
|
@ -6,10 +6,7 @@
|
|||
<script>
|
||||
var table;
|
||||
document.querySelector("#hostTable").addEventListener('click', function(e) {
|
||||
if (e.target.matches('.update-btn')) {
|
||||
let id = e.target.getAttribute('data-id');
|
||||
updateRecord(id);
|
||||
} else if (e.target.matches('.delete-btn')) {
|
||||
if (e.target.matches('.delete-btn')) {
|
||||
let id = e.target.getAttribute('data-id');
|
||||
deleteRecord(id);
|
||||
}
|
||||
|
@ -23,26 +20,76 @@
|
|||
|
||||
function actionsFormatter(cell, formatterParams, onRendered) {
|
||||
return `
|
||||
<button class="btn btn-primary btn-icon update-btn" data-id="${cell.getRow().getData().id}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></button>
|
||||
<a class="btn btn-primary btn-icon update-btn" href="host/update/${cell.getRow().getData().name}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a>
|
||||
<button class="btn btn-danger btn-icon delete-btn" data-id="${cell.getRow().getData().id}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 7h16"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path><path d="M10 12l4 4m0 -4l-4 4"></path></svg></button>
|
||||
`;
|
||||
}
|
||||
|
||||
function statusFormatter(cell) {
|
||||
var statusArray = cell.getValue();
|
||||
if (statusArray && Array.isArray(statusArray)) {
|
||||
return statusArray.map(item => item.status).join(', ');
|
||||
var rowData = cell.getRow().getData(); // Get the entire row data
|
||||
|
||||
// Function to create a badge
|
||||
function createBadge(text, badgeClass) {
|
||||
return `<span class="badge bg-${badgeClass}-lt">${text}</span>`;
|
||||
}
|
||||
return "";
|
||||
|
||||
// Check if statusArray is empty or not
|
||||
if (statusArray && Array.isArray(statusArray) && statusArray.length > 0) {
|
||||
return statusArray.map(item => createBadge(item.status, 'azure')).join(' ');
|
||||
} else {
|
||||
// Fallback to rgpstatus column if statusArray is empty
|
||||
return rowData.rgpstatus ? createBadge(rowData.rgpstatus, 'lime') : "";
|
||||
}
|
||||
}
|
||||
|
||||
var searchTerm = ""; // global variable to hold the search term
|
||||
|
||||
function updateSearchTerm(term) {
|
||||
searchTerm = term;
|
||||
table.replaceData();
|
||||
}
|
||||
|
||||
table = new Tabulator("#hostTable", {
|
||||
ajaxURL:"/api/records/host?join=host_status", // Set the URL for your JSON data
|
||||
ajaxConfig:"GET",
|
||||
pagination:"local",
|
||||
paginationSize:10,
|
||||
ajaxResponse:function(url, params, response){
|
||||
return response.records;
|
||||
pagination: true,
|
||||
paginationMode: "remote",
|
||||
paginationSize: 10,
|
||||
ajaxURL: "/api/records/host",
|
||||
ajaxParams: {
|
||||
join: "host_status"
|
||||
},
|
||||
ajaxURLGenerator: function(url, config, params) {
|
||||
var queryParts = ["join=host_status"];
|
||||
|
||||
// Handle search term
|
||||
if (searchTerm) {
|
||||
queryParts.push("filter1=name,cs," + encodeURIComponent(searchTerm));
|
||||
queryParts.push("filter2=crdate,cs," + encodeURIComponent(searchTerm));
|
||||
}
|
||||
|
||||
queryParts.push("order=id");
|
||||
|
||||
// Include pagination parameters
|
||||
if (params.page) {
|
||||
queryParts.push("page=" + params.page + "," + params.size);
|
||||
}
|
||||
|
||||
return url + "?" + queryParts.join("&");
|
||||
},
|
||||
ajaxResponse: function(url, params, response) {
|
||||
if (response && Array.isArray(response.records) && typeof response.results === 'number') {
|
||||
var lastPage = Math.ceil(response.results / this.options.paginationSize);
|
||||
return {
|
||||
last_page: lastPage, // Calculated total number of pages
|
||||
data: response.records, // Data for the current page
|
||||
};
|
||||
} else {
|
||||
console.error('Unexpected response format', response);
|
||||
return { last_page: 1, data: [] };
|
||||
}
|
||||
},
|
||||
dataReceiveParams: {
|
||||
"last_page": "results", // Mapping 'results' to 'last_page'
|
||||
},
|
||||
layout:"fitDataFill",
|
||||
responsiveLayout: "collapse",
|
||||
|
@ -50,8 +97,8 @@
|
|||
resizableColumns:false,
|
||||
columns:[
|
||||
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
|
||||
{title:"Name", field:"name", width:200, headerSort:true, formatter: hostLinkFormatter, responsive:0},
|
||||
{title:"Creation Date", field:"crdate", width:300, minWidth:200, headerSort:true, responsive:2},
|
||||
{title:"Name", field:"name", width:300, headerSort:false, formatter: hostLinkFormatter, responsive:0},
|
||||
{title:"Creation Date", field:"crdate", width:300, minWidth:200, headerSort:false, responsive:2},
|
||||
{title:"Status", field:"host_status", width:300, minWidth:200, formatter: statusFormatter, headerSort:false, download:false, responsive:2},
|
||||
{title: "Actions", formatter: actionsFormatter, headerSort: false, download:false, hozAlign: "center", responsive:0, cellClick:function(e, cell){ e.stopPropagation(); }},
|
||||
],
|
||||
|
@ -61,26 +108,10 @@
|
|||
});
|
||||
var searchInput = document.getElementById("search-input");
|
||||
searchInput.addEventListener("input", function () {
|
||||
var term = searchInput.value.toLowerCase();
|
||||
|
||||
if (term) { // Only apply filter when there's a term to search for
|
||||
table.setFilter(function (data) {
|
||||
return (
|
||||
String(data.name).toLowerCase().includes(term) ||
|
||||
String(data.crdate).toLowerCase().includes(term) ||
|
||||
String(data.host_status).toLowerCase().includes(term)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
table.clearFilter(); // Clear the filter when the search box is emptied
|
||||
}
|
||||
updateSearchTerm(searchInput.value);
|
||||
});
|
||||
});
|
||||
|
||||
function updateRecord(id) {
|
||||
console.log("Updating record with ID: " + id);
|
||||
}
|
||||
|
||||
|
||||
function deleteRecord(id) {
|
||||
console.log("Deleting record with ID: " + id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue