Skip to content

Commit ffd2e7d

Browse files
author
reriksso
committed
logout menu
1 parent 12dea45 commit ffd2e7d

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

webui/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
<div class="title">
1717
System version <span id="systemVersion"></span> Example Package Application
1818
</div>
19+
<div class="flex title-left">
20+
<div class="menu-div">
21+
<div id="menu-holder">
22+
<div class="top-div" onclick="showLogout();">
23+
<a class="menu-text"><span id="username">user</span></a>
24+
</div>
25+
<div id="logout-div" onclick="logout();">
26+
<a class="menu-text">logout</a>
27+
</div>
28+
</div>
29+
</div>
30+
</div>
1931
</div>
2032
</div>
2133
<div class="content">

webui/script.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,44 @@ const jsonrpc = (method, params) => {
3636
});
3737
};
3838

39+
// show/hide logout menu
40+
const showLogout = () => { // eslint-disable-line no-unused-vars
41+
const element = document.getElementById('logout-div');
42+
const style = window.getComputedStyle(element);
43+
const disp = style.getPropertyValue('display');
44+
45+
if (disp === 'block') {
46+
document.getElementById('menu-holder').style.border = '1px solid rgb(255, 255, 255)';
47+
document.getElementById('logout-div').style.display = 'none';
48+
} else {
49+
document.getElementById('menu-holder').style.border = '1px solid rgb(4, 159, 217)';
50+
document.getElementById('logout-div').style.display = 'block';
51+
}
52+
};
53+
54+
// logout and direct browser to login page
55+
const logout = () => { // eslint-disable-line no-unused-vars
56+
jsonrpc('logout', {});
57+
window.location.href = '/webui-one';
58+
};
59+
3960
// fetch the system version with the get_system_setting method.
4061
// Return request promise
4162
const fetchSystemVersion = () => jsonrpc('get_system_setting', { operation: 'version' });
4263

64+
// fetch the current user with the get_system_setting method.
65+
// Return request promise
66+
const getCurrentUser = () => {
67+
jsonrpc('get_system_setting', { operation: 'user' }).then((username) => {
68+
document.getElementById('username').textContent = username;
69+
});
70+
};
71+
4372
// update the systemVersion element when the window has loaded.
4473
window.addEventListener('load', () => {
4574
fetchSystemVersion().then((version) => {
4675
const element = document.getElementById('systemVersion');
4776
element.innerText = version;
4877
});
78+
getCurrentUser();
4979
});

webui/style.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,35 @@ h1 {
5353
.content {
5454
margin: 4rem 2rem;
5555
}
56+
.flex {
57+
display: flex;
58+
}
59+
.title-left {
60+
margin-left: auto;
61+
}
62+
.menu-div {
63+
margin: 0.5rem;
64+
font-size: 13.8px;
65+
font-family: CiscoSans;
66+
color: rgb(4, 159, 217);
67+
z-index: 2;
68+
}
69+
#menu-holder {
70+
border: 1px solid rgb(255, 255, 255);
71+
outline: none;
72+
top: 9px;
73+
padding: 0;
74+
background-color: white;
75+
}
76+
.top-div {
77+
margin: 5px;
78+
}
79+
#logout-div {
80+
margin: 14px 5px 5px 5px;
81+
display: none;
82+
}
83+
.menu-text {
84+
cursor: pointer;
85+
padding: 8px 6px;
86+
white-space: nowrap;
87+
}

0 commit comments

Comments
 (0)