Added test button to notification edit

pull/3113/head
Mark McDowall 12 years ago
parent 38589742e3
commit 1f4cf0034e

@ -34,6 +34,7 @@ namespace NzbDrone.Api.Notifications
var notificationResource = new NotificationResource();
notificationResource.InjectFrom(notification);
notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
notificationResource.Command = String.Format("test{0}", notification.Implementation.ToLowerInvariant());
result.Add(notificationResource);
}

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

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using NzbDrone.Api.ClientSchema;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Annotations;
@ -21,8 +22,6 @@ namespace NzbDrone.Api.Notifications
private List<NotificationResource> GetSchema()
{
//Need to get all the possible Notification's same as we would for settiings (but keep them empty)
var notifications = _notificationService.Schema();
var result = new List<NotificationResource>(notifications.Count);
@ -32,6 +31,7 @@ namespace NzbDrone.Api.Notifications
var notificationResource = new NotificationResource();
notificationResource.InjectFrom(notification);
notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
notificationResource.Command = String.Format("test{0}", notification.Implementation.ToLowerInvariant());
result.Add(notificationResource);
}

@ -107,11 +107,16 @@ namespace NzbDrone.Core.Notifications.Xbmc
Username = message.Username,
Password = message.Password
};
Logger.Trace("Determining version of XBMC Host: {0}", settings.Address);
var version = GetJsonVersion(settings);
Logger.Trace("Version is: {0}", version);
if (version == new XbmcVersion(0))
{
throw new InvalidXbmcVersionException("Verion received from XBMC is invalid, please correct your settings.");
}
Notify(settings, "Test Notification", "Success! XBMC has been successfully configured!");
}
}

@ -1,11 +1,17 @@
"use strict";
define(['app'], function () {
NzbDrone.Commands.Execute = function (name) {
NzbDrone.Commands.Execute = function (name, properties) {
var data = { command: name };
if (properties !== undefined) {
$.extend(data, properties);
}
return $.ajax({
type: 'POST',
url : NzbDrone.Constants.ApiRoot + '/command',
data: JSON.stringify({command: name})
data: JSON.stringify(data)
});
};
});

@ -57,6 +57,13 @@
</div>
{{formBuilder}}
<div class="control-group">
<label class="control-label">Test</label>
<div class="controls">
<button class="btn x-test"><i class="icon-question x-test-icon"/> Test</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">

@ -11,8 +11,14 @@ define([
template : 'Settings/Notifications/EditTemplate',
events: {
'click .x-save': '_saveNotification',
'click .x-remove': '_deleteNotification'
'click .x-save' : '_saveNotification',
'click .x-remove' : '_deleteNotification',
'click .x-test' : '_test'
},
ui: {
testButton : '.x-test',
testIcon : '.x-test-icon'
},
initialize: function (options) {
@ -40,6 +46,50 @@ define([
_saveSuccess: function () {
this.notificationCollection.add(this.model, { merge: true });
NzbDrone.modalRegion.closeModal();
},
_test: function () {
var command = this.model.get('command');
if (command) {
this.idle = false;
this.ui.testButton.addClass('disabled');
this.ui.testIcon.removeClass('icon-question');
this.ui.testIcon.addClass('icon-spinner icon-spin');
var properties = {};
_.each(this.model.attributes.fields, function (field) {
properties[field.name] = field.value;
});
var self = this;
var commandPromise = NzbDrone.Commands.Execute(command, properties);
commandPromise.done(function () {
NzbDrone.Shared.Messenger.show({
message: 'Notification settings tested successfully'
});
});
commandPromise.fail(function (options) {
if (options.readyState === 0 || options.status === 0) {
return;
}
NzbDrone.Shared.Messenger.show({
message: 'Failed to test notification settings',
type : 'error'
});
});
commandPromise.always(function () {
if (!self.isClosed) {
self.ui.testButton.removeClass('disabled');
self.ui.testIcon.addClass('icon-question');
self.ui.testIcon.removeClass('icon-spinner icon-spin');
self.idle = true;
}
});
}
}
});
});

Loading…
Cancel
Save