New: Show previously installed version in Updates UI

Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
pull/59/head
Qstick 4 years ago
parent e3a4cd8b19
commit 86eeb3cc57

@ -11,9 +11,43 @@ import UpdateChanges from 'System/Updates/UpdateChanges';
import translate from 'Utilities/String/translate'; import translate from 'Utilities/String/translate';
import styles from './AppUpdatedModalContent.css'; import styles from './AppUpdatedModalContent.css';
function mergeUpdates(items, version, prevVersion) {
let installedIndex = items.findIndex((u) => u.version === version);
let installedPreviouslyIndex = items.findIndex((u) => u.version === prevVersion);
if (installedIndex === -1) {
installedIndex = 0;
}
if (installedPreviouslyIndex === -1) {
installedPreviouslyIndex = items.length;
} else if (installedPreviouslyIndex === installedIndex && items.size()) {
installedPreviouslyIndex += 1;
}
const appliedUpdates = items.slice(installedIndex, installedPreviouslyIndex);
if (!appliedUpdates.length) {
return null;
}
const appliedChanges = { new: [], fixed: [] };
appliedUpdates.forEach((u) => {
if (u.changes) {
appliedChanges.new.push(... u.changes.new);
appliedChanges.fixed.push(... u.changes.fixed);
}
});
const mergedUpdate = Object.assign({}, appliedUpdates[0], { changes: appliedChanges });
return mergedUpdate;
}
function AppUpdatedModalContent(props) { function AppUpdatedModalContent(props) {
const { const {
version, version,
prevVersion,
isPopulated, isPopulated,
error, error,
items, items,
@ -21,7 +55,7 @@ function AppUpdatedModalContent(props) {
onModalClose onModalClose
} = props; } = props;
const update = items[0]; const update = mergeUpdates(items, version, prevVersion);
return ( return (
<ModalContent onModalClose={onModalClose}> <ModalContent onModalClose={onModalClose}>
@ -89,6 +123,7 @@ function AppUpdatedModalContent(props) {
AppUpdatedModalContent.propTypes = { AppUpdatedModalContent.propTypes = {
version: PropTypes.string.isRequired, version: PropTypes.string.isRequired,
prevVersion: PropTypes.string,
isPopulated: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired,
error: PropTypes.object, error: PropTypes.object,
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,

@ -8,8 +8,9 @@ import AppUpdatedModalContent from './AppUpdatedModalContent';
function createMapStateToProps() { function createMapStateToProps() {
return createSelector( return createSelector(
(state) => state.app.version, (state) => state.app.version,
(state) => state.app.prevVersion,
(state) => state.system.updates, (state) => state.system.updates,
(version, updates) => { (version, prevVersion, updates) => {
const { const {
isPopulated, isPopulated,
error, error,
@ -18,6 +19,7 @@ function createMapStateToProps() {
return { return {
version, version,
prevVersion,
isPopulated, isPopulated,
error, error,
items items

@ -117,6 +117,9 @@ export const reducers = createHandleActions({
}; };
if (state.version !== version) { if (state.version !== version) {
if (!state.prevVersion) {
newState.prevVersion = state.version;
}
newState.isUpdated = true; newState.isUpdated = true;
} }

@ -10,6 +10,7 @@ import PageContent from 'Components/Page/PageContent';
import PageContentBody from 'Components/Page/PageContentBody'; import PageContentBody from 'Components/Page/PageContentBody';
import { icons, kinds } from 'Helpers/Props'; import { icons, kinds } from 'Helpers/Props';
import formatDate from 'Utilities/Date/formatDate'; import formatDate from 'Utilities/Date/formatDate';
import formatDateTime from 'Utilities/Date/formatDateTime';
import translate from 'Utilities/String/translate'; import translate from 'Utilities/String/translate';
import UpdateChanges from './UpdateChanges'; import UpdateChanges from './UpdateChanges';
import styles from './Updates.css'; import styles from './Updates.css';
@ -32,6 +33,8 @@ class Updates extends Component {
isDocker, isDocker,
updateMechanismMessage, updateMechanismMessage,
shortDateFormat, shortDateFormat,
longDateFormat,
timeFormat,
onInstallLatestPress onInstallLatestPress
} = this.props; } = this.props;
@ -138,7 +141,12 @@ class Updates extends Component {
<div className={styles.info}> <div className={styles.info}>
<div className={styles.version}>{update.version}</div> <div className={styles.version}>{update.version}</div>
<div className={styles.space}>&mdash;</div> <div className={styles.space}>&mdash;</div>
<div className={styles.date}>{formatDate(update.releaseDate, shortDateFormat)}</div> <div
className={styles.date}
title={formatDateTime(update.releaseDate, longDateFormat, timeFormat)}
>
{formatDate(update.releaseDate, shortDateFormat)}
</div>
{ {
update.branch === 'master' ? update.branch === 'master' ?
@ -155,11 +163,24 @@ class Updates extends Component {
<Label <Label
className={styles.label} className={styles.label}
kind={kinds.SUCCESS} kind={kinds.SUCCESS}
title={formatDateTime(update.installedOn, longDateFormat, timeFormat)}
> >
Currently Installed Currently Installed
</Label> : </Label> :
null null
} }
{
update.version !== currentVersion && update.installedOn ?
<Label
className={styles.label}
kind={kinds.INVERSE}
title={formatDateTime(update.installedOn, longDateFormat, timeFormat)}
>
Previously Installed
</Label> :
null
}
</div> </div>
{ {
@ -222,6 +243,8 @@ Updates.propTypes = {
updateMechanism: PropTypes.string, updateMechanism: PropTypes.string,
updateMechanismMessage: PropTypes.string, updateMechanismMessage: PropTypes.string,
shortDateFormat: PropTypes.string.isRequired, shortDateFormat: PropTypes.string.isRequired,
longDateFormat: PropTypes.string.isRequired,
timeFormat: PropTypes.string.isRequired,
onInstallLatestPress: PropTypes.func.isRequired onInstallLatestPress: PropTypes.func.isRequired
}; };

@ -48,7 +48,9 @@ function createMapStateToProps() {
isDocker: systemStatus.isDocker, isDocker: systemStatus.isDocker,
updateMechanism: generalSettings.item.updateMechanism, updateMechanism: generalSettings.item.updateMechanism,
updateMechanismMessage: status.packageUpdateMechanismMessage, updateMechanismMessage: status.packageUpdateMechanismMessage,
shortDateFormat: uiSettings.shortDateFormat shortDateFormat: uiSettings.shortDateFormat,
longDateFormat: uiSettings.longDateFormat,
timeFormat: uiSettings.timeFormat
}; };
} }
); );

@ -47,7 +47,7 @@ namespace NzbDrone.Core.Test.UpdateTests
{ {
const string branch = "develop"; const string branch = "develop";
UseRealHttp(); UseRealHttp();
var recent = Subject.GetRecentUpdates(branch, new Version(2, 0)); var recent = Subject.GetRecentUpdates(branch, new Version(2, 0), null);
var recentWithChanges = recent.Where(c => c.Changes != null); var recentWithChanges = recent.Where(c => c.Changes != null);
recent.Should().NotBeEmpty(); recent.Should().NotBeEmpty();

@ -0,0 +1,24 @@
using System;
using System.Data;
using Dapper;
namespace NzbDrone.Core.Datastore.Converters
{
public class SystemVersionConverter : SqlMapper.TypeHandler<Version>
{
public override Version Parse(object value)
{
if (value is string version)
{
return Version.Parse((string)value);
}
return null;
}
public override void SetValue(IDbDataParameter parameter, Version value)
{
parameter.Value = value.ToString();
}
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(004)]
public class add_update_history : NzbDroneMigrationBase
{
protected override void LogDbUpgrade()
{
Create.TableForModel("UpdateHistory")
.WithColumn("Date").AsDateTime().NotNullable().Indexed()
.WithColumn("Version").AsString().NotNullable()
.WithColumn("EventType").AsInt32().NotNullable();
}
}
}

@ -18,6 +18,7 @@ using NzbDrone.Core.Notifications;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tags; using NzbDrone.Core.Tags;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Update.History;
using static Dapper.SqlMapper; using static Dapper.SqlMapper;
namespace NzbDrone.Core.Datastore namespace NzbDrone.Core.Datastore
@ -84,6 +85,7 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<ApplicationStatus>("ApplicationStatus").RegisterModel(); Mapper.Entity<ApplicationStatus>("ApplicationStatus").RegisterModel();
Mapper.Entity<CustomFilter>("CustomFilters").RegisterModel(); Mapper.Entity<CustomFilter>("CustomFilters").RegisterModel();
Mapper.Entity<UpdateHistory>("UpdateHistory").RegisterModel();
} }
private static void RegisterMappers() private static void RegisterMappers()
@ -108,6 +110,7 @@ namespace NzbDrone.Core.Datastore
SqlMapper.RemoveTypeMap(typeof(Guid?)); SqlMapper.RemoveTypeMap(typeof(Guid?));
SqlMapper.AddTypeHandler(new GuidConverter()); SqlMapper.AddTypeHandler(new GuidConverter());
SqlMapper.AddTypeHandler(new CommandConverter()); SqlMapper.AddTypeHandler(new CommandConverter());
SqlMapper.AddTypeHandler(new SystemVersionConverter());
} }
private static void RegisterProviderSettingConverter() private static void RegisterProviderSettingConverter()

@ -0,0 +1,17 @@
using System;
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Update.History.Events
{
public class UpdateInstalledEvent : IEvent
{
public Version PreviousVerison { get; set; }
public Version NewVersion { get; set; }
public UpdateInstalledEvent(Version previousVersion, Version newVersion)
{
PreviousVerison = previousVersion;
NewVersion = newVersion;
}
}
}

@ -0,0 +1,12 @@
using System;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Update.History
{
public class UpdateHistory : ModelBase
{
public DateTime Date { get; set; }
public Version Version { get; set; }
public UpdateHistoryEventType EventType { get; set; }
}
}

@ -0,0 +1,9 @@
namespace NzbDrone.Core.Update.History
{
public enum UpdateHistoryEventType
{
Unknown = 0,
Initiated = 1,
Installed = 2
}
}

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Update.History
{
public interface IUpdateHistoryRepository : IBasicRepository<UpdateHistory>
{
UpdateHistory LastInstalled();
UpdateHistory PreviouslyInstalled();
List<UpdateHistory> InstalledSince(DateTime dateTime);
}
public class UpdateHistoryRepository : BasicRepository<UpdateHistory>, IUpdateHistoryRepository
{
public UpdateHistoryRepository(ILogDatabase logDatabase, IEventAggregator eventAggregator)
: base(logDatabase, eventAggregator)
{
}
public UpdateHistory LastInstalled()
{
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
.OrderBy(v => v.Date)
.Take(1)
.FirstOrDefault();
return history;
}
public UpdateHistory PreviouslyInstalled()
{
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
.OrderBy(v => v.Date)
.Skip(1)
.Take(1)
.FirstOrDefault();
return history;
}
public List<UpdateHistory> InstalledSince(DateTime dateTime)
{
var history = Query(v => v.EventType == UpdateHistoryEventType.Installed && v.Date >= dateTime)
.OrderBy(v => v.Date)
.ToList();
return history;
}
}
}

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Update.History.Events;
namespace NzbDrone.Core.Update.History
{
public interface IUpdateHistoryService
{
Version PreviouslyInstalled();
List<UpdateHistory> InstalledSince(DateTime dateTime);
}
public class UpdateHistoryService : IUpdateHistoryService, IHandle<ApplicationStartedEvent>, IHandleAsync<ApplicationStartedEvent>
{
private readonly IUpdateHistoryRepository _repository;
private readonly IEventAggregator _eventAggregator;
private Version _prevVersion;
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator)
{
_repository = repository;
_eventAggregator = eventAggregator;
}
public Version PreviouslyInstalled()
{
var history = _repository.PreviouslyInstalled();
return history?.Version;
}
public List<UpdateHistory> InstalledSince(DateTime dateTime)
{
return _repository.InstalledSince(dateTime);
}
public void Handle(ApplicationStartedEvent message)
{
if (BuildInfo.Version.Major == 10)
{
// Don't save dev versions, they change constantly
return;
}
var history = _repository.LastInstalled();
if (history == null || history.Version != BuildInfo.Version)
{
_prevVersion = history.Version;
_repository.Insert(new UpdateHistory
{
Date = DateTime.UtcNow,
Version = BuildInfo.Version,
EventType = UpdateHistoryEventType.Installed
});
}
}
public void HandleAsync(ApplicationStartedEvent message)
{
if (_prevVersion != null)
{
_eventAggregator.PublishEvent(new UpdateInstalledEvent(_prevVersion, BuildInfo.Version));
}
}
}
}

@ -1,6 +1,8 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Update.History;
namespace NzbDrone.Core.Update namespace NzbDrone.Core.Update
{ {
@ -13,18 +15,23 @@ namespace NzbDrone.Core.Update
{ {
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
private readonly IUpdatePackageProvider _updatePackageProvider; private readonly IUpdatePackageProvider _updatePackageProvider;
private readonly IUpdateHistoryService _updateHistoryService;
public RecentUpdateProvider(IConfigFileProvider configFileProvider, public RecentUpdateProvider(IConfigFileProvider configFileProvider,
IUpdatePackageProvider updatePackageProvider) IUpdatePackageProvider updatePackageProvider,
IUpdateHistoryService updateHistoryService)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_updatePackageProvider = updatePackageProvider; _updatePackageProvider = updatePackageProvider;
_updateHistoryService = updateHistoryService;
} }
public List<UpdatePackage> GetRecentUpdatePackages() public List<UpdatePackage> GetRecentUpdatePackages()
{ {
var branch = _configFileProvider.Branch; var branch = _configFileProvider.Branch;
return _updatePackageProvider.GetRecentUpdates(branch, BuildInfo.Version); var version = BuildInfo.Version;
var prevVersion = _updateHistoryService.PreviouslyInstalled();
return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion);
} }
} }
} }

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Update
public interface IUpdatePackageProvider public interface IUpdatePackageProvider
{ {
UpdatePackage GetLatestUpdate(string branch, Version currentVersion); UpdatePackage GetLatestUpdate(string branch, Version currentVersion);
List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion); List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion, Version previousVersion = null);
} }
public class UpdatePackageProvider : IUpdatePackageProvider public class UpdatePackageProvider : IUpdatePackageProvider
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Update
return update.UpdatePackage; return update.UpdatePackage;
} }
public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion) public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersion, Version previousVersion)
{ {
var request = _requestBuilder.Create() var request = _requestBuilder.Create()
.Resource("/update/{branch}/changes") .Resource("/update/{branch}/changes")
@ -67,6 +67,11 @@ namespace NzbDrone.Core.Update
.AddQueryParam("runtimeVer", _platformInfo.Version) .AddQueryParam("runtimeVer", _platformInfo.Version)
.SetSegment("branch", branch); .SetSegment("branch", branch);
if (previousVersion != null && previousVersion != currentVersion)
{
request.AddQueryParam("prevVersion", previousVersion);
}
if (_analyticsService.IsEnabled) if (_analyticsService.IsEnabled)
{ {
// Send if the system is active so we know which versions to deprecate/ignore // Send if the system is active so we know which versions to deprecate/ignore

@ -2,7 +2,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Update; using NzbDrone.Core.Update;
using NzbDrone.Core.Update.History;
using Prowlarr.Http; using Prowlarr.Http;
namespace Prowlarr.Api.V1.Update namespace Prowlarr.Api.V1.Update
@ -11,10 +13,12 @@ namespace Prowlarr.Api.V1.Update
public class UpdateController : Controller public class UpdateController : Controller
{ {
private readonly IRecentUpdateProvider _recentUpdateProvider; private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IUpdateHistoryService _updateHistoryService;
public UpdateController(IRecentUpdateProvider recentUpdateProvider) public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService)
{ {
_recentUpdateProvider = recentUpdateProvider; _recentUpdateProvider = recentUpdateProvider;
_updateHistoryService = updateHistoryService;
} }
[HttpGet] [HttpGet]
@ -40,6 +44,18 @@ namespace Prowlarr.Api.V1.Update
{ {
installed.Installed = true; installed.Installed = true;
} }
var installDates = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate)
.DistinctBy(v => v.Version)
.ToDictionary(v => v.Version);
foreach (var resource in resources)
{
if (installDates.TryGetValue(resource.Version, out var installDate))
{
resource.InstalledOn = installDate.Date;
}
}
} }
return resources; return resources;

@ -15,6 +15,7 @@ namespace Prowlarr.Api.V1.Update
public string FileName { get; set; } public string FileName { get; set; }
public string Url { get; set; } public string Url { get; set; }
public bool Installed { get; set; } public bool Installed { get; set; }
public DateTime? InstalledOn { get; set; }
public bool Installable { get; set; } public bool Installable { get; set; }
public bool Latest { get; set; } public bool Latest { get; set; }
public UpdateChanges Changes { get; set; } public UpdateChanges Changes { get; set; }

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using NzbDrone.Core.Update;
using Radarr.Http.REST;
namespace Radarr.Api.V3.Update
{
public class UpdateResource : RestResource
{
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
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 bool Installed { get; set; }
public DateTime? InstalledOn { get; set; }
public bool Installable { get; set; }
public bool Latest { get; set; }
public UpdateChanges Changes { get; set; }
public string Hash { get; set; }
}
public static class UpdateResourceMapper
{
public static UpdateResource ToResource(this UpdatePackage model)
{
if (model == null)
{
return null;
}
return new UpdateResource
{
Version = model.Version,
Branch = model.Branch,
ReleaseDate = model.ReleaseDate,
FileName = model.FileName,
Url = model.Url,
//Installed
//Installable
//Latest
Changes = model.Changes,
Hash = model.Hash,
};
}
public static List<UpdateResource> ToResource(this IEnumerable<UpdatePackage> models)
{
return models.Select(ToResource).ToList();
}
}
}
Loading…
Cancel
Save