forked from NejcZivic/yatb-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
195 lines (160 loc) · 7 KB
/
index.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BSMG Ticket Transcripts</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
background-color: #1f2937;
}
</style>
</head>
<body class="bg-gray-900 text-white">
<div class="container mx-auto p-6">
<header class="text-center py-6">
<h1 class="text-3xl font-bold text-white">BSMG Ticket Transcripts</h1>
</header>
<div class="flex justify-between mb-6 space-x-4">
<input type="text" id="search-bar"
class="w-full md:w-1/3 bg-gray-800 text-white rounded-lg py-2 px-4 focus:outline-none focus:ring-2 focus:ring-indigo-600"
placeholder="Search for username..." />
<select id="filter-type"
class="bg-gray-800 text-white rounded-lg py-2 px-4 focus:outline-none focus:ring-2 focus:ring-indigo-600">
<option value="Ban">Ban</option>
<option value="Mute">Mute</option>
<option value="Unhelpable">Unhelpable</option>
<option value="Unrequestable">Unrequestable</option>
<!-- Add more options and values here to your needs -->
</select>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6" id="tickets-container"></div>
<div class="flex justify-center items-center space-x-2 mt-6" id="pagination-container">
<button id="prev-button" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700"
onclick="changePage(currentPage - 1)">
Previous
</button>
<input id="page-input" type="text"
class="bg-gray-800 text-white rounded-lg py-2 px-4 focus:outline-none focus:ring-2 focus:ring-indigo-600 w-20"
placeholder="Page" maxlength="3" />
<span class="text-white mx-2">of <span id="total-pages">1</span> pages</span>
<button id="next-button" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700"
onclick="changePage(currentPage + 1)">
Next
</button>
</div>
</div>
<script>
let token = null;
let currentPage = 1;
let totalPages = 1;
let type = "";
let search = "";
window.onload = () => {
const url = new URL(window.location.href);
const jwt = url.searchParams.get('token');
let verified = false;
if (!jwt) {
try {
token = document.cookie.split('; ').find(row => row.startsWith('token='))?.split('=')[1];
} catch (e) {
window.location.href = "/login";
}
if (!token) {
window.location.href = "/login";
} else {
verified = true;
}
} else {
verified = true;
document.cookie = `token=${jwt}; path=/; max-age=${60 * 60 * 24 * 30}`;
window.history.replaceState({}, document.title, "/");
token = jwt;
}
if (verified) {
fetchTickets(token, currentPage);
}
document.getElementById('search-bar').addEventListener('input', function () {
search = this.value;
fetchTickets(token, currentPage, search, type);
});
document.getElementById('filter-type').addEventListener('change', function () {
type = this.value;
console.log(this.value);
fetchTickets(token, currentPage, search, type);
});
document.getElementById('page-input').addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
const typedPage = parseInt(this.value);
if (typedPage >= 1 && typedPage <= totalPages) {
currentPage = typedPage;
fetchTickets(token, currentPage);
}
}
});
}
function fetchTickets(token, page, searchTerm = '', typeFilter = '') {
const response = fetch(`/transcripts?page=${page}&size=20&search=${searchTerm}&type=${typeFilter}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
}
}).then(async res => {
if (res.status === 401 || res.status === 403) {
document.cookie = 'token=; path=/; max-age=0';
window.location.href = "/login";
} else {
const data = await res.json();
renderTickets(data.transcripts);
totalPages = data.totalPages;
renderPagination();
}
})
}
function renderTickets(tickets) {
const container = document.getElementById('tickets-container');
container.innerHTML = '';
tickets.forEach(ticket => {
const card = document.createElement('div');
card.classList.add(
'bg-gray-800', 'rounded-lg', 'p-6', 'shadow-lg', 'transition-all',
'duration-300', 'cursor-pointer',
'hover:shadow-xl', 'hover:scale-105', 'hover:shadow-indigo-500/50'
);
card.innerHTML = `
<h3 class="text-xl font-semibold text-indigo-300">Transcript of ${ticket.ticket}</h3>
<p class="text-sm mt-2 text-gray-300">Type: <span class="text-indigo-400">${ticket.type}</span></p>
<p class="text-sm text-gray-300">Appealer: <span class="text-indigo-400">${ticket.username}</span></p>
`;
card.onclick = () => {
window.open(`/transcript/${ticket.ticket}`, '_blank');
};
container.appendChild(card);
});
}
function renderPagination() {
document.getElementById('total-pages').textContent = totalPages;
document.getElementById('page-input').value = currentPage;
const prevButton = document.getElementById('prev-button');
const nextButton = document.getElementById('next-button');
if (currentPage === 1) {
prevButton.disabled = true;
} else {
prevButton.disabled = false;
}
if (currentPage === totalPages) {
nextButton.disabled = true;
} else {
nextButton.disabled = false;
}
}
function changePage(page) {
if (page >= 1 && page <= totalPages) {
currentPage = page;
fetchTickets(token, currentPage);
}
}
</script>
</body>
</html>