1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Can add indexer (in UI)

This commit is contained in:
Mark McDowall 2013-05-27 17:19:07 -07:00
parent 6351011cce
commit ea929974f3
8 changed files with 168 additions and 4 deletions

View File

@ -0,0 +1,37 @@
using System.Collections.Generic;
using NzbDrone.Api.ClientSchema;
using NzbDrone.Core.Indexers;
using Omu.ValueInjecter;
namespace NzbDrone.Api.Indexers
{
public class IndexerSchemaModule : NzbDroneRestModule<IndexerResource>
{
private readonly IIndexerService _indexerService;
public IndexerSchemaModule(IIndexerService indexerService)
: base("indexer/schema")
{
_indexerService = indexerService;
GetResourceAll = GetSchema;
}
private List<IndexerResource> GetSchema()
{
var indexers = _indexerService.Schema();
var result = new List<IndexerResource>(indexers.Count);
foreach (var indexer in indexers)
{
var indexerResource = new IndexerResource();
indexerResource.InjectFrom(indexer);
indexerResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
result.Add(indexerResource);
}
return result;
}
}
}

View File

@ -16,10 +16,10 @@ public NotificationSchemaModule(INotificationService notificationService)
{ {
_notificationService = notificationService; _notificationService = notificationService;
GetResourceAll = GetAll; GetResourceAll = GetSchema;
} }
private List<NotificationResource> GetAll() private List<NotificationResource> GetSchema()
{ {
//Need to get all the possible Notification's same as we would for settiings (but keep them empty) //Need to get all the possible Notification's same as we would for settiings (but keep them empty)

View File

@ -111,6 +111,7 @@
<Compile Include="Frontend\StaticResourceMapper.cs" /> <Compile Include="Frontend\StaticResourceMapper.cs" />
<Compile Include="History\HistoryResource.cs" /> <Compile Include="History\HistoryResource.cs" />
<Compile Include="History\HistoryModule.cs" /> <Compile Include="History\HistoryModule.cs" />
<Compile Include="Indexers\IndexerSchemaModule.cs" />
<Compile Include="Indexers\IndexerModule.cs" /> <Compile Include="Indexers\IndexerModule.cs" />
<Compile Include="Indexers\IndexerResource.cs" /> <Compile Include="Indexers\IndexerResource.cs" />
<Compile Include="Indexers\ReleaseModule.cs" /> <Compile Include="Indexers\ReleaseModule.cs" />

View File

@ -3,6 +3,7 @@
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.Indexers namespace NzbDrone.Core.Indexers
@ -21,6 +22,7 @@ public interface IIndexerService
List<Indexer> All(); List<Indexer> All();
List<IIndexer> GetAvailableIndexers(); List<IIndexer> GetAvailableIndexers();
Indexer Get(string name); Indexer Get(string name);
List<Indexer> Schema();
} }
public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent> public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
@ -52,6 +54,20 @@ public Indexer Get(string name)
return ToIndexer(_indexerRepository.Get(name)); return ToIndexer(_indexerRepository.Get(name));
} }
public List<Indexer> Schema()
{
var indexers = new List<Indexer>();
var newznab = new Indexer();
newznab.Instance = new Newznab.Newznab();
newznab.Id = 1;
newznab.Name = "Newznab";
newznab.Settings = new NewznabSettings();
indexers.Add(newznab);
return indexers.OrderBy(n => n.Name).ToList();
}
private Indexer ToIndexer(IndexerDefinition definition) private Indexer ToIndexer(IndexerDefinition definition)
{ {

View File

@ -1,4 +1,10 @@
<div class="row"> <div class="row">
<div class="span12">
<button class="btn btn-success x-add">Add</button>
</div>
</div>
<div class="row">
<div class="span12"> <div class="span12">
<div id="x-indexers" class="form-horizontal"></div> <div id="x-indexers" class="form-horizontal"></div>
</div> </div>

View File

@ -1,8 +1,32 @@
'use strict'; 'use strict';
define(['app', 'Settings/Indexers/ItemView'], function () { define(['app',
'Settings/Indexers/ItemView',
'Settings/Indexers/EditView'],
function () {
NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({ NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Settings.Indexers.ItemView, itemView : NzbDrone.Settings.Indexers.ItemView,
itemViewContainer : '#x-indexers', itemViewContainer : '#x-indexers',
template : 'Settings/Indexers/CollectionTemplate' template : 'Settings/Indexers/CollectionTemplate',
events: {
'click .x-add': 'openSchemaModal'
},
openSchemaModal: function () {
//TODO: Is there a better way to deal with changing URLs?
var schema = new NzbDrone.Settings.Indexers.Collection();
schema.url = '/api/indexer/schema';
schema.fetch({
success: function (collection) {
collection.url = '/api/indexer';
var model = _.first(collection.models);
model.set('id', undefined);
model.set('name', '');
var view = new NzbDrone.Settings.Indexers.EditView({ model: model});
NzbDrone.modalRegion.show(view);
}
});
}
}); });
}); });

View File

@ -0,0 +1,44 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
{{#if id}}
<h3>Edit</h3>
{{else}}
<h3>Add</h3>
{{/if}}
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" name="name"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Enable</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="enable"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"></div>
</label>
</div>
</div>
{{formBuilder}}
</div>
</div>
<div class="modal-footer">
{{#if id}}
<button class="btn btn-danger pull-left x-remove">delete</button>
{{/if}}
<button class="btn" data-dismiss="modal">cancel</button>
<button class="btn btn-primary x-save">save</button>
</div>

View File

@ -0,0 +1,36 @@
"use strict";
define([
'app',
'Settings/Indexers/Model'
], function () {
NzbDrone.Settings.Indexers.EditView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Indexers/EditTemplate',
events: {
'click .x-save': 'save'
},
save: function () {
this.model.save();
// window.alert('saving');
// this.model.save(undefined, this.syncNotification("Notification Settings Saved", "Couldn't Save Notification Settings"));
},
syncNotification: function (success, error) {
return {
success: function () {
window.alert(success);
},
error: function () {
window.alert(error);
}
};
}
});
});