all files / app/main/apps/scrumboard/sidenavs/settings/menus/labels/ labels-menu.controller.js

21.74% Statements 5/23
0% Branches 0/4
14.29% Functions 1/7
21.74% Lines 5/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                                                                                                                                                      
(function ()
{
    'use strict';
 
    angular
        .module('app.scrumboard')
        .controller('LabelsMenuController', LabelsMenuController);
 
    /** @ngInject */
    function LabelsMenuController($document, $mdColorPalette, $mdDialog, fuseGenerator, msUtils, BoardService)
    {
        var vm = this;
 
        // Data
        vm.board = BoardService.data;
        vm.palettes = $mdColorPalette;
        vm.rgba = fuseGenerator.rgba;
        vm.hue = 500;
        vm.newLabelColor = 'red';
        vm.newLabelName = '';
 
        // Methods
        vm.addNewLabel = addNewLabel;
        vm.removeLabel = removeLabel;
 
        ////////
 
        /**
         * Add New Label
         */
        function addNewLabel()
        {
            vm.board.labels.push({
                id   : msUtils.guidGenerator(),
                name : vm.newLabelName,
                color: vm.newLabelColor
            });
            vm.newLabelName = '';
        }
 
        /**
         * Remove label
         *
         * @param ev
         * @param labelId
         */
        function removeLabel(ev, labelId)
        {
            var confirm = $mdDialog.confirm({
                title              : 'Remove Label',
                parent             : $document.find('#scrumboard'),
                textContent        : 'Are you sure want to remove label?',
                ariaLabel          : 'remove label',
                targetEvent        : ev,
                clickOutsideToClose: true,
                escapeToClose      : true,
                ok                 : 'Remove',
                cancel             : 'Cancel'
            });
 
            $mdDialog.show(confirm).then(function ()
            {
                var arr = vm.board.labels;
                arr.splice(arr.indexOf(arr.getById(labelId)), 1);
 
                angular.forEach(vm.board.cards, function (card)
                {
                    if ( card.idLabels && card.idLabels.indexOf(labelId) > -1 )
                    {
                        card.idLabels.splice(card.idLabels.indexOf(labelId), 1);
                    }
                });
            }, function ()
            {
                // Canceled
            });
        }
 
    }
})();