Commit 107cf6b8 by Rashid Khan

Added creating and sharing of short url links to dashboards

parent 6d2af0d8
......@@ -31,7 +31,7 @@
<h6 ng-hide="elasticsearch.dashboards.length">No dashboards matching your query found</h6>
<table class="table table-condensed table-striped">
<tr ng-repeat="dashboard in elasticsearch.dashboards">
<td><a ng-click="delete_elasticsearch(dashboard)"><i class="icon-remove"></i></a></td>
<td><a ng-click="elasticsearch_delete(dashboard)"><i class="icon-remove"></i></a></td>
<td><a ng-click="dash_load(dashboard['_source']['dashboard'])">{{dashboard._id}}</a></td>
<td><a><i class="icon-share" ng-click="share_link(dashboard._id,'elasticsearch',dashboard._id)" bs-modal="'panels/dashcontrol/share.html'"></i></a></td>
</tr>
......
......@@ -2,4 +2,5 @@
<label class='small'>Dashboard Control</label>
<button class='btn' ng-show="panel.load.gist || panel.load.elasticsearch || panel.load.local" data-placement="bottom" data-unique="1" ng-click="elasticsearch_dblist(elasticsearch.query)" bs-popover="'panels/dashcontrol/load.html'"><i class='icon-folder-open'></i> <i class='icon-caret-down'></i></button>
<button class='btn' ng-show="panel.save.gist || panel.save.elasticsearch || panel.save.local || panel.save.default" data-placement="bottom" data-unique="1" bs-popover="'panels/dashcontrol/save.html'"><i class='icon-save'></i> <i class='icon-caret-down'></i></button>
<button class='btn' ng-click="elasticsearch_save('temp')" bs-modal="'panels/dashcontrol/share.html'"><i class='icon-share'></i></button>
</kibana-panel>
\ No newline at end of file
......@@ -17,6 +17,7 @@ angular.module('kibana.dashcontrol', [])
},
elasticsearch_size: 20,
elasticsearch_saveto: $scope.config.kibana_index,
temp_ttl: '30d',
}
_.defaults($scope.panel,_d);
......@@ -36,9 +37,11 @@ angular.module('kibana.dashcontrol', [])
var _type = $routeParams.type;
var _id = $routeParams.id;
if(_type === 'elasticsearch') {
$scope.elasticsearch_load(_id)
}
if(_type === 'elasticsearch')
$scope.elasticsearch_load('dashboard',_id)
if(_type === 'temp')
$scope.elasticsearch_load('temp',_id)
// No dashboard in the URL
} else {
// Check if browser supports localstorage, and if there's a dashboard
......@@ -94,7 +97,8 @@ angular.module('kibana.dashcontrol', [])
location : location.href.replace(location.hash,""),
type : type,
id : id,
link : location.href.replace(location.hash,"")+"#dashboard/"+type+"/"+id
link : location.href.replace(location.hash,"")+"#dashboard/"+type+"/"+id,
title : title,
};
}
......@@ -111,23 +115,37 @@ angular.module('kibana.dashcontrol', [])
}
}
$scope.save_elasticsearch = function() {
$scope.elasticsearch_save = function(type) {
console.log(type)
// Clone object so we can modify it without influencing the existing obejct
var save = _.clone($scope.dashboards)
save.title = $scope.elasticsearch.title;
var result = $scope.ejs.Document($scope.panel.elasticsearch_saveto,'dashboard',save.title).source({
// Change title on object clone
if(type === 'dashboard')
var id = save.title = $scope.elasticsearch.title;
// Create request with id as title. Rethink this.
var request = $scope.ejs.Document($scope.panel.elasticsearch_saveto,type,id).source({
user: 'guest',
group: 'guest',
title: save.title,
dashboard: angular.toJson(save)
}).doIndex();
result.then(function(result) {
})
if(type === 'temp')
request = request.ttl($scope.panel.temp_ttl)
var result = request.doIndex();
var id = result.then(function(result) {
$scope.alert('Dashboard Saved','This dashboard has been saved to Elasticsearch','success',5000)
$scope.elasticsearch_dblist($scope.elasticsearch.query);
$scope.elasticsearch.title = '';
if(type === 'temp')
$scope.share_link($scope.dashboards.title,'temp',result._id)
})
}
$scope.delete_elasticsearch = function(dashboard) {
$scope.elasticsearch_delete = function(dashboard) {
var result = $scope.ejs.Document($scope.panel.elasticsearch_saveto,'dashboard',dashboard._id).doDelete();
result.then(function(result) {
$scope.alert('Dashboard Deleted','','success',5000)
......@@ -135,8 +153,8 @@ angular.module('kibana.dashcontrol', [])
})
}
$scope.elasticsearch_load = function(id) {
var request = $scope.ejs.Request().indices($scope.panel.elasticsearch_saveto).types('dashboard');
$scope.elasticsearch_load = function(type,id) {
var request = $scope.ejs.Request().indices($scope.panel.elasticsearch_saveto).types(type);
var results = request.query(
$scope.ejs.IdsQuery(id)
).size($scope.panel.elasticsearch_size).doSearch();
......
......@@ -23,7 +23,7 @@
<h5>Elasticsearch</h5>
<form class="input-append">
<input class='input-medium' placeholder='Title' type="text" ng-model="elasticsearch.title"/>
<button class="btn" ng-click="save_elasticsearch()"><i class="icon-save"></i></button>
<button class="btn" ng-click="elasticsearch_save('dashboard')"><i class="icon-save"></i></button>
</form>
</div>
</div>
\ No newline at end of file
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>{{share.id}} <small>shareable link</small></h3>
<h3>{{share.title}} <small>shareable link</small></h3>
</div>
<div class="modal-body">
<label>Share this dashboard with this URL</label>
<input ng-model='share.link' type="text" style="width:90%" onclick="this.select()" onfocus="this.select()" ng-change="share_link(share.type,share.id)">
<input ng-model='share.link' type="text" style="width:90%" onclick="this.select()" onfocus="this.select()" ng-change="share_link(share.title,share.type,share.id)">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" ng-click="dismiss();$broadcast('render')">Close</button>
......
<div class="row-fluid" style="margin-top:15%">
<form class="span4 offset4 form-inline" ng-submit="$parent.search()">
<input class="input-xlarge" ng-model="$parent.queryTerm" type="text"
placeholder="Search" autofocus>
<button class="btn" type="submit">Search</button>
</form>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment