Removed check for update button, latest version will have install link

pull/6/head
Mark McDowall 11 years ago
parent e4b2c30616
commit 03fac8bfe5

@ -1,6 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.SignalR.Hosting;
using Nancy;
using Nancy.ModelBinding;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Core.Update; using NzbDrone.Core.Update;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
@ -9,33 +14,40 @@ namespace NzbDrone.Api.Update
{ {
public class UpdateModule : NzbDroneRestModule<UpdateResource> public class UpdateModule : NzbDroneRestModule<UpdateResource>
{ {
private readonly ICheckUpdateService _checkUpdateService;
private readonly IRecentUpdateProvider _recentUpdateProvider; private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IInstallUpdates _installUpdateService;
public UpdateModule(ICheckUpdateService checkUpdateService, public UpdateModule(IRecentUpdateProvider recentUpdateProvider,
IRecentUpdateProvider recentUpdateProvider) IInstallUpdates installUpdateService)
{ {
_checkUpdateService = checkUpdateService;
_recentUpdateProvider = recentUpdateProvider; _recentUpdateProvider = recentUpdateProvider;
_installUpdateService = installUpdateService;
GetResourceAll = GetRecentUpdates; GetResourceAll = GetRecentUpdates;
Post["/"] = x=> InstallUpdate();
} }
private UpdateResource GetAvailableUpdate() private List<UpdateResource> GetRecentUpdates()
{ {
var update = _checkUpdateService.AvailableUpdate(); var resources = _recentUpdateProvider.GetRecentUpdatePackages()
var response = new UpdateResource(); .OrderByDescending(u => u.Version)
.InjectTo<List<UpdateResource>>();
if (update != null) if (resources.Any())
{ {
return update.InjectTo<UpdateResource>(); resources.First().Latest = true;
} }
return response; return resources;
} }
private List<UpdateResource> GetRecentUpdates() private Response InstallUpdate()
{ {
return ToListResource(_recentUpdateProvider.GetRecentUpdatePackages); var updateResource = Request.Body.FromJson<UpdateResource>();
var updatePackage = updateResource.InjectTo<UpdatePackage>();
_installUpdateService.InstallUpdate(updatePackage);
return updateResource.AsResponse();
} }
} }
@ -48,7 +60,7 @@ namespace NzbDrone.Api.Update
public DateTime ReleaseDate { get; set; } public DateTime ReleaseDate { get; set; }
public String FileName { get; set; } public String FileName { get; set; }
public String Url { get; set; } public String Url { get; set; }
public Boolean Latest { get; set; }
public UpdateChanges Changes { get; set; } public UpdateChanges Changes { get; set; }
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Security.Cryptography.X509Certificates;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -10,7 +11,12 @@ using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Core.Update namespace NzbDrone.Core.Update
{ {
public class InstallUpdateService : IExecute<ApplicationUpdateCommand> public interface IInstallUpdates
{
void InstallUpdate(UpdatePackage updatePackage);
}
public class InstallUpdateService : IInstallUpdates, IExecute<ApplicationUpdateCommand>
{ {
private readonly ICheckUpdateService _checkUpdateService; private readonly ICheckUpdateService _checkUpdateService;
private readonly Logger _logger; private readonly Logger _logger;
@ -35,19 +41,7 @@ namespace NzbDrone.Core.Update
_logger = logger; _logger = logger;
} }
public void InstallUpdate(UpdatePackage updatePackage)
public void Execute(ApplicationUpdateCommand message)
{
_logger.ProgressDebug("Checking for updates");
var latestAvailable = _checkUpdateService.AvailableUpdate();
if (latestAvailable != null)
{
InstallUpdate(latestAvailable);
}
}
private void InstallUpdate(UpdatePackage updatePackage)
{ {
try try
{ {
@ -84,5 +78,16 @@ namespace NzbDrone.Core.Update
_logger.ErrorException("Update process failed", ex); _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);
}
}
} }
} }

@ -5,15 +5,11 @@ namespace NzbDrone.Core.Update
{ {
public class UpdatePackage public class UpdatePackage
{ {
public string Id { get; set; }
public Version Version { get; set; } public Version Version { get; set; }
public String Branch { get; set; } public String Branch { get; set; }
public DateTime ReleaseDate { get; set; } public DateTime ReleaseDate { get; set; }
public String FileName { get; set; } public String FileName { get; set; }
public String Url { get; set; } public String Url { get; set; }
public UpdateChanges Changes { get; set; } public UpdateChanges Changes { get; set; }
} }
} }

@ -5,7 +5,7 @@ define(
'handlebars' 'handlebars'
], function (Handlebars) { ], function (Handlebars) {
Handlebars.registerHelper('currentVersion', function (version) { Handlebars.registerHelper('currentVersion', function (version, latest) {
var currentVersion = window.NzbDrone.ServerStatus.version; var currentVersion = window.NzbDrone.ServerStatus.version;
if (currentVersion === version) if (currentVersion === version)
@ -13,6 +13,10 @@ define(
return new Handlebars.SafeString('<i class="icon-ok" title="Installed"></i>'); return new Handlebars.SafeString('<i class="icon-ok" title="Installed"></i>');
} }
if (latest) {
return new Handlebars.SafeString('<span class="label label-inverse install-update x-install-update">Install</span>');
}
return ''; return '';
}); });
}); });

@ -6,6 +6,14 @@ define(
'marionette' 'marionette'
], function (App, Marionette) { ], function (App, Marionette) {
return Marionette.ItemView.extend({ return Marionette.ItemView.extend({
template: 'System/Update/UpdateItemViewTemplate' template: 'System/Update/UpdateItemViewTemplate',
events: {
'click .x-install-update': '_installUpdate'
},
_installUpdate: function () {
this.model.save();
}
}); });
}); });

@ -1,6 +1,6 @@
<div class="update"> <div class="update">
<fieldset> <fieldset>
<legend>{{version}} <span class="date">- {{ShortDate releaseDate}} {{currentVersion version}}</span></legend> <legend>{{version}} <span class="date">- {{ShortDate releaseDate}} {{currentVersion version latest}}</span></legend>
{{#with changes}} {{#with changes}}
{{#each new}} {{#each new}}

@ -5,28 +5,13 @@ define(
'backgrid', 'backgrid',
'System/Update/UpdateCollection', 'System/Update/UpdateCollection',
'System/Update/UpdateCollectionView', 'System/Update/UpdateCollectionView',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView' 'Shared/LoadingView'
], function (Marionette, Backgrid, UpdateCollection, UpdateCollectionView, ToolbarLayout, LoadingView) { ], function (Marionette, Backgrid, UpdateCollection, UpdateCollectionView, LoadingView) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'System/Update/UpdateLayoutTemplate', template: 'System/Update/UpdateLayoutTemplate',
regions: { regions: {
updates: '#x-updates', updates: '#x-updates'
toolbar: '#x-toolbar'
},
leftSideButtons: {
type : 'default',
storeState: false,
items :
[
{
title : 'Check for Update',
icon : 'icon-nd-update',
command: 'applicationUpdate'
}
]
}, },
initialize: function () { initialize: function () {
@ -35,7 +20,6 @@ define(
onRender: function () { onRender: function () {
this.updates.show(new LoadingView()); this.updates.show(new LoadingView());
this._showToolbar();
var self = this; var self = this;
var promise = this.updateCollection.fetch(); var promise = this.updateCollection.fetch();
@ -43,16 +27,6 @@ define(
promise.done(function (){ promise.done(function (){
self.updates.show(new UpdateCollectionView({ collection: self.updateCollection })); self.updates.show(new UpdateCollectionView({ collection: self.updateCollection }));
}); });
},
_showToolbar: function () {
this.toolbar.show(new ToolbarLayout({
left :
[
this.leftSideButtons
],
context: this
}));
} }
}); });
}); });

@ -1,5 +1,4 @@
<div id="x-toolbar"/> <div class="row">
<div class="row">
<div class="span12"> <div class="span12">
<div id="x-updates"/> <div id="x-updates"/>
</div> </div>

@ -1,3 +1,5 @@
@import '../../Shared/Styles/clickable';
.update { .update {
margin-bottom: 30px; margin-bottom: 30px;
@ -22,4 +24,9 @@
margin-bottom: 2px; margin-bottom: 2px;
font-size: 13px; font-size: 13px;
} }
.install-update {
.clickable();
margin-left: 10px;
}
} }
Loading…
Cancel
Save