-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
270 lines (243 loc) · 7.86 KB
/
app.js
File metadata and controls
270 lines (243 loc) · 7.86 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import { Holo } from 'holo-js';
const holo = Holo.init();
holo.setTitle("MrServer Apps Repository");
holo.render(`
<header>
<div class="navbar">
<div class="logo">
<img width="25" src="https://raw.githubusercontent.com/mrserver-org/ui/refs/heads/main/logo.png"></img>
<span>MrServer Apps</span>
</div>
<div class="search-bar">
<i class="fas fa-search"></i>
<input type="text" id="search-input" placeholder="Search apps...">
</div>
</div>
</header>
<main>
<div class="hero">
<h1>MrServer Apps Repository</h1>
<p>Discover and install powerful applications for your MrServer instance with a single command</p>
</div>
<div class="filter-area">
<div class="sort-dropdown">
<select id="sort-select">
<option value="name-asc">Name (A-Z)</option>
<option value="name-desc">Name (Z-A)</option>
<option value="publisher">Publisher</option>
</select>
</div>
</div>
<div class="loader" id="loader">
<div class="loader-spinner"></div>
</div>
<div class="apps-grid" id="apps-grid"></div>
</main>
<footer>
<div class="footer-content">
<div class="footer-logo">
<img width="25" src="https://raw.githubusercontent.com/mrserver-org/ui/refs/heads/main/logo.png"></img>
<span>MrServer Apps Repository</span>
</div>
<div class="footer-links">
<a href="#about">About</a>
<a href="https://mrserverdocs.now.sh">Documentation</a>
<a href="https://github.com/mrserver-org/apps">Publish App</a>
<a href="https://github.com/mrserver-org">GitHub</a>
</div>
</div>
</footer>
<div class="copy-notification" id="copy-notification">
Command copied to clipboard!
</div>
<div class="modal" id="install-modal">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title">Install App</div>
<button class="close-modal">×</button>
</div>
<div class="modal-body">
<p>Follow these steps to install the app on your MrServer instance:</p>
<ul class="install-steps">
<li>
<div class="step-number">1</div>
<div>Open the terminal inside/outside of MrServer</div>
</li>
<li>
<div class="step-number">2</div>
<div>
<p>Run the following command:</p>
<div class="command-box">
<code id="modal-command">mr app-install app-uuid</code>
<button class="command-copy" id="modal-copy-btn">
<i class="far fa-copy"></i>
</button>
</div>
</div>
</li>
<li>
<div class="step-number">3</div>
<div>Wait for the installation process to complete</div>
</li>
<li>
<div class="step-number">4</div>
<div>Refresh the browser to take full effect. (the app may appear but won't launch.)</div>
</li>
</ul>
<div class="modal-app-info">
<p>The app will be installed on your MrServer instance and ready to use immediately after installation.</p>
</div>
</div>
</div>
</div>
`);
const appsGrid = document.getElementById('apps-grid');
const loader = document.getElementById('loader');
const searchInput = document.getElementById('search-input');
const sortSelect = document.getElementById('sort-select');
const filterBadges = document.querySelectorAll('.filter-badge');
const copyNotification = document.getElementById('copy-notification');
const installModal = document.getElementById('install-modal');
const closeModal = document.querySelector('.close-modal');
const modalCommand = document.getElementById('modal-command');
const modalCopyBtn = document.getElementById('modal-copy-btn');
let apps = [];
let filteredApps = [];
const urlParams = new URLSearchParams(window.location.search);
let currentFilter = urlParams.has("install") ? 'all' : 'listed';
async function fetchApps() {
try {
const response = await fetch('./metadata.json');
apps = await response.json();
filteredApps = [...apps];
loader.style.display = 'none';
if (apps.length === 0) {
appsGrid.innerHTML = '<div class="no-apps"><i class="fas fa-box-open fa-3x"></i><p>No apps found</p></div>';
return;
}
sortApps('name-asc');
renderApps();
} catch (error) {
console.error('Error fetching apps:', error);
loader.style.display = 'none';
appsGrid.innerHTML = '<div class="no-apps"><i class="fas fa-exclamation-triangle fa-3x"></i><p>Failed to load apps</p></div>';
}
}
function renderApps() {
appsGrid.innerHTML = '';
if (filteredApps.length === 0) {
appsGrid.innerHTML = '<div class="no-apps"><i class="fas fa-search fa-3x"></i><p>No apps match your search</p></div>';
return;
}
filteredApps.forEach(app => {
if (currentFilter === 'listed' && app.listed === false) return;
if (currentFilter === 'unlisted' && app.listed !== false) return;
const card = document.createElement('div');
card.className = 'app-card';
const bannerUrl = app.banner || '';
const logoUrl = app.logo || null;
card.innerHTML = `
<div class="app-banner" style="background-image: url('${bannerUrl}')">
<div class="app-logo">
${logoUrl ? `<img src="${logoUrl}" alt="${app.name} logo">` : `<i class="fas fa-cube app-logo-placeholder"></i>`}
</div>
</div>
<div class="app-content">
<div class="app-header">
<div class="app-name">${app.name}</div>
<div class="app-publisher">
<div class="publisher-avatar">
<img src="https://github.com/${app.publisher}.png" alt="${app.publisher}" onerror="this.src=''">
</div>
<a href="https://github.com/${app.publisher}">@${app.publisher}</a>
</div>
</div>
<div class="app-description">${app.description || 'No description provided'}</div>
<div class="app-footer">
<button class="install-btn" data-uuid="${app.uuid}">
<i class="fas fa-download"></i> Install
</button>
<div class="app-uuid">
<span class="copy-cmd" data-command="mr app-install ${app.uuid}" title="Copy install command">
<i class="far fa-copy"></i>
</span>
${app.uuid}
</div>
</div>
</div>
`;
appsGrid.appendChild(card);
});
document.querySelectorAll('.copy-cmd').forEach(btn => {
btn.addEventListener('click', (e) => {
const command = e.currentTarget.dataset.command;
copyToClipboard(command);
e.stopPropagation();
});
});
document.querySelectorAll('.install-btn').forEach(btn => {
btn.addEventListener('click', () => {
const uuid = btn.dataset.uuid;
showInstallModal(uuid);
});
if (urlParams.get("install") == btn.dataset.uuid) {
btn.click();
}
});
}
function filterApps() {
const searchTerm = searchInput.value.toLowerCase();
filteredApps = apps.filter(app => {
const nameMatch = app.name.toLowerCase().includes(searchTerm);
const descMatch = app.description && app.description.toLowerCase().includes(searchTerm);
const publisherMatch = app.publisher.toLowerCase().includes(searchTerm);
const uuidMatch = app.uuid.toLowerCase().includes(searchTerm);
return nameMatch || descMatch || publisherMatch || uuidMatch;
});
sortApps(sortSelect.value);
renderApps();
}
function sortApps(sortType) {
switch (sortType) {
case 'name-asc':
filteredApps.sort((a, b) => a.name.localeCompare(b.name));
break;
case 'name-desc':
filteredApps.sort((a, b) => b.name.localeCompare(a.name));
break;
case 'publisher':
filteredApps.sort((a, b) => a.publisher.localeCompare(b.publisher));
break;
}
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
copyNotification.classList.add('active');
setTimeout(() => {
copyNotification.classList.remove('active');
}, 2000);
}).catch(err => {
console.error('Failed to copy text: ', err);
});
}
function showInstallModal(uuid) {
modalCommand.textContent = `mr app-install ${uuid}`;
installModal.classList.add('active');
}
closeModal.addEventListener('click', () => {
installModal.classList.remove('active');
});
installModal.addEventListener('click', (e) => {
if (e.target === installModal) {
installModal.classList.remove('active');
}
});
modalCopyBtn.addEventListener('click', () => {
copyToClipboard(modalCommand.textContent);
});
searchInput.addEventListener('input', filterApps);
sortSelect.addEventListener('change', () => {
sortApps(sortSelect.value);
renderApps();
});
fetchApps();