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 rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<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 there 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>
<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">MR Spend Automation</a>
</li>
<li class="nav-item sidebar-item active">
<a style ="color: #c0c4cc" class="nav-link" href="spend_index.html">Spend API</a>
</li>
</ul>
</div>
<div class="container my-4">

<h2 class="my-4">Spend Api</h2>
<form id="form">
<div class="form-group">
<label for="col">Enter Column Name:</label>
<input type="text" id="col" class="form-control form-control-sm">
</div>
<div class="form-group">
<label for="val">Enter Value:</label>
<input type="text" id="val" class="form-control form-control-sm">
</div>
</form>
<button id="fetchButton" class="btn btn-primary" mb-4>Submit</button>
<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 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];
const fetchButton = document.getElementById('fetchButton');

let json = null;
let currentPage = 1;
const itemsPerPage = 5;
const param1Value = document.getElementById('col').value;
const param2Value = document.getElementById('val').value;
async function fetchDataUrl(url) {
try {
preloader.classList.remove('d-none'); //show the preloader
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
preloader.classList.add('d-none'); // hide the preloader
return JSON.parse(data);
} catch (error) {
console.error('Error:', error);
throw error;
}
}

fetchButton.addEventListener('click', async () => {
try {
clearTable();

const param1Value = document.getElementById('col').value.trim();
const param2Value = document.getElementById('val').value.trim();
if (param1Value === '' || param2Value === '') {
alert('Please enter valid inputs in both fields.');
return;
}
const url = `http://127.0.0.1:5000/refresh_compare?first_report=${param1Value}&second_report=${param2Value}`;

json = await fetchDataUrl(url);
downloadBtn.disabled = false;
currentPage = 1;
if (json && json.columns) {
createTableHeaders(json.columns);
}
createTableBody(json.data, 0, itemsPerPage);
createPagination(json.data);
// processData(json);
} catch (error) {
// Handle any errors that occur during the request or processing
console.error('Error:', error);
}
});
function clearTable() {
thead.innerHTML = '';
tbody.innerHTML = '';
tfoot.innerHTML = '';
}
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 createPagination(data) {
if(data){console.log("pagination check")}
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;
const currentDate = new Date();
const param1Value = document.getElementById('col').value;
const param2Value = document.getElementById('val').value;
const filename = `${param1Value}_${param2Value}`;
const extension = '.csv';
// Append the current date and time to the filename
const appendedFilename = `${filename}_${currentDate.getTime()}${extension}`;

link.download = appendedFilename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
downloadBtn.addEventListener('click', () => {
if (json) {
console.log(json)
downloadCSV();
}
});

</script>
</body>
</html>




     
 
what is notes.io
 

Notes is a web-based application for online 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 14 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.