Rewrites checkVersion and checkVersionNewer in utils-service.js, refines upgradeToVersion
- Adds unit tests that cover all cases. - Adds call to parseVersionString() so we can pass it version string e.g. '1.0.1' - persistence-service.js now also manages JamstashVersion. It is set in localStorage from app.js's constant, and not from the changelog so we don't have to add a version to the changelog to actually do stuff. - persistence-service.js's upgradeToVersion() now only applies newer changesets. This ensures we won't erase users' settings with changesets at every new version, e.g. resetting songSearchType to song every time. - upgradeToVersion() will also notify the user of the upgrade, which was formerly done in settings.js
This commit is contained in:
parent
ae703c1542
commit
fe6c10bc4a
6 changed files with 274 additions and 92 deletions
|
@ -235,6 +235,7 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
var u = strurl.substring(0, strurl.indexOf('?'));
|
||||
return u;
|
||||
};
|
||||
|
||||
this.parseVersionString = function (str) {
|
||||
if (typeof (str) !== 'string') { return false; }
|
||||
var x = str.split('.');
|
||||
|
@ -248,31 +249,21 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
patch: pat
|
||||
};
|
||||
};
|
||||
//TODO: Hyz: have "checkVersion" do the conversion themselves
|
||||
this.checkVersion = function (runningVersion, minimumVersion) {
|
||||
if (runningVersion.major >= minimumVersion.major) {
|
||||
if (runningVersion.minor >= minimumVersion.minor) {
|
||||
if (runningVersion.patch >= minimumVersion.patch) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
||||
this.checkVersion = function (newerVersion, olderVersion) {
|
||||
if (!angular.isObject(newerVersion)) {
|
||||
newerVersion = this.parseVersionString(newerVersion);
|
||||
}
|
||||
};
|
||||
//TODO: Hyz: have "checkVersion" do the conversion themselves
|
||||
this.checkVersionNewer = function (runningVersion, newVersion) {
|
||||
if (runningVersion.major < newVersion.major) {
|
||||
if (!angular.isObject(olderVersion)) {
|
||||
olderVersion = this.parseVersionString(olderVersion);
|
||||
}
|
||||
if (olderVersion.major !== undefined && newerVersion.major !== undefined && newerVersion.major > olderVersion.major) {
|
||||
return true;
|
||||
} else {
|
||||
if (runningVersion.minor < newVersion.minor) {
|
||||
if (olderVersion.minor !== undefined && newerVersion.minor !== undefined && newerVersion.minor > olderVersion.minor) {
|
||||
return true;
|
||||
} else {
|
||||
if (runningVersion.patch < newVersion.patch) {
|
||||
if (olderVersion.patch !== undefined && newerVersion.patch !== undefined && newerVersion.patch >= olderVersion.patch) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -280,6 +271,29 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.checkVersionNewer = function (newerVersion, olderVersion) {
|
||||
if (!angular.isObject(newerVersion)) {
|
||||
newerVersion = this.parseVersionString(newerVersion);
|
||||
}
|
||||
if (!angular.isObject(olderVersion)) {
|
||||
olderVersion = this.parseVersionString(olderVersion);
|
||||
}
|
||||
if (olderVersion.major !== undefined && newerVersion.major !== undefined && newerVersion.major > olderVersion.major) {
|
||||
return true;
|
||||
} else {
|
||||
if (olderVersion.minor !== undefined && newerVersion.minor !== undefined && newerVersion.minor > olderVersion.minor) {
|
||||
return true;
|
||||
} else {
|
||||
if (olderVersion.patch !== undefined && newerVersion.patch !== undefined && newerVersion.patch > olderVersion.patch) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.reloadRoute = function (date) {
|
||||
if (reload) {
|
||||
$window.location.reload();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue