Can add indexer (in UI)

pull/4/head
Mark McDowall 11 years ago
parent 6351011cce
commit ea929974f3

@ -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;
}
}
}

@ -16,10 +16,10 @@ namespace NzbDrone.Api.Notifications
{
_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)

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

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.Indexers
@ -21,6 +22,7 @@ namespace NzbDrone.Core.Indexers
List<Indexer> All();
List<IIndexer> GetAvailableIndexers();
Indexer Get(string name);
List<Indexer> Schema();
}
public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
@ -52,6 +54,20 @@ namespace NzbDrone.Core.Indexers
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)
{

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

@ -1,8 +1,32 @@
'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({
itemView : NzbDrone.Settings.Indexers.ItemView,
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);
}
});
}
});
});

@ -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>

@ -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);
}
};
}
});
});
Loading…
Cancel
Save