Skip to content

Commit

Permalink
OOB: cleaning up the get version code, starting potential cache busti…
Browse files Browse the repository at this point in the history
…ng method for monster urls
  • Loading branch information
JRMaitre committed Jan 4, 2017
1 parent 8eb2e55 commit 3ee8050
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 36 deletions.
2 changes: 2 additions & 0 deletions gulp/tasks/write-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var writeFile = function(fileName, content) {
gulp.task('write-config-prod', function() {
var mainFileName = paths.tmp + '/build-config.json',
content = {
type: 'production',
preloadedApps: helpers.getAppsToInclude()
};

Expand All @@ -42,6 +43,7 @@ gulp.task('write-config-prod', function() {
gulp.task('write-config-dev', function() {
var fileName = paths.tmp + '/build-config.json',
content = {
type: 'development',
preloadedApps: []
};

Expand Down
23 changes: 17 additions & 6 deletions src/apps/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,25 @@ define(function(require){
callback && callback();
},

displayVersion: function(container) {
var self = this;
/* Had to update that code because mainTemplate is no longer the main container, it's an array of divs, where one of them is the core-footer,
so we look through that array and once we found it we add the version */
displayVersion: function(mainTemplate) {
var self = this,
version = monster.util.getVersion(),
container,
$potentialContainer;

monster.getVersion(function(version) {
container.find('.core-footer .tag-version').html('('+version+')');
_.each(mainTemplate, function(potentialContainer) {
$potentialContainer = $(potentialContainer);

monster.config.version = version;
if($potentialContainer.hasClass('core-footer')) {
container = $potentialContainer;
}
});

if(container) {
container.find('.tag-version').html('('+version+')');
}
},

displayLogo: function(container) {
Expand Down Expand Up @@ -673,7 +684,7 @@ define(function(require){
account: acc,
authToken: self.getAuthToken(),
apiUrl: self.apiUrl,
version: monster.config.version,
version: monster.util.getVersion(),
hideApiUrl: monster.util.isWhitelabeling() && !monster.util.isSuperDuper()
},
template = monster.template(self, 'dialog-accountInfo', dataTemplate);
Expand Down
4 changes: 2 additions & 2 deletions src/js/lib/monster.apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ define(function(){
authToken: params.authToken || app.getAuthToken(),
apiRoot: params.apiUrl || app.apiUrl,
uiMetadata: {
version: monster.config.version,
version: monster.util.getVersion(),
ui: 'monster-ui',
origin: app.name
},
Expand Down Expand Up @@ -585,7 +585,7 @@ define(function(){
monster.pub('monster.requestStart');

$.ajax({
url: app.appPath + '/i18n/' + language + '.json',
url: monster.util.cacheUrl(app.appPath + '/i18n/' + language + '.json'),
dataType: 'json',
async: false,
success: function(data){
Expand Down
66 changes: 39 additions & 27 deletions src/js/lib/monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ define(function(require){

if(!data.hasOwnProperty('removeMetadataAPI') || data.removeMetadataAPI === false) {
payload.data.ui_metadata = {
version: monster.config.version,
version: monster.util.getVersion(),
ui: 'monster-ui'
};
}
Expand Down Expand Up @@ -216,7 +216,7 @@ define(function(require){
}, config),

css: function(href){
$('<link/>', { rel: 'stylesheet', href: href }).appendTo('head');
$('<link/>', { rel: 'stylesheet', href: monster.util.cacheUrl(href) }).appendTo('head');
},

domain: function(){
Expand Down Expand Up @@ -397,34 +397,46 @@ define(function(require){
next && next();
},

getVersion: function(callback) {
$.ajax({
url: 'VERSION',
cache: false,
success: function(version) {
version = version.replace(/\n.*/g,'')
.trim();

callback(version);
}
});
},

loadBuildConfig: function(callback) {
$.ajax({
url: 'build-config.json',
dataType: 'json',
cache: false,
success: function(config) {
monster.config.developerFlags.build = config;
loadBuildConfig: function(globalCallback) {
var self = this;

callback();
monster.parallel({
version: function(callback) {
$.ajax({
url: 'VERSION',
cache: false,
success: function(version) {
version = version.replace(/\n.*/g,'')
.trim();

callback(null, version);
},
error: function() {
callback(null, null);
}
});
},
buildFile: function(callback) {
$.ajax({
url: 'build-config.json',
dataType: 'json',
cache: false,
success: function(config) {
callback(null, config);
},
error: function() {
callback(null, {});
}
});
}
},
error: function() {
monster.config.developerFlags.build = monster.config.developerFlags.build || {};
callback();
function(err, results) {
monster.config.developerFlags.build = results.buildFile;
monster.config.developerFlags.build.version = results.version;

globalCallback && globalCallback(monster.config.developerFlags.build);
}
});
);
},

getScript: function(url, callback) {
Expand Down
25 changes: 25 additions & 0 deletions src/js/lib/monster.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,31 @@ define(function(require){
return authToken;
},

getVersion: function(callback) {
return monster.config.developerFlags.build.version;
},

cacheUrl: function(url) {
var self = this;

return url;

/* Commenting this as we don't want to add this just yet. We have issues with this code because versions from apps != versions in VERSION
If we were to use this, and just updated monster-ui-voip, the VERSION file wouldn't change, which means we wouldn't change the query sting used to get assets from any app, even monster-ui-voip...
This only gets incremented when master build runs, whereas we need it to be changed when an app is built as well...
Leaving this here for now, might have to just remove and forget about it eventually :/
var self = this,
prepend = url.indexOf('?') >= 0 ? '&' : '?',
isDev = monster.config.developerFlags.build.type === 'development',
devCacheString = (new Date()).getTime(),
prodCacheString = monster.util.getVersion(),
cacheString = prepend + '_=' + (isDev ? devCacheString : prodCacheString),
finalString = url + cacheString;
return finalString;*/
},

dataFlags: {
get: function(flagName, object) {
object.markers = object.markers || {};
Expand Down
2 changes: 1 addition & 1 deletion src/js/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Handlebars.getTemplate = function(app, name, ignoreCache) {
monster.pub('monster.requestStart');

$.ajax({
url: app.appPath + '/views/' + name + '.html',
url: monster.util.cacheUrl(app.appPath + '/views/' + name + '.html'),
dataType: 'text',
async: false,
success: function(result){
Expand Down

0 comments on commit 3ee8050

Please sign in to comment.