mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 18:42:42 +01:00
Indexers are saved when settings are saved
This commit is contained in:
parent
4a39faeb39
commit
d2a59ea404
@ -17,7 +17,8 @@ public IndexerModule(IIndexerService indexerService)
|
||||
{
|
||||
_indexerService = indexerService;
|
||||
GetResourceAll = GetAll;
|
||||
CreateResource = Create;
|
||||
CreateResource = CreateIndexer;
|
||||
UpdateResource = UpdateIndexer;
|
||||
}
|
||||
|
||||
private List<IndexerResource> GetAll()
|
||||
@ -38,22 +39,9 @@ private List<IndexerResource> GetAll()
|
||||
return result;
|
||||
}
|
||||
|
||||
private IndexerResource Create(IndexerResource indexerResource)
|
||||
private IndexerResource CreateIndexer(IndexerResource indexerResource)
|
||||
{
|
||||
var indexer = _indexerService.Schema()
|
||||
.SingleOrDefault(i =>
|
||||
i.Implementation.Equals(indexerResource.Implementation,
|
||||
StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (indexer == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid Indexer Implementation");
|
||||
}
|
||||
|
||||
indexer.Name = indexerResource.Name;
|
||||
indexer.Enable = indexerResource.Enable;
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
var indexer = GetIndexer(indexerResource);
|
||||
indexer = _indexerService.Create(indexer);
|
||||
|
||||
var response = indexer.InjectTo<IndexerResource>();
|
||||
@ -61,5 +49,36 @@ private IndexerResource Create(IndexerResource indexerResource)
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private IndexerResource UpdateIndexer(IndexerResource indexerResource)
|
||||
{
|
||||
var indexer = _indexerService.Get(indexerResource.Id);
|
||||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
indexer = _indexerService.Update(indexer);
|
||||
|
||||
var response = indexer.InjectTo<IndexerResource>();
|
||||
response.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private Indexer GetIndexer(IndexerResource indexerResource)
|
||||
{
|
||||
var indexer = _indexerService.Schema()
|
||||
.SingleOrDefault(i =>
|
||||
i.Implementation.Equals(indexerResource.Implementation,
|
||||
StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (indexer == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid Indexer Implementation");
|
||||
}
|
||||
|
||||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
return indexer;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using Omu.ValueInjecter;
|
||||
|
||||
namespace NzbDrone.Core.Indexers
|
||||
{
|
||||
@ -23,9 +24,11 @@ public interface IIndexerService
|
||||
{
|
||||
List<Indexer> All();
|
||||
List<IIndexer> GetAvailableIndexers();
|
||||
Indexer Get(int id);
|
||||
Indexer Get(string name);
|
||||
List<Indexer> Schema();
|
||||
Indexer Create(Indexer indexer);
|
||||
Indexer Update(Indexer indexer);
|
||||
}
|
||||
|
||||
public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
|
||||
@ -52,6 +55,11 @@ public List<IIndexer> GetAvailableIndexers()
|
||||
return All().Where(c => c.Enable && c.Settings.IsValid).Select(c => c.Instance).ToList();
|
||||
}
|
||||
|
||||
public Indexer Get(int id)
|
||||
{
|
||||
return ToIndexer(_indexerRepository.Get(id));
|
||||
}
|
||||
|
||||
public Indexer Get(string name)
|
||||
{
|
||||
return ToIndexer(_indexerRepository.Get(name));
|
||||
@ -73,6 +81,7 @@ public List<Indexer> Schema()
|
||||
return indexers;
|
||||
}
|
||||
|
||||
|
||||
public Indexer Create(Indexer indexer)
|
||||
{
|
||||
var definition = new IndexerDefinition
|
||||
@ -89,6 +98,16 @@ public Indexer Create(Indexer indexer)
|
||||
return indexer;
|
||||
}
|
||||
|
||||
public Indexer Update(Indexer indexer)
|
||||
{
|
||||
var definition = _indexerRepository.Get(indexer.Id);
|
||||
definition.InjectFrom(indexer);
|
||||
definition.Settings = indexer.Settings.ToJson();
|
||||
_indexerRepository.Update(definition);
|
||||
|
||||
return indexer;
|
||||
}
|
||||
|
||||
private Indexer ToIndexer(IndexerDefinition definition)
|
||||
{
|
||||
var indexer = new Indexer();
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<button class="btn btn-success x-add">Add</button>
|
||||
<button class="btn btn-success x-add">Add Newznab</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -35,17 +35,21 @@ define(['app',
|
||||
},
|
||||
|
||||
saveSettings: function () {
|
||||
//TODO: check if any models in the collection have changed and sync them only
|
||||
// this.collection.sync();
|
||||
// if (!this.model.isSaved) {
|
||||
// this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings"));
|
||||
// }
|
||||
var self = this;
|
||||
|
||||
//For now loop through and save all the models
|
||||
|
||||
_.each(this.collection.models, function (model, index, list) {
|
||||
var name = model.get('name');
|
||||
var error = 'Failed to save indexer: ' + name;
|
||||
|
||||
model.save(undefined, self.syncNotification(error));
|
||||
});
|
||||
},
|
||||
|
||||
syncNotification: function (success, error) {
|
||||
syncNotification: function (error) {
|
||||
return {
|
||||
success: function () {
|
||||
NzbDrone.Shared.Messenger.show({message: 'General Settings Saved'});
|
||||
},
|
||||
error : function () {
|
||||
NzbDrone.Shared.Messenger.show({message: "Couldn't Save General Settings", type: 'error'});
|
||||
|
@ -3,7 +3,7 @@
|
||||
{{#if id}}
|
||||
<h3>Edit</h3>
|
||||
{{else}}
|
||||
<h3>Add</h3>
|
||||
<h3>Add Newznab</h3>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
Loading…
Reference in New Issue
Block a user