Moved the optin setting (and a couple others) from cookie's into localStorage.

Previously the options were at cookies.marvelXXX. They are now stored at marvelOpts.report/lastReport/version
This commit is contained in:
Spencer Alger 2014-01-24 14:52:01 -07:00
parent 56c7c20505
commit 9cf2021ccb
4 changed files with 49 additions and 27 deletions

View file

@ -15,11 +15,11 @@
<div class="section">
<div class="editor-option">
<label class="small">Send statistics<tip>Help make Elasticsearch better by sharing anonymous usage data.</tip></label>
<input type="checkbox" ng-model="cookies.marvelOptIn" ng-true-value="IN" ng-false-value="OUT" />
<input type="checkbox" ng-model="marvelOpts.report"/>
</div>
<div ng-show="kbnVersion == '@REV@'" class="editor-option">
<label class="small">Clear Marvel Cookies <tip>Only shown in unbuilt versions, clear optin and version cookies</tip></label>
<button class="btn btn-danger" ng-click="clearMarvelCookies()">Clear</button>
<label class="small">Clear marvelOpts <tip>Only shown in unbuilt versions, clear stored optin and version data</tip></label>
<button class="btn btn-danger" ng-click="clearMarvelStorage()">Clear</button>
</div>
</div>
</div>

View file

@ -21,7 +21,7 @@ function (angular, app, _, kbn) {
var module = angular.module('kibana.panels.marvel.cluster', []);
app.useModule(module);
module.controller('marvel.cluster', function($scope, $modal, $q, $cookies, $http,
module.controller('marvel.cluster', function($scope, $modal, $q, $http,
querySrv, dashboard, filterSrv, kbnVersion) {
$scope.panelMeta = {
modals : [],
@ -37,15 +37,43 @@ function (angular, app, _, kbn) {
_.defaults($scope.panel,_d);
var reportInterval = 86400000;
//var reportInterval = 30000;
function store(expression) {
// get the current value, parse if it exists
var current = localStorage.getItem(expression);
if (current != null) {
try {
current = JSON.parse(current);
} catch (e) {
current = null;
}
}
// listen for changes and store them in localStorage,
// unless it is set to undefined then it will be removed
$scope.$watch(expression, function (val) {
if (_.isUndefined(val)) {
localStorage.removeItem(expression);
} else {
localStorage.setItem(expression, JSON.stringify(val));
}
});
return current;
}
// setup the optIn and version values
var marvelOpts = $scope.marvelOpts = {
report: store('marvelOpts.report'),
version: store('marvelOpts.version'),
lastReport: store('marvelOpts.lastReport')
};
$scope.init = function () {
// So we can access the cookies object from the view
$scope.cookies = $cookies;
$scope.kbnVersion = kbnVersion;
// If the user hasn't opted in or out, ask them to.
if(_.isUndefined($cookies.marvelOptIn) || $cookies.marvelVersion !== kbnVersion) {
if(_.isUndefined(marvelOpts.version) || marvelOpts.version !== kbnVersion) {
$scope.optInModal();
}
@ -129,15 +157,15 @@ function (angular, app, _, kbn) {
$scope.inspector = angular.toJson(JSON.parse(request.toString()),true);
};
$scope.setOptIn = function(c) {
$cookies.marvelVersion = kbnVersion;
$cookies.marvelOptIn = c;
$scope.setOptIn = function(val) {
marvelOpts.version = kbnVersion;
marvelOpts.report = val;
};
$scope.clearMarvelCookies = function() {
delete $cookies.marvelOptIn;
delete $cookies.marvelVersion;
delete $cookies.marvelLastReport;
$scope.clearMarvelStorage = function() {
marvelOpts.report = void 0;
marvelOpts.version = void 0;
marvelOpts.lastReport = void 0;
};
$scope.optInModal = function() {
@ -157,10 +185,10 @@ function (angular, app, _, kbn) {
// Checks if we should send a report
var checkReport = function() {
if($cookies.marvelOptIn === 'IN') {
if(_.isUndefined($cookies.marvelLastReport)) {
if(marvelOpts.report) {
if(_.isUndefined(marvelOpts.lastReport)) {
return true;
} else if (new Date().getTime() - parseInt($cookies.marvelLastReport,10) > reportInterval) {
} else if (new Date().getTime() - parseInt(marvelOpts.lastReport,10) > reportInterval) {
return true;
} else {
return false;
@ -182,7 +210,7 @@ function (angular, app, _, kbn) {
$scope.config.stats_report_url,
data
).success(function() {
$cookies.marvelLastReport = thisReport;
marvelOpts.lastReport = thisReport;
});
};

View file

@ -26,8 +26,7 @@
</div>
<div class="modal-footer">
<!-- these set strings since cookies don't deal with boolean -->
<button ng-click="setOptIn('IN');dismiss();" class="btn btn-success">Count me in!</button>
<span ng-click="setOptIn('OUT');dismiss();" class="pointer small">No Thanks</span>
<button ng-click="setOptIn(true);dismiss();" class="btn btn-success">Count me in!</button>
<span ng-click="setOptIn(false);dismiss();" class="pointer small">No Thanks</span>
</div>

View file

@ -1,9 +1,4 @@
<div ng-controller='marvel.navigation' ng-init="init()">
<style>
.marvel-navigation-dropdown {
margin: 0px !important;
}
</style>
<!-- This is a complete hack. The form actually exists in the modal, but due to transclusion
$scope.input isn't available on the controller unless the form element is in this file -->
<form name="input" style="margin:3px 0 0 0">