luci-base: add full page overlay during apply
After applying uci configuration, a full map reload is required in many cases as the anonymous section identifiers might have been rehashed, causing the rendered map to go out of sync. To avoid that, add both a full page overlay preventing further page interaction and let the apply widget forcibly reload the current view once the operation is complete. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
5452cc214e
commit
5427395649
1 changed files with 90 additions and 58 deletions
|
@ -1,59 +1,98 @@
|
||||||
<% export("cbi_apply_widget", function(redirect_ok) -%>
|
<% export("cbi_apply_widget", function(redirect_ok) -%>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#cbi_apply_status {
|
.alert-message.notice {
|
||||||
|
background: linear-gradient(#fff 0%, #eee 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#cbi_apply_overlay {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.7);
|
||||||
|
display: none;
|
||||||
|
z-index: 20000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cbi_apply_overlay .alert-message {
|
||||||
|
position: relative;
|
||||||
|
top: 10%;
|
||||||
|
width: 60%;
|
||||||
|
margin: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
min-height: 32px;
|
min-height: 32px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 1.5em 0 1.5em 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#cbi_apply_status > h4,
|
#cbi_apply_overlay .alert-message > h4,
|
||||||
#cbi_apply_status > p,
|
#cbi_apply_overlay .alert-message > p,
|
||||||
#cbi_apply_status > div {
|
#cbi_apply_overlay .alert-message > div {
|
||||||
flex-basis: 100%;
|
flex-basis: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cbi_apply_status > img {
|
#cbi_apply_overlay .alert-message > img {
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
flex-basis: 32px;
|
flex-basis: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cbi_apply_status + script + .cbi-section {
|
body.apply-overlay-active {
|
||||||
margin-top: -1em;
|
overflow: hidden;
|
||||||
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert-message.notice {
|
body.apply-overlay-active #cbi_apply_overlay {
|
||||||
background: linear-gradient(#fff 0%, #eee 100%);
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
|
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.138.59467-72fe5dd"></script>
|
||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">//<![CDATA[
|
||||||
var xhr = new XHR(),
|
var xhr = new XHR(),
|
||||||
stat, indicator,
|
|
||||||
uci_apply_auth = { sid: '<%=luci.dispatcher.context.authsession%>', token: '<%=token%>' },
|
uci_apply_auth = { sid: '<%=luci.dispatcher.context.authsession%>', token: '<%=token%>' },
|
||||||
uci_apply_rollback = <%=math.max(luci.config and luci.config.apply and luci.config.apply.rollback or 30, 30)%>,
|
uci_apply_rollback = <%=math.max(luci.config and luci.config.apply and luci.config.apply.rollback or 30, 30)%>,
|
||||||
uci_apply_holdoff = <%=math.max(luci.config and luci.config.apply and luci.config.apply.holdoff or 4, 1)%>,
|
uci_apply_holdoff = <%=math.max(luci.config and luci.config.apply and luci.config.apply.holdoff or 4, 1)%>,
|
||||||
uci_apply_timeout = <%=math.max(luci.config and luci.config.apply and luci.config.apply.timeout or 5, 1)%>,
|
uci_apply_timeout = <%=math.max(luci.config and luci.config.apply and luci.config.apply.timeout or 5, 1)%>,
|
||||||
uci_apply_display = <%=math.max(luci.config and luci.config.apply and luci.config.apply.display or 1.5, 1)%>;
|
uci_apply_display = <%=math.max(luci.config and luci.config.apply and luci.config.apply.display or 1.5, 1)%>;
|
||||||
|
|
||||||
|
function uci_status_message(type, content) {
|
||||||
|
var overlay = document.getElementById('cbi_apply_overlay') || document.body.appendChild(E('<div id="cbi_apply_overlay"><div class="alert-message"></div></div>')),
|
||||||
|
message = overlay.querySelector('.alert-message');
|
||||||
|
|
||||||
|
if (message && type) {
|
||||||
|
if (!message.classList.contains(type)) {
|
||||||
|
message.classList.remove('notice');
|
||||||
|
message.classList.remove('warning');
|
||||||
|
message.classList.add(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content)
|
||||||
|
message.innerHTML = content;
|
||||||
|
|
||||||
|
document.body.classList.add('apply-overlay-active');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.body.classList.remove('apply-overlay-active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function uci_rollback(checked) {
|
function uci_rollback(checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
stat.classList.remove('notice');
|
uci_status_message('warning',
|
||||||
stat.classList.add('warning');
|
'<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
||||||
stat.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
'<%:Failed to confirm apply within %ds, waiting for rollback…%>'.format(uci_apply_rollback));
|
||||||
'<%:Failed to confirm apply within %ds, waiting for rollback…%>'.format(uci_apply_rollback);
|
|
||||||
|
|
||||||
var call = function(r) {
|
var call = function(r) {
|
||||||
if (r.status === 204) {
|
if (r.status === 204) {
|
||||||
stat.innerHTML = '<h4><%:Configuration has been rolled back!%></h4>' +
|
uci_status_message('warning',
|
||||||
|
'<h4><%:Configuration has been rolled back!%></h4>' +
|
||||||
'<p><%:The device could not be reached within %d seconds after applying the pending changes, which caused the configuration to be rolled back for safety reasons. If you believe that the configuration changes are correct nonetheless, perform an unchecked configuration apply. Alternatively, you can dismiss this warning and edit changes before attempting to apply again, or revert all pending changes to keep the currently working configuration state.%></p>'.format(uci_apply_rollback) +
|
'<p><%:The device could not be reached within %d seconds after applying the pending changes, which caused the configuration to be rolled back for safety reasons. If you believe that the configuration changes are correct nonetheless, perform an unchecked configuration apply. Alternatively, you can dismiss this warning and edit changes before attempting to apply again, or revert all pending changes to keep the currently working configuration state.%></p>'.format(uci_apply_rollback) +
|
||||||
'<div class="right">' +
|
'<div class="right">' +
|
||||||
'<input type="button" class="btn" onclick="this.parentNode.parentNode.style.display=\'none\'" value="<%:Dismiss%>" /> ' +
|
'<input type="button" class="btn" onclick="uci_status_message(false)" value="<%:Dismiss%>" /> ' +
|
||||||
'<input type="button" class="btn" onclick="uci_revert()" value="<%:Revert changes%>" /> ' +
|
'<input type="button" class="btn" onclick="uci_revert()" value="<%:Revert changes%>" /> ' +
|
||||||
'<input type="button" class="btn danger" onclick="uci_apply(false)" value="<%:Apply unchecked%>" />' +
|
'<input type="button" class="btn danger" onclick="uci_apply(false)" value="<%:Apply unchecked%>" />' +
|
||||||
'</div>';
|
'</div>');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,10 +103,9 @@
|
||||||
call({ status: 0 });
|
call({ status: 0 });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stat.classList.remove('notice');
|
uci_status_message('warning',
|
||||||
stat.classList.add('warning');
|
'<h4><%:Device unreachable!%></h4>' +
|
||||||
stat.innerHTML = '<h4><%:Device unreachable!%></h4>' +
|
'<p><%:Could not regain access to the device after applying the configuration changes. You might need to reconnect if you modified network related settings such as the IP address or wireless security credentials.%></p>');
|
||||||
'<p><%:Could not regain access to the device after applying the configuration changes. You might need to reconnect if you modified network related settings such as the IP address or wireless security credentials.%></p>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +113,7 @@
|
||||||
var tt;
|
var tt;
|
||||||
var ts = Date.now();
|
var ts = Date.now();
|
||||||
|
|
||||||
stat = document.getElementById('cbi_apply_status');
|
uci_status_message('notice');
|
||||||
stat.style.display = '';
|
|
||||||
stat.classList.remove('warning');
|
|
||||||
stat.classList.add('notice');
|
|
||||||
|
|
||||||
indicator = document.querySelector('.uci_change_indicator');
|
|
||||||
|
|
||||||
var call = function(r) {
|
var call = function(r) {
|
||||||
if (Date.now() >= deadline) {
|
if (Date.now() >= deadline) {
|
||||||
|
@ -88,15 +121,18 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (r && (r.status === 200 || r.status === 204)) {
|
else if (r && (r.status === 200 || r.status === 204)) {
|
||||||
if (indicator)
|
var indicator = document.querySelector('.uci_change_indicator');
|
||||||
indicator.style.display = 'none';
|
if (indicator) indicator.style.display = 'none';
|
||||||
|
|
||||||
stat.innerHTML = '<%:Configuration has been applied.%>';
|
uci_status_message('notice', '<%:Configuration has been applied.%>');
|
||||||
|
|
||||||
window.clearTimeout(tt);
|
window.clearTimeout(tt);
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
stat.style.display = 'none';
|
<% if redirect_ok then -%>
|
||||||
<% if redirect_ok then %>location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');<% end %>
|
location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');
|
||||||
|
<%- else -%>
|
||||||
|
window.location = window.location.href.split('#')[0];
|
||||||
|
<% end %>
|
||||||
}, uci_apply_display * 1000);
|
}, uci_apply_display * 1000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -108,8 +144,9 @@
|
||||||
var tick = function() {
|
var tick = function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
stat.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
uci_status_message('notice',
|
||||||
'<%:Waiting for configuration to get applied… %ds%>'.format(Math.max(Math.floor((deadline - Date.now()) / 1000), 0));
|
'<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
||||||
|
'<%:Waiting for configuration to get applied… %ds%>'.format(Math.max(Math.floor((deadline - Date.now()) / 1000), 0)));
|
||||||
|
|
||||||
if (now >= deadline)
|
if (now >= deadline)
|
||||||
return;
|
return;
|
||||||
|
@ -125,43 +162,39 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function uci_apply(checked) {
|
function uci_apply(checked) {
|
||||||
stat = document.getElementById('cbi_apply_status');
|
uci_status_message('notice',
|
||||||
stat.style.display = '';
|
'<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
||||||
stat.classList.remove('warning');
|
'<%:Starting configuration apply…%>');
|
||||||
stat.classList.add('notice');
|
|
||||||
stat.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
|
||||||
'<%:Starting configuration apply…%>';
|
|
||||||
|
|
||||||
xhr.post('<%=url("admin/uci")%>/' + (checked ? 'apply_rollback' : 'apply_unchecked'), uci_apply_auth, function(r) {
|
xhr.post('<%=url("admin/uci")%>/' + (checked ? 'apply_rollback' : 'apply_unchecked'), uci_apply_auth, function(r) {
|
||||||
if (r.status === (checked ? 200 : 204)) {
|
if (r.status === (checked ? 200 : 204)) {
|
||||||
uci_confirm(checked, Date.now() + uci_apply_rollback * 1000);
|
uci_confirm(checked, Date.now() + uci_apply_rollback * 1000);
|
||||||
}
|
}
|
||||||
else if (checked && r.status === 204) {
|
else if (checked && r.status === 204) {
|
||||||
stat.innerHTML = '<%:There are no changes to apply.%>';
|
uci_status_message('notice', '<%:There are no changes to apply.%>');
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
stat.style.display = 'none';
|
<% if redirect_ok then -%>
|
||||||
<% if redirect_ok then %>location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');<% end %>
|
location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');
|
||||||
|
<%- else -%>
|
||||||
|
uci_status_message(false);
|
||||||
|
<%- end %>
|
||||||
}, uci_apply_display * 1000);
|
}, uci_apply_display * 1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stat.classList.add('warning');
|
uci_status_message('warning', '<%_Apply request failed with status <code>%h</code>%>'.format(r.responseText || r.statusText || r.status));
|
||||||
stat.classList.remove('notice');
|
window.setTimeout(function() { uci_status_message(false); }, uci_apply_display * 1000);
|
||||||
stat.innerHTML = '<%_Apply request failed with status <code>%h</code>%>'.format(r.responseText || r.statusText || r.status);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function uci_revert() {
|
function uci_revert() {
|
||||||
stat = document.getElementById('cbi_apply_status');
|
uci_status_message('notice',
|
||||||
stat.style.display = '';
|
'<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
||||||
stat.classList.remove('warning');
|
'<%:Reverting configuration…%>');
|
||||||
stat.classList.add('notice');
|
|
||||||
stat.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="" style="vertical-align:middle" /> ' +
|
|
||||||
'<%:Reverting configuration…%>';
|
|
||||||
|
|
||||||
xhr.post('<%=url("admin/uci/revert")%>', uci_apply_auth, function(r) {
|
xhr.post('<%=url("admin/uci/revert")%>', uci_apply_auth, function(r) {
|
||||||
if (r.status === 200) {
|
if (r.status === 200) {
|
||||||
stat.innerHTML = '<%:Changes have been reverted.%>';
|
uci_status_message('notice', '<%:Changes have been reverted.%>');
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
<% if redirect_ok then -%>
|
<% if redirect_ok then -%>
|
||||||
location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');
|
location.href = decodeURIComponent('<%=luci.util.urlencode(redirect_ok)%>');
|
||||||
|
@ -171,9 +204,8 @@
|
||||||
}, uci_apply_display * 1000);
|
}, uci_apply_display * 1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stat.classList.add('warning');
|
uci_status_message('warning', '<%_Revert request failed with status <code>%h</code>%>'.format(r.statusText || r.status));
|
||||||
stat.classList.remove('notice');
|
window.setTimeout(function() { uci_status_message(false); }, uci_apply_display * 1000);
|
||||||
stat.innerHTML = '<%_Revert request failed with status <code>%h</code>%>'.format(r.statusText || r.status);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue