Actually set notifier config when sending notifications

This commit is contained in:
JonnyWong16 2016-10-09 15:19:58 -07:00 committed by JonnyWong16
parent f42d7b0da0
commit 44f39e7fea
3 changed files with 16 additions and 14 deletions

View file

@ -14,7 +14,7 @@
<div class="row"> <div class="row">
<ul class="nav nav-tabs list-unstyled" role="tablist"> <ul class="nav nav-tabs list-unstyled" role="tablist">
<li role="presentation" class="active"><a href="#tabs-config" aria-controls="tabs-config" role="tab" data-toggle="tab">Configuration</a></li> <li role="presentation" class="active"><a href="#tabs-config" aria-controls="tabs-config" role="tab" data-toggle="tab">Configuration</a></li>
<li role="presentation"><a href="#tabs-triggers" aria-controls="tabs-triggers" role="tab" data-toggle="tab">Triggers</a></li> <li role="presentation"><a href="#tabs-notify_triggers" aria-controls="tabs-notify_triggers" role="tab" data-toggle="tab">Notification Triggers</a></li>
<li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">Notification Text</a></li> <li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">Notification Text</a></li>
<li role="presentation"><a href="#tabs-test_notifications" aria-controls="tabs-test_notifications" role="tab" data-toggle="tab">Test Notifications</a></li> <li role="presentation"><a href="#tabs-test_notifications" aria-controls="tabs-test_notifications" role="tab" data-toggle="tab">Test Notifications</a></li>
</ul> </ul>
@ -26,7 +26,7 @@
<div class="col-md-12"> <div class="col-md-12">
<input type="hidden" id="notifier_id" name="notifier_id" value="${notifier['id']}" /> <input type="hidden" id="notifier_id" name="notifier_id" value="${notifier['id']}" />
<input type="hidden" id="agent_id" name="agent_id" value="${notifier['agent_id']}" /> <input type="hidden" id="agent_id" name="agent_id" value="${notifier['agent_id']}" />
% for item in notifier['config']: % for item in notifier['config_options']:
% if item['input_type'] == 'help': % if item['input_type'] == 'help':
<div class="form-group"> <div class="form-group">
<label>${item['label']}</label> <label>${item['label']}</label>
@ -92,12 +92,12 @@
<input type="text" class="form-control" id="friendly_name" name="friendly_name" value="${notifier['friendly_name']}" size="30"> <input type="text" class="form-control" id="friendly_name" name="friendly_name" value="${notifier['friendly_name']}" size="30">
</div> </div>
</div> </div>
<p class="help-block">Optional: enter a friendly identifier the notification agent (e.g. Recently Added)</p> <p class="help-block">Optional: Enter a friendly identifier for the notification agent (e.g. Recently Added)</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div role="tabpanel" class="tab-pane" id="tabs-triggers"> <div role="tabpanel" class="tab-pane" id="tabs-notify_triggers">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<p class="help-block"> <p class="help-block">
@ -178,7 +178,7 @@
<div class="form-group"> <div class="form-group">
<label for="test_script">Script</label> <label for="test_script">Script</label>
<select class="form-control" id="test_script" name="test_script"> <select class="form-control" id="test_script" name="test_script">
% for key, value in sorted(notifier['config'][2]['select_options'].iteritems()): % for key, value in sorted(notifier['config_options'][2]['select_options'].iteritems()):
<option value="${key}">${value}</option> <option value="${key}">${value}</option>
% endfor % endfor
</select> </select>
@ -323,7 +323,7 @@
} }
} }
$("${', '.join(['#' + c['name'] for c in notifier['config'] if c.get('refresh')])}").on('change', function () { $("${', '.join(['#' + c['name'] for c in notifier['config_options'] if c.get('refresh')])}").on('change', function () {
// Reload modal to update certain fields // Reload modal to update certain fields
doAjaxCall('set_notifier_config', $(this), 'tabs', true, false, reloadModal); doAjaxCall('set_notifier_config', $(this), 'tabs', true, false, reloadModal);
return false; return false;

View file

@ -381,7 +381,8 @@ def get_notifier_config(notifier_id=None):
notifier_text[k] = {'subject': result.pop(k + '_subject'), notifier_text[k] = {'subject': result.pop(k + '_subject'),
'body': result.pop(k + '_body')} 'body': result.pop(k + '_body')}
result['config'] = notifier_config result['config'] = config
result['config_options'] = notifier_config
result['actions'] = notifier_actions result['actions'] = notifier_actions
result['notify_text'] = notifier_text result['notify_text'] = notifier_text
@ -478,7 +479,8 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs):
def send_notification(notifier_id=None, subject='', body='', notify_action='', **kwargs): def send_notification(notifier_id=None, subject='', body='', notify_action='', **kwargs):
notifier_config = get_notifier_config(notifier_id=notifier_id) notifier_config = get_notifier_config(notifier_id=notifier_id)
if notifier_config: if notifier_config:
agent = get_agent_class(notifier_config['agent_id']) agent = get_agent_class(agent_id=notifier_config['agent_id'],
config=notifier_config['config'])
return agent.notify(subject=subject, return agent.notify(subject=subject,
body=body, body=body,
action=notify_action, action=notify_action,

View file

@ -2897,6 +2897,11 @@ class WebInterface(object):
"incl_subject": 1, "incl_subject": 1,
"disable_web_preview": 0 "disable_web_preview": 0
}, },
"config_options": [{...}, ...]
"actions": {"on_play": 0,
"on_stop": 0,
...
},
"notify_text": {"on_play": {"subject": "...", "notify_text": {"on_play": {"subject": "...",
"body": "..." "body": "..."
} }
@ -2904,12 +2909,7 @@ class WebInterface(object):
"body": "..." "body": "..."
} }
... ...
}, }
"actions": {"on_play": 0,
"on_stop": 0,
...
}
} }
``` ```
""" """