Skip to content

Commit

Permalink
Fix markdown template's id to indexPattern title
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-jung committed Oct 7, 2017
1 parent 690c458 commit d753730
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion public/doc_view/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DocViewsRegistryProvider.register(markdownTemplates => {
},
link: ($scope, elem) => {
const { indexPattern, hit } = $scope;
markdownTemplates.get(indexPattern.id)
markdownTemplates.get(indexPattern.title)
.then(template => template.isEmpty() ? defaultTemplate : template.render(convertDocToVars(indexPattern, hit)))
.then(renderedHtml => elem.empty().append(renderedHtml));
}
Expand Down
5 changes: 4 additions & 1 deletion public/doc_view/no_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
</div>

<div class="kuiPromptForItems__actions">
<a class="kuiButton kuiButton--primary kuiButton--iconText" href="#/management/kibana/markdown_template/{{indexPattern.id}}">
<a
class="kuiButton kuiButton--primary kuiButton--iconText"
href="#/management/kibana/markdown_template/{{indexPattern.title}}?indexPatternId={{indexPattern.id}}"
>
<span class="kuiButton__inner">
<span class="kuiButton__icon kuiIcon fa-plus"></span>
<span>Create markdown template</span>
Expand Down
14 changes: 12 additions & 2 deletions public/management/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1 class="kuiTitle">
</h1>
</div>
<div class="kuiToolBarSection">
<a class="kuiButton kuiButton--basic kuiButton--iconText" ng-href="#/discover?_a=(index:'{{editingId}}')">
<a class="kuiButton kuiButton--basic kuiButton--iconText" ng-href="#/discover?_a=(index:'{{indexPattern.id}}')">
<span class="kuiButton__inner">
<span class="kuiButton__icon kuiIcon fa-eye"></span>
<span>View in discover</span>
Expand Down Expand Up @@ -83,6 +83,7 @@ <h1 class="kuiTitle">
The following variables can be used in the Markdown by using
<a href="http://handlebarsjs.com/expressions.html" target="_BLANK">the Handlebar (mustache) syntax.</a>
</p>

<div class="kuiInfoPanel kuiInfoPanel--info kuiVerticalRhythm">
<div class="kuiInfoPanelHeader">
<span class="kuiInfoPanelHeader__icon kuiIcon kuiIcon--info fa-info"></span>
Expand All @@ -92,7 +93,16 @@ <h1 class="kuiTitle">
</div>
</div>

<table class="table kuiVerticalRhythm">
<div class="kuiInfoPanel kuiInfoPanel--error kuiVerticalRhythm" ng-if="noIndexPattern">
<div class="kuiInfoPanelHeader">
<span class="kuiInfoPanelHeader__icon kuiIcon kuiIcon--error fa-warning"></span>
<span class="kuiInfoPanelHeader__title">
Cannot load document sample. IndexPattern not found.
</span>
</div>
</div>

<table class="table kuiVerticalRhythm" ng-if="!noIndexPattern">
<thead>
<tr>
<th>Name</th>
Expand Down
16 changes: 11 additions & 5 deletions public/management/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@ useful for creating lists with data from a group by...
const renderError = compileTemplate(renderErrorTemplate);

uiRoutes
.when('/management/kibana/markdown_template/:indexPatternId', {
.when('/management/kibana/markdown_template/:id', {
template,
resolve: {
indexPattern: ($route, courier) => {
const { indexPatternId } = $route.current.params;

if (isEmpty(indexPatternId)) return;

return courier.indexPatterns
.get($route.current.params.indexPatternId)
.catch(courier.redirectWhenMissing('/management/kibana/markdown_template'));
.get(indexPatternId)
.catch(courier.redirectWhenMissing('/management/kibana/markdown_template'));
},
markdownTemplate: ($route, markdownTemplates) => {
return markdownTemplates
.get($route.current.params.indexPatternId);
.get($route.current.params.id);
}
},
controller: ($scope, $route, $compile, $window, markdownTemplates, es, confirmModal, Notifier) => {
const notify = new Notifier({ location: 'Markdown Template Editor' });
$scope.messages = messages;
$scope.indexPattern = $route.current.locals.indexPattern;
$scope.editingId = $route.current.params.indexPatternId;
$scope.editingId = $route.current.params.id;
$scope.editingSource = $route.current.locals.markdownTemplate;
$scope.editorOptions = {
autofocus: true,
Expand Down Expand Up @@ -84,6 +88,8 @@ uiRoutes
};

$scope.convertDocToVars = (indexPattern, doc) => {
if (!indexPattern) return $scope.noIndexPattern = true;

$scope.vars = convertDocToVars(indexPattern, doc);
$scope.varIndex = chain($scope.vars._all)
.map(({ label, raw, formatted }) => {
Expand Down
2 changes: 1 addition & 1 deletion public/management/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ <h1 class="kuiTitle">
</td>
<td class="kuiTableRowCell">
<div class="kuiTableRowCell__liner">
<a ng-href="#/management/kibana/markdown_template/{{item._id}}">{{item._id}}</a>
<a ng-href="#/management/kibana/markdown_template/{{item._id}}?indexPatternId={{item.indexPatternId}}">{{item._id}}</a>
</div>
</td>
<td class="kuiTableRowCell">
Expand Down
23 changes: 18 additions & 5 deletions public/management/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,45 @@ import Promise from 'bluebird';
import angular from 'angular';
import { saveAs } from '@elastic/filesaver';
import uiRoutes from 'ui/routes';
import { SavedObjectsClientProvider } from 'ui/saved_objects';
import template from './list.html';

uiRoutes
.when('/management/kibana/markdown_template', {
template,
controller: ($scope, $route, courier, markdownTemplates, confirmModal, esAdmin, kbnIndex, Notifier) => {
controller: ($scope, $route, courier, markdownTemplates, confirmModal, esAdmin, kbnIndex, Notifier, Private) => {
const notify = new Notifier({ location: 'Markdown Templates' });
const savedObjectsClient = Private(SavedObjectsClientProvider);
$scope.list = [];
$scope.templates = [];
$scope.selectedItems = [];
$scope.listOrder = '+_id';

$scope.getData = () => {
return Promise.all([
courier.indexPatterns.getIds(),
savedObjectsClient.find({
type: 'index-pattern',
fields: [],
perPage: 10000
})
.then(resp => resp.savedObjects),
markdownTemplates.list()
])
.then(([indexPatterns, templates]) => {
$scope.list = chain(indexPatterns)
.map(id => ({ _id: id, _type: 'index-pattern' }))
.map(indexPattern => ({
_id: indexPattern.attributes.title,
_type: 'index-pattern',
indexPatternId: indexPattern.id
}))
.concat(templates)
.reduce((map, hit) => {
const { _id, _type, _source } = hit;
const { _id, _type, _source, indexPatternId } = hit;
const item = map[_id] || (map[_id] = { _id });
item[`has${upperFirst(camelCase(_type))}`] = true;
if (_type === 'markdown_template') {
if (_type === 'index-pattern') {
item.indexPatternId = indexPatternId;
} else if (_type === 'markdown_template') {
item._type = _type;
item._source = _source;
}
Expand Down

0 comments on commit d753730

Please sign in to comment.