Closes #6896typescript-utilities
parent
a80f5b794b
commit
6dd85a5af9
@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import translate from 'Utilities/String/translate';
|
||||||
|
import FilterBuilderRowValue from './FilterBuilderRowValue';
|
||||||
|
|
||||||
|
const seasonsMonitoredStatusList = [
|
||||||
|
{
|
||||||
|
id: 'all',
|
||||||
|
get name() {
|
||||||
|
return translate('SeasonsMonitoredAll');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'partial',
|
||||||
|
get name() {
|
||||||
|
return translate('SeasonsMonitoredPartial');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'none',
|
||||||
|
get name() {
|
||||||
|
return translate('SeasonsMonitoredNone');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function SeasonsMonitoredStatusFilterBuilderRowValue(props) {
|
||||||
|
return (
|
||||||
|
<FilterBuilderRowValue
|
||||||
|
tagList={seasonsMonitoredStatusList}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SeasonsMonitoredStatusFilterBuilderRowValue;
|
@ -0,0 +1,372 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Migration;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class add_monitored_seasons_filterFixture : MigrationTest<add_monitored_seasons_filter>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void equal_both_becomes_equal_every_option()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { true, false },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all", "partial", "none" });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void notEqual_both_becomes_notEqual_every_option()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { true, false },
|
||||||
|
type = "notEqual"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all", "partial", "none" });
|
||||||
|
filters[0].type.Should().Be("notEqual");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void equal_true_becomes_notEqual_all()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { true },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all" });
|
||||||
|
filters[0].type.Should().Be("notEqual");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void notEqual_true_becomes_equal_all()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { true },
|
||||||
|
type = "notEqual"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all" });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void equal_false_becomes_equal_all()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { false },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all" });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void notEqual_false_becomes_notEqual_all()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { false },
|
||||||
|
type = "notEqual"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { "all" });
|
||||||
|
filters[0].type.Should().Be("notEqual");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void missing_hasUnmonitored_unchanged()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "monitored",
|
||||||
|
value = new List<object> { false },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("monitored");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { false });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void has_hasUnmonitored_not_in_first_entry()
|
||||||
|
{
|
||||||
|
var filter1 = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "monitored",
|
||||||
|
value = new List<object> { false },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
var filter2 = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { true },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter1, filter2 };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("monitored");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { false });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
filters[1].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[1].value.Should().BeEquivalentTo(new List<object> { "all" });
|
||||||
|
filters[1].type.Should().Be("notEqual");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void has_umonitored_is_empty()
|
||||||
|
{
|
||||||
|
var filter = new FilterSettings210
|
||||||
|
{
|
||||||
|
key = "hasUnmonitoredSeason",
|
||||||
|
value = new List<object> { },
|
||||||
|
type = "equal"
|
||||||
|
};
|
||||||
|
|
||||||
|
var filtersJson = new List<FilterSettings210> { filter };
|
||||||
|
|
||||||
|
var filtersString = filtersJson.ToJson();
|
||||||
|
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("CustomFilters").Row(new
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Type = "series",
|
||||||
|
Label = "Is Both",
|
||||||
|
Filters = filtersString
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<FilterDefinition210>("SELECT * FROM \"CustomFilters\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
items.First().Type.Should().Be("series");
|
||||||
|
items.First().Label.Should().Be("Is Both");
|
||||||
|
|
||||||
|
var filters = JsonConvert.DeserializeObject<List<FilterSettings210>>(items.First().Filters);
|
||||||
|
filters[0].key.Should().Be("seasonsMonitoredStatus");
|
||||||
|
filters[0].value.Should().BeEquivalentTo(new List<object> { });
|
||||||
|
filters[0].type.Should().Be("equal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FilterDefinition210
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
public string Label { get; set; }
|
||||||
|
public string Filters { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FilterSettings210
|
||||||
|
{
|
||||||
|
public string key { get; set; }
|
||||||
|
public List<object> value { get; set; }
|
||||||
|
public string type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using FluentMigrator;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Migration(210)]
|
||||||
|
public class add_monitored_seasons_filter : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Execute.WithConnection(ChangeHasUnmonitoredSeason);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeHasUnmonitoredSeason(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
var updated = new List<object>();
|
||||||
|
using (var getUnmonitoredSeasonFilter = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
getUnmonitoredSeasonFilter.Transaction = tran;
|
||||||
|
getUnmonitoredSeasonFilter.CommandText = "SELECT \"Id\", \"Filters\" FROM \"CustomFilters\" WHERE \"Type\" = 'series'";
|
||||||
|
|
||||||
|
using (var reader = getUnmonitoredSeasonFilter.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var id = reader.GetInt32(0);
|
||||||
|
var filters = JArray.Parse(reader.GetString(1));
|
||||||
|
|
||||||
|
foreach (var filter in filters)
|
||||||
|
{
|
||||||
|
if (filter["key"]?.ToString() == "hasUnmonitoredSeason")
|
||||||
|
{
|
||||||
|
var value = filter["value"].ToString();
|
||||||
|
var type = filter["type"].ToString();
|
||||||
|
|
||||||
|
filter["key"] = "seasonsMonitoredStatus";
|
||||||
|
|
||||||
|
if (value.Contains("true") && value.Contains("false"))
|
||||||
|
{
|
||||||
|
filter["value"] = new JArray("all", "partial", "none");
|
||||||
|
}
|
||||||
|
else if (value.Contains("true"))
|
||||||
|
{
|
||||||
|
filter["type"] = type == "equal" ? "notEqual" : "equal";
|
||||||
|
filter["value"] = new JArray("all");
|
||||||
|
}
|
||||||
|
else if (value.Contains("false"))
|
||||||
|
{
|
||||||
|
filter["value"] = new JArray("all");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filter["value"] = new JArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updated.Add(new
|
||||||
|
{
|
||||||
|
Filters = filters.ToJson(),
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateSql = "UPDATE \"CustomFilters\" SET \"Filters\" = @Filters WHERE \"Id\" = @Id";
|
||||||
|
conn.Execute(updateSql, updated, transaction: tran);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue