Skip to content

Commit

Permalink
Merge pull request #2088 from Kaiserdragon2/Site-Improvements
Browse files Browse the repository at this point in the history
add sorting remove unused function
  • Loading branch information
Kaiserdragon2 authored Apr 12, 2024
2 parents 731e7ce + 47c0009 commit e8bc1dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 63 deletions.
93 changes: 32 additions & 61 deletions docs/js/updatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const batchSize = 50; // Number of rows to load at a time
let startIndex = 0; // Start index for lazy loading
let appEntriesData = []; // Store the original data for sorting
// Global variables to track sorting column and direction
let sortingColumnIndex = 3;
let sortingColumnIndex = 3;
let sortingDirection = 'desc';

// Debounce function for search input
Expand Down Expand Up @@ -53,6 +53,7 @@ fetch(`https://raw.githubusercontent.com/${RepoOwner}/${RepoName}/${RepoBranch}/
});
});
appEntriesDataGlobal = appEntriesData;
updateHeaderText(`${appEntriesData.length} Possible Appfilter Updates`);

// Example usage:
fetch(`https://raw.githubusercontent.com/${RepoOwner}/${RepoName}/icon-requests/docs/assets/combined_appfilter.xml`)
Expand Down Expand Up @@ -88,23 +89,23 @@ fetch(`https://raw.githubusercontent.com/${RepoOwner}/${RepoName}/${RepoBranch}/



// Filter appEntriesData based on appfilter content
function filterAppfilter(appEntriesData, appfilterContent) {
const appfilterItems = parseAppfilter(appfilterContent);
const filteredOutEntries = [];
const filteredData = appEntriesData.filter(entry => {
const entryAppfilter = entry.appfilter.trim().split('"')[1].trim();
// Check if the entry is filtered out
const isFiltered = appfilterItems.some(component => component === entryAppfilter);
if (isFiltered) {
filteredOutEntries.push(entryAppfilter);
}
return !isFiltered;
});
console.log("Filtered out entries:", filteredOutEntries);
return filteredData;
}
// Filter appEntriesData based on appfilter content
function filterAppfilter(appEntriesData, appfilterContent) {
const appfilterItems = parseAppfilter(appfilterContent);
const filteredOutEntries = [];

const filteredData = appEntriesData.filter(entry => {
const entryAppfilter = entry.appfilter.trim().split('"')[1].trim();
// Check if the entry is filtered out
const isFiltered = appfilterItems.some(component => component === entryAppfilter);
if (isFiltered) {
filteredOutEntries.push(entryAppfilter);
}
return !isFiltered;
});
console.log("Filtered out entries:", filteredOutEntries);
return filteredData;
}

// Parse appfilter content
function parseAppfilter(appfilterContent) {
Expand Down Expand Up @@ -161,7 +162,7 @@ function renderTable(data) {
let cell4 = row.insertCell(3);
index = index + startIndex;
cell1.innerHTML = entry.appName;
cell2.innerHTML = `<div class="package-name"><div id="packagename">`+entry.packageName + `</div><div id="package-copy"><button class="copy-package" onclick="copyToClipboard(${index}, 'package')"><img src="img/requests/copy.svg"></button></div></div>`;
cell2.innerHTML = `<div class="package-name"><div id="packagename">` + entry.packageName + `</div><div id="package-copy"><button class="copy-package" onclick="copyToClipboard(${index}, 'package')"><img src="img/requests/copy.svg"></button></div></div>`;
cell3.innerHTML = entry.appfilter.replace('<', '&lt;').replace('>', '&gt;').replace(/"/g, '&quot;').trim();
cell4.innerHTML = `<button class="copy-button" onclick="copyToClipboard(${index}, 'appfilter')">Copy</button>`;
});
Expand All @@ -180,12 +181,12 @@ function copyToClipboard(index, event) {
const entry = appEntriesDataGlobal[index];
let copyText = "";

if (event == "package"){
copyText = `${entry.packageName}`;
}else if (event == "appfilter"){
copyText = `${entry.appfilter}`;
if (event == "package") {
copyText = `${entry.packageName}`;
} else if (event == "appfilter") {
copyText = `${entry.appfilter}`;
}

navigator.clipboard.writeText(copyText).then(() => {
// Show the copy notification
document.getElementById('copy-notification').innerText = `Copied: ${copyText}`;
Expand All @@ -204,7 +205,7 @@ function copyToClipboard(index, event) {
const updatableButton = document.getElementById("updatable-button");

// Add an event listener to the button
updatableButton.addEventListener("click", function() {
updatableButton.addEventListener("click", function () {
// Define the URL to redirect to
const updatableURL = `https://${RepoOwner}.github.io/${RepoName}/requests.html`;
// Redirect to the specified URL
Expand Down Expand Up @@ -250,32 +251,16 @@ function sortTable(columnIndex) {
sortingColumnIndex = columnIndex;
// Sort the data
const sortedData = sortData(sortingDirection, columnIndex, [...appEntriesDataGlobal]);

updateTable(sortedData);
}

function sortData(sortingDirection, columnIndex, sortedData){
function sortData(sortingDirection, columnIndex, sortedData) {
sortedData.sort((a, b) => {
if (columnIndex === 4) { // Check if sorting the 'Last Requested' column
const cellA = getCellValue(a, columnIndex);
const cellB = getCellValue(b, columnIndex);

// Handle dates
return sortingDirection === 'asc' ? cellA - cellB : cellB - cellA;
} else if (columnIndex === 3) {
const cellA = getCellValue(a, columnIndex);
const cellB = getCellValue(b, columnIndex);

// Handle numerical values
if (!isNaN(cellA) && !isNaN(cellB)) {
return sortingDirection === 'asc' ? cellA - cellB : cellB - cellA;
}
} else {
// Default to string comparison
const cellA = a[Object.keys(a)[columnIndex]].toLowerCase();
const cellB = b[Object.keys(b)[columnIndex]].toLowerCase();
return sortingDirection === 'asc' ? cellA.localeCompare(cellB) : cellB.localeCompare(cellA);
}
// Default to string comparison
const cellA = a[Object.keys(a)[columnIndex]].toLowerCase();
const cellB = b[Object.keys(b)[columnIndex]].toLowerCase();
return sortingDirection === 'asc' ? cellA.localeCompare(cellB) : cellB.localeCompare(cellA);
});
return sortedData;
}
Expand All @@ -284,17 +269,3 @@ function sortData(sortingDirection, columnIndex, sortedData){
function initializeTable() {
renderTable(appEntriesData);
}

// Helper function to get cell value by column index
function getCellValue(row, columnIndex) {
const key = Object.keys(row)[columnIndex];
if (key === 'lastRequestedTime') {
// Parse date strings to Date objects for sorting
const dateString = row[key].split(',')[0]; // Extract date part from the string
const [day, month, year] = dateString.split('/').map(Number); // Split the date string and convert parts to numbers
const timeString = row[key].split(',')[1].trim(); // Extract time part from the string
const [hour, minute, second] = timeString.split(':').map(Number); // Split the time string and convert parts to numbers
return new Date(year, month - 1, day, hour, minute, second); // Return a Date object with year, month, day, hour, minute, second
}
return isNaN(row[key]) ? row[key] : parseFloat(row[key]);
}
4 changes: 2 additions & 2 deletions docs/updatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ <h1 id="header">Possible Appfilter Updates</h1>
<tr>
<th class="sortable-header" onclick="sortTable(0)">App
Name</th>
<th>Package Name</th>
<th>Appfilter Text</th>
<th class="sortable-header" onclick="sortTable(1)">Package Name</th>
<th class="sortable-header" onclick="sortTable(2)">Appfilter Text</th>
<th>Appfilter</th>
</tr>
</thead>
Expand Down

0 comments on commit e8bc1dc

Please sign in to comment.