angular.module('myApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap', 'ngIdle']);
angular.module('myApp').config(['KeepaliveProvider', 'IdleProvider', function(KeepaliveProvider, IdleProvider) {
IdleProvider.idle(5);
IdleProvider.timeout(5);
KeepaliveProvider.interval(10);
IdleProvider.interrupt('keydown wheel mousedown touchstart touchmove scroll');
}]);
// This will check the idle status when the app starts
// angular.module('myApp').run(['Idle', function(Idle) {
// Idle.watch();
// }]);
angular.module('myApp').controller('DemoCtrl', function ($scope, Idle, Keepalive, $uibModal) {
var pc = this;
pc.data = "You're Idle. Do Something!!!";
$scope.started = false;
function closeModals() {
if( $scope.warning ) {
$scope.warning.close();
$scope.warning = null;
}
if( $scope.timeout ) {
$scope.timeout.close();
$scope.timeout = null;
}
}
$scope.$on('IdleStart', function() {
$scope.warning = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'warning-dialog.html',
controller: 'ModalInstanceCtrl',
controllerAs: 'pc',
size: 'sm',
resolve: {
data: function () {
return pc.data;
}
}
});
$scope.warning.result.then(function () {
console.log('Warning modal is closing now...');
});
});
$scope.$on('IdleTimeout', function() {
console.log('Idle timeout');
closeModals();
$scope.timeout = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'timeout-dialog.html',
controller: 'ModalInstanceCtrl',
controllerAs: 'pc',
size: 'sm',
resolve: {
data: function () {
return pc.data;
}
}
});
// Your log out code goes here
console.log('Your log out code may goes here...');
$scope.timeout.result.then(function () {
console.log('Timeout modal is closing now...');
});
});
$scope.$on('IdleEnd', function() {
console.log('Start closing warning modal');
closeModals();
});
$scope.start = function() {
Idle.watch();
$scope.started = true;
}
$scope.stop = function() {
Idle.unwatch();
$scope.started = false;
}
})
angular.module('myApp').controller('ModalInstanceCtrl', function (data) {
var pc = this;
pc.title = data;
});