Notification settings added to the UI

This commit is contained in:
Mark McDowall 2013-05-19 21:19:54 -07:00
parent a153599d50
commit c5376319fe
21 changed files with 168 additions and 35 deletions

View File

@ -7,5 +7,6 @@
public string Label { get; set; } public string Label { get; set; }
public string HelpText { get; set; } public string HelpText { get; set; }
public string Value { get; set; } public string Value { get; set; }
public string Type { get; set; }
} }
} }

View File

@ -25,7 +25,7 @@ namespace NzbDrone.Api.ClientSchema
Label = fieldAttribute.Label, Label = fieldAttribute.Label,
HelpText = fieldAttribute.HelpText, HelpText = fieldAttribute.HelpText,
Order = fieldAttribute.Order, Order = fieldAttribute.Order,
Type = fieldAttribute.Type.ToString().ToLowerInvariant()
}; };
var value = propertyInfo.GetValue(model, null); var value = propertyInfo.GetValue(model, null);

View File

@ -4,8 +4,6 @@ using System.Linq;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Api.Commands namespace NzbDrone.Api.Commands
{ {
@ -24,8 +22,6 @@ namespace NzbDrone.Api.Commands
private CommandResource RunCommand(CommandResource resource) private CommandResource RunCommand(CommandResource resource)
{ {
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(new RemoteEpisode()));
var commandType = var commandType =
_container.GetImplementations(typeof(ICommand)) _container.GetImplementations(typeof(ICommand))
.Single(c => c.Name.Replace("Command", "") .Single(c => c.Name.Replace("Command", "")

View File

@ -7,8 +7,9 @@ namespace NzbDrone.Api.Notifications
{ {
public class NotificationResource : RestResource public class NotificationResource : RestResource
{ {
public Boolean Enable { get; set; }
public String Name { get; set; } public String Name { get; set; }
public Boolean OnGrab { get; set; }
public Boolean OnDownload { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
} }
} }

View File

@ -13,5 +13,13 @@ namespace NzbDrone.Core.Annotations
public int Order { get; private set; } public int Order { get; private set; }
public string Label { get; set; } public string Label { get; set; }
public string HelpText { get; set; } public string HelpText { get; set; }
public FieldType Type { get; set; }
}
public enum FieldType
{
Textbox,
Password,
Checkbox
} }
} }

View File

@ -39,7 +39,6 @@ namespace NzbDrone.Core.Notifications
public List<Notification> All() public List<Notification> All()
{ {
var test = _notificationRepository.All();//.Select(ToNotification).ToList();
return _notificationRepository.All().Select(ToNotification).ToList(); return _notificationRepository.All().Select(ToNotification).ToList();
} }

View File

@ -21,14 +21,21 @@ namespace NzbDrone.Core.Notifications.Xbmc
{ {
const string header = "NzbDrone [TV] - Grabbed"; const string header = "NzbDrone [TV] - Grabbed";
_xbmcProvider.Notify(Settings, header, message); if (Settings.Notify)
{
_xbmcProvider.Notify(Settings, header, message);
}
} }
public override void OnDownload(string message, Series series) public override void OnDownload(string message, Series series)
{ {
const string header = "NzbDrone [TV] - Downloaded"; const string header = "NzbDrone [TV] - Downloaded";
_xbmcProvider.Notify(Settings, header, message); if (Settings.Notify)
{
_xbmcProvider.Notify(Settings, header, message);
}
UpdateAndClean(series); UpdateAndClean(series);
} }

View File

@ -8,25 +8,28 @@ namespace NzbDrone.Core.Notifications.Xbmc
{ {
public class XbmcSettings : INotifcationSettings public class XbmcSettings : INotifcationSettings
{ {
[FieldDefinition(0, Label = "Host", HelpText = "XBMC Hostnname or IP")] [FieldDefinition(0, Label = "Host")]
public String Host { get; set; } public String Host { get; set; }
[FieldDefinition(1, Label = "Port", HelpText = "Webserver port")] [FieldDefinition(1, Label = "Port")]
public Int32 Port { get; set; } public Int32 Port { get; set; }
[FieldDefinition(2, Label = "Username", HelpText = "Webserver Username")] [FieldDefinition(2, Label = "Username")]
public String Username { get; set; } public String Username { get; set; }
[FieldDefinition(3, Label = "Password", HelpText = "Webserver Password ")] [FieldDefinition(3, Label = "Password", Type = FieldType.Password)]
public String Password { get; set; } public String Password { get; set; }
[FieldDefinition(4, Label = "Update Library", HelpText = "Update Library on Download & Rename?")] [FieldDefinition(4, Label = "GUI Notification", HelpText = "Show GUI notifications?", Type = FieldType.Checkbox)]
public Boolean Notify { get; set; }
[FieldDefinition(5, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Checkbox)]
public Boolean UpdateLibrary { get; set; } public Boolean UpdateLibrary { get; set; }
[FieldDefinition(5, Label = "Update Library", HelpText = "Clean Library after update?")] [FieldDefinition(6, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Checkbox)]
public Boolean CleanLibrary { get; set; } public Boolean CleanLibrary { get; set; }
[FieldDefinition(6, Label = "Always Update", HelpText = "Update Library even when a video is playing?")] [FieldDefinition(7, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Checkbox)]
public Boolean AlwaysUpdate { get; set; } public Boolean AlwaysUpdate { get; set; }
public bool IsValid public bool IsValid

View File

@ -12,8 +12,10 @@
<div class="btn btn-primary slide-button"></div> <div class="btn btn-primary slide-button"></div>
</label> </label>
{{#if helpText}}
<span class="help-inline-checkbox"> <span class="help-inline-checkbox">
<i class="icon-question-sign" title="{{helpText}}"></i> <i class="icon-question-sign" title="{{helpText}}"></i>
</span> </span>
{{/if}}
</div> </div>
</div> </div>

View File

@ -0,0 +1,12 @@
<div class="control-group">
<label class="control-label">{{label}}</label>
<div class="controls">
<input type="password" name="fields.{{order}}.value"/>
{{#if helpText}}
<span class="help-inline">
<i class="icon-question-sign" title="{{helpText}}"></i>
</span>
{{/if}}
</div>
</div>

View File

@ -3,8 +3,10 @@
<div class="controls"> <div class="controls">
<input type="text" name="fields.{{order}}.value"/> <input type="text" name="fields.{{order}}.value"/>
<span class="help-inline"> {{#if helpText}}
<i class="icon-question-sign" title="{{helpText}}"></i> <span class="help-inline">
</span> <i class="icon-question-sign" title="{{helpText}}"></i>
</span>
{{/if}}
</div> </div>
</div> </div>

View File

@ -12,6 +12,14 @@ Handlebars.registerHelper('formField', function () {
return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']);
} }
if (this.type === 'password') {
return Handlebars.helpers.partial.apply(this, ['Form/PasswordTemplate']);
}
if (this.type === 'checkbox') {
return Handlebars.helpers.partial.apply(this, ['Form/CheckboxTemplate']);
}
return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']);
}); });

View File

@ -0,0 +1,7 @@
"use strict";
define(['app', 'Settings/Notifications/Model'], function () {
NzbDrone.Settings.Notifications.Collection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/notification',
model: NzbDrone.Settings.Notifications.Model
});
});

View File

@ -0,0 +1,5 @@
<div class="row">
<div class="span12">
<div id="x-notifications" class="form-horizontal"></div>
</div>
</div>

View File

@ -0,0 +1,8 @@
'use strict';
define(['app', 'Settings/Notifications/ItemView'], function () {
NzbDrone.Settings.Notifications.CollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Settings.Notifications.ItemView,
itemViewContainer : '#x-notifications',
template : 'Settings/Notifications/CollectionTemplate'
});
});

View File

@ -0,0 +1,47 @@
<fieldset>
<legend>{{name}}</legend>
<div class="control-group">
<label class="control-label">On Grab</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="onGrab"/>
<p>
<span>On</span>
<span>Off</span>
</p>
<div class="btn btn-primary slide-button"></div>
</label>
<span class="help-inline-checkbox">
<i class="icon-question-sign" title="Do you want to get notifications when episodes are grabbed?"></i>
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">On Download</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="onDownload"/>
<p>
<span>On</span>
<span>Off</span>
</p>
<div class="btn btn-primary slide-button"></div>
</label>
<span class="help-inline-checkbox">
<i class="icon-question-sign" title="Do you want to get notifications when episodes are downloaded?"></i>
</span>
</div>
</div>
{{#each fields}}
{{formField}}
{{/each}}
</fieldset>

View File

@ -0,0 +1,33 @@
"use strict";
define([
'app',
'Settings/Notifications/Collection'
], function () {
NzbDrone.Settings.Notifications.ItemView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Notifications/ItemTemplate',
initialize: function () {
NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this);
},
saveSettings: function () {
//this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings"));
},
syncNotification: function (success, error) {
return {
success: function () {
window.alert(success);
},
error: function () {
window.alert(error);
}
};
}
});
});

View File

@ -0,0 +1,5 @@
"use strict";
define(['app'], function () {
NzbDrone.Settings.Notifications.Model = Backbone.DeepModel.extend({
});
});

View File

@ -1,3 +0,0 @@
<div>
Notification settings will go here
</div>

View File

@ -1,11 +0,0 @@
'use strict';
define([
'app', 'Settings/SettingsModel'
], function () {
NzbDrone.Settings.Notifications.NotificationsView = Backbone.Marionette.ItemView.extend({
template: 'Settings/Notifications/NotificationsTemplate'
});
});

View File

@ -5,7 +5,7 @@ define([
'Settings/Quality/QualityLayout', 'Settings/Quality/QualityLayout',
'Settings/Indexers/CollectionView', 'Settings/Indexers/CollectionView',
'Settings/DownloadClient/DownloadClientView', 'Settings/DownloadClient/DownloadClientView',
'Settings/Notifications/NotificationsView', 'Settings/Notifications/CollectionView',
'Settings/System/SystemView', 'Settings/System/SystemView',
'Settings/Misc/MiscView' 'Settings/Misc/MiscView'
], ],
@ -117,6 +117,9 @@ define([
this.indexerSettings = new NzbDrone.Settings.Indexers.Collection(); this.indexerSettings = new NzbDrone.Settings.Indexers.Collection();
this.indexerSettings.fetch(); this.indexerSettings.fetch();
this.notificationSettings = new NzbDrone.Settings.Notifications.Collection();
this.notificationSettings.fetch();
if (options.action) { if (options.action) {
this.action = options.action.toLowerCase(); this.action = options.action.toLowerCase();
} }
@ -127,7 +130,7 @@ define([
this.quality.show(new NzbDrone.Settings.Quality.QualityLayout({settings: this.settings})); this.quality.show(new NzbDrone.Settings.Quality.QualityLayout({settings: this.settings}));
this.indexers.show(new NzbDrone.Settings.Indexers.CollectionView({collection: this.indexerSettings})); this.indexers.show(new NzbDrone.Settings.Indexers.CollectionView({collection: this.indexerSettings}));
this.downloadClient.show(new NzbDrone.Settings.DownloadClient.DownloadClientView({model: this.settings})); this.downloadClient.show(new NzbDrone.Settings.DownloadClient.DownloadClientView({model: this.settings}));
this.notifications.show(new NzbDrone.Settings.Notifications.NotificationsView({model: this.settings})); this.notifications.show(new NzbDrone.Settings.Notifications.CollectionView({collection: this.notificationSettings}));
this.system.show(new NzbDrone.Settings.System.SystemView({model: this.settings})); this.system.show(new NzbDrone.Settings.System.SystemView({model: this.settings}));
this.misc.show(new NzbDrone.Settings.Misc.MiscView({model: this.settings})); this.misc.show(new NzbDrone.Settings.Misc.MiscView({model: this.settings}));
}, },