Skip to content
Permalink
Browse files

ReWriting of Update section

- implemented own version checks to be prepared for 1.5.10 (double digit versions)
- set 'news.newsdate.date' to optional to not run in an error if not provided.
- First check .org then .com due to some special behaviours of IDS. This is to get around of some not provided date datas of .com IDS
  • Loading branch information
MartinH0 committed Jan 12, 2020
1 parent 62c21f3 commit f6e1179576593a2ee94a3dac6849ae18f6a8c96d
Showing with 47 additions and 19 deletions.
  1. +47 −19 application/modules/settings/views/partial_settings_updates.php
@@ -1,22 +1,52 @@
<script>
// Update check
$(function () {
// function to check if update excists for a version if atm on currend version
function update(currend, checked) {
// Get the current version
var curr = currend;
// set the version to check to the passed variable
var check = checked;
if (curr === check) {
return 0;
}
var curr_components = curr.split(".");
var check_components = check.split(".");

var len = Math.min(curr_components.length, check_components.length);
for (var i = 0; i < len; i++) {
// curr bigger than check
if (parseInt(curr_components[i]) > parseInt(check_components[i])) {
return 0;
}
// check bigger than curr
if (parseInt(curr_components[i]) < parseInt(check_components[i])) {
return 1;
}
}
if (curr_components.length > check_components.length) {
return 0;
}
if (curr_components.length < check_components.length) {
return 1;
}
return 0;
}
var checktime = 2000;
// Get the current version
var ip_version = "<?php echo get_setting('current_version'); ?>";
var current_version = ip_version.replace(/\./g, ''); // Remove the dots from the version
// Get the latest version from the InvoicePlane IDS
$.ajax({
'url': 'https://ids.invoiceplane.com/updatecheck?cv=' + ip_version,
'url': 'https://ids.invoiceplane.org/updatecheck?cv=' + ip_version,
'dataType': 'json',
success: function(data) {
<?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
var updatecheck = data.current_version.replace(/\./g, '');
var updatecheck = data.current_version;
// Compare each versions and replace the placeholder with a download button
// or info label after 2 seconds
setTimeout(function() {
if (current_version < updatecheck) {
$('#updatecheck-updates-available').attr("href", "https://www.invoiceplane.com/downloads")
if (update(ip_version, updatecheck)) {
$('#updatecheck-updates-available').attr("href", "https://www.invoiceplane.org/downloads")
$('#updatecheck-loading').addClass('hidden');
$('#updatecheck-updates-available').removeClass('hidden');
}
@@ -28,16 +58,16 @@
},
error: function(data) {
$.ajax({
'url': 'https://ids.invoiceplane.org/updatecheck?cv=' + ip_version,
'url': 'https://ids.invoiceplane.com/updatecheck?cv=' + ip_version,
'dataType': 'json',
success: function(data) {
<?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
var updatecheck = data.current_version.replace(/\./g, '');
var updatecheck = data.current_version;
// Compare each versions and replace the placeholder with a download button
// or info label after 2 seconds
setTimeout(function() {
if (current_version < updatecheck) {
$('#updatecheck-updates-available').attr("href", "https://www.invoiceplane.org/downloads")
if (update(ip_version, updatecheck)) {
$('#updatecheck-updates-available').attr("href", "https://www.invoiceplane.com/downloads")
$('#updatecheck-loading').addClass('hidden');
$('#updatecheck-updates-available').removeClass('hidden');
}
@@ -57,7 +87,7 @@
});
// Get the latest news
$.ajax({
'url': 'https://ids.invoiceplane.com/get_news',
'url': 'https://ids.invoiceplane.org/get_news',
'dataType': 'json',
'success': function(data) {
<?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
@@ -67,16 +97,16 @@
var ipnews = '<div class="alert alert-' + news.type + '">';
ipnews += '<b>' + news.title + '</b><br/>';
ipnews += news.text + '<br/>';
ipnews += '<small><?php echo trans('date')?>: ' + news.newsdate.date.substr(0, 11) +
'</b><br/>';
if(news.newsdate.date) ipnews += '<small><?php echo trans('date')?>: ' + news.newsdate.date.substr(0, 11) + '</b><br/>';
ipnews += '</div>';
ipnews = ipnews.replace(/\n/g, "<br />")
$('#ipnews-container').append(ipnews);
});
}, checktime);
},
'error': function(data) {
$.ajax({
'url': 'https://ids.invoiceplane.org/get_news',
'url': 'https://ids.invoiceplane.com/get_news',
'dataType': 'json',
'success': function(data) {
<?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
@@ -86,9 +116,9 @@
var ipnews = '<div class="alert alert-' + news.type + '">';
ipnews += '<b>' + news.title + '</b><br/>';
ipnews += news.text + '<br/>';
ipnews += '<small><?php echo trans('date')?>: ' + news.newsdate.date.substr(0, 11) +
'</b><br/>';
if(news.newsdate.date) ipnews += '<small><?php echo trans('date')?>: ' + news.newsdate.date.substr(0, 11) + '</b><br/>';
ipnews += '</div>';
ipnews = ipnews.replace(/\n/g, "<br />")
$('#ipnews-container').append(ipnews);
});
}, checktime);
@@ -113,8 +143,7 @@
<div class="panel-body">

<div class="form-group">
<input type="text" class="form-control"
value="<?php echo get_setting('current_version'); ?>" readonly="readonly">
<input type="text" class="form-control" value="<?php echo get_setting('current_version'); ?>" readonly="readonly">
</div>
<div id="updatecheck-results">
<div id="updatecheck-loading" class="btn btn-default btn-sm disabled">
@@ -129,8 +158,7 @@
<?php _trans('updatecheck_failed'); ?>
</div>

<a href="" id="updatecheck-updates-available"
class="btn btn-success btn-sm hidden" target="_blank">
<a href="" id="updatecheck-updates-available" class="btn btn-success btn-sm hidden" target="_blank">
<?php _trans('updates_available'); ?>
</a>
</div>

0 comments on commit f6e1179

Please sign in to comment.
You can’t perform that action at this time.