Sha256: c39e41ae3c50135736a2990c536e4f4940f498a0169bac0cdba6a6b79da5a62d

Contents?: true

Size: 1.77 KB

Versions: 15

Compression:

Stored size: 1.77 KB

Contents

/**
 * @ngdoc directive
 * @name Bastion.components.directive:currentTasks
 *
 * @requires $document
 * @requires CurrentUser
 * @requires Task
 *
 * @description
 *  Provides a widget showing current number of runnings tasks, popping
 *  up the table of recent tasks when clicked on.
 *
 * @example
    <span current-tasks></span>
 */
angular.module('Bastion.components').directive('currentTasks',
    ['$document', 'CurrentUser', 'Task',
    function ($document, CurrentUser, Task) {

        return {
            restrict: 'A',
            scope: true,
            templateUrl: 'components/views/current-tasks.html',

            controller: ['$scope', function ($scope) {
                // Hide the current tasks list if the user clicks outside of it
                var currentTasksMenu = angular.element('#currentTasks');
                $scope.visible = false;
                $scope.currentUser = CurrentUser;
                $scope.count = 0;

                $scope.toggleVisibility = function () {
                    $scope.visible = !$scope.visible;
                };

                $scope.updateTasks = function (tasks) {
                    $scope.count = tasks.length;
                };

                $document.bind('click', function (event) {
                    var target = angular.element(event.target);
                    if (!currentTasksMenu.find(target).length) {
                        $scope.visible = false;
                        if (!$scope.$$phase) {
                            $scope.$apply();
                        }
                    }
                });
            }],
            link: function (scope) {
                Task.registerSearch({ 'active_only': true, 'type': 'user', 'user_id': CurrentUser.id}, scope.updateTasks);
            }
        };
    }]);

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bastion-3.3.1 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.3.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.2.2 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.2.1 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.2.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.1.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.0.1 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-3.0.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.1.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.0.4 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.0.3 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.0.2 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.0.1 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-2.0.0 app/assets/javascripts/bastion/components/current-tasks.directive.js
bastion-1.0.2 app/assets/javascripts/bastion/components/current-tasks.directive.js