linting and added filter states
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/*jshint globalstrict:true */
|
||||
/*global angular:true */
|
||||
/*global FileReader:false*/
|
||||
/*
|
||||
|
||||
## Dashcontrol
|
||||
@@ -20,11 +23,8 @@
|
||||
* temp :: Allow saving of temp dashboards
|
||||
* temp_ttl :: How long should temp dashboards persist
|
||||
|
||||
### Group Events
|
||||
#### Sends
|
||||
* dashboard :: An object containing an entire dashboard to be loaded
|
||||
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
angular.module('kibana.dashcontrol', [])
|
||||
.controller('dashcontrol', function($scope, $http, timer, dashboard) {
|
||||
@@ -49,7 +49,7 @@ angular.module('kibana.dashcontrol', [])
|
||||
elasticsearch_size: 20,
|
||||
temp: true,
|
||||
temp_ttl: '30d'
|
||||
}
|
||||
};
|
||||
_.defaults($scope.panel,_d);
|
||||
|
||||
// A hash of defaults for the dashboard object
|
||||
@@ -58,63 +58,63 @@ angular.module('kibana.dashcontrol', [])
|
||||
editable: true,
|
||||
rows: [],
|
||||
services: {}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
||||
$scope.gist = {};
|
||||
$scope.elasticsearch = {};
|
||||
}
|
||||
};
|
||||
|
||||
$scope.set_default = function() {
|
||||
if(dashboard.set_default()) {
|
||||
$scope.alert('Local Default Set',dashboard.current.title+' has been set as your local default','success',5000)
|
||||
$scope.alert('Local Default Set',dashboard.current.title+' has been set as your local default','success',5000);
|
||||
} else {
|
||||
$scope.alert('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000)
|
||||
$scope.alert('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.purge_default = function() {
|
||||
if(dashboard.purge_default()) {
|
||||
$scope.alert('Local Default Clear','Your local default dashboard has been cleared','success',5000)
|
||||
$scope.alert('Local Default Clear','Your local default dashboard has been cleared','success',5000);
|
||||
} else {
|
||||
$scope.alert('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000)
|
||||
$scope.alert('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.elasticsearch_save = function(type,ttl) {
|
||||
dashboard.elasticsearch_save(type,($scope.elasticsearch.title || dashboard.current.title),ttl).then(
|
||||
function(result) {
|
||||
if(!_.isUndefined(result._id)) {
|
||||
$scope.alert('Dashboard Saved','This dashboard has been saved to Elasticsearch as "' +
|
||||
result._id + '"','success',5000)
|
||||
result._id + '"','success',5000);
|
||||
if(type === 'temp') {
|
||||
$scope.share = dashboard.share_link(dashboard.current.title,'temp',result._id)
|
||||
$scope.share = dashboard.share_link(dashboard.current.title,'temp',result._id);
|
||||
}
|
||||
} else {
|
||||
$scope.alert('Save failed','Dashboard could not be saved to Elasticsearch','error',5000)
|
||||
$scope.alert('Save failed','Dashboard could not be saved to Elasticsearch','error',5000);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.elasticsearch_delete = function(id) {
|
||||
dashboard.elasticsearch_delete(id).then(
|
||||
function(result) {
|
||||
if(!_.isUndefined(result)) {
|
||||
if(result.found) {
|
||||
$scope.alert('Dashboard Deleted',id+' has been deleted','success',5000)
|
||||
$scope.alert('Dashboard Deleted',id+' has been deleted','success',5000);
|
||||
// Find the deleted dashboard in the cached list and remove it
|
||||
var toDelete = _.where($scope.elasticsearch.dashboards,{_id:id})[0]
|
||||
$scope.elasticsearch.dashboards = _.without($scope.elasticsearch.dashboards,toDelete)
|
||||
var toDelete = _.where($scope.elasticsearch.dashboards,{_id:id})[0];
|
||||
$scope.elasticsearch.dashboards = _.without($scope.elasticsearch.dashboards,toDelete);
|
||||
} else {
|
||||
$scope.alert('Dashboard Not Found','Could not find '+id+' in Elasticsearch','warning',5000)
|
||||
$scope.alert('Dashboard Not Found','Could not find '+id+' in Elasticsearch','warning',5000);
|
||||
}
|
||||
} else {
|
||||
$scope.alert('Dashboard Not Deleted','An error occurred deleting the dashboard',error,5000)
|
||||
$scope.alert('Dashboard Not Deleted','An error occurred deleting the dashboard','error',5000);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.elasticsearch_dblist = function(query) {
|
||||
dashboard.elasticsearch_list(query,$scope.panel.elasticsearch_size).then(
|
||||
@@ -122,10 +122,10 @@ angular.module('kibana.dashcontrol', [])
|
||||
if(!_.isUndefined(result.hits)) {
|
||||
$scope.panel.error = false;
|
||||
$scope.hits = result.hits.total;
|
||||
$scope.elasticsearch.dashboards = result.hits.hits
|
||||
$scope.elasticsearch.dashboards = result.hits.hits;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.save_gist = function() {
|
||||
dashboard.save_gist($scope.gist.title).then(
|
||||
@@ -134,10 +134,10 @@ angular.module('kibana.dashcontrol', [])
|
||||
$scope.gist.last = link;
|
||||
$scope.alert('Gist saved','You will be able to access your exported dashboard file at <a href="'+link+'">'+link+'</a> in a moment','success');
|
||||
} else {
|
||||
$scope.alert('Save failed','Gist could not be saved','error',5000)
|
||||
$scope.alert('Save failed','Gist could not be saved','error',5000);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.gist_dblist = function(id) {
|
||||
dashboard.gist_list(id).then(
|
||||
@@ -145,10 +145,10 @@ angular.module('kibana.dashcontrol', [])
|
||||
if(files && files.length > 0) {
|
||||
$scope.gist.files = files;
|
||||
} else {
|
||||
$scope.alert('Gist Failed','Could not retrieve dashboard list from gist','error',5000)
|
||||
$scope.alert('Gist Failed','Could not retrieve dashboard list from gist','error',5000);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
})
|
||||
.directive('dashUpload', function(timer, dashboard){
|
||||
return {
|
||||
@@ -159,14 +159,15 @@ angular.module('kibana.dashcontrol', [])
|
||||
|
||||
// files is a FileList of File objects. List some properties.
|
||||
var output = [];
|
||||
var readerOnload = function(theFile) {
|
||||
return function(e) {
|
||||
dashboard.dash_load(JSON.parse(e.target.result));
|
||||
scope.$apply();
|
||||
};
|
||||
};
|
||||
for (var i = 0, f; f = files[i]; i++) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = (function(theFile) {
|
||||
return function(e) {
|
||||
dashboard.dash_load(JSON.parse(e.target.result))
|
||||
scope.$apply();
|
||||
};
|
||||
})(f);
|
||||
reader.onload = (readerOnload)(f);
|
||||
reader.readAsText(f);
|
||||
}
|
||||
}
|
||||
@@ -179,15 +180,16 @@ angular.module('kibana.dashcontrol', [])
|
||||
alert('Sorry, the HTML5 File APIs are not fully supported in this browser.');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}).filter('gistid', function() {
|
||||
var gist_pattern = /(\d{5,})|([a-z0-9]{10,})|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
||||
return function(input, scope) {
|
||||
//return input+"boners"
|
||||
if(!(_.isUndefined(input))) {
|
||||
var output = input.match(gist_pattern);
|
||||
if(!_.isNull(output) && !_.isUndefined(output))
|
||||
return output[0].replace(/.*\//, '');
|
||||
}
|
||||
var gist_pattern = /(\d{5,})|([a-z0-9]{10,})|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
||||
return function(input, scope) {
|
||||
//return input+"boners"
|
||||
if(!(_.isUndefined(input))) {
|
||||
var output = input.match(gist_pattern);
|
||||
if(!_.isNull(output) && !_.isUndefined(output)) {
|
||||
return output[0].replace(/.*\//, '');
|
||||
}
|
||||
}
|
||||
});;
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user