-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
244 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('theHiveDirectives').directive('dashboardText', function($q, $http, $state, DashboardSrv, GlobalSearchSrv, NotificationSrv) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
filter: '=?', | ||
options: '=', | ||
entity: '=', | ||
autoload: '=', | ||
mode: '=', | ||
refreshOn: '@', | ||
resizeOn: '@', | ||
metadata: '=' | ||
}, | ||
templateUrl: 'views/directives/dashboard/text/view.html', | ||
link: function(scope, elem) { | ||
|
||
scope.error = false; | ||
scope.data = null; | ||
scope.globalQuery = null; | ||
|
||
scope.load = function() { | ||
if(!scope.options.series || scope.options.series.length === 0) { | ||
scope.error = true; | ||
return; | ||
} | ||
|
||
var query = DashboardSrv.buildChartQuery(scope.filter, scope.options.query); | ||
scope.globalQuery = query; | ||
|
||
var stats = { | ||
stats: _.map(scope.options.series || [], function(serie, index) { | ||
var s = { | ||
_agg: serie.agg, | ||
_name: serie.name || 'agg_' + (index + 1), | ||
_query: serie.query || {} | ||
}; | ||
|
||
if(serie.agg !== 'count') { | ||
s._field = serie.field; | ||
} | ||
|
||
return { | ||
model: serie.entity, | ||
query: query, | ||
stats: [s] | ||
}; | ||
}) | ||
}; | ||
|
||
var statsPromise = $http.post('./api/_stats', stats); | ||
|
||
statsPromise.then(function(response) { | ||
scope.error = false; | ||
scope.data = response.data; | ||
|
||
var template = scope.options.template; | ||
Object.keys(scope.data).forEach(function(key){ | ||
var regex = new RegExp('{{' + key + '}}', 'gi'); | ||
|
||
template = template.replace(regex, scope.data[key]); | ||
}); | ||
|
||
scope.content = template; | ||
|
||
}, function(/*err*/) { | ||
scope.error = true; | ||
|
||
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error'); | ||
}); | ||
}; | ||
|
||
scope.copyHTML = function() { | ||
var html = elem[0].querySelector('.widget-content').innerHTML; | ||
function listener(e) { | ||
e.clipboardData.setData('text/html', html); | ||
e.clipboardData.setData('text/plain', html); | ||
e.preventDefault(); | ||
} | ||
document.addEventListener('copy', listener); | ||
document.execCommand('copy'); | ||
document.removeEventListener('copy', listener); | ||
} | ||
|
||
if (scope.autoload === true) { | ||
scope.load(); | ||
} | ||
|
||
if (!_.isEmpty(scope.refreshOn)) { | ||
scope.$on(scope.refreshOn, function(event, filter) { | ||
scope.filter = filter; | ||
scope.load(); | ||
}); | ||
} | ||
} | ||
}; | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="form-group"> | ||
<label>Title</label> | ||
<input type="text" class="form-control" placeholder="Ex: Summary" ng-model="component.options.title"> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<div class="form-group"> | ||
<label>Template</label> | ||
<textarea class="content-box" name="template" | ||
placeholder="Close summary" markdown-editor="{ | ||
'fullscreen': {enable: false}, | ||
'iconlibrary': 'fa', | ||
addExtraButtons: true, | ||
resize: 'vertical'}" rows="6" ng-model="component.options.template" required></textarea> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<uib-tabset class="nav-tabs-custom" active="layout.activeTab"> | ||
<uib-tab index="0"> | ||
<uib-tab-heading> | ||
<i class="fa fa-bars"></i> Basic | ||
</uib-tab-heading> | ||
<ng-include src="'views/directives/dashboard/text/basic.html'"></ng-include> | ||
</uib-tab> | ||
<uib-tab index="1"> | ||
<uib-tab-heading> | ||
<i class="fa fa-sort"></i> Series | ||
</uib-tab-heading> | ||
<ng-include src="'views/directives/dashboard/text/series.html'"></ng-include> | ||
</uib-tab> | ||
</uib-tabset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div ng-if="serie.filters.length > 0"> | ||
<strong>Serie's filter</strong> | ||
</div> | ||
<div class="row mb-xxxs" ng-repeat="filter in serie.filters track by $index"> | ||
<div class="col-sm-4"> | ||
<div class="input-group"> | ||
<span class="input-group-btn"> | ||
<button class="btn btn-default" type="button" ng-click="removeSerieFilter(serie, $index)"> | ||
<i class="fa fa-times text-danger"></i> | ||
</button> | ||
</span> | ||
<select class="form-control" ng-model="filter.field" | ||
ng-options="item.name as item.name for (key, item) in metadata[serie.entity].attributes" | ||
ng-change="setFilterField(filter, serie.entity)"></select> | ||
</div> | ||
</div> | ||
<div class="col-sm-8"> | ||
<filter-editor metadata="metadata" filter="filter" entity="serie.entity"></filter-editor> | ||
</div> | ||
</div> | ||
<div class="mt-xxs"> | ||
<a href ng-click="addSerieFilter(serie)"> | ||
<i class="fa fa-plus"></i> Add a filter | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div ng-if="!component.options.series || component.options.series.length === 0" class="empty-message"> | ||
No series defined. <a href ng-click="addSerie()">Add a serie</a> | ||
</div> | ||
<div class="mb-xxxs dashboard-serie" ng-repeat="serie in component.options.series track by $index"> | ||
<div class="form-inline mb-xxxs"> | ||
<div class="input-group"> | ||
<span class="input-group-btn"> | ||
<button class="btn btn-default" type="button" ng-click="removeSerie($index)"> | ||
<i class="fa fa-times text-danger"></i> | ||
</button> | ||
</span> | ||
<div class="form-group"> | ||
<select class="form-control" ng-model="serie.entity" | ||
ng-options="item as metadata[item].label for item in metadata.entities"></select> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<select class="form-control" ng-model="serie.agg" | ||
ng-options="item.label as item.id for (key, item) in aggregations" | ||
ng-change="setSerieAgg(serie)"> | ||
<option value="" disabled selected></option> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<select class="form-control" ng-model="serie.field" ng-disabled="serie.agg === 'count'" | ||
ng-options="item.name as item.name for (key, item) in fieldsForAggregation(metadata[serie.entity].attributes, serie.agg)"> | ||
<option value="" disabled selected>-- Select field --</option> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<input class="form-control" type="text" ng-model="serie.name" placeholder="Variable name"> | ||
</div> | ||
</div> | ||
<div class="ml-m mt-xs"> | ||
<ng-include src="'views/directives/dashboard/text/serie.filters.html'"></ng-include> | ||
</div> | ||
</div> | ||
<div ng-if="component.options.series && component.options.series.length > 0" class="mv-xs"> | ||
<a href ng-click="addSerie()"> | ||
<i class="fa fa-plus"></i> Add a serie | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="c3-container"> | ||
<div class="c3-error" ng-if="error"> | ||
<div class="text-center"> | ||
<h4 class="text-danger"> | ||
<div class="mb-xxs"><i class="fa fa-2x fa-exclamation-triangle"></i></div> | ||
<div>Failed to fetch data, please edit the widget definition</div> | ||
</h4> | ||
</div> | ||
</div> | ||
<div ng-if="!error" class="row"> | ||
<div class="col-sm-12"> | ||
<div class="clearfix" ng-show="content"> | ||
<a class="pull-right ml-xxs" href ng-click="copyHTML()"><i class="fa fa-file-text-o mr-xxxs"></i>HTML</a> | ||
<strong class="text-primary pull-right">Copy</strong> | ||
</div> | ||
<div marked="content" class="markdown widget-content"></div> | ||
</div> | ||
</div> | ||
</div> |