mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Add notifier text preview
This commit is contained in:
parent
cb5252b8d4
commit
d874697eef
6 changed files with 91 additions and 4 deletions
|
@ -151,6 +151,13 @@
|
|||
<input class="form-control" type="text" id="${action['name']}_subject" name="${action['name']}_subject" value="${notifier['notify_text'][action['name']]['subject']}" data-parsley-trigger="change" required>
|
||||
<p class="help-block">Set custom arguments passed to the script.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<input type="button" class="btn btn-bright notifier-text-preview" data-action="${action['name']}" value="Preview Arguments">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -171,6 +178,13 @@
|
|||
<textarea class="form-control" id="${action['name']}_body" name="${action['name']}_body" data-parsley-trigger="change" data-autoresize required>${notifier['notify_text'][action['name']]['body']}</textarea>
|
||||
<p class="help-block">Set a custom body.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<input type="button" class="btn btn-bright notifier-text-preview" data-action="${action['name']}" value="Preview Text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -335,6 +349,28 @@
|
|||
})
|
||||
% endif
|
||||
|
||||
$('.notifier-text-preview').click(function () {
|
||||
var action = $(this).data('action');
|
||||
var subject = $('#' + action + '_subject').val();
|
||||
var body = $('#' + action + '_body').val();
|
||||
|
||||
$.ajax({
|
||||
url: 'get_notify_text_preview',
|
||||
data: {
|
||||
notify_action: action,
|
||||
subject: subject,
|
||||
body: body,
|
||||
agent_id: "${notifier['agent_id']}",
|
||||
agent_name: "${notifier['agent_name']}"
|
||||
},
|
||||
cache: false,
|
||||
async: true,
|
||||
complete: function (xhr, status) {
|
||||
$("#notifier-text-preview-modal").html(xhr.responseText).modal('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#test_notifier').click(function () {
|
||||
doAjaxCall('set_notifier_config', $(this), 'tabs', true, false, sendTestNotification);
|
||||
});
|
||||
|
|
23
data/interfaces/default/notifier_text_preview.html
Normal file
23
data/interfaces/default/notifier_text_preview.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
% if text:
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
|
||||
<h4 class="modal-title">Notification Text Preview</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
% for item in text:
|
||||
<div style="padding-bottom: 10px;">
|
||||
<h4>${item['media_type'].capitalize()}</h4>
|
||||
<pre>${item['subject']}</pre>
|
||||
% if agent != 'scripts':
|
||||
<pre>${item['body']}</pre>
|
||||
% endif
|
||||
</div>
|
||||
% endfor
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
% endif
|
|
@ -1925,6 +1925,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="notifier-text-preview-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="notifier-text-preview-modal">
|
||||
</div>
|
||||
<div id="changelog-modal" class="modal fade wide" tabindex="-1" role="dialog" aria-labelledby="changelog-modal">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
|
|
|
@ -39,7 +39,7 @@ class BleachSanitizerMixin(HTMLSanitizerMixin):
|
|||
if isinstance(self.allowed_attributes, dict):
|
||||
allowed_attributes = self.allowed_attributes.get(
|
||||
token['name'], [])
|
||||
print callable(allowed_attributes)
|
||||
#print callable(allowed_attributes)
|
||||
if not callable(allowed_attributes):
|
||||
allowed_attributes += self.wildcard_attributes
|
||||
else:
|
||||
|
|
|
@ -557,7 +557,7 @@ def build_server_notify_params(notify_action=None, **kwargs):
|
|||
return available_params
|
||||
|
||||
|
||||
def build_notify_text(subject='', body='', notify_action=None, parameters=None, agent_id=None):
|
||||
def build_notify_text(subject='', body='', notify_action=None, parameters=None, agent_id=None, test=False):
|
||||
media_type = parameters.get('media_type')
|
||||
|
||||
all_tags = r'<movie>.*?</movie>|' \
|
||||
|
@ -596,8 +596,13 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
|
|||
default_body = default_action.get('body', '')
|
||||
|
||||
# Use default subject and body if they are blank
|
||||
subject = subject or default_subject
|
||||
body = body or default_body
|
||||
# only if the notification is not script
|
||||
if agent_id != 15:
|
||||
subject = subject or default_subject
|
||||
body = body or default_body
|
||||
|
||||
if test:
|
||||
return subject, body
|
||||
|
||||
try:
|
||||
subject = unicode(subject).format(**parameters)
|
||||
|
|
|
@ -39,6 +39,7 @@ import http_handler
|
|||
import libraries
|
||||
import log_reader
|
||||
import logger
|
||||
import notification_handler
|
||||
import notifiers
|
||||
import plextv
|
||||
import plexivity_import
|
||||
|
@ -2985,6 +2986,26 @@ class WebInterface(object):
|
|||
else:
|
||||
return {'result': 'error', 'message': 'Failed to add notification agent.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
def get_notify_text_preview(self, notify_action='', subject='', body='', agent_id=0, agent_name='', **kwargs):
|
||||
if str(agent_id).isdigit():
|
||||
agent_id = int(agent_id)
|
||||
|
||||
text = []
|
||||
|
||||
for media_type in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track'):
|
||||
test_subject, test_body = notification_handler.build_notify_text(subject=subject,
|
||||
body=body,
|
||||
notify_action=notify_action,
|
||||
parameters={'media_type': media_type},
|
||||
agent_id=agent_id,
|
||||
test=True)
|
||||
|
||||
text.append({'media_type': media_type, 'subject': test_subject, 'body': test_body})
|
||||
|
||||
return serve_template(templatename="notifier_text_preview.html", text=text, agent=agent_name)
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi("notify")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue