Skip to content

Commit

Permalink
Merge pull request #170 from EverythingMe/feature_usage_tracking
Browse files Browse the repository at this point in the history
Feature: basic usage tracking
  • Loading branch information
arikfr committed Apr 10, 2014
2 parents 52441ec + 881e44f commit 185b1c9
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 229 deletions.
35 changes: 18 additions & 17 deletions rd_ui/app/scripts/controllers/admin_controllers.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
(function () {
var AdminStatusCtrl = function ($scope, $http, $timeout) {
$scope.$parent.pageTitle = "System Status";
var AdminStatusCtrl = function ($scope, Events, $http, $timeout) {
Events.record(currentUser, "view", "page", "admin/status");
$scope.$parent.pageTitle = "System Status";

var refresh = function () {
$scope.refresh_time = moment().add('minutes', 1);
$http.get('/status.json').success(function (data) {
$scope.workers = data.workers;
delete data.workers;
$scope.manager = data.manager;
delete data.manager;
$scope.status = data;
});
var refresh = function () {
$scope.refresh_time = moment().add('minutes', 1);
$http.get('/status.json').success(function (data) {
$scope.workers = data.workers;
delete data.workers;
$scope.manager = data.manager;
delete data.manager;
$scope.status = data;
});

$timeout(refresh, 59 * 1000);
};
$timeout(refresh, 59 * 1000);
};

refresh();
}
refresh();
}

angular.module('redash.admin_controllers', [])
.controller('AdminStatusCtrl', ['$scope', '$http', '$timeout', AdminStatusCtrl])
angular.module('redash.admin_controllers', [])
.controller('AdminStatusCtrl', ['$scope', 'Events', '$http', '$timeout', AdminStatusCtrl])
})();
6 changes: 4 additions & 2 deletions rd_ui/app/scripts/controllers/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@
});
}

var IndexCtrl = function($scope, Dashboard) {
var IndexCtrl = function($scope, Events, Dashboard) {
Events.record(currentUser, "view", "page", "homepage");
$scope.$parent.pageTitle = "Home";

$scope.archiveDashboard = function(dashboard) {
if (confirm('Are you sure you want to delete "' + dashboard.name + '" dashboard?')) {
Events.record(currentUser, "archive", "dashboard", dashboard.id);
dashboard.$delete(function() {
$scope.$parent.reloadDashboards();
});
Expand All @@ -150,6 +152,6 @@

angular.module('redash.controllers', [])
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
.controller('IndexCtrl', ['$scope', 'Dashboard', IndexCtrl])
.controller('IndexCtrl', ['$scope', 'Events', 'Dashboard', IndexCtrl])
.controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', MainCtrl]);
})();
16 changes: 12 additions & 4 deletions rd_ui/app/scripts/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(function() {
var DashboardCtrl = function($scope, $routeParams, $http, $timeout, Dashboard) {
var DashboardCtrl = function($scope, Events, $routeParams, $http, $timeout, Dashboard) {
Events.record(currentUser, "view", "dashboard", dashboard.id);

$scope.refreshEnabled = false;
$scope.refreshRate = 60;
$scope.dashboard = Dashboard.get({
Expand Down Expand Up @@ -35,6 +37,8 @@
$scope.triggerRefresh = function() {
$scope.refreshEnabled = !$scope.refreshEnabled;

Events.record(currentUser, "autorefresh", "dashboard", dashboard.id, {'enable': $scope.refreshEnabled});

if ($scope.refreshEnabled) {
var refreshRate = _.min(_.flatten($scope.dashboard.widgets), function(widget) {
return widget.visualization.query.ttl;
Expand All @@ -47,12 +51,14 @@
};
};

var WidgetCtrl = function($scope, $http, $location, Query) {
var WidgetCtrl = function($scope, Events, $http, $location, Query) {
$scope.deleteWidget = function() {
if (!confirm('Are you sure you want to remove "' + $scope.widget.visualization.name + '" from the dashboard?')) {
return;
}

Events.record(currentUser, "delete", "widget", $scope.widget.id);

$http.delete('/api/widgets/' + $scope.widget.id).success(function() {
$scope.dashboard.widgets = _.map($scope.dashboard.widgets, function(row) {
return _.filter(row, function(widget) {
Expand All @@ -62,6 +68,8 @@
});
};

// TODO: fire event for query view for each query

$scope.query = new Query($scope.widget.visualization.query);
$scope.queryResult = $scope.query.getQueryResult();

Expand All @@ -72,7 +80,7 @@
};

angular.module('redash.controllers')
.controller('DashboardCtrl', ['$scope', '$routeParams', '$http', '$timeout', 'Dashboard', DashboardCtrl])
.controller('WidgetCtrl', ['$scope', '$http', '$location', 'Query', WidgetCtrl])
.controller('DashboardCtrl', ['$scope', 'Events', '$routeParams', '$http', '$timeout', 'Dashboard', DashboardCtrl])
.controller('WidgetCtrl', ['$scope', 'Events', '$http', '$location', 'Query', WidgetCtrl])

})();
9 changes: 7 additions & 2 deletions rd_ui/app/scripts/controllers/query_source.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(function() {
'use strict';

function QuerySourceCtrl($controller, $scope, $location, Query, Visualization, KeyboardShortcuts) {
function QuerySourceCtrl(Events, $controller, $scope, $location, Query, Visualization, KeyboardShortcuts) {
// extends QueryViewCtrl
$controller('QueryViewCtrl', {$scope: $scope});
// TODO:
// This doesn't get inherited. Setting it on this didn't work either (which is weird).
// Obviously it shouldn't be repeated, but we got bigger fish to fry.
var DEFAULT_TAB = 'table';

Events.record(currentUser, 'view_source', 'query', $scope.query.id);

var isNewQuery = !$scope.query.id,
queryText = $scope.query.query,
// ref to QueryViewCtrl.saveQuery
Expand Down Expand Up @@ -47,6 +49,7 @@
};

$scope.duplicateQuery = function() {
Events.record(currentUser, 'fork', 'query', $scope.query.id);
$scope.query.id = null;
$scope.query.ttl = -1;

Expand All @@ -62,6 +65,8 @@
$scope.deleteVisualization = function($e, vis) {
$e.preventDefault();
if (confirm('Are you sure you want to delete ' + vis.name + ' ?')) {
Events.record(currentUser, 'delete', 'visualization', vis.id);

Visualization.delete(vis);
if ($scope.selectedTab == vis.id) {
$scope.selectedTab = DEFAULT_TAB;
Expand Down Expand Up @@ -94,7 +99,7 @@
}

angular.module('redash.controllers').controller('QuerySourceCtrl', [
'$controller', '$scope', '$location', 'Query',
'Events', '$controller', '$scope', '$location', 'Query',
'Visualization', 'KeyboardShortcuts', QuerySourceCtrl
]);
})();
86 changes: 46 additions & 40 deletions rd_ui/app/scripts/controllers/query_view.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(function() {
'use strict';

function QueryViewCtrl($scope, $route, $location, notifications, growl, Query, DataSource) {
function QueryViewCtrl($scope, Events, $route, $location, notifications, growl, Query, DataSource) {
var DEFAULT_TAB = 'table';

$scope.query = $route.current.locals.query;
Events.record(currentUser, 'view', 'query', $scope.query.id);
$scope.queryResult = $scope.query.getQueryResult();
$scope.queryExecuting = false;

Expand Down Expand Up @@ -37,39 +38,43 @@
growl.addSuccessMessage(options.successMessage);
}, function(httpResponse) {
growl.addErrorMessage(options.errorMessage);
})
.$promise;
}).$promise;
}

$scope.saveDescription = function() {
Events.record(currentUser, 'edit_description', 'query', $scope.query.id);
$scope.saveQuery(undefined, {'description': $scope.query.description});
};

$scope.saveName = function() {
Events.record(currentUser, 'edit_name', 'query', $scope.query.id);
$scope.saveQuery(undefined, {'name': $scope.query.name});
};

$scope.executeQuery = function() {
$scope.queryResult = $scope.query.getQueryResult(0);
$scope.lockButton(true);
$scope.cancelling = false;
Events.record(currentUser, 'execute', 'query', $scope.query.id);
};

$scope.cancelExecution = function() {
$scope.cancelling = true;
$scope.queryResult.cancelExecution();
Events.record(currentUser, 'cancel_execute', 'query', $scope.query.id);
};

$scope.updateDataSource = function() {
$scope.query.latest_query_data = null;
$scope.query.latest_query_data_id = null;
Query.save({
'id': $scope.query.id,
'data_source_id': $scope.query.data_source_id,
'latest_query_data_id': null
});
Events.record(currentUser, 'update_data_source', 'query', $scope.query.id);
$scope.query.latest_query_data = null;
$scope.query.latest_query_data_id = null;
Query.save({
'id': $scope.query.id,
'data_source_id': $scope.query.data_source_id,
'latest_query_data_id': null
});

$scope.executeQuery();
$scope.executeQuery();
};

$scope.setVisualizationTab = function (visualization) {
Expand All @@ -81,38 +86,36 @@
$scope.$parent.pageTitle = $scope.query.name;
});

$scope.$watch('queryResult && queryResult.getError()',
function(newError, oldError) {
if (newError == undefined) {
return;
}

if (oldError == undefined && newError != undefined) {
$scope.lockButton(false);
}
});
$scope.$watch('queryResult && queryResult.getError()', function(newError, oldError) {
if (newError == undefined) {
return;
}

$scope.$watch('queryResult && queryResult.getData()',
function(data, oldData) {
if (!data) {
return;
}
if (oldError == undefined && newError != undefined) {
$scope.lockButton(false);
}
});

$scope.filters = $scope.queryResult.getFilters();
$scope.$watch('queryResult && queryResult.getData()', function(data, oldData) {
if (!data) {
return;
}

if ($scope.queryResult.getId() == null) {
$scope.dataUri = "";
} else {
$scope.dataUri =
'/api/queries/' + $scope.query.id + '/results/' +
$scope.queryResult.getId() + '.csv';
$scope.filters = $scope.queryResult.getFilters();

$scope.dataFilename =
$scope.query.name.replace(" ", "_") +
moment($scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") +
".csv";
}
});
if ($scope.queryResult.getId() == null) {
$scope.dataUri = "";
} else {
$scope.dataUri =
'/api/queries/' + $scope.query.id + '/results/' +
$scope.queryResult.getId() + '.csv';

$scope.dataFilename =
$scope.query.name.replace(" ", "_") +
moment($scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") +
".csv";
}
});

$scope.$watch("queryResult && queryResult.getStatus()", function(status) {
if (!status) {
Expand All @@ -139,11 +142,14 @@
$scope.$watch(function() {
return $location.hash()
}, function(hash) {
if (hash == 'pivot') {
Events.record(currentUser, 'pivot', 'query', $scope.query && $scope.query.id);
}
$scope.selectedTab = hash || DEFAULT_TAB;
});
};

angular.module('redash.controllers')
.controller('QueryViewCtrl',
['$scope', '$route', '$location', 'notifications', 'growl', 'Query', 'DataSource', QueryViewCtrl]);
['$scope', 'Events', '$route', '$location', 'notifications', 'growl', 'Query', 'DataSource', QueryViewCtrl]);
})();
12 changes: 7 additions & 5 deletions rd_ui/app/scripts/directives/dashboard_directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

var directives = angular.module('redash.directives');

directives.directive('editDashboardForm', ['$http', '$location', '$timeout', 'Dashboard',
function($http, $location, $timeout, Dashboard) {
directives.directive('editDashboardForm', ['Events', '$http', '$location', '$timeout', 'Dashboard',
function(Events, $http, $location, $timeout, Dashboard) {
return {
restrict: 'E',
scope: {
Expand Down Expand Up @@ -54,7 +54,6 @@
_.each(layout, function(item) {
var el = gsItemTemplate.replace('{id}', item.id).replace('{name}', item.name);
gridster.add_widget(el, item.xSize, item.ySize, item.col, item.row);

});
}
});
Expand Down Expand Up @@ -89,14 +88,17 @@
$scope.dashboard = new Dashboard(response);
$scope.saveInProgress = false;
$(element).modal('hide');
})
});
Events.record(currentUser, 'edit', 'dashboard', $scope.dashboard.id);
} else {

$http.post('/api/dashboards', {
'name': $scope.dashboard.name
}).success(function(response) {
$(element).modal('hide');
$location.path('/dashboard/' + response.slug).replace();
})
});
Events.record(currentUser, 'create', 'dashboard');
}
}

Expand Down
5 changes: 3 additions & 2 deletions rd_ui/app/scripts/services/notifications.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function () {
var notifications = function () {
var notifications = function (Events) {
var notificationService = {};
var lastNotification = null;

Expand Down Expand Up @@ -40,6 +40,7 @@
notification.onclick = function () {
window.focus();
this.cancel();
Events.record(currentUser, 'click', 'notification');
};

notification.show()
Expand All @@ -49,5 +50,5 @@
}

angular.module('redash.services')
.factory('notifications', notifications);
.factory('notifications', ['Events', notifications]);
})();
Loading

0 comments on commit 185b1c9

Please sign in to comment.