parent
afc4aeb25f
commit
b0070e0229
@ -1,126 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import getProgressBarKind from 'Utilities/Artist/getProgressBarKind';
|
|
||||||
import ProgressBar from 'Components/ProgressBar';
|
|
||||||
import VirtualTableRowCell from 'Components/Table/Cells/VirtualTableRowCell';
|
|
||||||
import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector';
|
|
||||||
import QualityProfileNameConnector from 'Settings/Profiles/Quality/QualityProfileNameConnector';
|
|
||||||
import ArtistNameLink from 'Artist/ArtistNameLink';
|
|
||||||
import ArtistIndexItemConnector from 'Artist/Index/ArtistIndexItemConnector';
|
|
||||||
import ArtistIndexActionsCell from './ArtistIndexActionsCell';
|
|
||||||
import ArtistStatusCell from './ArtistStatusCell';
|
|
||||||
|
|
||||||
export default function artistIndexCellRenderers(cellProps) {
|
|
||||||
const {
|
|
||||||
cellKey,
|
|
||||||
dataKey,
|
|
||||||
rowData,
|
|
||||||
...otherProps
|
|
||||||
} = cellProps;
|
|
||||||
|
|
||||||
const {
|
|
||||||
id,
|
|
||||||
monitored,
|
|
||||||
status,
|
|
||||||
name,
|
|
||||||
nameSlug,
|
|
||||||
foreignArtistId,
|
|
||||||
qualityProfileId,
|
|
||||||
nextAiring,
|
|
||||||
previousAiring,
|
|
||||||
albumCount,
|
|
||||||
trackCount,
|
|
||||||
trackFileCount
|
|
||||||
} = rowData;
|
|
||||||
|
|
||||||
const progress = trackCount ? trackFileCount / trackCount * 100 : 100;
|
|
||||||
|
|
||||||
if (dataKey === 'status') {
|
|
||||||
return (
|
|
||||||
<ArtistStatusCell
|
|
||||||
key={cellKey}
|
|
||||||
monitored={monitored}
|
|
||||||
status={status}
|
|
||||||
component={VirtualTableRowCell}
|
|
||||||
{...otherProps}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'sortName') {
|
|
||||||
return (
|
|
||||||
<VirtualTableRowCell
|
|
||||||
key={cellKey}
|
|
||||||
{...otherProps}
|
|
||||||
>
|
|
||||||
<ArtistNameLink
|
|
||||||
foreignArtistId={foreignArtistId}
|
|
||||||
name={name}
|
|
||||||
/>
|
|
||||||
</VirtualTableRowCell>
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'qualityProfileId') {
|
|
||||||
return (
|
|
||||||
<VirtualTableRowCell
|
|
||||||
key={cellKey}
|
|
||||||
{...otherProps}
|
|
||||||
>
|
|
||||||
<QualityProfileNameConnector
|
|
||||||
qualityProfileId={qualityProfileId}
|
|
||||||
/>
|
|
||||||
</VirtualTableRowCell>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'nextAiring') {
|
|
||||||
return (
|
|
||||||
<RelativeDateCellConnector
|
|
||||||
key={cellKey}
|
|
||||||
date={nextAiring}
|
|
||||||
component={VirtualTableRowCell}
|
|
||||||
{...otherProps}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'albumCount') {
|
|
||||||
return (
|
|
||||||
<VirtualTableRowCell
|
|
||||||
key={cellKey}
|
|
||||||
{...otherProps}
|
|
||||||
>
|
|
||||||
{albumCount}
|
|
||||||
</VirtualTableRowCell>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'trackProgress') {
|
|
||||||
return (
|
|
||||||
<VirtualTableRowCell
|
|
||||||
key={cellKey}
|
|
||||||
{...otherProps}
|
|
||||||
>
|
|
||||||
<ProgressBar
|
|
||||||
progress={progress}
|
|
||||||
kind={getProgressBarKind(status, monitored, progress)}
|
|
||||||
showText={true}
|
|
||||||
text={`${trackFileCount} / ${trackCount}`}
|
|
||||||
width={125}
|
|
||||||
/>
|
|
||||||
</VirtualTableRowCell>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataKey === 'actions') {
|
|
||||||
return (
|
|
||||||
<ArtistIndexItemConnector
|
|
||||||
key={cellKey}
|
|
||||||
component={ArtistIndexActionsCell}
|
|
||||||
id={id}
|
|
||||||
{...otherProps}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
|
||||||
using FluentValidation.Validators;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Core.Music;
|
|
||||||
using NzbDrone.Test.Common;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.TvTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class ArtistNameSlugValidatorFixture : CoreTest<ArtistSlugValidator>
|
|
||||||
{
|
|
||||||
private List<Artist> _artist;
|
|
||||||
private TestValidator<Artist> _validator;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_artist = Builder<Artist>.CreateListOfSize(1)
|
|
||||||
.Build()
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_validator = new TestValidator<Artist>
|
|
||||||
{
|
|
||||||
v => v.RuleFor(s => s.NameSlug).SetValidator(Subject)
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>()
|
|
||||||
.Setup(s => s.GetAllArtists())
|
|
||||||
.Returns(_artist);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_be_valid_if_there_is_an_existing_artist_with_the_same_title_slug()
|
|
||||||
{
|
|
||||||
var series = Builder<Artist>.CreateNew()
|
|
||||||
.With(s => s.Id = 100)
|
|
||||||
.With(s => s.NameSlug = _artist.First().NameSlug)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_validator.Validate(series).IsValid.Should().BeFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_valid_if_there_is_not_an_existing_artist_with_the_same_title_slug()
|
|
||||||
{
|
|
||||||
var series = Builder<Artist>.CreateNew()
|
|
||||||
.With(s => s.NameSlug = "MyNameSlug")
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_validator.Validate(series).IsValid.Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_valid_if_there_is_an_existing_artist_with_a_null_title_slug()
|
|
||||||
{
|
|
||||||
_artist.First().NameSlug = null;
|
|
||||||
|
|
||||||
var series = Builder<Artist>.CreateNew()
|
|
||||||
.With(s => s.NameSlug = "MyNameSlug")
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_validator.Validate(series).IsValid.Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_valid_when_updating_an_existing_artist()
|
|
||||||
{
|
|
||||||
_validator.Validate(_artist.First().JsonClone()).IsValid.Should().BeTrue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using FluentValidation.Validators;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music
|
|
||||||
{
|
|
||||||
public class ArtistSlugValidator : PropertyValidator
|
|
||||||
{
|
|
||||||
private readonly IArtistService _artistService;
|
|
||||||
|
|
||||||
public ArtistSlugValidator(IArtistService artistService)
|
|
||||||
: base("Name slug '{slug}' is in use by artist '{artistName}'")
|
|
||||||
{
|
|
||||||
_artistService = artistService;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
|
||||||
{
|
|
||||||
if (context.PropertyValue == null) return true;
|
|
||||||
|
|
||||||
dynamic instance = context.ParentContext.InstanceToValidate;
|
|
||||||
var instanceId = (int)instance.Id;
|
|
||||||
var slug = context.PropertyValue.ToString();
|
|
||||||
|
|
||||||
var conflictingArtist = _artistService.GetAllArtists()
|
|
||||||
.FirstOrDefault(s => s.NameSlug.IsNotNullOrWhiteSpace() &&
|
|
||||||
s.NameSlug.Equals(context.PropertyValue.ToString()) &&
|
|
||||||
s.Id != instanceId);
|
|
||||||
|
|
||||||
if (conflictingArtist == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.MessageFormatter.AppendArgument("slug", slug);
|
|
||||||
context.MessageFormatter.AppendArgument("artistName", conflictingArtist.Name);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue