From aa6c8f493e0176bf86de3330da0c0f1f6ea49843 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 9 Jul 2020 12:30:34 -0400 Subject: [PATCH] New: Refresh Selected in Editor Mode --- frontend/src/Movie/Index/MovieIndex.js | 11 ++++-- .../src/Movie/Index/MovieIndexConnector.js | 5 +-- .../MovieTests/RefreshMovieServiceFixture.cs | 10 +++--- .../Movies/Commands/RefreshMovieCommand.cs | 11 +++--- src/NzbDrone.Core/Movies/MovieAddedHandler.cs | 5 +-- .../Movies/RefreshMovieService.cs | 35 ++++++++++--------- .../IntegrationTestBase.cs | 2 +- 7 files changed, 47 insertions(+), 32 deletions(-) diff --git a/frontend/src/Movie/Index/MovieIndex.js b/frontend/src/Movie/Index/MovieIndex.js index f86079e9e..dd0a9cee8 100644 --- a/frontend/src/Movie/Index/MovieIndex.js +++ b/frontend/src/Movie/Index/MovieIndex.js @@ -281,6 +281,13 @@ class MovieIndex extends Component { this.setState({ isConfirmSearchModalOpen: true, searchType: 'moviesSearch' }); } + onRefreshMoviePress = () => { + const selectedMovieIds = this.getSelectedIds(); + const refreshIds = this.state.isMovieEditorActive && selectedMovieIds.length > 0 ? selectedMovieIds : []; + + this.props.onRefreshMoviePress(refreshIds); + } + onSearchConfirmed = () => { const selectedMovieIds = this.getSelectedIds(); const searchIds = this.state.isMovieEditorActive && selectedMovieIds.length > 0 ? selectedMovieIds : this.props.items.map((m) => m.id); @@ -356,12 +363,12 @@ class MovieIndex extends Component { 0 ? 'Update Selected' : 'Update All'} iconName={icons.REFRESH} spinningName={icons.REFRESH} isSpinning={isRefreshingMovie} isDisabled={hasNoMovie} - onPress={onRefreshMoviePress} + onPress={this.onRefreshMoviePress} /> { _movie.Id })); Mocker.GetMock() .Verify(v => v.UpdateMovie(It.Is>(s => s.First().ImdbId == newMovieInfo.ImdbId), true)); @@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.MovieTests [Test] public void should_log_error_if_tmdb_id_not_found() { - Subject.Execute(new RefreshMovieCommand(_movie.Id)); + Subject.Execute(new RefreshMovieCommand(new List { _movie.Id })); Mocker.GetMock() .Verify(v => v.UpdateMovie(It.Is(s => s.Status == MovieStatusType.Deleted)), Times.Once()); @@ -76,7 +76,7 @@ namespace NzbDrone.Core.Test.MovieTests GivenNewMovieInfo(newMovieInfo); - Subject.Execute(new RefreshMovieCommand(_movie.Id)); + Subject.Execute(new RefreshMovieCommand(new List { _movie.Id })); Mocker.GetMock() .Verify(v => v.UpdateMovie(It.Is>(s => s.First().TmdbId == newMovieInfo.TmdbId), true)); @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Test.MovieTests [Test] public void should_mark_as_deleted_if_tmdb_id_not_found() { - Subject.Execute(new RefreshMovieCommand(_movie.Id)); + Subject.Execute(new RefreshMovieCommand(new List { _movie.Id })); Mocker.GetMock() .Verify(v => v.UpdateMovie(It.Is(s => s.Status == MovieStatusType.Deleted)), Times.Once()); @@ -100,7 +100,7 @@ namespace NzbDrone.Core.Test.MovieTests { _movie.Status = MovieStatusType.Deleted; - Subject.Execute(new RefreshMovieCommand(_movie.Id)); + Subject.Execute(new RefreshMovieCommand(new List { _movie.Id })); Mocker.GetMock() .Verify(v => v.UpdateMovie(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core/Movies/Commands/RefreshMovieCommand.cs b/src/NzbDrone.Core/Movies/Commands/RefreshMovieCommand.cs index 5565f4f9d..da6611ace 100644 --- a/src/NzbDrone.Core/Movies/Commands/RefreshMovieCommand.cs +++ b/src/NzbDrone.Core/Movies/Commands/RefreshMovieCommand.cs @@ -1,24 +1,27 @@ +using System.Collections.Generic; +using System.Linq; using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Movies.Commands { public class RefreshMovieCommand : Command { - public int? MovieId { get; set; } + public List MovieIds { get; set; } public bool IsNewMovie { get; set; } public RefreshMovieCommand() { + MovieIds = new List(); } - public RefreshMovieCommand(int? movieId, bool isNewMovie = false) + public RefreshMovieCommand(List movieIds, bool isNewMovie = false) { - MovieId = movieId; + MovieIds = movieIds; IsNewMovie = isNewMovie; } public override bool SendUpdatesToClient => true; - public override bool UpdateScheduledTask => !MovieId.HasValue; + public override bool UpdateScheduledTask => !MovieIds.Any(); } } diff --git a/src/NzbDrone.Core/Movies/MovieAddedHandler.cs b/src/NzbDrone.Core/Movies/MovieAddedHandler.cs index 91412edec..fecb27460 100644 --- a/src/NzbDrone.Core/Movies/MovieAddedHandler.cs +++ b/src/NzbDrone.Core/Movies/MovieAddedHandler.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; @@ -17,12 +18,12 @@ namespace NzbDrone.Core.Movies public void Handle(MovieAddedEvent message) { - _commandQueueManager.Push(new RefreshMovieCommand(message.Movie.Id, true)); + _commandQueueManager.Push(new RefreshMovieCommand(new List { message.Movie.Id }, true)); } public void Handle(MoviesImportedEvent message) { - _commandQueueManager.PushMany(message.MovieIds.Select(s => new RefreshMovieCommand(s, true)).ToList()); + _commandQueueManager.PushMany(message.MovieIds.Select(s => new RefreshMovieCommand(new List { s }, true)).ToList()); } } } diff --git a/src/NzbDrone.Core/Movies/RefreshMovieService.cs b/src/NzbDrone.Core/Movies/RefreshMovieService.cs index ef92a9ad7..f0ed8365d 100644 --- a/src/NzbDrone.Core/Movies/RefreshMovieService.cs +++ b/src/NzbDrone.Core/Movies/RefreshMovieService.cs @@ -178,24 +178,27 @@ namespace NzbDrone.Core.Movies var isNew = message.IsNewMovie; _eventAggregator.PublishEvent(new MovieRefreshStartingEvent(message.Trigger == CommandTrigger.Manual)); - if (message.MovieId.HasValue) + if (message.MovieIds.Any()) { - var movie = _movieService.GetMovie(message.MovieId.Value); - - try - { - RefreshMovieInfo(movie); - RescanMovie(movie, isNew, trigger); - } - catch (MovieNotFoundException) + foreach (var movieId in message.MovieIds) { - _logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); - } - catch (Exception e) - { - _logger.Error(e, "Couldn't refresh info for {0}", movie); - RescanMovie(movie, isNew, trigger); - throw; + var movie = _movieService.GetMovie(movieId); + + try + { + RefreshMovieInfo(movie); + RescanMovie(movie, isNew, trigger); + } + catch (MovieNotFoundException) + { + _logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); + } + catch (Exception e) + { + _logger.Error(e, "Couldn't refresh info for {0}", movie); + RescanMovie(movie, isNew, trigger); + throw; + } } } else diff --git a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs index 3a9f92427..4e0173137 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs @@ -305,7 +305,7 @@ namespace NzbDrone.Integration.Test //File.Copy(sourcePath, path); File.WriteAllText(path, "Fake Movie"); - Commands.PostAndWait(new RefreshMovieCommand(movie.Id)); + Commands.PostAndWait(new RefreshMovieCommand(new List { movie.Id })); Commands.WaitAll(); result = Movies.Get(movie.Id);