-
Notifications
You must be signed in to change notification settings - Fork 28
/
navbar-old.js
74 lines (70 loc) · 3.46 KB
/
navbar-old.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
/* global getStorePath, Swal, $ */
$(document).ready(() => {
// add page header
$('#header').load('/header-old.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.attr('class', 'dropdown-toggle');
authDrop.attr('data-toggle', 'dropdown');
authDrop.after("<ul class='dropdown-menu' role='menu' aria-labelledby='dropdownMenu'></ul>");
const dropdownMenu = $('ul .dropdown-menu');
dropdownMenu.append('<li><a href="/conf/versions.html">Version</a></li>');
if (window.auth.authenticated) {
authDrop.html(`${window.auth.username} <b class='caret'></b>`);
dropdownMenu.append('<li><a href="/user/v2/profile">Profile</a></li>');
dropdownMenu.append('<li><a 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 {
alert('No MQTT permissions');
}
});
dropdownMenu.append('<li><a href="/user/v2/logout">Logout</a></li>');
} else {
authDrop.html('Login <b class="caret"></b>');
dropdownMenu.append('<li><a href="/user/v2/login">Login</a></li>').on('click', (e) => {
localStorage.setItem('request_uri', window.location.href);
});
}
});
// 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') {
$('#btn-copy-store-path').show();
} else {
$('#btn-copy-store-path').hide();
}
return link === loc;
})
.parent()
.addClass('active');
// copy the file store public path
$('#btn-copy-store-path').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');
});
});
});