-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.html
161 lines (145 loc) · 6.94 KB
/
notes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NotesShare | Notes</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<!-- Navbar -->
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark shadow">
<div class="container">
<a class="navbar-brand fw-bold" href="index.html">NotesShare</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="categories.html">Categories</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="notes.html">All Notes </a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!-- Notes Section with Filters -->
<section class="py-5">
<div class="container mt-5">
<h1 class="text-center mb-4">Notes</h1>
<!-- Category Selection -->
<div class="form-group mb-4">
<label for="category-select">Select Category:</label>
<select id="category-select" class="form-control" onchange="filterNotes()">
<option value="">All Categories</option>
</select>
</div>
<div id="notes-container" class="row"></div>
</div>
</section>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<script>
let notesData = []; // Array to store notes data
let categoriesData = []; // Array to store categories data
// Fetch categories and notes from JSON files
Promise.all([
fetch('categories.json').then(response => response.json()),
fetch('notes.json').then(response => response.json())
])
.then(([categories, notes]) => {
categoriesData = categories;
notesData = notes;
populateCategorySelect(categories);
// Check if there is a category ID in the URL
const categoryId = getQueryParameter('category');
if (categoryId) {
document.getElementById('category-select').value = categoryId; // Auto-select category
filterNotes(categoryId); // Filter notes by selected category
} else {
renderNotes(notesData); // Render all notes if no category is selected
}
})
.catch(error => console.error('Error fetching data:', error));
function populateCategorySelect(categories) {
const categorySelect = document.getElementById('category-select');
categories.forEach(category => {
const option = document.createElement('option');
option.value = category.id; // Use category ID
option.textContent = category.header;
categorySelect.appendChild(option);
});
}
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
function filterNotes() {
const categoryId = document.getElementById('category-select').value; // Get selected category from the dropdown
const filteredNotes = categoryId ?
notesData.filter(note => note.category === categoryId) :
notesData;
renderNotes(filteredNotes);
}
function renderNotes(notes) {
const notesContainer = document.getElementById('notes-container');
notesContainer.innerHTML = ''; // Clear previous content
if (notes.length === 0) {
notesContainer.innerHTML = '<div class="col-12"><p class="text-center">No notes found for this category.</p></div>';
return;
}
notes.forEach(note => {
// Get file size dynamically
fetch(note.pdfPath)
.then(response => {
if (response.ok) {
const sizeInBytes = parseInt(response.headers.get('Content-Length'), 10);
const sizeInMB = (sizeInBytes / (1024 * 1024)).toFixed(2) + ' MB';
createNoteCard(note, sizeInMB);
} else {
createNoteCard(note, 'Size unavailable');
}
})
.catch(() => createNoteCard(note, 'Size unavailable'));
});
}
function createNoteCard(note, fileSize) {
const notesContainer = document.getElementById('notes-container');
// Find the category for the note
const category = categoriesData.find(cat => cat.id === note.category);
const noteCard = `
<div class="col-md-4 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">${note.title}</h5>
<span class="badge badge-info">${category ? category.header : 'Unknown Category'}</span>
<p class="card-text mt-2">${note.description}</p>
<p class="card-text"><small class="text-muted">Author: ${note.author}</small></p>
<p class="card-text"><small class="text-muted">File Size: ${fileSize}</small></p>
<a href="${note.pdfPath}" class="btn btn-primary" download>Download PDF</a>
</div>
</div>
</div>
`;
notesContainer.innerHTML += noteCard;
}
</script>
<!-- Bootstrap JavaScript and Custom Script for Sorting -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/script.js"></script>
</body>
</html>