raspberrymatic-addon-rmupdate/addon/www/index.html

180 lines
6.4 KiB
HTML
Raw Normal View History

2017-03-24 19:57:23 +01:00
<!DOCTYPE HTML>
<!--
RaspMatic update addon
Copyright (C) 2017 Jan Schneider <oss@janschneider.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" integrity="sha256-wT6CFc7EKRuf7uyVfi+MQNHUzojuHN2pSw0YWFt2K5E=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js" integrity="sha256-flVaeawsBV96vCHiLmXn03IRJym7+ZfcLVvUWONCas8=" crossorigin="anonymous"></script>
<style>
</style>
<title>RaspberryMatic Update Addon</title>
<script>
2017-03-25 01:45:39 +01:00
var message_timer_id = null;
2017-03-26 00:26:39 +01:00
var install_running = false;
2017-03-25 01:45:39 +01:00
function display_message(type, html, millis) {
clear_message();
$('#message').html(html);
$('#message').attr('class', 'ui ' + type + ' message visible');
2017-03-26 00:26:39 +01:00
$('#message-log').html(html);
$('#message-log').attr('class', 'ui ' + type + ' message visible');
2017-03-25 01:45:39 +01:00
message_timer_id = setTimeout(clear_message, millis);
}
function clear_message() {
if (message_timer_id != null) {
clearTimeout(message_timer_id);
}
message_timer_id = null;
$('#message').html('');
$('#message').attr('class', 'ui message hidden');
2017-03-26 00:26:39 +01:00
$('#message-log').html('');
$('#message-log').attr('class', 'ui message hidden');
}
function default_error_callback(xhr, ajaxOptions, thrownError) {
console.error(xhr);
err = thrownError;
try {
obj = JSON.parse(xhr.responseText);
if (obj.error != null) {
err = obj.error;
}
}
catch(e) {
}
display_message('error', 'An error occurred: ' + err, 6000000);
2017-03-25 01:45:39 +01:00
}
function rest(method, path, data, success_callback, error_callback) {
if (!error_callback) {
2017-03-26 00:26:39 +01:00
error_callback = default_error_callback
2017-03-25 01:45:39 +01:00
}
$.ajax({
url: "rest.cgi?" + path,
type: method,
data: data,
context: document.body,
success: success_callback,
error: error_callback
});
}
2017-03-26 00:26:39 +01:00
function update_install_log() {
rest("GET", "/read_install_log", null, function(data) {
$('#log-content').html(data.replace(/\n/g, '<br />'));
$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
if (install_running) {
setTimeout(update_install_log, 1000);
}
});
}
2017-03-25 01:45:39 +01:00
function install_firmware(version) {
2017-03-26 00:26:39 +01:00
display_message('info', 'Installing firmware ' + version + '.', 6000000);
install_running = true;
clear_message();
$('#log-content').html('');
2017-03-25 01:45:39 +01:00
$('#modal-log').modal('show');
2017-03-26 00:26:39 +01:00
rest("POST", "/start_install_firmware", version,
function(data) {
install_running = false;
display_message('success', 'Firmware ' + version + ' successfully installed.', 6000000);
},
function(xhr, ajaxOptions, thrownError) {
install_running = false;
//$('#modal-log').modal('hide');
default_error_callback(xhr, ajaxOptions, thrownError);
2017-03-25 01:45:39 +01:00
}
2017-03-26 00:26:39 +01:00
);
setTimeout(update_install_log, 1000);
2017-03-25 01:45:39 +01:00
}
$(document).ready(function() {
rest("GET", "/version", null, function(version) {
document.title = document.title + " " + version;
});
rest("GET", "/get_firmware_info", null, function(data) {
$('#firmware_info tbody').empty();
data.forEach(function(fw) {
var disabled = (fw.image || fw.url ? '' : 'disabled');
var binstall = $('<button class="ui green basic '+disabled+' button">').attr('data-version', fw.version).text('install');
binstall.click(function() {
install_firmware(this.getAttribute('data-version'));
});
var latest = (fw.latest ? 'checked=""' : '')
var installed = (fw.installed ? 'checked=""' : '')
var available = (fw.url ? 'checked=""' : '')
var downloaded = (fw.image ? 'checked=""' : '')
$("#firmware_info tbody").append($('<tr>').append(
$('<td>').text(fw.version),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+latest+'>'),$('<label></label>'))),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+installed+'>'),$('<label></label>'))),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+available+'>'),$('<label></label>'))),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+downloaded+'>'),$('<label></label>'))),
$('<td class="center aligned">').append(binstall)
));
});
});
});
2017-03-24 19:57:23 +01:00
</script>
</head>
<body>
2017-03-25 01:45:39 +01:00
<div style="padding-top: 5vw" class="ui container">
<h1 class="ui header">RaspberryMatic Update</h1>
<div id="message" class="ui message hidden">
</div>
<h2 class="ui dividing header">Firmwares</h2>
<table id="firmware_info" class="ui celled stackable table">
<thead>
<tr>
<th>Version</th>
<th class="center aligned">Latest</th>
<th class="center aligned">Installed</th>
<th class="center aligned">Available</th>
<th class="center aligned">Downloaded</th>
<th class="center aligned">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
2017-03-26 00:26:39 +01:00
<div style="height:80%" id="modal-log" class="ui modal">
2017-03-25 01:45:39 +01:00
<i class="close icon"></i>
<div class="header">
Progress
</div>
2017-03-26 00:26:39 +01:00
<div class="content">
<div id="message-log" class="ui message hidden">
</div>
<pre style="max-height:80%; overflow-x:hidden; overflow-y:auto; white-space: pre-wrap;" id="log-content" class="content">
</pre>
2017-03-25 01:45:39 +01:00
</div>
</div>
2017-03-24 19:57:23 +01:00
</body>
</html>