Skip to content

Instantly share code, notes, and snippets.

@mrsweaters
Created November 18, 2015 18:01
Show Gist options
  • Select an option

  • Save mrsweaters/22ac20b73756022648dc to your computer and use it in GitHub Desktop.

Select an option

Save mrsweaters/22ac20b73756022648dc to your computer and use it in GitHub Desktop.
Intercom Angular.
dashboard.controller('DashboardController', ['$scope', '$state', '$rootScope', 'flash', '$location', 'Account', 'User', 'Test', 'Activity', 'Pusher', 'Alert', function($scope, $state, $rootScope, flash, $location, Account, User, Test, Activity, Pusher, Alert) {
$scope.setRootRecords = function () {
$rootScope.account = new Account(initialRecords.account);
$rootScope.currentUser = new User(initialRecords.currentUser);
$scope.activities = initialRecords.activities;
$scope.alerts = initialRecords.alerts;
$scope.projects = initialRecords.projects;
$rootScope.location = $location;
$scope.chartData = [$rootScope.account.alerts_last_30_days];
$scope.chartLabels = Array(30).join(".").split(".");
$scope.chartColors = ['rgba(255,255,255, 0.4)']
$scope.series = ['Alerts last 30 days'];
$scope.chartOptions = {
barValueSpacing: 2,
barShowStroke: false,
showTooltips: false,
showScale: false,
responsive: false
};
if (!$rootScope.account.wizard_dismissed && $rootScope.account.tests_used == 0) $state.go('home.wizard');
if (window.Intercom && !impersonating) {
window.Intercom('boot', {
app_id: 'i52lirka',
email: $rootScope.currentUser.email,
user_id: $rootScope.currentUser.id,
created_at: $rootScope.currentUser.created_at,
active_alert_count: $scope.alerts.length,
project_count: $scope.projects.length,
test_count: $rootScope.account.tests_used,
tests_run_count: $rootScope.account.tests_run_count,
resolved_alerts_count: $rootScope.account.resolved_alerts_count,
widget: {
activator: '#IntercomDefaultWidget'
}
});
}
Pusher.subscribe('updated_test_in_account', $rootScope.account.id, function() {
$scope.activities = Activity.query();
$scope.alerts = Alert.query();
});
};
$scope.trendDirection = function () {
var delta = parseFloat($scope.currentUser.alert_delta);
if (delta === 0) return '';
if (delta > 0) return 'up';
if (delta < 0) return 'down';
};
$scope.set_panel = function () {
return $rootScope.panel;
};
$scope.chart_has_data = function () {
return chartData().length;
};
$scope.is = function(sections) {
sections = sections.split(',');
for (var i=0; i<sections.length; i++) {
var isSection = new RegExp(sections[i]).test($rootScope.location.path());
if (isSection) {return true;}
}
return false;
};
$scope.set_account = function (e, account) {
e.preventDefault();
$rootScope.currentUser.current_account_id = account.id;
$rootScope.currentUser.$update(function (user) {
window.location.reload();
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment