NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
<meta charset="UTF-8">
<title>Snowflake Data</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
tfoot td {
text-align: left;
background-color: #f2f2f2;
} th {
position: sticky;
white-space: nowrap;
top: 2px;
padding: 2px;
background-color: gray;
color: black;
text-align: left;
/*border: 1px solid gray;*/
}
#preloader {
position: fixed;
z-index: 9999;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}

#preloader p {
margin-top: 1rem;
color: white;
}
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100;
padding-top: 20px; /* Adjust this value if you have a fixed top navbar */
background-color: #212529;
height: 100vh;
color: white;
font-size: 14px;
width:220px;
font-family: ArtifaktElement-Bold,sans-serif;/*Arial sans-serif;*/

}
sidebar-logo {
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}

.sidebar-logo img {
width: 230px; /* Adjust the image width */
}
.sidebar-item {
padding: 15px;
color: white;
transition: background-color 0.3s ease;
}

.sidebar-item:hover {
background-color: hsla(0,0%,100%,.12);
}

.content {
margin-left: 220px; /* Adjust this value based on the sidebar width */
padding: 2px;
}
</style>
</head>

<body class="content">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>


<div class="sidebar">
<div class="sidebar-logo">
<a class="navbar-brand" href="#">
<img src="logo2.png" alt="Logo" class="navbar-logo">
</a></div>
<ul class="nav flex-column">
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link " href="index.html">Spend BO-Snapshot</a>
</li>
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link" href="spend_index.html">Spend API</a>
</li>
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link " href="index.html">Spend BO-Refresh</a>
</li>
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link " href="index.html">Spend Anaplan-EDH</a>
</li>
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link " href="dynamic_index.html">Dynamic_Spend</a>
</li>
</ul>
</div>

<div class="container my-4">
<h3 class="my-4">SPEND BO API - SNAPSHOT</h3>
<label for="api-select">Select the Report:</label>
<select id="api-select" class="form-select mb-4">
<option value="">-- Select the Report --</option>
</select>

<button id="download-btn" class="btn btn-primary mb-4" disabled>Download CSV</button>
<div id="preloader" class="d-none">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p class="text-center">Please wait while the data is being fetched...</p>
</div>
<div class=" table-responsive">
<table id="json-table" class="table table-stripped table-hover" ><!--sm, lg,xl,md class="table-hover" class="table-striped" class="table-responsive">-->
<tfoot></tfoot>
<thead></thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
</div>

</div>
<script>
const preloader = document.getElementById('preloader');
const apiSelect = document.getElementById('api-select');
const table = document.getElementById('json-table');
const downloadBtn = document.getElementById('download-btn');
const thead = table.getElementsByTagName('thead')[0];
const tbody = table.getElementsByTagName('tbody')[0];
const tfoot = table.getElementsByTagName('tfoot')[0];

let json = null;
let currentPage = 1;
const itemsPerPage = 5;
async function readExcel(filename) {
// Fetch the file from the server
const response = await fetch(filename);

// Read the file as an ArrayBuffer
const arrayBuffer = await response.arrayBuffer();

// Convert the ArrayBuffer to a Uint8Array
var data = new Uint8Array(arrayBuffer);

// Read the Excel file
var workbook = XLSX.read(data, {type: 'array'});

var worksheet = workbook.Sheets[workbook.SheetNames[0]];
var jsonData = XLSX.utils.sheet_to_json(worksheet, {header: 1});

// Remove header row
jsonData.shift();

// Populate the dropdown
jsonData.forEach(row => {
var displayName = row[0]; // Display_Name
var reportName = row[1]; // Report_Name

// Create the URL
var url = `http://127.0.0.1:5000/compare?first_report=${reportName}&second_report=${reportName}`;

// Create a new option element
var option = new Option(displayName, url);

// Append the new option to the dropdown
apiSelect.appendChild(option);
});
}

// Call readExcel function with the Excel file name
readExcel('report_config.xlsx');



async function fetchData(url) {
preloader.classList.remove('d-none'); // show the preloader
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
}
const jsonData = await response.json();
preloader.classList.add('d-none'); // hide the preloader
return JSON.parse(jsonData);
}


function createTableHeaders(headers) {
const tr = document.createElement('tr');
headers.forEach(header => {
const th = document.createElement('th');
th.innerText = header;
tr.appendChild(th);
});
thead.appendChild(tr);
}

function createTableBody(data, start, end) {
tbody.innerHTML = '';
for (let i = start; i < end; i++) {
if (data[i]) {
const tr = document.createElement('tr');
data[i].forEach(cell => {
const td = document.createElement('td');
td.innerText = cell;
tr.appendChild(td);
});
tbody.appendChild(tr);
}
}
}

function clearTable() {
thead.innerHTML = '';
tbody.innerHTML = '';
tfoot.innerHTML = '';
}

function createPagination(data) {
tfoot.innerHTML = '';

const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = json.columns.length;

const prevBtn = document.createElement('button');

prevBtn.innerText = 'Prev';
prevBtn.classList.add('btn', 'btn-sm', 'mx-1', 'btn-outline-primary');
prevBtn.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
createTableBody(json.data, (currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
}
});
td.appendChild(prevBtn);

const nextBtn = document.createElement('button');
nextBtn.innerText = 'Next';
nextBtn.classList.add('btn', 'btn-sm', 'mx-1', 'btn-outline-primary');
nextBtn.addEventListener('click', () => {
const pageCount = Math.ceil(data.length / itemsPerPage);
if (currentPage < pageCount) {
currentPage++;
createTableBody(json.data, (currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
}
});
td.appendChild(nextBtn);

tr.appendChild(td);
tfoot.appendChild(tr);
}

function downloadCSV() {
const csvData = [json.columns].concat(json.data);
const csv = Papa.unparse(csvData);
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);

const link = document.createElement('a');
link.href = url;
link.download = apiSelect.options[apiSelect.selectedIndex].text + '.csv';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

apiSelect.addEventListener('change', async () => {
clearTable();
if (apiSelect.value) {
try {
json = await fetchData(apiSelect.value);
currentPage = 1;
if (json && json.columns) {
createTableHeaders(json.columns);
// ... rest of the code that uses the json object
createTableBody(json.data, 0, itemsPerPage);
createPagination(json.data);
downloadBtn.disabled = false;
} else {
console.error('Error fetching data: invalid JSON data');
}
//createTableHeaders(json.columns);
} catch (error) {
console.error('Error fetching data:', error);
}
}
});





downloadBtn.addEventListener('click', () => {
if (json) {
downloadCSV();
}
});
</script>
</body>
</html>
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.