mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-05 20:42:19 -07:00
New: Real time UI updates for provider changes
(cherry picked from commit 20ef22be94f4bdb5633ddfb080e91c8d5b0229da) Closes #5178
This commit is contained in:
parent
345bbcd992
commit
7217e891f7
7 changed files with 99 additions and 16 deletions
|
@ -172,7 +172,7 @@ class SignalRConnector extends Component {
|
||||||
const status = resource.status;
|
const status = resource.status;
|
||||||
|
|
||||||
// Both successful and failed commands need to be
|
// Both successful and failed commands need to be
|
||||||
// completed, otherwise they spin until they timeout.
|
// completed, otherwise they spin until they time out.
|
||||||
|
|
||||||
if (status === 'completed' || status === 'failed') {
|
if (status === 'completed' || status === 'failed') {
|
||||||
this.props.dispatchFinishCommand(resource);
|
this.props.dispatchFinishCommand(resource);
|
||||||
|
@ -224,10 +224,58 @@ class SignalRConnector extends Component {
|
||||||
repopulatePage('trackFileUpdated');
|
repopulatePage('trackFileUpdated');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleDownloadclient = ({ action, resource }) => {
|
||||||
|
const section = 'settings.downloadClients';
|
||||||
|
|
||||||
|
if (action === 'created' || action === 'updated') {
|
||||||
|
this.props.dispatchUpdateItem({ section, ...resource });
|
||||||
|
} else if (action === 'deleted') {
|
||||||
|
this.props.dispatchRemoveItem({ section, id: resource.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
handleHealth = () => {
|
handleHealth = () => {
|
||||||
this.props.dispatchFetchHealth();
|
this.props.dispatchFetchHealth();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleImportlist = ({ action, resource }) => {
|
||||||
|
const section = 'settings.importLists';
|
||||||
|
|
||||||
|
if (action === 'created' || action === 'updated') {
|
||||||
|
this.props.dispatchUpdateItem({ section, ...resource });
|
||||||
|
} else if (action === 'deleted') {
|
||||||
|
this.props.dispatchRemoveItem({ section, id: resource.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleIndexer = ({ action, resource }) => {
|
||||||
|
const section = 'settings.indexers';
|
||||||
|
|
||||||
|
if (action === 'created' || action === 'updated') {
|
||||||
|
this.props.dispatchUpdateItem({ section, ...resource });
|
||||||
|
} else if (action === 'deleted') {
|
||||||
|
this.props.dispatchRemoveItem({ section, id: resource.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMetadata = ({ action, resource }) => {
|
||||||
|
const section = 'settings.metadata';
|
||||||
|
|
||||||
|
if (action === 'updated') {
|
||||||
|
this.props.dispatchUpdateItem({ section, ...resource });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleNotification = ({ action, resource }) => {
|
||||||
|
const section = 'settings.notifications';
|
||||||
|
|
||||||
|
if (action === 'created' || action === 'updated') {
|
||||||
|
this.props.dispatchUpdateItem({ section, ...resource });
|
||||||
|
} else if (action === 'deleted') {
|
||||||
|
this.props.dispatchRemoveItem({ section, id: resource.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
handleArtist = (body) => {
|
handleArtist = (body) => {
|
||||||
const action = body.action;
|
const action = body.action;
|
||||||
const section = 'artist';
|
const section = 'artist';
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.DownloadClient
|
namespace Lidarr.Api.V1.DownloadClient
|
||||||
{
|
{
|
||||||
|
@ -10,8 +11,8 @@ namespace Lidarr.Api.V1.DownloadClient
|
||||||
public static readonly DownloadClientResourceMapper ResourceMapper = new ();
|
public static readonly DownloadClientResourceMapper ResourceMapper = new ();
|
||||||
public static readonly DownloadClientBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly DownloadClientBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public DownloadClientController(IDownloadClientFactory downloadClientFactory)
|
public DownloadClientController(IBroadcastSignalRMessage signalRBroadcaster, IDownloadClientFactory downloadClientFactory)
|
||||||
: base(downloadClientFactory, "downloadclient", ResourceMapper, BulkResourceMapper)
|
: base(signalRBroadcaster, downloadClientFactory, "downloadclient", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50);
|
SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Lidarr.Http;
|
||||||
using NzbDrone.Core.ImportLists;
|
using NzbDrone.Core.ImportLists;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
using NzbDrone.Core.Validation.Paths;
|
using NzbDrone.Core.Validation.Paths;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.ImportLists
|
namespace Lidarr.Api.V1.ImportLists
|
||||||
{
|
{
|
||||||
|
@ -12,11 +13,12 @@ namespace Lidarr.Api.V1.ImportLists
|
||||||
public static readonly ImportListResourceMapper ResourceMapper = new ();
|
public static readonly ImportListResourceMapper ResourceMapper = new ();
|
||||||
public static readonly ImportListBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly ImportListBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public ImportListController(IImportListFactory importListFactory,
|
public ImportListController(IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
RootFolderExistsValidator rootFolderExistsValidator,
|
IImportListFactory importListFactory,
|
||||||
QualityProfileExistsValidator qualityProfileExistsValidator,
|
RootFolderExistsValidator rootFolderExistsValidator,
|
||||||
MetadataProfileExistsValidator metadataProfileExistsValidator)
|
QualityProfileExistsValidator qualityProfileExistsValidator,
|
||||||
: base(importListFactory, "importlist", ResourceMapper, BulkResourceMapper)
|
MetadataProfileExistsValidator metadataProfileExistsValidator)
|
||||||
|
: base(signalRBroadcaster, importListFactory, "importlist", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
SharedValidator.RuleFor(c => c.RootFolderPath).Cascade(CascadeMode.Stop)
|
SharedValidator.RuleFor(c => c.RootFolderPath).Cascade(CascadeMode.Stop)
|
||||||
.IsValidPath()
|
.IsValidPath()
|
||||||
|
|
|
@ -2,6 +2,7 @@ using FluentValidation;
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.Indexers
|
namespace Lidarr.Api.V1.Indexers
|
||||||
{
|
{
|
||||||
|
@ -11,8 +12,10 @@ namespace Lidarr.Api.V1.Indexers
|
||||||
public static readonly IndexerResourceMapper ResourceMapper = new ();
|
public static readonly IndexerResourceMapper ResourceMapper = new ();
|
||||||
public static readonly IndexerBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly IndexerBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public IndexerController(IndexerFactory indexerFactory, DownloadClientExistsValidator downloadClientExistsValidator)
|
public IndexerController(IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
: base(indexerFactory, "indexer", ResourceMapper, BulkResourceMapper)
|
IndexerFactory indexerFactory,
|
||||||
|
DownloadClientExistsValidator downloadClientExistsValidator)
|
||||||
|
: base(signalRBroadcaster, indexerFactory, "indexer", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50);
|
SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50);
|
||||||
SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator);
|
SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator);
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Core.Extras.Metadata;
|
using NzbDrone.Core.Extras.Metadata;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.Metadata
|
namespace Lidarr.Api.V1.Metadata
|
||||||
{
|
{
|
||||||
|
@ -11,8 +12,8 @@ namespace Lidarr.Api.V1.Metadata
|
||||||
public static readonly MetadataResourceMapper ResourceMapper = new ();
|
public static readonly MetadataResourceMapper ResourceMapper = new ();
|
||||||
public static readonly MetadataBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly MetadataBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public MetadataController(IMetadataFactory metadataFactory)
|
public MetadataController(IBroadcastSignalRMessage signalRBroadcaster, IMetadataFactory metadataFactory)
|
||||||
: base(metadataFactory, "metadata", ResourceMapper, BulkResourceMapper)
|
: base(signalRBroadcaster, metadataFactory, "metadata", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Core.Notifications;
|
using NzbDrone.Core.Notifications;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.Notifications
|
namespace Lidarr.Api.V1.Notifications
|
||||||
{
|
{
|
||||||
|
@ -11,8 +12,8 @@ namespace Lidarr.Api.V1.Notifications
|
||||||
public static readonly NotificationResourceMapper ResourceMapper = new ();
|
public static readonly NotificationResourceMapper ResourceMapper = new ();
|
||||||
public static readonly NotificationBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly NotificationBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public NotificationController(NotificationFactory notificationFactory)
|
public NotificationController(IBroadcastSignalRMessage signalRBroadcaster, NotificationFactory notificationFactory)
|
||||||
: base(notificationFactory, "notification", ResourceMapper, BulkResourceMapper)
|
: base(signalRBroadcaster, notificationFactory, "notification", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,19 @@ using Lidarr.Http.REST.Attributes;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Serializer;
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Events;
|
||||||
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
|
using NzbDrone.Core.ThingiProvider.Events;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1
|
namespace Lidarr.Api.V1
|
||||||
{
|
{
|
||||||
public abstract class ProviderControllerBase<TProviderResource, TBulkProviderResource, TProvider, TProviderDefinition> : RestController<TProviderResource>
|
public abstract class ProviderControllerBase<TProviderResource, TBulkProviderResource, TProvider, TProviderDefinition> : RestControllerWithSignalR<TProviderResource, TProviderDefinition>,
|
||||||
|
IHandle<ProviderAddedEvent<TProvider>>,
|
||||||
|
IHandle<ProviderUpdatedEvent<TProvider>>,
|
||||||
|
IHandle<ProviderDeletedEvent<TProvider>>
|
||||||
where TProviderDefinition : ProviderDefinition, new()
|
where TProviderDefinition : ProviderDefinition, new()
|
||||||
where TProvider : IProvider
|
where TProvider : IProvider
|
||||||
where TProviderResource : ProviderResource<TProviderResource>, new()
|
where TProviderResource : ProviderResource<TProviderResource>, new()
|
||||||
|
@ -22,11 +29,13 @@ namespace Lidarr.Api.V1
|
||||||
private readonly ProviderResourceMapper<TProviderResource, TProviderDefinition> _resourceMapper;
|
private readonly ProviderResourceMapper<TProviderResource, TProviderDefinition> _resourceMapper;
|
||||||
private readonly ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> _bulkResourceMapper;
|
private readonly ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> _bulkResourceMapper;
|
||||||
|
|
||||||
protected ProviderControllerBase(IProviderFactory<TProvider,
|
protected ProviderControllerBase(IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
|
IProviderFactory<TProvider,
|
||||||
TProviderDefinition> providerFactory,
|
TProviderDefinition> providerFactory,
|
||||||
string resource,
|
string resource,
|
||||||
ProviderResourceMapper<TProviderResource, TProviderDefinition> resourceMapper,
|
ProviderResourceMapper<TProviderResource, TProviderDefinition> resourceMapper,
|
||||||
ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> bulkResourceMapper)
|
ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> bulkResourceMapper)
|
||||||
|
: base(signalRBroadcaster)
|
||||||
{
|
{
|
||||||
_providerFactory = providerFactory;
|
_providerFactory = providerFactory;
|
||||||
_resourceMapper = resourceMapper;
|
_resourceMapper = resourceMapper;
|
||||||
|
@ -261,6 +270,24 @@ namespace Lidarr.Api.V1
|
||||||
return Content(data.ToJson(), "application/json");
|
return Content(data.ToJson(), "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public virtual void Handle(ProviderAddedEvent<TProvider> message)
|
||||||
|
{
|
||||||
|
BroadcastResourceChange(ModelAction.Created, message.Definition.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public virtual void Handle(ProviderUpdatedEvent<TProvider> message)
|
||||||
|
{
|
||||||
|
BroadcastResourceChange(ModelAction.Updated, message.Definition.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public virtual void Handle(ProviderDeletedEvent<TProvider> message)
|
||||||
|
{
|
||||||
|
BroadcastResourceChange(ModelAction.Deleted, message.ProviderId);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Validate(TProviderDefinition definition, bool includeWarnings)
|
protected virtual void Validate(TProviderDefinition definition, bool includeWarnings)
|
||||||
{
|
{
|
||||||
var validationResult = definition.Settings.Validate();
|
var validationResult = definition.Settings.Validate();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue