From 0916c8b8d134d67959962e601841ce0a7ac21da8 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 20 Jun 2013 17:06:56 -0700 Subject: [PATCH] cache busting for js file based on server version. --- NzbDrone.Api/System/SystemModule.cs | 4 +- NzbDrone.Common/IEnvironmentProvider.cs | 2 +- UI/Constants.js | 4 + UI/Handlebars/Helpers/DateTime.js | 18 ++ UI/Index.html | 5 +- UI/Routing.js | 2 +- UI/ServerStatus.js | 7 + UI/Shared/Footer/Model.js | 18 -- UI/Shared/Footer/Template.html | 4 +- UI/Shared/Footer/View.js | 20 +-- UI/System/StatusModel.js | 16 ++ UI/app.js | 227 +++++++++++++++--------- 12 files changed, 203 insertions(+), 124 deletions(-) create mode 100644 UI/Constants.js create mode 100644 UI/Handlebars/Helpers/DateTime.js create mode 100644 UI/ServerStatus.js delete mode 100644 UI/Shared/Footer/Model.js create mode 100644 UI/System/StatusModel.js diff --git a/NzbDrone.Api/System/SystemModule.cs b/NzbDrone.Api/System/SystemModule.cs index b98797bcc..266721510 100644 --- a/NzbDrone.Api/System/SystemModule.cs +++ b/NzbDrone.Api/System/SystemModule.cs @@ -24,13 +24,13 @@ namespace NzbDrone.Api.System { return new { - Version = _environmentProvider.Version, + Version = _environmentProvider.Version.ToString(), AppData = _environmentProvider.GetAppDataPath(), IsAdmin = _environmentProvider.IsAdmin, IsUserInteractive = _environmentProvider.IsUserInteractive, BuildTime = _environmentProvider.BuildDateTime, StartupPath = _environmentProvider.StartUpPath, - OsVersion = _environmentProvider.GetOsVersion(), + OsVersion = _environmentProvider.GetOsVersion().ToString(), IsMono = EnvironmentProvider.IsMono, IsProduction = EnvironmentProvider.IsProduction, IsDebug = EnvironmentProvider.IsDebug, diff --git a/NzbDrone.Common/IEnvironmentProvider.cs b/NzbDrone.Common/IEnvironmentProvider.cs index e3fec5dca..c7fd9ec47 100644 --- a/NzbDrone.Common/IEnvironmentProvider.cs +++ b/NzbDrone.Common/IEnvironmentProvider.cs @@ -134,7 +134,7 @@ namespace NzbDrone.Common get { var fileLocation = Assembly.GetCallingAssembly().Location; - return new FileInfo(fileLocation).CreationTime; + return new FileInfo(fileLocation).LastWriteTimeUtc; } } diff --git a/UI/Constants.js b/UI/Constants.js new file mode 100644 index 000000000..e1a115d3a --- /dev/null +++ b/UI/Constants.js @@ -0,0 +1,4 @@ +"use strict"; +define({ + ApiRoot : '/api' +}); diff --git a/UI/Handlebars/Helpers/DateTime.js b/UI/Handlebars/Helpers/DateTime.js new file mode 100644 index 000000000..cf5db55c4 --- /dev/null +++ b/UI/Handlebars/Helpers/DateTime.js @@ -0,0 +1,18 @@ +"use strict"; +define( + [ + 'sugar' + ], { + register: function (handlebars) { + handlebars.registerHelper("ShortDate", function (input) { + if (!input) { + return ''; + } + + var date = Date.create(input); + var result = '' + date.short() + ''; + + return new handlebars.SafeString(result); + }); + } + }); diff --git a/UI/Index.html b/UI/Index.html index 73fc8e89e..44694d987 100644 --- a/UI/Index.html +++ b/UI/Index.html @@ -77,8 +77,7 @@ - - + + - diff --git a/UI/Routing.js b/UI/Routing.js index 954d7cad0..fd28b0a16 100644 --- a/UI/Routing.js +++ b/UI/Routing.js @@ -1,5 +1,5 @@ "use strict"; -require(['app', 'Controller', 'RouteBinder', 'Shared/Footer/View'], function (App, Controller, RouteBinder, FooterView) { +require(['Controller', 'RouteBinder', 'Shared/Footer/View'], function (Controller, RouteBinder, FooterView) { NzbDrone.Router = Backbone.Marionette.AppRouter.extend({ diff --git a/UI/ServerStatus.js b/UI/ServerStatus.js new file mode 100644 index 000000000..1ce174ef4 --- /dev/null +++ b/UI/ServerStatus.js @@ -0,0 +1,7 @@ +var statusText = $.ajax({ + type : "GET", + url : 'api/system/status', + async: false, +}).responseText; + +window.ServerStatus = JSON.parse(statusText); diff --git a/UI/Shared/Footer/Model.js b/UI/Shared/Footer/Model.js deleted file mode 100644 index da81af62a..000000000 --- a/UI/Shared/Footer/Model.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -define(['app'], function () { - - return Backbone.Model.extend({ - defaults: { - 'version' : '0.0.0.0', - 'buildDate' : Date.create() - }, - - mutators: { - humanizedBuildDate: function () { - var date = Date.create(this.get('buildDate')); - - return date.short(); - } - } - }); -}); diff --git a/UI/Shared/Footer/Template.html b/UI/Shared/Footer/Template.html index 45ecea1b1..36085cf7c 100644 --- a/UI/Shared/Footer/Template.html +++ b/UI/Shared/Footer/Template.html @@ -1,2 +1,2 @@ -

© Copyright 2013 NzbDrone

-

v{{version}} ({{humanizedBuildDate}})

\ No newline at end of file +© Copyright 2013 NzbDrone +

v{{version}} ({{ShortDate buildTime}})

diff --git a/UI/Shared/Footer/View.js b/UI/Shared/Footer/View.js index 34cfcd31f..0c29c66f4 100644 --- a/UI/Shared/Footer/View.js +++ b/UI/Shared/Footer/View.js @@ -1,14 +1,12 @@ "use strict"; -define(['app', - 'Shared/Footer/Model'], function (App, FooterModel) { - return Backbone.Marionette.ItemView.extend({ +define( + [ + 'marionette', + 'System/StatusModel' + ], function (Marionette, StatusModel) { + return Marionette.ItemView.extend({ - template: 'Shared/Footer/Template', - - initialize: function () { - this.model = new FooterModel(); - this.model.set('version', NzbDrone.Constants.Version); - this.model.set('buildDate', NzbDrone.Constants.BuildDate); - } + template: 'Shared/Footer/Template', + model : StatusModel + }); }); -}); diff --git a/UI/System/StatusModel.js b/UI/System/StatusModel.js new file mode 100644 index 000000000..4bc625dae --- /dev/null +++ b/UI/System/StatusModel.js @@ -0,0 +1,16 @@ +"use strict"; +define( + [ + 'backbone', + 'constants' + ], function (Backbone) { + + var model = Backbone.Model.extend({ + url: Constants.ApiRoot + '/system/status' + }); + + + var instance = new model(); + instance.fetch(); + return instance; + }); diff --git a/UI/app.js b/UI/app.js index 8dba99cbe..35fe8b317 100644 --- a/UI/app.js +++ b/UI/app.js @@ -1,8 +1,11 @@ "use strict"; require.config({ + urlArgs: 'bust=' + window.ServerStatus.version, + paths: { 'backbone' : 'JsLibraries/backbone', + 'sugar' : 'JsLibraries/sugar', 'handlebars' : 'JsLibraries/handlebars.runtime', 'bootstrap' : 'JsLibraries/bootstrap', 'bootstrap.slider' : 'JsLibraries/bootstrap.slider', @@ -24,58 +27,100 @@ require.config({ shim: { $: { - exports: '$' + exports: '$', + init : function () { + window.Constants = { + ApiRoot: '/api' + }; + } }, bootstrap: { - deps: ['$'] + deps: + [ + '$' + ] }, 'bootstrap.slider': { - deps: ['$'] + deps: + [ + '$' + ] }, backstrech: { - deps: ['$'] + deps: + [ + '$' + ] }, 'underscore': { - deps : ['$'], + deps : + [ + '$' + ], exports: '_' }, backbone: { - deps : ['underscore', '$'], + deps : + [ + 'underscore', + '$' + ], exports: 'Backbone' }, + 'backbone.deepmodel': { - deps: ['mixins/underscore.mixin.deepExtend'] + deps: + [ + 'mixins/underscore.mixin.deepExtend' + ] }, marionette: { - deps : [ - 'backbone', - 'mixins/backbone.marionette.templates', - 'mixins/AsNamedView' - ], + deps: + [ + 'backbone', + 'handlebars', + 'mixins/backbone.marionette.templates', + 'mixins/AsNamedView', + + 'Handlebars/Helpers/DateTime' + ], + exports: 'Marionette', - init : function (Backbone, TemplateMixin, AsNamedView) { + init : function (Backbone, Handlebars, TemplateMixin, AsNamedView, DateTimeHelpers) { TemplateMixin.call(Marionette.TemplateCache); AsNamedView.call(Marionette.ItemView.prototype); + DateTimeHelpers.register(Handlebars); + } }, + signalR: { - deps: ['$'] + deps: + [ + '$' + ] }, 'backbone.pageable': { - deps: ['backbone'] + deps: + [ + 'backbone' + ] }, backgrid : { - deps: ['backbone'], + deps: + [ + 'backbone' + ], init: function () { Backgrid.Column.prototype.defaults = { name : undefined, @@ -90,102 +135,112 @@ require.config({ } }, 'backgrid.paginator': { - deps: ['backgrid'] + deps: + [ + 'backgrid' + ] } } }); -define([ - 'marionette', - 'shared/modal/region', - 'Instrumentation/StringFormat', - 'Instrumentation/ErrorHandler' -], function (Marionette, ModalRegion) { +define( + [ + 'marionette', + 'shared/modal/region', + 'Instrumentation/StringFormat', + 'Instrumentation/ErrorHandler' + ], function (Marionette, ModalRegion) { - require(['libs/backbone.mutators']); + require( + [ + 'libs/backbone.mutators' + ]); - window.NzbDrone = new Marionette.Application(); - window.NzbDrone.Config = {}; - window.NzbDrone.Form = {}; + window.NzbDrone = new Marionette.Application(); + window.NzbDrone.Config = {}; + window.NzbDrone.Form = {}; - window.NzbDrone.Series = { - Index : { - Table : {}, - List : {}, - Posters: {} + window.NzbDrone.Series = { + Index : { + Table : {}, + List : {}, + Posters: {} - }, - Edit : {}, - Delete : {}, - Details: {} - }; + }, + Edit : {}, + Delete : {}, + Details: {} + }; - window.NzbDrone.AddSeries = { - New : {}, - Existing : {}, - RootFolders: {} - }; + window.NzbDrone.AddSeries = { + New : {}, + Existing : {}, + RootFolders: {} + }; - window.NzbDrone.Episode = { - Search : {}, - Summary : {}, - Activity: {} - }; + window.NzbDrone.Episode = { + Search : {}, + Summary : {}, + Activity: {} + }; - window.NzbDrone.Quality = {}; + window.NzbDrone.Quality = {}; - window.NzbDrone.Commands = {}; + window.NzbDrone.Commands = {}; - window.NzbDrone.Shared = { - Toolbar : {}, - Messenger : {}, - FormatHelpers: {}, - Grid : {}, - Footer : {} - }; + window.NzbDrone.Shared = { + Toolbar : {}, + Messenger : {}, + FormatHelpers: {}, + Grid : {} + }; - window.NzbDrone.Cells = {}; + window.NzbDrone.Cells = {}; - window.NzbDrone.Calendar = {}; + window.NzbDrone.Calendar = {}; - window.NzbDrone.Missing = {}; - window.NzbDrone.History = {}; - window.NzbDrone.Logs = {}; - window.NzbDrone.Release = {}; - window.NzbDrone.Mixins = {}; + window.NzbDrone.Missing = {}; + window.NzbDrone.History = {}; + window.NzbDrone.Logs = {}; + window.NzbDrone.Release = {}; + window.NzbDrone.Mixins = {}; - window.NzbDrone.Events = { - SeriesAdded: 'seriesAdded' - }; + window.NzbDrone.Events = { + SeriesAdded: 'seriesAdded' + }; - window.NzbDrone.Commands = { - SaveSettings: 'saveSettings' - }; + window.NzbDrone.Commands = { + SaveSettings: 'saveSettings' + }; - window.NzbDrone.Constants = { - ApiRoot : '/api', - Version : '0.0.0.0', - BuildDate: '2013-01-01T00:00:00Z' - }; + window.NzbDrone.Constants = { + ApiRoot: '/api' + }; - window.NzbDrone.addInitializer(function () { + window.NzbDrone.addInitializer(function () { - console.log('starting application'); + console.log('starting application'); - }); + }); - NzbDrone.addRegions({ - mainRegion : '#main-region', - notificationRegion: '#notification-region', - modalRegion : ModalRegion, - footerRegion : '#footer-region' - }); + NzbDrone.addRegions({ + mainRegion : '#main-region', + notificationRegion: '#notification-region', + modalRegion : ModalRegion, + footerRegion : '#footer-region' + }); - window.NzbDrone.start(); + window.NzbDrone.start(); - return NzbDrone; -}); + + window.require( + [ + 'Routing' + ]); + + return NzbDrone; + });