More notificationUI changes, start notification updates

pull/4/head
Mark McDowall 12 years ago
parent c5376319fe
commit 63f2ba7f77

@ -1,5 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications;
using Omu.ValueInjecter; using Omu.ValueInjecter;
@ -12,7 +14,9 @@ namespace NzbDrone.Api.Notifications
public NotificationModule(INotificationService notificationService) public NotificationModule(INotificationService notificationService)
{ {
_notificationService = notificationService; _notificationService = notificationService;
GetResourceAll = GetAll; GetResourceAll = GetAll;
UpdateResource = Update;
} }
private List<NotificationResource> GetAll() private List<NotificationResource> GetAll()
@ -23,14 +27,42 @@ namespace NzbDrone.Api.Notifications
foreach (var notification in notifications) foreach (var notification in notifications)
{ {
var indexerResource = new NotificationResource(); var notificationResource = new NotificationResource();
indexerResource.InjectFrom(notification); notificationResource.InjectFrom(notification);
indexerResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings); notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
result.Add(indexerResource); result.Add(notificationResource);
} }
return result; return result;
} }
private NotificationResource Update(NotificationResource notificationResource)
{
//Todo: Convert Resource back to Settings
var notification = _notificationService.Get(notificationResource.Id);
notification.OnGrab = notificationResource.OnGrab;
notification.OnDownload = notificationResource.OnDownload;
var properties = notification.Settings.GetType().GetSimpleProperties();
foreach (var propertyInfo in properties)
{
var fieldAttribute = propertyInfo.GetAttribute<FieldDefinitionAttribute>(false);
if (fieldAttribute != null)
{
//Find coresponding field
var field = notificationResource.Fields.Find(f => f.Name == propertyInfo.Name);
propertyInfo.SetValue(notification.Settings, field.Value, null);
}
}
return notificationResource;
}
} }
} }

@ -11,5 +11,6 @@ namespace NzbDrone.Api.Notifications
public Boolean OnGrab { get; set; } public Boolean OnGrab { get; set; }
public Boolean OnDownload { get; set; } public Boolean OnDownload { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
public String Implementation { get; set; }
} }
} }

@ -13,5 +13,6 @@ namespace NzbDrone.Core.Notifications
public bool OnDownload { get; set; } public bool OnDownload { get; set; }
public INotifcationSettings Settings { get; set; } public INotifcationSettings Settings { get; set; }
public INotification Instance { get; set; } public INotification Instance { get; set; }
public string Implementation { get; set; }
} }
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using Newtonsoft.Json;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
@ -13,6 +14,7 @@ namespace NzbDrone.Core.Notifications
public interface INotificationService public interface INotificationService
{ {
List<Notification> All(); List<Notification> All();
Notification Get(int id);
} }
public class NotificationService public class NotificationService
@ -42,6 +44,11 @@ namespace NzbDrone.Core.Notifications
return _notificationRepository.All().Select(ToNotification).ToList(); return _notificationRepository.All().Select(ToNotification).ToList();
} }
public Notification Get(int id)
{
return ToNotification(_notificationRepository.Get(id));
}
private Notification ToNotification(NotificationDefinition definition) private Notification ToNotification(NotificationDefinition definition)
{ {
var notification = new Notification(); var notification = new Notification();
@ -50,6 +57,7 @@ namespace NzbDrone.Core.Notifications
notification.OnDownload = definition.OnDownload; notification.OnDownload = definition.OnDownload;
notification.Instance = GetInstance(definition); notification.Instance = GetInstance(definition);
notification.Name = definition.Name; notification.Name = definition.Name;
notification.Implementation = definition.Implementation;
notification.Settings = ((dynamic)notification.Instance).ImportSettingsFromJson(definition.Settings); notification.Settings = ((dynamic)notification.Instance).ImportSettingsFromJson(definition.Settings);
return notification; return notification;

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

@ -1,5 +1,12 @@
<div class="row"> <table class="table table-hover">
<div class="span12"> <thead>
<div id="x-notifications" class="form-horizontal"></div> <tr>
</div> <th>Type</th>
</div> <th>Name</th>
<th>On Grab</th>
<th>On Download</th>
<th>Controls</th>
</tr>
</thead>
<tbody></tbody>
</table>

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

@ -0,0 +1,67 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Edit</h3>
</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">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}}
{{debug}}
{{order}}
{{value}}
{{formField}}
{{/each}}
</div>
</div>
<div class="modal-footer">
<button class="btn btn-danger pull-left x-remove">delete</button>
<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/Notifications/Model'
], function () {
NzbDrone.Settings.Notifications.EditView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Notifications/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);
}
};
}
});
});

@ -1,47 +1,9 @@
<fieldset> <td><img src="/content/images/notifications/{{implementation}}.png" alt="{{implementation}}"/></td>
<legend>{{name}}</legend> <td name="name"></td>
<td name="onGrab"></td>
<div class="control-group"> <td name="onDownload"></td>
<label class="control-label">On Grab</label> <td name="cutoffName"></td>
<td>
<div class="controls"> <i class="icon-cog x-edit" title="Edit"></i>
<label class="checkbox toggle well"> | Delete
<input type="checkbox" name="onGrab"/> </td>
<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>

@ -2,32 +2,28 @@
define([ define([
'app', 'app',
'Settings/Notifications/Collection' 'Settings/Notifications/Collection',
'Settings/Notifications/EditView'
], function () { ], function () {
NzbDrone.Settings.Notifications.ItemView = Backbone.Marionette.ItemView.extend({ NzbDrone.Settings.Notifications.ItemView = Backbone.Marionette.ItemView.extend({
template : 'Settings/Notifications/ItemTemplate', template : 'Settings/Notifications/ItemTemplate',
initialize: function () { tagName: 'tr',
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")); events: {
'click .x-edit' : 'edit',
'click .x-remove': 'remove'
}, },
edit: function () {
var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model});
NzbDrone.modalRegion.show(view);
},
syncNotification: function (success, error) { remove: function () {
return { var view = new NzbDrone.Settings.Notifications.DeleteView({ model: this.model});
success: function () { NzbDrone.modalRegion.show(view);
window.alert(success);
},
error: function () {
window.alert(error);
}
};
} }
}); });
}); });

@ -16,16 +16,16 @@ define([
}, },
events: { events: {
'click .x-edit' : 'editSeries', 'click .x-edit' : 'edit',
'click .x-remove': 'removeSeries' 'click .x-remove': 'remove'
}, },
editSeries: function () { edit: function () {
var view = new NzbDrone.Settings.Quality.Profile.EditQualityProfileView({ model: this.model}); var view = new NzbDrone.Settings.Quality.Profile.EditQualityProfileView({ model: this.model});
NzbDrone.modalRegion.show(view); NzbDrone.modalRegion.show(view);
}, },
removeSeries: function () { remove: function () {
var view = new NzbDrone.Series.Delete.DeleteSeriesView({ model: this.model }); var view = new NzbDrone.Series.Delete.DeleteSeriesView({ model: this.model });
NzbDrone.modalRegion.show(view); NzbDrone.modalRegion.show(view);
} }

Loading…
Cancel
Save