-
Notifications
You must be signed in to change notification settings - Fork 28
/
navbar.js
80 lines (76 loc) · 3.76 KB
/
navbar.js
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
/* global getStorePath, Swal, $ */
$(document).ready(() => {
// add page header
$('#header').load('/header.html', () => {
// update auth state in nav bar
fetch('/user/v2/user_state')
.then((response) => response.json())
.then((data) => {
window.auth = data;
const authDrop = $('#auth-dropdown');
authDrop.addClass('dropdown-toggle');
authDrop.attr('data-bs-toggle', 'dropdown');
authDrop.attr('aria-haspopup', 'true');
authDrop.attr('aria-expanded', 'false');
authDrop.after(
"<ul class='dropdown-menu dropdown-menu-end' role='menu' aria-labelledby='auth-dropdown'></ul>"
);
const dropdownMenu = $('ul .dropdown-menu');
dropdownMenu.append('<li><a class="dropdown-item" href="/conf/versions.html">Version</a></li>');
if (window.auth.authenticated) {
authDrop.html(window.auth.username);
dropdownMenu.append('<li><a class="dropdown-item" href="/user/v2/profile">Profile</a></li>');
dropdownMenu.append('<li><a class="dropdown-item" id="show_perms" href="#">Permissions</a></li>');
$('#show_perms').on('click', () => {
const frame = document.getElementsByTagName('iframe');
const win = frame && frame.length > 0 ? frame[0].contentWindow : window;
if (typeof win.ARENAAUTH.showPerms !== 'undefined') {
win.ARENAAUTH.showPerms();
} else {
window.alert('No MQTT permissions');
}
});
dropdownMenu.append('<li><a class="dropdown-item" href="/user/v2/logout">Logout</a></li>');
} else {
authDrop.html('Login');
dropdownMenu
.append('<li><a class="dropdown-item" href="/user/v2/login">Login</a></li>')
.on('click', (e) => {
localStorage.setItem('request_uri', window.location.href);
});
}
});
const btnCopyStorePath = $('#btn-copy-store-path');
// highlight active page in navbar
$('.nav-item a')
.filter(function checkActiveURL() {
const link = new URL(this.href).pathname.replace(/^\/+|\/+$/g, '');
const loc = window.location.pathname.replace(/^\/+|\/+$/g, '');
if (loc === 'files') {
btnCopyStorePath.show();
} else {
btnCopyStorePath.hide();
}
return link === loc;
})
.addClass('active');
// copy the file store public path
btnCopyStorePath.on('click', (e) => {
e.preventDefault();
let storePath = getStorePath();
if (storePath.startsWith('/storemng/files')) {
storePath = storePath.replace('/storemng/files', '');
const storeUnscopedPrefix = window.auth.is_staff ? '' : `/users/${window.auth.username}`;
const fullPath = `${window.location.protocol}//${window.location.host}/store${storeUnscopedPrefix}${storePath}`;
navigator.clipboard.writeText(fullPath);
Swal.fire('Copied!', fullPath, 'success');
} else {
Swal.fire('Invalid path', 'Please navigate to another File Store file or folder', 'warning');
}
});
$('.coming-soon').on('click', (e) => {
e.preventDefault();
alert('COMING SOON');
});
});
});