diff --git a/src/NzbDrone.Api/Update/UpdateModule.cs b/src/NzbDrone.Api/Update/UpdateModule.cs index e4a8cbf3a..20bcf55e8 100644 --- a/src/NzbDrone.Api/Update/UpdateModule.cs +++ b/src/NzbDrone.Api/Update/UpdateModule.cs @@ -1,6 +1,11 @@ using System; using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNet.SignalR.Hosting; +using Nancy; +using Nancy.ModelBinding; using Newtonsoft.Json; +using NzbDrone.Api.Extensions; using NzbDrone.Api.REST; using NzbDrone.Core.Update; using NzbDrone.Api.Mapping; @@ -9,33 +14,40 @@ namespace NzbDrone.Api.Update { public class UpdateModule : NzbDroneRestModule { - private readonly ICheckUpdateService _checkUpdateService; private readonly IRecentUpdateProvider _recentUpdateProvider; + private readonly IInstallUpdates _installUpdateService; - public UpdateModule(ICheckUpdateService checkUpdateService, - IRecentUpdateProvider recentUpdateProvider) + public UpdateModule(IRecentUpdateProvider recentUpdateProvider, + IInstallUpdates installUpdateService) { - _checkUpdateService = checkUpdateService; _recentUpdateProvider = recentUpdateProvider; + _installUpdateService = installUpdateService; GetResourceAll = GetRecentUpdates; + Post["/"] = x=> InstallUpdate(); } - private UpdateResource GetAvailableUpdate() + private List GetRecentUpdates() { - var update = _checkUpdateService.AvailableUpdate(); - var response = new UpdateResource(); + var resources = _recentUpdateProvider.GetRecentUpdatePackages() + .OrderByDescending(u => u.Version) + .InjectTo>(); - if (update != null) + if (resources.Any()) { - return update.InjectTo(); + resources.First().Latest = true; } - return response; + return resources; } - private List GetRecentUpdates() + private Response InstallUpdate() { - return ToListResource(_recentUpdateProvider.GetRecentUpdatePackages); + var updateResource = Request.Body.FromJson(); + + var updatePackage = updateResource.InjectTo(); + _installUpdateService.InstallUpdate(updatePackage); + + return updateResource.AsResponse(); } } @@ -48,7 +60,7 @@ namespace NzbDrone.Api.Update public DateTime ReleaseDate { get; set; } public String FileName { get; set; } public String Url { get; set; } - + public Boolean Latest { get; set; } public UpdateChanges Changes { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index b0088ee87..6b4b10ab3 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Security.Cryptography.X509Certificates; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; @@ -10,7 +11,12 @@ using NzbDrone.Core.Instrumentation; namespace NzbDrone.Core.Update { - public class InstallUpdateService : IExecute + public interface IInstallUpdates + { + void InstallUpdate(UpdatePackage updatePackage); + } + + public class InstallUpdateService : IInstallUpdates, IExecute { private readonly ICheckUpdateService _checkUpdateService; private readonly Logger _logger; @@ -35,19 +41,7 @@ namespace NzbDrone.Core.Update _logger = logger; } - - public void Execute(ApplicationUpdateCommand message) - { - _logger.ProgressDebug("Checking for updates"); - var latestAvailable = _checkUpdateService.AvailableUpdate(); - - if (latestAvailable != null) - { - InstallUpdate(latestAvailable); - } - } - - private void InstallUpdate(UpdatePackage updatePackage) + public void InstallUpdate(UpdatePackage updatePackage) { try { @@ -84,5 +78,16 @@ namespace NzbDrone.Core.Update _logger.ErrorException("Update process failed", ex); } } + + public void Execute(ApplicationUpdateCommand message) + { + _logger.ProgressDebug("Checking for updates"); + var latestAvailable = _checkUpdateService.AvailableUpdate(); + + if (latestAvailable != null) + { + InstallUpdate(latestAvailable); + } + } } } diff --git a/src/NzbDrone.Core/Update/UpdatePackage.cs b/src/NzbDrone.Core/Update/UpdatePackage.cs index f8159686a..a7ed63b5a 100644 --- a/src/NzbDrone.Core/Update/UpdatePackage.cs +++ b/src/NzbDrone.Core/Update/UpdatePackage.cs @@ -5,15 +5,11 @@ namespace NzbDrone.Core.Update { public class UpdatePackage { - public string Id { get; set; } - public Version Version { get; set; } - public String Branch { get; set; } public DateTime ReleaseDate { get; set; } public String FileName { get; set; } public String Url { get; set; } - public UpdateChanges Changes { get; set; } } } diff --git a/src/UI/Handlebars/Helpers/Version.js b/src/UI/Handlebars/Helpers/Version.js index ca6dad750..583c56b5e 100644 --- a/src/UI/Handlebars/Helpers/Version.js +++ b/src/UI/Handlebars/Helpers/Version.js @@ -5,7 +5,7 @@ define( 'handlebars' ], function (Handlebars) { - Handlebars.registerHelper('currentVersion', function (version) { + Handlebars.registerHelper('currentVersion', function (version, latest) { var currentVersion = window.NzbDrone.ServerStatus.version; if (currentVersion === version) @@ -13,6 +13,10 @@ define( return new Handlebars.SafeString(''); } + if (latest) { + return new Handlebars.SafeString('Install'); + } + return ''; }); }); diff --git a/src/UI/System/Update/UpdateItemView.js b/src/UI/System/Update/UpdateItemView.js index 5271ec9b6..682b5d77f 100644 --- a/src/UI/System/Update/UpdateItemView.js +++ b/src/UI/System/Update/UpdateItemView.js @@ -6,6 +6,14 @@ define( 'marionette' ], function (App, Marionette) { return Marionette.ItemView.extend({ - template: 'System/Update/UpdateItemViewTemplate' + template: 'System/Update/UpdateItemViewTemplate', + + events: { + 'click .x-install-update': '_installUpdate' + }, + + _installUpdate: function () { + this.model.save(); + } }); }); diff --git a/src/UI/System/Update/UpdateItemViewTemplate.html b/src/UI/System/Update/UpdateItemViewTemplate.html index 6c9df0a15..e83c425ee 100644 --- a/src/UI/System/Update/UpdateItemViewTemplate.html +++ b/src/UI/System/Update/UpdateItemViewTemplate.html @@ -1,6 +1,6 @@ 
- {{version}} - {{ShortDate releaseDate}} {{currentVersion version}} + {{version}} - {{ShortDate releaseDate}} {{currentVersion version latest}} {{#with changes}} {{#each new}} diff --git a/src/UI/System/Update/UpdateLayout.js b/src/UI/System/Update/UpdateLayout.js index fa2393afe..026170265 100644 --- a/src/UI/System/Update/UpdateLayout.js +++ b/src/UI/System/Update/UpdateLayout.js @@ -5,28 +5,13 @@ define( 'backgrid', 'System/Update/UpdateCollection', 'System/Update/UpdateCollectionView', - 'Shared/Toolbar/ToolbarLayout', 'Shared/LoadingView' - ], function (Marionette, Backgrid, UpdateCollection, UpdateCollectionView, ToolbarLayout, LoadingView) { + ], function (Marionette, Backgrid, UpdateCollection, UpdateCollectionView, LoadingView) { return Marionette.Layout.extend({ template: 'System/Update/UpdateLayoutTemplate', regions: { - updates: '#x-updates', - toolbar: '#x-toolbar' - }, - - leftSideButtons: { - type : 'default', - storeState: false, - items : - [ - { - title : 'Check for Update', - icon : 'icon-nd-update', - command: 'applicationUpdate' - } - ] + updates: '#x-updates' }, initialize: function () { @@ -35,7 +20,6 @@ define( onRender: function () { this.updates.show(new LoadingView()); - this._showToolbar(); var self = this; var promise = this.updateCollection.fetch(); @@ -43,16 +27,6 @@ define( promise.done(function (){ self.updates.show(new UpdateCollectionView({ collection: self.updateCollection })); }); - }, - - _showToolbar: function () { - this.toolbar.show(new ToolbarLayout({ - left : - [ - this.leftSideButtons - ], - context: this - })); } }); }); diff --git a/src/UI/System/Update/UpdateLayoutTemplate.html b/src/UI/System/Update/UpdateLayoutTemplate.html index c405cb562..e77ec44f7 100644 --- a/src/UI/System/Update/UpdateLayoutTemplate.html +++ b/src/UI/System/Update/UpdateLayoutTemplate.html @@ -1,5 +1,4 @@ -
-
+
diff --git a/src/UI/System/Update/update.less b/src/UI/System/Update/update.less index e25b23b70..26751cd49 100644 --- a/src/UI/System/Update/update.less +++ b/src/UI/System/Update/update.less @@ -1,3 +1,5 @@ +@import '../../Shared/Styles/clickable'; + .update { margin-bottom: 30px; @@ -22,4 +24,9 @@ margin-bottom: 2px; font-size: 13px; } + + .install-update { + .clickable(); + margin-left: 10px; + } } \ No newline at end of file