diff --git a/VERSION.md b/VERSION.md index e29889a..a4e45fe 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -23.9 +23.10 diff --git a/modules/routes.py b/modules/routes.py index d483ec1..9ae437d 100644 --- a/modules/routes.py +++ b/modules/routes.py @@ -10,7 +10,7 @@ from modules.reportstate import ReportState from modules.database import db, User, Settings from modules.domoticz import saveJson, getDomoticzDevices -from modules.helpers import logger, get_devices, generateToken, remove_user +from modules.helpers import logger, get_devices, generateToken, remove_user, getVersion from sqlalchemy import or_ report_state = ReportState() @@ -21,6 +21,7 @@ def dashboard(): reportstate = report_state.report_state_enabled() devices = get_devices(current_user.username) + version = getVersion() if devices is None: getDomoticzDevices(current_user.username) @@ -30,7 +31,8 @@ def dashboard(): user=User.query.filter_by(username=current_user.username).first(), reportstate=reportstate, devices=devices, - _csrf_token=session['_csrf_token'] + _csrf_token=session['_csrf_token'], + version = version ) @@ -41,6 +43,7 @@ def devices(): dbsettings = Settings.query.get_or_404(1) devices = get_devices(current_user.username) dbuser = User.query.filter_by(username=current_user.username).first() + version = getVersion() if request.method == "POST": @@ -164,7 +167,8 @@ def devices(): dbsettings=dbsettings, reportstate=reportstate, devices=devices, - _csrf_token=session['_csrf_token'] + _csrf_token=session['_csrf_token'], + version = version ) @@ -283,6 +287,7 @@ def settings(): dbusers = User.query.all() reportstate = report_state.report_state_enabled() devices = get_devices(current_user.username) + version = getVersion() return render_template('settings.html', user=User.query.filter_by(username=current_user.username).first(), @@ -290,7 +295,8 @@ def settings(): dbusers=dbusers, reportstate=reportstate, devices=devices, - _csrf_token=session['_csrf_token'] + _csrf_token=session['_csrf_token'], + version = version ) diff --git a/static/js/smarthome.js b/static/js/smarthome.js index dcbd9a1..82a1cd4 100644 --- a/static/js/smarthome.js +++ b/static/js/smarthome.js @@ -294,11 +294,11 @@ function getUser(user) { } }); } -function getVersion() { +function getDzVersion() { var url = "/api?type=command¶m=getversion" requestAPI(url).then(jsonData => { var data = jsonData - $('#dzga-version').html('23.9') + $('#dzga-version').html(dzga_version) $('#dz-version').html(data.version) }); } @@ -367,6 +367,50 @@ function showDiv(that) { } } +function checkVersion() { + $.ajax({ + url: "https://raw.githubusercontent.com/DewGew/DZGA-Flask/development/VERSION.md", + cache: false, + success: function( data ) { + dataFloat = data.split(",")[0]; + var compare = versionCompare(dataFloat, dzga_version); + if (compare == 1) { + console.log(compare) + $('#newver').html(" (New version " + dataFloat + " is avalible.)"); + $('#newver_note').html('A new version ' + dataFloat + ' is avalible here'); + $('#badge').show(); + $("#notes").html('You have 1 new notifications'); + $("#shownotes" ).show(); + } + }, + async:true + }); +} + +function versionCompare(a, b) { + if (a === b) { + return 0; + } + var a_components = a.split("."); + var b_components = b.split("."); + var len = Math.min(a_components.length, b_components.length); + for (var i = 0; i < len; i++) { + if (parseInt(a_components[i]) > parseInt(b_components[i])) { + return 1; + } + if (parseInt(a_components[i]) < parseInt(b_components[i])) { + return -1; + } + } + if (a_components.length > b_components.length) { + return 1; + } + if (a_components.length < b_components.length) { + return -1; + } + return 0; +} + function decodeBase64(string) { characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; diff --git a/templates/dashboard.html b/templates/dashboard.html index 9810aee..227663e 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -711,7 +711,7 @@
Hidden devices Description | {{ v['name']['name'] }}
{% include 'footer.html' %} diff --git a/templates/header.html b/templates/header.html index 5613739..6f24a5b 100644 --- a/templates/header.html +++ b/templates/header.html @@ -30,28 +30,29 @@ - +