0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 01:07:56 +01:00

Display more specific texts in update panel.

Fix minor bugs in update code.
Display release dates of updates.
This commit is contained in:
Wouter R 2014-02-25 17:06:08 +01:00
parent 0b52f928ca
commit 9a620fd9ce
2 changed files with 50 additions and 10 deletions

View File

@ -23,6 +23,8 @@ function UpdatePanel() {
this.canUpdate = false; this.canUpdate = false;
this.currentVersion = ""; this.currentVersion = "";
this.newestVersion; this.newestVersion;
this.currentReleaseDate;
this.newestReleaseDate;
this.progress; this.progress;
this.imageSize; this.imageSize;
var _inAccessPointMode; var _inAccessPointMode;
@ -59,21 +61,26 @@ function UpdatePanel() {
this.checkStatus(false); this.checkStatus(false);
} }
this.retainChanged = function(e) { this.retainChanged = function(e) {
//console.log("UpdatePanel:retainChanged"); //console.log("UpdatePanel:retainChanged");
//this call ensures that the update button gets enabled if (!retainChanged && !canUpdate) //this call ensures that the update button gets enabled if (!retainChanged && !canUpdate)
self.setState(self.state,true); self.setState(self.state,true);
} }
this.includeBetasChanged = function() { this.includeBetasChanged = function() {
//console.log("UpdatePanel:includeBetasChanged"); //console.log("UpdatePanel:includeBetasChanged");
_form.saveSettings(_form.readForm(),function(validated, data) { _form.saveSettings(_form.readForm(),function(validated, data) {
if(validated) self.checkStatus(false); if(validated) self.checkStatus(false);
}); });
} }
this.update = function() { this.update = function() {
console.log("UpdatePanel:update"); console.log("UpdatePanel:update");
self.downloadUpdate(); self.downloadUpdate();
} }
this.downloadUpdate = function() { this.downloadUpdate = function() {
console.log("UpdatePanel:downloadUpdate"); console.log("UpdatePanel:downloadUpdate");
$.ajax({ $.ajax({
@ -89,6 +96,7 @@ function UpdatePanel() {
self.setState(UpdatePanel.DOWNLOADING); self.setState(UpdatePanel.DOWNLOADING);
self.startCheckingStatus(); self.startCheckingStatus();
} }
this.installUpdate = function() { this.installUpdate = function() {
console.log("UpdatePanel:installUpdate"); console.log("UpdatePanel:installUpdate");
@ -115,15 +123,18 @@ function UpdatePanel() {
self.installedDelayer = setTimeout(function() { self.setState(UpdatePanel.INSTALLED) },self.installedDelay); self.installedDelayer = setTimeout(function() { self.setState(UpdatePanel.INSTALLED) },self.installedDelay);
} }
this.startCheckingStatus = function() { this.startCheckingStatus = function() {
clearTimeout(self.statusCheckDelayer); clearTimeout(self.statusCheckDelayer);
clearTimeout(self.retryDelayer); clearTimeout(self.retryDelayer);
self.statusCheckDelayer = setTimeout(function() { self.checkStatus(true) },self.statusCheckInterval); self.statusCheckDelayer = setTimeout(function() { self.checkStatus(true) },self.statusCheckInterval);
} }
this.stopCheckingStatus = function() { this.stopCheckingStatus = function() {
clearTimeout(self.statusCheckDelayer); clearTimeout(self.statusCheckDelayer);
clearTimeout(self.retryDelayer); clearTimeout(self.retryDelayer);
} }
this.checkStatus = function(keepChecking) { this.checkStatus = function(keepChecking) {
if (!communicateWithWifibox) return; if (!communicateWithWifibox) return;
$.ajax({ $.ajax({
@ -161,15 +172,19 @@ function UpdatePanel() {
}); });
} }
this.handleStatusData = function(data) { this.handleStatusData = function(data) {
//console.log("UpdatePanel:handleStatusData"); //console.log("UpdatePanel:handleStatusData");
var refreshUI = (self.canUpdate != data.can_update); //status texts and button state might have to be updated if the newest version changes (e.g., after (un)ticking include betas checkbox)
var refreshUI = (self.newestVersion != data.newest_version);
self.canUpdate = data.can_update; self.canUpdate = data.can_update;
if(self.currentVersion != data.current_version || self.newestVersion != data.newest_version) { if(self.currentVersion != data.current_version || self.newestVersion != data.newest_version) {
self.currentVersion = data.current_version; self.currentVersion = data.current_version;
self.newestVersion = data.newest_version; self.newestVersion = data.newest_version;
self.currentReleaseDate = data.current_release_date; // not always available (for older versions)
self.newestReleaseDate = data.newest_release_date; // not always available (for older versions)
self.updateInfoDisplay(); self.updateInfoDisplay();
} }
@ -185,6 +200,7 @@ function UpdatePanel() {
break; break;
} }
} }
this.setState = function(newState,refresh) { this.setState = function(newState,refresh) {
//console.log("UpdatePanel:setState"); //console.log("UpdatePanel:setState");
if(!refresh && this.state == newState) return; if(!refresh && this.state == newState) return;
@ -221,15 +237,25 @@ function UpdatePanel() {
} }
this.updateStatusDisplay(); this.updateStatusDisplay();
} }
this.updateStatusDisplay = function() { this.updateStatusDisplay = function() {
var text = ""; var text = "";
if(self.newestVersion != undefined) { if(self.newestVersion != undefined) {
switch(this.state){ switch(this.state){
case UpdatePanel.NONE: case UpdatePanel.NONE:
if(self.canUpdate) { if(self.canUpdate) {
var settings = _form.readForm(); var currIsBeta = self.versionIsBeta(self.currentVersion);
if (self.versionIsBeta(self.currentVersion) && !settings.includeBetas) text = "You can switch back to the latest stable release."; var newIsBeta = self.versionIsBeta(self.newestVersion);
else text = "Update(s) available."; var relIsNewer = (self.newestReleaseDate && self.currentReleaseDate) ? (self.newestReleaseDate - self.currentReleaseDate > 0) : true;
if (!newIsBeta) {
if (relIsNewer) text = "Update available.";
else text = "You can switch back to the latest stable release."; //this case is always a beta->stable 'downgrade'
} else {
//NOTE: actually, an older beta will never be presented as update by the API
var prefixText = currIsBeta ? "A" : (relIsNewer ? "A newer" : "An older");
text = prefixText + " beta release is available.";
}
} else { } else {
text = "You're up to date."; text = "You're up to date.";
} }
@ -263,22 +289,36 @@ function UpdatePanel() {
} }
this.statusDisplay.html(text); this.statusDisplay.html(text);
} }
this.updateInfoDisplay = function() { this.updateInfoDisplay = function() {
var html = 'Current version: ' + self.currentVersion + var html = 'Current version: ' + self.currentVersion;
' (<a target="d3d-curr-relnotes" href="ReleaseNotes.html">release notes</a>). '; if (self.currentReleaseDate) html += '; released: ' + self.formatDate(self.currentReleaseDate);
html += ' (<a target="d3d-curr-relnotes" href="ReleaseNotes.html">release notes</a>).';
if(self.canUpdate) { if(self.canUpdate) {
html += 'Latest version: ' + self.newestVersion + html += '<br/>Latest version: ' + self.newestVersion;
' (<a target="d3d-new-relnotes" href="http://doodle3d.com/updates/images/ReleaseNotes.md">release notes</a>).'; if (self.newestReleaseDate) html += '; released: ' + self.formatDate(self.newestReleaseDate);
html += ' (<a target="d3d-new-relnotes" href="http://doodle3d.com/updates/images/ReleaseNotes.md">release notes</a>).';
} }
self.infoDisplay.html(html); self.infoDisplay.html(html);
} }
this.setInAccessPointMode = function(inAccessPointMode) { this.setInAccessPointMode = function(inAccessPointMode) {
_inAccessPointMode = inAccessPointMode; _inAccessPointMode = inAccessPointMode;
self.updateStatusDisplay(); self.updateStatusDisplay();
} }
this.formatDate = function(ts) {
if (!ts || ts.length != 8 || !/^[0-9]+$/.test(ts)) return null;
var fields = [ ts.substr(0, 4), ts.substr(4, 2), ts.substr(6, 2) ];
if (!fields || fields.length != 3 || fields[1] > 12) return null;
var abbrMonths = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Sep', 'Aug', 'Oct', 'Nov', 'Dec' ];
return abbrMonths[fields[1] - 1] + " " + fields[2] + ", " + fields[0];
}
this.versionIsBeta = function(version) { this.versionIsBeta = function(version) {
return version.match(/.*-.*/g) != null; return version ? /.*-.*/g.test(version) : null;
} }
} }

View File

@ -166,7 +166,7 @@
<fieldset id="updatePanel"> <fieldset id="updatePanel">
<legend>Update</legend> <legend>Update</legend>
<input id="retainConfiguration" type="checkbox" name="" value="retainConfiguration" checked="true"> <label for="retainConfiguration" id="retainConfigurationLabel">Preserve personal sketches and settings</label><br/> <input id="retainConfiguration" type="checkbox" name="" value="retainConfiguration" checked="true"> <label for="retainConfiguration" id="retainConfigurationLabel">Preserve personal sketches and settings</label><br/>
<input id="includeBetas" type="checkbox" name="doodle3d.includeBetas" value="includeBetas"> <label for="includeBetas" id="includeBetasLabel">Include beta releases (<a target="beta-info" href="http://doodle3d.com/help/beta">read more</a>)</label><br/> <input id="includeBetas" type="checkbox" name="doodle3d.update.includeBetas" value="includeBetas"> <label for="includeBetas" id="includeBetasLabel">Include beta releases (<a target="beta-info" href="http://doodle3d.com/help/beta">read more</a>)</label><br/>
<br/> <br/>
<input type="button" name="update" value="Update" class="button" id="update"/> <input type="button" name="update" value="Update" class="button" id="update"/>
<span id="updateState"></span><br/> <span id="updateState"></span><br/>