Add update functionality to Domoboard

This commit is contained in:
wez3 2017-01-07 14:31:17 +01:00
parent 204b16542f
commit 9673bfe69b
8 changed files with 150 additions and 10 deletions

View File

@ -79,6 +79,8 @@ def gateway():
writeToConfig(idx, page, component, description, extra)
elif custom == 'indexPlugins':
result = json.dumps(indexPlugins(request.args))
elif custom == "performUpgrade":
result = json.dumps(performUpgrade())
elif custom in apiDict:
module = apiDict.get(custom)[0]
function = apiDict.get(custom)[1]
@ -163,6 +165,10 @@ def getPluginVersion(loc):
c += 1
return float(_version)
def performUpgrade():
git.cmd.Git('.').pull("https://github.com/wez3/domoboard.git")
return "Upgrade completed."
def indexPlugins(params={}):
tmpFolder = 'static/tmp'
indexFolderPath = 'static/tmp/pluginsIndex/'

View File

@ -45,7 +45,9 @@ def generatePage():
return render_template('index.html',
configValues = configValues,
blockArray = blockArray,
_csrf_token = session['_csrf_token'])
_csrf_token = session['_csrf_token'],
version = getVersion(),
debug = app.debug)
else:
abort(404)
@ -128,6 +130,12 @@ def appendDefaultPages(config):
config['log'] = {'display_components': {'components': 'serverlog'}}
return config
def getVersion():
f = open('VERSION.md', 'r')
version = f.read().rstrip()
f.close()
return version
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", dest="configfile",
@ -166,6 +174,6 @@ if __name__ == '__main__':
app.add_url_rule('/logout/', 'logout', logout_view, methods=['GET'])
app.add_url_rule('/api', 'api', api.gateway, methods=['POST'])
try:
app.run(host=flask_server_location.split(":")[0],port=int(flask_server_location.split(":")[1]),threaded=True, extra_files=watchfiles, debug=args.debug)
app.run(host=flask_server_location.split(":")[0],port=int(flask_server_location.split(":")[1]), threaded=True, extra_files=watchfiles, debug=args.debug)
except socket.error, exc:
sys.exit("Error when starting the Flask server: %s" % exc)
sys.exit("Error when starting the Flask server: {}".format(exc))

View File

@ -6383,12 +6383,17 @@ ul.notifications {
overflow: visible;
}
#time-part {
padding-top: 16px;
padding-bottom: 16px;
padding-top: 16px;
padding-bottom: 16px;
}
#date-part {
padding-top: 16px;
padding-bottom: 16px;
padding-top: 16px;
padding-bottom: 16px;
}
#version_div {
float: right;
margin-top:15px;
margin-right:10px;
}
.show_date {
display: inline-block;
@ -6396,3 +6401,9 @@ ul.notifications {
.hide_date {
display: None;
}
.show_update {
display: inline-block;
}
.hide_update {
display: None;
}

View File

@ -341,3 +341,53 @@ function changeDown(idx, block) {
changeSetpoint(idx, newVal);
}, 400);
}
// Update functions
function performUpgrade() {
requestAPI('/api?custom=performUpgrade');
$( "#version_div" ).removeClass("show_update");
$( "#version_div" ).addClass("hide_update");
$( "#updateView_available" ).removeClass("show_update");
$( "#updateView_available" ).addClass("hide_update");
$( "#updateView_not_available" ).removeClass("hide_update");
$( "#updateView_not_available" ).addClass("show_update");
}
function checkVersion() {
$.ajax({
url: "https://domoboard.nl/version.md",
cache: false,
success: function( data ) {
dataFloat = parseFloat(data);
versionFloat = parseFloat(version);
if (dataFloat > versionFloat) {
document.getElementById('curver').innerHTML = version;
document.getElementById('newver').innerHTML = data;
$( "#version_div" ).removeClass("hide_update");
$( "#version_div" ).addClass("show_update");
}
},
async:true
});
}
function checkVersionSettings() {
$.ajax({
url: "https://domoboard.nl/version.md",
cache: false,
success: function( data ) {
dataFloat = parseFloat(data);
versionFloat = parseFloat(version);
if (dataFloat > versionFloat) {
$( "#updateView_available" ).removeClass("hide_update");
$( "#updateView_available" ).addClass("show_update");
document.getElementById('curver_settings').innerHTML = version;
document.getElementById('newver_settings').innerHTML = data;
} else {
$( "#updateView_not_available" ).removeClass("hide_update");
$( "#updateView_not_available" ).addClass("show_update");
}
},
async:true
});
}

View File

@ -36,7 +36,12 @@
}
});
});
</script>
{% endif %}
<script>
$(document).ready(function() {
setInterval(checkVersion, 43200000);
});
</script>
</body>
</html>

View File

@ -32,7 +32,7 @@
<link href="/static/images/icons/logo-114x114.png" sizes="114x114" rel="apple-touch-icon-precomposed">
<!-- iPhone non-retina icon (iOS < 7) -->
<link href="/static/images/icons/logo-57x57.png" sizes="57x57" rel="apple-touch-icon-precomposed">
<title>Domoboard</title>
<!-- Bootstrap core CSS -->
<script src="/static/js/jquery-2.2.3.min.js"></script>
@ -61,6 +61,7 @@
var flask_server = "{{ request.url_root[:-1] }}";
var csrf_token = "{{ _csrf_token }}";
var googleMapEmbedKey = "{{ configValues["domoboard"].get("google_maps_api_key") }}"
var version = "{{ version }}";
</script>
<script type="text/javascript" src="/static/js/domoboard.js"></script>

View File

@ -63,6 +63,11 @@
</div>
<div class="show_date" style="cursor: pointer; margin-left: -70px; min-height: 51px;" id="time-part"></div>
<div class="hide_date" style="cursor: pointer; padding-left: 2px;" id="date-part"></div>
<div id="version_div" class="hide_update">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#upgradeModal">
Update available
</button>
</div>
</div>
</nav>
</div>
@ -70,5 +75,36 @@
</div>
<!-- /top navigation -->
<!-- Upgrade Modal -->
<div class="modal fade" id="upgradeModal" tabindex="-1" role="dialog" aria-labelledby="upgradeModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="upgradeModalLabel">Update available</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
</button>
</div>
<div class="modal-body">
<h2>A new update is available for Domoboard.</h2><br />
The current version is <b><span id="curver"></span></b>.<br />
The new version available is: <b><span id="newver"></span></b>.<br />
<br />
{% if debug == True %}
<p><b>Install the new version by pressing the "Upgrade" button below.</b></p>
{% endif %}
{% if debug == False %}
<p><b>Upgrading through Domoboard is only possible when running in debug mode (pass "-d" parameter to server.py). Manual upgrade is possible by performing a "git pull" command.</b></p>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
{% if debug == True %}
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="javascript:performUpgrade()">Upgrade</button>
{% endif %}
</div>
</div>
</div>
</div>
<!-- page content -->
<div class="right_col" role="main">

View File

@ -1,5 +1,8 @@
<link href="static/css/settings.css" rel="stylesheet" type="text/css"/>
<ul class="tab">
<li><a href="javascript:void(0)" id="defaultOpen" class="tablinks"
onclick="openCat(event, 'updates')">Updates</a>
</li>
<li><a href="javascript:void(0)" id="defaultOpen" class="tablinks"
onclick="openCat(event, 'plugins')">Plugins</a>
</li>
@ -7,7 +10,27 @@
onclick="openCat(event, 'settings')">Settings</a>
</li>
</ul>
<div id="updates" class="tabcontent">
<div id="updateView_available" class="hide_update">
<h2>A new update is available for Domoboard.</h2><br />
The current version is <b><span id="curver_settings"></span></b><br />
The new version available is: <b><span id="newver_settings"></span></b><br />
<br />
{% if debug == True %}
<p><b>Install the new version by pressing the "Upgrade" button below.</b></p>
{% endif %}
{% if debug == False %}
<p><b>Upgrading through Domoboard is only possible when running in debug mode (pass "-d" parameter to server.py). Manual upgrade is possible by performing a "git pull" command.</b></p>
{% endif %}
{% if debug == True %}
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="javascript:performUpgrade()">Upgrade</button>
{% endif %}
</div>
<div id="updateView_not_available" class="hide_update">
<h2>Hurray!</h2><br />
There is no update available for Domoboard.<br /><br />
</div>
</div>
<div id="plugins" class="tabcontent">
<div id="pluginView">
</div>
@ -147,8 +170,8 @@
document.getElementById("defaultOpen").click();
setInterval(automaticIndex(), 9000);
$('.fullSummary').hide();
checkVersionSettings();
});
retrieveAvailableDevices();
selected_page_settings();
selected_component_settings();