Merge remote-tracking branch 'origin/develop' into develop

pull/2795/head
Leonardo Galli 6 years ago
commit 0903269b7c

@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Validation;
@ -8,14 +11,26 @@ namespace NzbDrone.Api.Profiles
public class ProfileModule : NzbDroneRestModule<ProfileResource>
{
private readonly IProfileService _profileService;
private readonly ICustomFormatService _formatService;
public ProfileModule(IProfileService profileService)
public ProfileModule(IProfileService profileService, ICustomFormatService formatService)
{
_profileService = profileService;
_formatService = formatService;
SharedValidator.RuleFor(c => c.Name).NotEmpty();
SharedValidator.RuleFor(c => c.Cutoff).NotNull();
SharedValidator.RuleFor(c => c.Items).MustHaveAllowedQuality();
SharedValidator.RuleFor(c => c.Language).ValidLanguage();
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
{
var all = _formatService.All().Select(f => f.Id).ToList();
all.Add(CustomFormat.None.Id);
var ids = items.Select(i => i.Id);
return all.Except(ids).Empty();
}).WithMessage("All Custom Formats and no extra ones need to be present inside your Profile! Try refreshing your browser.");
SharedValidator.RuleFor(c => c.FormatCutoff)
.Must(c => _formatService.All().Select(f => f.Id).Contains(c.Id) || c.Id == CustomFormat.None.Id).WithMessage("The Custom Format Cutoff must be a valid Custom Format! Try refreshing your browser.");
GetResourceAll = GetAll;
GetResourceById = GetById;

@ -48,6 +48,12 @@ namespace NzbDrone.Core.Datastore.Converters
}
var quality = (CustomFormat) clrValue;
if (CustomFormatService.AllCustomFormats?.ContainsKey(quality.Id) == false)
{
//throw new Exception("Attempted to save an unknown custom format! Make sure you do not have stale custom formats lying around!");
}
return quality.Id;
}

@ -1,8 +1,28 @@
var Backbone = require('backbone');
var IndexerModel = require('./CustomFormatModel');
var vent = require('vent');
module.exports = Backbone.Collection.extend({
model : IndexerModel,
url : window.NzbDrone.ApiRoot + '/customformat'
url : window.NzbDrone.ApiRoot + '/customformat',
sync : function(method, model, options) {
vent.trigger(vent.Events.CustomFormatsChanged, {method : method});
Backbone.Collection.prototype.sync.apply(this, arguments);
},
add : function(model, options) {
vent.trigger(vent.Events.CustomFormatsChanged, {options : options});
Backbone.Collection.prototype.add.apply(this, arguments);
},
remove : function(model, options) {
vent.trigger(vent.Events.CustomFormatsChanged, {options : options});
Backbone.Collection.prototype.remove.apply(this, arguments);
}
});

@ -5,6 +5,8 @@ var DelayProfileLayout = require('./Delay/DelayProfileLayout');
var DelayProfileCollection = require('./Delay/DelayProfileCollection');
var LanguageCollection = require('./Language/LanguageCollection');
var vent = require('vent');
module.exports = Marionette.Layout.extend({
template : 'Settings/Profile/ProfileLayoutTemplate',
@ -17,6 +19,10 @@ module.exports = Marionette.Layout.extend({
this.settings = options.settings;
ProfileCollection.fetch();
vent.on(vent.Events.CustomFormatsChanged, function(options) {
ProfileCollection.fetch();
});
this.delayProfileCollection = new DelayProfileCollection();
this.delayProfileCollection.fetch();
},

@ -7,7 +7,8 @@ vent.Events = {
MovieDeleted : 'movie:deleted',
CommandComplete : 'command:complete',
ServerUpdated : 'server:updated',
EpisodeFileDeleted : 'episodefile:deleted'
EpisodeFileDeleted : 'episodefile:deleted',
CustomFormatsChanged : 'customformat:changed'
};
vent.Commands = {

Loading…
Cancel
Save