Last active
October 28, 2016 09:39
-
-
Save warrenbuckley/010aaf893551953732cc508c6b76d569 to your computer and use it in GitHub Desktop.
This is a way to determine what version of Umbraco is being used & conditionally change Angular views or logic based on that.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get the current umbraco version we are using when logged into the backoffice | |
var umbracoVersion = Umbraco.Sys.ServerVariables.application.version; | |
var compareOptions = { | |
zeroExtend: true | |
}; | |
//Check what version of Umbraco we have is greater than 7.4 or not | |
//So we can load old or new editor UI | |
var versionCompare = utilityService.compareVersions(umbracoVersion, "7.4", compareOptions); | |
//If value is 0 then versions are an exact match | |
//If 1 then we are greater than 7.4.x | |
//If it's -1 then we are less than 7.4.x | |
if(versionCompare < 0) { | |
//I am less than 7.4 - load the legacy editor | |
vm.editUrl = 'edit-legacy'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool UseLegacyEditors() | |
{ | |
return UmbracoVersion.Current < new Version(7, 4); | |
} | |
var someRoutePath = Core.Configuration.UseLegacyEditors() | |
? "/myApp/treeAlias/edit-legacy/" + someObj.Id | |
: "/myApp/treeAlias/edit/" + someObj.Id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Compares two software version numbers (e.g. "1.7.1" or "1.2b"). | |
* | |
* | |
* @param {string} v1 The first version to be compared. | |
* @param {string} v2 The second version to be compared. | |
* @param {object} [options] Optional flags that affect comparison behavior: | |
* <ul> | |
* <li> | |
* <tt>lexicographical: true</tt> compares each part of the version strings lexicographically instead of | |
* naturally; this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than | |
* "1.2". | |
* </li> | |
* <li> | |
* <tt>zeroExtend: true</tt> changes the result if one version string has less parts than the other. In | |
* this case the shorter string will be padded with "zero" parts instead of being considered smaller. | |
* </li> | |
* </ul> | |
* @returns {number|NaN} | |
* <ul> | |
* <li>0 if the versions are equal</li> | |
* <li>a negative integer iff v1 < v2</li> | |
* <li>a positive integer iff v1 > v2</li> | |
* <li>NaN if either version string is in the wrong format</li> | |
* </ul> | |
*/ | |
(function() { | |
'use strict'; | |
function utilityService() { | |
function compareVersions(v1, v2, options) { | |
var lexicographical = options && options.lexicographical, | |
zeroExtend = options && options.zeroExtend, | |
v1parts = v1.split('.'), | |
v2parts = v2.split('.'); | |
function isValidPart(x) { | |
return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x); | |
} | |
if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) { | |
return NaN; | |
} | |
if (zeroExtend) { | |
while (v1parts.length < v2parts.length) { | |
v1parts.push("0"); | |
} | |
while (v2parts.length < v1parts.length) { | |
v2parts.push("0"); | |
} | |
} | |
if (!lexicographical) { | |
v1parts = v1parts.map(Number); | |
v2parts = v2parts.map(Number); | |
} | |
for (var i = 0; i < v1parts.length; ++i) { | |
if (v2parts.length === i) { | |
return 1; | |
} | |
if (v1parts[i] === v2parts[i]) { | |
continue; | |
} else if (v1parts[i] > v2parts[i]) { | |
return 1; | |
} else { | |
return -1; | |
} | |
} | |
if (v1parts.length !== v2parts.length) { | |
return -1; | |
} | |
return 0; | |
} | |
var service = { | |
compareVersions: compareVersions, | |
}; | |
return service; | |
} | |
angular.module('umbraco.services').factory('utilityService', utilityService); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment