From 1d286df85d3741c4047e5f23a20508edfcc6e64f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 25 Sep 2024 05:17:17 +0300 Subject: [PATCH] Display naming example errors when all fields are empty --- .../src/Settings/MediaManagement/Naming/Naming.js | 8 ++------ .../MediaManagement/Naming/NamingConnector.js | 7 +++---- src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 6 ++++++ src/NzbDrone.Core/Organizer/FileNameSampleService.cs | 2 ++ src/Radarr.Api.V3/Config/NamingConfigController.cs | 11 +++++------ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/frontend/src/Settings/MediaManagement/Naming/Naming.js b/frontend/src/Settings/MediaManagement/Naming/Naming.js index 94ed8538c..1e13396bc 100644 --- a/frontend/src/Settings/MediaManagement/Naming/Naming.js +++ b/frontend/src/Settings/MediaManagement/Naming/Naming.js @@ -112,17 +112,13 @@ class Naming extends Component { if (examples.movieExample) { standardMovieFormatHelpTexts.push(`${translate('Movie')}: ${examples.movieExample}`); } else { - standardMovieFormatErrors.push({ get message() { - return translate('MovieInvalidFormat'); - } }); + standardMovieFormatErrors.push({ message: translate('MovieInvalidFormat') }); } if (examples.movieFolderExample) { movieFolderFormatHelpTexts.push(`${translate('Example')}: ${examples.movieFolderExample}`); } else { - movieFolderFormatErrors.push({ get message() { - return translate('InvalidFormat'); - } }); + movieFolderFormatErrors.push({ message: translate('InvalidFormat') }); } } diff --git a/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js b/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js index 2b033f918..55c3bc597 100644 --- a/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js +++ b/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -15,11 +14,11 @@ function createMapStateToProps() { (state) => state.settings.advancedSettings, (state) => state.settings.namingExamples, createSettingsSectionSelector(SECTION), - (advancedSettings, examples, sectionSettings) => { + (advancedSettings, namingExamples, sectionSettings) => { return { advancedSettings, - examples: examples.item, - examplesPopulated: !_.isEmpty(examples.item), + examples: namingExamples.item, + examplesPopulated: namingExamples.isPopulated, ...sectionSettings }; } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 53ae1a948..fe81e168d 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -107,7 +107,13 @@ namespace NzbDrone.Core.Organizer return GetOriginalTitle(movieFile, false); } + if (namingConfig.StandardMovieFormat.IsNullOrWhiteSpace()) + { + throw new NamingFormatException("Standard movie format cannot be empty"); + } + var pattern = namingConfig.StandardMovieFormat; + var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); var multipleTokens = TitleRegex.Matches(pattern).Count > 1; diff --git a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs index ff887adf2..c8e70e685 100644 --- a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs @@ -90,6 +90,8 @@ namespace NzbDrone.Core.Organizer var result = new SampleResult { FileName = BuildSample(_movie, _movieFile, nameSpec), + Movie = _movie, + MovieFile = _movieFile }; return result; diff --git a/src/Radarr.Api.V3/Config/NamingConfigController.cs b/src/Radarr.Api.V3/Config/NamingConfigController.cs index 7ca6cf96d..cd9d2b5e3 100644 --- a/src/Radarr.Api.V3/Config/NamingConfigController.cs +++ b/src/Radarr.Api.V3/Config/NamingConfigController.cs @@ -17,17 +17,14 @@ namespace Radarr.Api.V3.Config private readonly INamingConfigService _namingConfigService; private readonly IFilenameSampleService _filenameSampleService; private readonly IFilenameValidationService _filenameValidationService; - private readonly IBuildFileNames _filenameBuilder; public NamingConfigController(INamingConfigService namingConfigService, IFilenameSampleService filenameSampleService, - IFilenameValidationService filenameValidationService, - IBuildFileNames filenameBuilder) + IFilenameValidationService filenameValidationService) { _namingConfigService = namingConfigService; _filenameSampleService = filenameSampleService; _filenameValidationService = filenameValidationService; - _filenameBuilder = filenameBuilder; SharedValidator.RuleFor(c => c.StandardMovieFormat).ValidMovieFormat(); SharedValidator.RuleFor(c => c.MovieFolderFormat).ValidMovieFolderFormat(); @@ -72,11 +69,11 @@ namespace Radarr.Api.V3.Config var movieSampleResult = _filenameSampleService.GetMovieSample(nameSpec); sampleResource.MovieExample = nameSpec.StandardMovieFormat.IsNullOrWhiteSpace() - ? "Invalid Format" + ? null : movieSampleResult.FileName; sampleResource.MovieFolderExample = nameSpec.MovieFolderFormat.IsNullOrWhiteSpace() - ? "Invalid format" + ? null : _filenameSampleService.GetMovieFolderSample(nameSpec); return sampleResource; @@ -90,6 +87,8 @@ namespace Radarr.Api.V3.Config var validationFailures = new List(); + validationFailures.AddIfNotNull(standardMovieValidationResult); + if (validationFailures.Any()) { throw new ValidationException(validationFailures.DistinctBy(v => v.PropertyName).ToArray());