WIP UI Update for adding lists.

Leonardo Galli 8 years ago
parent 451f2d30e4
commit dd553b9439

@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json.Linq;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Profiles;
namespace NzbDrone.Api.ClientSchema
{
@ -147,6 +150,18 @@ namespace NzbDrone.Api.ClientSchema
private static List<SelectOption> GetSelectOptions(Type selectOptions)
{
if (selectOptions == typeof(Profile))
{
return new List<SelectOption>();
}
if (selectOptions == typeof(Quality))
{
var qOptions = from Quality q in selectOptions.GetProperties(BindingFlags.Static | BindingFlags.Public)
select new SelectOption {Name = q.Name, Value = q.Id};
return qOptions.OrderBy(o => o.Value).ToList();
}
var options = from Enum e in Enum.GetValues(selectOptions)
select new SelectOption { Value = Convert.ToInt32(e), Name = e.ToString() };

@ -1,12 +1,16 @@
using NzbDrone.Core.NetImport;
using NzbDrone.Api.ClientSchema;
using NzbDrone.Core.NetImport;
using NzbDrone.Core.Profiles;
namespace NzbDrone.Api.NetImport
{
public class NetImportModule : ProviderModuleBase<NetImportResource, INetImport, NetImportDefinition>
{
public NetImportModule(NetImportFactory indexerFactory)
private readonly IProfileService _profileService;
public NetImportModule(NetImportFactory indexerFactory, IProfileService profileService)
: base(indexerFactory, "netimport")
{
_profileService = profileService;
}
protected override void MapToResource(NetImportResource resource, NetImportDefinition definition)
@ -14,6 +18,20 @@ namespace NzbDrone.Api.NetImport
base.MapToResource(resource, definition);
resource.Enabled = definition.Enabled;
Field theField = null;
int index = 0;
foreach (var field in resource.Fields)
{
if (field.Label == "Quality")
{
index = resource.Fields.FindIndex(f => f.Label == field.Label);
field.SelectOptions =
_profileService.All().ConvertAll(p => new SelectOption {Name = p.Name, Value = p.Id});
theField = field;
}
}
}
protected override void MapToModel(NetImportDefinition definition, NetImportResource resource)

@ -3,7 +3,7 @@ using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(119)]
[Migration(125)]
public class create_netimport_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()

@ -1,7 +1,7 @@
var _ = require('underscore');
var AppLayout = require('../../../AppLayout');
var Backbone = require('backbone');
var SchemaCollection = require('../IndexerCollection');
var SchemaCollection = require('../NetImportCollection');
var AddCollectionView = require('./IndexerAddCollectionView');
module.exports = {

@ -1,25 +0,0 @@
var Marionette = require('marionette');
var ItemView = require('./IndexerItemView');
var SchemaModal = require('./Add/IndexerSchemaModal');
module.exports = Marionette.CompositeView.extend({
itemView : ItemView,
itemViewContainer : '.indexer-list',
template : 'Settings/Indexers/IndexerCollectionViewTemplate',
ui : {
'addCard' : '.x-add-card'
},
events : {
'click .x-add-card' : '_openSchemaModal'
},
appendHtml : function(collectionView, itemView, index) {
collectionView.ui.addCard.parent('li').before(itemView.el);
},
_openSchemaModal : function() {
SchemaModal.open(this.collection);
}
});

@ -1,16 +0,0 @@
<fieldset>
<legend>Indexers</legend>
<div class="row">
<div class="col-md-12">
<ul class="indexer-list thingies">
<li>
<div class="indexer-item thingy add-card x-add-card">
<span class="center well">
<i class="icon-sonarr-add"/>
</span>
</div>
</li>
</ul>
</div>
</div>
</fieldset>

@ -1,24 +0,0 @@
var AppLayout = require('../../AppLayout');
var Marionette = require('marionette');
var EditView = require('./Edit/IndexerEditView');
module.exports = Marionette.ItemView.extend({
template : 'Settings/Indexers/IndexerItemViewTemplate',
tagName : 'li',
events : {
'click' : '_edit'
},
initialize : function() {
this.listenTo(this.model, 'sync', this.render);
},
_edit : function() {
var view = new EditView({
model : this.model,
targetCollection : this.model.collection
});
AppLayout.modalRegion.show(view);
}
});

@ -1,27 +0,0 @@
<div class="indexer-item thingy">
<div>
<h3>{{name}}</h3>
</div>
<div class="settings">
{{#if supportsRss}}
{{#if enableRss}}
<span class="label label-success">RSS</span>
{{else}}
<span class="label label-default">RSS</span>
{{/if}}
{{else}}
<span class="label label-default label-disabled">RSS</span>
{{/if}}
{{#if supportsSearch}}
{{#if enableSearch}}
<span class="label label-success">Search</span>
{{else}}
<span class="label label-default">Search</span>
{{/if}}
{{else}}
<span class="label label-default label-disabled">Search</span>
{{/if}}
</div>
</div>

@ -1,30 +0,0 @@
var Marionette = require('marionette');
var IndexerCollection = require('./IndexerCollection');
var CollectionView = require('./IndexerCollectionView');
var OptionsView = require('./Options/IndexerOptionsView');
var RestrictionCollection = require('./Restriction/RestrictionCollection');
var RestrictionCollectionView = require('./Restriction/RestrictionCollectionView');
module.exports = Marionette.Layout.extend({
template : 'Settings/Indexers/IndexerLayoutTemplate',
regions : {
indexers : '#x-indexers-region',
indexerOptions : '#x-indexer-options-region',
restriction : '#x-restriction-region'
},
initialize : function() {
this.indexersCollection = new IndexerCollection();
this.indexersCollection.fetch();
this.restrictionCollection = new RestrictionCollection();
this.restrictionCollection.fetch();
},
onShow : function() {
this.indexers.show(new CollectionView({ collection : this.indexersCollection }));
this.indexerOptions.show(new OptionsView({ model : this.model }));
this.restriction.show(new RestrictionCollectionView({ collection : this.restrictionCollection }));
}
});

@ -1,5 +0,0 @@
<div id="x-indexers-region"></div>
<div class="form-horizontal">
<div id="x-indexer-options-region"></div>
<div id="x-restriction-region"></div>
</div>

@ -0,0 +1,16 @@
<fieldset>
<legend>Lists</legend>
<div class="row">
<div class="col-md-12">
<ul class="list-list thingies">
<li>
<div class="list-item thingy add-card x-add-card">
<span class="center well">
<i class="icon-sonarr-add"/>
</span>
</div>
</li>
</ul>
</div>
</div>
</fieldset>

@ -0,0 +1,25 @@
var Marionette = require('marionette');
var ItemView = require('./NetImportItemView');
var SchemaModal = require('./Add/IndexerSchemaModal');
module.exports = Marionette.CompositeView.extend({
itemView : ItemView,
itemViewContainer : '.list-list',
template : 'Settings/NetImport/NetImportCollectionViewTemplate',
ui : {
'addCard' : '.x-add-card'
},
events : {
'click .x-add-card' : '_openSchemaModal'
},
appendHtml : function(collectionView, itemView, index) {
collectionView.ui.addCard.parent('li').before(itemView.el);
},
_openSchemaModal : function() {
SchemaModal.open(this.collection);
}
});

@ -0,0 +1,24 @@
var AppLayout = require('../../AppLayout');
var Marionette = require('marionette');
var EditView = require('./Edit/IndexerEditView');
module.exports = Marionette.ItemView.extend({
template : 'Settings/NetImport/NetImportItemViewTemplate',
tagName : 'li',
events : {
'click' : '_edit'
},
initialize : function() {
this.listenTo(this.model, 'sync', this.render);
},
_edit : function() {
var view = new EditView({
model : this.model,
targetCollection : this.model.collection
});
AppLayout.modalRegion.show(view);
}
});

@ -0,0 +1,8 @@
<div class="list-item thingy">
<div>
<h3>{{name}}</h3>
</div>
<div class="settings">
</div>
</div>

@ -0,0 +1,23 @@
var Marionette = require('marionette');
var NetImportCollection = require('./NetImportCollection');
var CollectionView = require('./NetImportCollectionView');
var OptionsView = require('./Options/IndexerOptionsView');
module.exports = Marionette.Layout.extend({
template : 'Settings/NetImport/NetImportLayoutTemplate',
regions : {
lists : '#x-lists-region',
listOption : '#x-list-options-region',
},
initialize : function() {
this.indexersCollection = new NetImportCollection();
this.indexersCollection.fetch();
},
onShow : function() {
this.lists.show(new CollectionView({ collection : this.indexersCollection }));
this.listOption.show(new OptionsView({ model : this.model }));
}
});

@ -0,0 +1,4 @@
<div id="x-lists-region"></div>
<div class="form-horizontal">
<div id="x-list-options-region"></div>
</div>

@ -13,6 +13,8 @@ var IndexerLayout = require('./Indexers/IndexerLayout');
var IndexerCollection = require('./Indexers/IndexerCollection');
var IndexerSettingsModel = require('./Indexers/IndexerSettingsModel');
var NetImportSettingsModel = require("./NetImport/NetImportSettingsModel");
var NetImportCollection = require('./NetImport/NetImportCollection');
var NetImportLayout = require('./NetImport/NetImportLayout');
var DownloadClientLayout = require('./DownloadClient/DownloadClientLayout');
var DownloadClientSettingsModel = require('./DownloadClient/DownloadClientSettingsModel');
var NotificationCollectionView = require('./Notifications/NotificationCollectionView');
@ -102,6 +104,7 @@ module.exports = Marionette.Layout.extend({
self.quality.show(new QualityLayout());
self.indexers.show(new IndexerLayout({ model : self.indexerSettings }));
self.downloadClient.show(new DownloadClientLayout({ model : self.downloadClientSettings }));
self.netImport.show(new NetImportLayout({model : self.netImportSettings}));
self.notifications.show(new NotificationCollectionView({ collection : self.notificationCollection }));
self.metadata.show(new MetadataLayout());
self.general.show(new GeneralView({ model : self.generalSettings }));
@ -190,7 +193,7 @@ module.exports = Marionette.Layout.extend({
e.preventDefault();
}
this.ui.downloadClientTab.tab('show');
this.ui.netImportTab.tab('show');
this._navigate('settings/netimport');
},

Loading…
Cancel
Save