From ea929974f3ddf9431ca8f8f6b4622b6cab23d0e1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 27 May 2013 17:19:07 -0700 Subject: [PATCH] Can add indexer (in UI) --- NzbDrone.Api/Indexers/IndexerSchemaModule.cs | 37 ++++++++++++++++ .../Notifications/NotificationSchemaModule.cs | 4 +- NzbDrone.Api/NzbDrone.Api.csproj | 1 + NzbDrone.Core/Indexers/IndexerService.cs | 16 +++++++ UI/Settings/Indexers/CollectionTemplate.html | 6 +++ UI/Settings/Indexers/CollectionView.js | 28 +++++++++++- UI/Settings/Indexers/EditTemplate.html | 44 +++++++++++++++++++ UI/Settings/Indexers/EditView.js | 36 +++++++++++++++ 8 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 NzbDrone.Api/Indexers/IndexerSchemaModule.cs create mode 100644 UI/Settings/Indexers/EditTemplate.html create mode 100644 UI/Settings/Indexers/EditView.js diff --git a/NzbDrone.Api/Indexers/IndexerSchemaModule.cs b/NzbDrone.Api/Indexers/IndexerSchemaModule.cs new file mode 100644 index 000000000..ad2ca7846 --- /dev/null +++ b/NzbDrone.Api/Indexers/IndexerSchemaModule.cs @@ -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 + { + private readonly IIndexerService _indexerService; + + public IndexerSchemaModule(IIndexerService indexerService) + : base("indexer/schema") + { + _indexerService = indexerService; + GetResourceAll = GetSchema; + } + + private List GetSchema() + { + var indexers = _indexerService.Schema(); + + var result = new List(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; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/Notifications/NotificationSchemaModule.cs b/NzbDrone.Api/Notifications/NotificationSchemaModule.cs index b5e839384..52a9dfa00 100644 --- a/NzbDrone.Api/Notifications/NotificationSchemaModule.cs +++ b/NzbDrone.Api/Notifications/NotificationSchemaModule.cs @@ -16,10 +16,10 @@ namespace NzbDrone.Api.Notifications { _notificationService = notificationService; - GetResourceAll = GetAll; + GetResourceAll = GetSchema; } - private List GetAll() + private List GetSchema() { //Need to get all the possible Notification's same as we would for settiings (but keep them empty) diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index d994c721b..516c737d6 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -111,6 +111,7 @@ + diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index f28ef1e43..7e3456026 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.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 All(); List GetAvailableIndexers(); Indexer Get(string name); + List Schema(); } public class IndexerService : IIndexerService, IHandle @@ -52,6 +54,20 @@ namespace NzbDrone.Core.Indexers return ToIndexer(_indexerRepository.Get(name)); } + public List Schema() + { + var indexers = new List(); + + 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) { diff --git a/UI/Settings/Indexers/CollectionTemplate.html b/UI/Settings/Indexers/CollectionTemplate.html index c42cbaa79..68ad64985 100644 --- a/UI/Settings/Indexers/CollectionTemplate.html +++ b/UI/Settings/Indexers/CollectionTemplate.html @@ -1,4 +1,10 @@ 
+
+ +
+
+ +
diff --git a/UI/Settings/Indexers/CollectionView.js b/UI/Settings/Indexers/CollectionView.js index 76a9ca9ce..6524b9294 100644 --- a/UI/Settings/Indexers/CollectionView.js +++ b/UI/Settings/Indexers/CollectionView.js @@ -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); + } + }); + } }); }); diff --git a/UI/Settings/Indexers/EditTemplate.html b/UI/Settings/Indexers/EditTemplate.html new file mode 100644 index 000000000..33b77847e --- /dev/null +++ b/UI/Settings/Indexers/EditTemplate.html @@ -0,0 +1,44 @@ + + + \ No newline at end of file diff --git a/UI/Settings/Indexers/EditView.js b/UI/Settings/Indexers/EditView.js new file mode 100644 index 000000000..10d3e3ebd --- /dev/null +++ b/UI/Settings/Indexers/EditView.js @@ -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); + } + }; + } + }); +});