Skip to content

Commit

Permalink
Merge pull request #66 from DewGew/Check-version
Browse files Browse the repository at this point in the history
Check for new version
  • Loading branch information
DewGew authored Dec 8, 2023
2 parents b94df82 + eba2104 commit 18f8327
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 22 deletions.
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23.9
23.10
14 changes: 10 additions & 4 deletions modules/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
)


Expand All @@ -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":

Expand Down Expand Up @@ -164,7 +167,8 @@ def devices():
dbsettings=dbsettings,
reportstate=reportstate,
devices=devices,
_csrf_token=session['_csrf_token']
_csrf_token=session['_csrf_token'],
version = version
)


Expand Down Expand Up @@ -283,14 +287,16 @@ 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(),
dbsettings=dbsettings,
dbusers=dbusers,
reportstate=reportstate,
devices=devices,
_csrf_token=session['_csrf_token']
_csrf_token=session['_csrf_token'],
version = version
)


Expand Down
48 changes: 46 additions & 2 deletions static/js/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ function getUser(user) {
}
});
}
function getVersion() {
function getDzVersion() {
var url = "/api?type=command&param=getversion"
requestAPI(url).then(jsonData => {
var data = jsonData
$('#dzga-version').html('23.9')
$('#dzga-version').html(dzga_version)
$('#dz-version').html(data.version)
});
}
Expand Down Expand Up @@ -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(" <i> (New version " + dataFloat + " is avalible.)</i>");
$('#newver_note').html('A new version ' + dataFloat + ' is avalible <a href="https://github.com/DewGew/DZGA-Flask" target="_blank">here</a>');
$('#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+/=";

Expand Down
2 changes: 1 addition & 1 deletion templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ <h5 id="title_hidden" style="cursor: pointer;">Hidden devices <i class="bi bi-ch
{% include 'footer.html' %}

<script>
var updateInterval = 9000
var updateInterval = 15000
var updateSwitches_block = [];
var updateScenes_block = [];
var updateDimmers_block = [];
Expand Down
2 changes: 1 addition & 1 deletion templates/devices.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ <h5 class="card-title">Description <span>| {{ v['name']['name'] }}</span></h5>
{% include 'footer.html' %}

<script>
var updateInterval = 9000
var updateInterval = 15000
var updateSwitches_block = [];
var updateScenes_block = [];
var updateDimmers_block = [];
Expand Down
4 changes: 3 additions & 1 deletion templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
<script>
var csrf_token = "{{ _csrf_token }}";
var flask_server = "{{ request.url_root[:-1] }}";
getVersion()
var dzga_version = "{{ version }}";
getDzVersion()
checkVersion()
</script>
23 changes: 12 additions & 11 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,29 @@

<a class="nav-link nav-icon" href="#" data-bs-toggle="dropdown">
<i class="bi bi-bell"></i>
<!-- <span class="badge bg-primary badge-number">2</span> -->
<span class="badge bg-primary badge-number" id="badge" style="display: none;">1</span>
</a><!-- End Notification Icon -->

<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow notifications">
<li class="dropdown-header">
You have 0 new notifications
<li class="dropdown-header" id="notes">
You have 0 notifications
<!-- <a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">View all</span></a> -->
</li>
<!-- <li>
<div id="shownotes" style="display: none;">
<li>
<hr class="dropdown-divider">
</li>

<li class="notification-item">
<i class="bi bi-exclamation-circle text-warning"></i>
<i class="bi bi-exclamation-circle text-success"></i>
<div>
<h4>Lorem Ipsum</h4>
<p>Quae dolorem earum veritatis oditseno</p>
<p>30 min. ago</p>
<h4>New version</h4>
<p id="newver_note">A new version is availible</p>
<p>just now</p>
</div>
</li>
<li>
</div>
<!-- <li>
<hr class="dropdown-divider">
</li>
Expand Down Expand Up @@ -109,4 +110,4 @@ <h6>{{ user.username }}</h6>
</ul>
</nav><!-- End Icons Navigation -->

</header><!-- End Header -->
</header><!-- End Header -->
3 changes: 2 additions & 1 deletion templates/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ <h5 class="card-title">Info <span>| {{ user.username }}</span></h5>
<div class="post-item clearfix">
<h4><a href="https://smarthome-test-suite.withgoogle.com/devices" target="_blank">About </a></h4>
<p>
<b>DZGA-Flask Version: </b><span id="dzga-version">Not available</span></br>
<b>DZGA-Flask Version: </b><span id="dzga-version">Not available</span><span id="newver"></span>
</br>
<b>Domoticz Version: </b><span id="dz-version">Not available</span></br>
</p>

Expand Down

0 comments on commit 18f8327

Please sign in to comment.