Permalink
Browse files

Initial implementation of email renderers

  • Loading branch information...
kiwiz committed Jun 6, 2017
1 parent c97d2e2 commit afe37bc9cb45217efef272109fa2a6481744e589
@@ -302,6 +302,9 @@ a {
.query-entry a.query {
width: 100%;
}
.preview a {
color: blue;
}
/**
* Theme fixes
@@ -33,6 +33,8 @@ define(function(require) {
'searches/changelogmodal': Handlebars.compile(require('text!templatefiles/searches/changelogmodal.html')),
'searches/statisticsmodal': Handlebars.compile(require('text!templatefiles/searches/statisticsmodal.html')),
'searches/jobsmodal': Handlebars.compile(require('text!templatefiles/searches/jobsmodal.html')),
'searches/fieldentry': Handlebars.compile(require('text!templatefiles/searches/fieldentry.html')),
'searches/fieldtable': Handlebars.compile(require('text!templatefiles/searches/fieldtable.html')),
'element': Handlebars.compile(require('text!templatefiles/element.html')),
'elementcompact': Handlebars.compile(require('text!templatefiles/elementcompact.html')),
'searches/search/ping/a': Handlebars.compile(require('text!templatefiles/searches/search/ping/a.html')),
@@ -199,8 +199,7 @@ define(function(require) {
'acknowledge',
'unresolve',
'addnote',
'savealertrenderers',
'savesearchrenderers'
'saverenderers'
];
for(var i = 0; i < actions.length; ++i) {
this.listenTo(this.App.Bus, actions[i], _.partial(this.processAction, actions[i]));
@@ -358,8 +357,7 @@ define(function(require) {
acknowledge: {action: 'acknowledge', type: 'success', icon: 'flash', name: 'Acknowledge', hotkey: 'K', help: 'Mark the selected Alert(s) as in progress'},
unresolve: {action: 'unresolve', type: 'success', icon: 'remove', name: 'Unresolve', hotkey: 'N', help: 'Mark the selected Alert(s) as new'},
addnote: {action: 'addnote', type: 'success', icon: 'floppy-disk', name: 'Add Note', hotkey: 'T', help: 'Add a note to the Alert'},
savealertrenderers: {action: 'savealertrenderers', type: 'success', icon: 'th', name: 'Save Alert Renderers', hotkey: 'L', help: 'Save the current set of renderers to the Alert'},
savesearchrenderers: {action: 'savesearchrenderers', type: 'success', icon: 'th-list', name: 'Save Search Renderers', hotkey: 'H', help: 'Save the current set of renderers to the Search'}
saverenderers: {action: 'saverenderers', type: 'success', icon: 'th-list', name: 'Save Renderers', hotkey: 'H', help: 'Save the current set of renderers'}
},
events: {
'click .alert-action': 'action',
@@ -443,12 +441,10 @@ define(function(require) {
this.groups.push(state_group);
// Determine whether to show the save button. Used on the single Alert page.
var misc_group = [this.actions.addnote];
this.groups.push([this.actions.addnote]);
if(this.settings.single) {
misc_group.push(this.actions.savealertrenderers);
misc_group.push(this.actions.savesearchrenderers);
this.groups.push([this.actions.saverenderers]);
}
this.groups.push(misc_group);
}
for(var i = 0; i < this.groups.length; ++i) {
@@ -375,16 +375,10 @@ define(function(require) {
var data = JSON.stringify(this.model);
Util.download(data, 'alert_' + this.model.id + '.json');
},
savealertrenderers: function() {
this.App.showLoader();
var out_mapping = Renderer.serialize(this.getView('collection[]'));
this.saveModel({renderer_data: out_mapping}, this.cbRendered(this.update));
},
savesearchrenderers: function() {
saverenderers: function() {
this.App.showLoader();
var search = this.App.Data.Searches.get(this.model.get('search_id'));
var out_mapping = Renderer.serialize(this.getView('collection[]'));
var out_mapping = _.extend({}, search.get('renderer_data'), Renderer.serialize(this.getView('collection[]')));
var data = {
renderer_data: out_mapping,
change_description: 'Modify renderer mapping'
@@ -86,6 +86,10 @@ define(function(require) {
className: 'col-xs-12',
template: _.constant(''),
// Title of the collection.
title: '',
// Whether to show a count of entries.
hide_count: false,
// The view to render for each model in the collection.
subView: null,
// Variables to pass to the view.
@@ -105,7 +109,7 @@ define(function(require) {
}
},
_render: function(vars) {
this.$el.html(this.template(_.extend(vars, this.vars)));
this.$el.html(this.template(_.extend(vars, {title: this.title, hide_count: this.hide_count}, this.vars)));
if(this.hiddenForm) {
this.$el.addClass('hidden-form');
}
@@ -133,10 +137,9 @@ define(function(require) {
this.destroyViews();
// Construct and add the Views to the fragment.
var t = this;
var models = this.filterCollection(this.collection);
for(var i = 0; i < models.length; ++i) {
var view = t.initializeSubView(models[i]);
var view = this.initializeSubView(models[i]);
frag.appendChild(view.el);
}
return [models, frag];
@@ -1,13 +1,19 @@
"use strict";
define(function(require) {
var _ = require('underscore'),
Model = require('model'),
Dragula = require('dragula'),
Moment = require('moment'),
Collection = require('collection'),
View = require('view'),
NavbarView = require('views/navbar'),
ModalView = require('views/modal'),
ModelView = require('views/model'),
TableView = require('views/table'),
ChartView = require('views/chart'),
ListView = require('views/list'),
Renderer = require('views/renderer'),
AlertGroupView = require('views/alerts/alertgroup'),
FilterView = require('views/filter'),
TargetView = require('views/target'),
@@ -28,6 +34,83 @@ define(function(require) {
var TIME_FMT = 'YYYY/MM/DD HH:mm:00';
var FieldConfigView = View.extend({
tagName: 'tr',
template: Templates['searches/fieldentry'],
events: {
'click .delete-button': 'delete',
},
initialize: function(options) {
this.key = this.model.get('key');
},
_render: function() {
var vars = this.model.toJSON();
_.extend(vars, {renderers: Renderer.renderers});
this.$el.html(this.template(vars));
},
getRenderers: function() {
var val = this.$('.renderer-select').val();
return val !== '' ? [val]:[];
},
delete: function() {
this.trigger('button:delete', this);
return false;
}
});
var FieldsConfigView = TableView.extend({
template: Templates['searches/fieldtable'],
title: 'Field configuration',
sortable: false,
subView: FieldConfigView,
hiddenForm: true,
columns: [
{name: 'Field', sorter: 'false', width: 50},
{name: 'Renderer', sorter: 'false', width: 50},
{name: '', sorter: 'false'},
],
emptyPlaceholder: false,
update: function(params) {
this.initializeCollection(params);
},
readForm: function() {
return Renderer.serialize(this.getView('collection[]'));
},
_render: function() {
TableView.prototype._render.call(this);
this.$('.add-field').keypress(this.cbLoaded(function(e) {
if(e.which != 13) {
return;
}
if(e.target.value.length > 0) {
this.addModel(e.target.value);
}
e.target.value = '';
e.preventDefault();
}));
},
initializeSubView: function(model) {
var view = TableView.prototype.initializeSubView.call(this, model);
this.listenTo(view, 'button:delete', this.deleteModel);
return view;
},
addModel: function(key) {
var model = new Model({key: key, renderer: ''});
var view = this.initializeSubView(model);
this.collection.add(model);
this.$('.results-wrapper table tbody').append(view.el);
this.trigger('change', this);
},
deleteModel: function(view) {
view.destroy(true);
view.model.destroy({defer: true});
this.trigger('change', this);
},
});
var ResultsModalView = ModalView.extend({
title: 'Results',
large: true,
@@ -141,7 +224,7 @@ define(function(require) {
events: {
'click *': 'disable'
},
subTemplate: function() { return this.html; },
subTemplate: function() { return '<div class="preview">' + this.html + '</div>'; },
initialize: function(options) {
this.html = options.html;
ModalView.prototype.initialize.call(this);
@@ -469,6 +552,16 @@ define(function(require) {
new TargetsListView(this.App, {collection: this.targets, model: this.model}),
true, this.$('#target-list'), 'targets'
);
var collection = new Collection();
var fields = this.model.get('renderer_data');
for(var k in fields) {
collection.add(new Model({key: k, renderer: fields[k]}));
}
this.registerView(
new FieldsConfigView(this.App, {collection: collection, model: this.model}),
true, this.$('#field-list'), 'fields'
);
}
Util.autosize(this.registerElement('textarea[name=description]'));
@@ -568,6 +661,8 @@ define(function(require) {
delete data.query;
}
data.renderer_data = this.getView('fields').readForm();
// Extract source_expr.
if('source_expr' in data) {
data.query_data.source_expr = data.source_expr;
@@ -6,7 +6,7 @@ define(function(require) {
/**
* Table View
* Renders a collection of modles via the given subView class.
* Renders a collection of models via the given subView class.
*/
var TableView = CollectionView.extend({
template: Templates['table'],
@@ -17,6 +17,8 @@ define(function(require) {
sortable: true,
// Views in sorted order.
orderedCollection: null,
// Show a placeholder if there are no results.
emptyPlaceholder: true,
initialize: function() {
CollectionView.prototype.initialize.call(this);
@@ -36,7 +38,7 @@ define(function(require) {
var models = arr[0],
frag = arr[1];
var show_table = !!models.length;
var show_table = !!models.length || !this.emptyPlaceholder;
// Clean up the old table, if it exists.
this.$('.results-wrapper table')
@@ -13,7 +13,7 @@
<span class="hoverable glyphicon glyphicon glyphicon-remove"></span>
</span><span class="sr-only">Close</span></button>
</div>
{{/unless}}
{{/unless}}
<div class="text-left">
<b>{{titlecase name}}</b>
@@ -77,6 +77,6 @@
</div>
{{/unless}}
{{#unless hide_chrome}}
{{#unless hide_chrome}}
</div>
{{/unless}}
@@ -0,0 +1,12 @@
<td>{{key}}</td>
<td>
<select class="form-control input-xs renderer-select">
<option></option>
{{#each renderers}}
<option value="{{@key}}"{{#ifeq @key ../renderer}} selected{{/ifeq}}>{{@key}}</option>
{{/each}}
</select>
</td>
<td width="0">
<button type="button" class="action delete-button"><span class="hoverable glyphicon glyphicon-remove"></span></button>
</td>
@@ -0,0 +1,27 @@
<div class="panel panel-default results-wrapper">
<div class="panel-heading clearfix">
<h4 class="panel-title">
<span>
{{ title }}
</span>
</h4>
</div>
<div class="table-responsive">
<table class="table table-condensed table-striped tablesorter">
<thead>
<tr>
{{#each columns}}
<th {{#if width}}width="{{ width }}%"{{/if}} {{#if sorter}}class="sorter-{{ sorter }}"{{/if}}>{{ name }}</th>
{{/each}}
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="panel-footer">
<label>New</label>
<input type="text" class="form-control add-field" />
</div>
</div>
View
@@ -171,6 +171,8 @@
</select>
</div>
<div id="field-list"></div>
<div class="col-xs-12">
<div class="text-center">
<button id="preview-notification-button" class="btn btn-sm btn-default" type="button">Preview</button>
@@ -209,6 +211,7 @@
<button id="save-elements-button" class="btn btn-sm btn-default" type="submit">Save Filters and Targets</button>
</div>
</div>
{{/if}}
</div>
@@ -1,7 +1,14 @@
<div class="panel panel-default hidden results-wrapper">
<div class="panel-heading clearfix">
<h4 class="panel-title pull-right">
<span class="badge count">0</span>
<h4 class="panel-title">
<span>
{{ title }}
</span>
{{#if hide_count}}
<span class="pull-right">
<span class="badge count">0</span>
</span>
{{/if}}
</h4>
</div>
Oops, something went wrong.

0 comments on commit afe37bc

Please sign in to comment.