function controller()

in ui-modules/utils/table/index.js [309:386]


    function controller($templateCache, brUtilsGeneral) {
        this.getColumnTemplate = (id) => {
            let column = this.state.columns.find(column => column.id === id);
            return column.hasOwnProperty('templateUrl') ? $templateCache.get(column.templateUrl) : column.template;
        };

        this.dragStart = (e) => {
            this.resizerTarget = angular.element(e.target);
            this.thTarget = findAncestor(this.resizerTarget, 'th');
            this.tableTarget = findAncestor(this.thTarget, 'table');
            if (!this.tableTarget[0]) throw new Error('Resizer tag hierarchy not as expected; cannot drag');
            
            this.tableWidth = this.tableTarget[0].offsetWidth;
            if (this.tableTarget[0].style.minWidth != 0) {
                // if a width is defined, we need to hardcode all column widths
                // this.tableTarget.find('colgroup').children().forEach(
                angular.forEach( this.tableTarget.find('thead').find("tr").children(), th => { th.width = th.offsetWidth; } );
                angular.forEach( this.tableTarget.find('colgroup').children(), col => { col.style.width = null; } );
                this.tableTarget[0].style.minWidth = 0;
            }
            this.width = this.thTarget[0].offsetWidth;
            this.start = e.clientX;

            document.addEventListener('mouseup', this.dragEnd, false);
            document.addEventListener('mousemove', this.dragging, false);

            this.resizerTarget.addClass('dragging');
            
            // Disable highlighting while dragging
            if (e.stopPropagation) e.stopPropagation();
            if (e.preventDefault) e.preventDefault();
        };
        this.dragging = (e) => {
            // 23px wide is bare minimum given padding settings
            // if user goes below this we could give some visual indication the column is being hidden 
            var newWidth = Math.max(this.width - this.start + e.clientX, 23);  
            this.thTarget[0].style['width'] = `${newWidth}px`;
            this.tableTarget[0].style['width'] = `${this.tableWidth + newWidth - this.width}px`;
        };
        this.dragEnd = (e) => {
            document.removeEventListener('mouseup', this.dragEnd, false);
            document.removeEventListener('mousemove', this.dragging, false);
            this.resizerTarget.removeClass('dragging');
        };

        this.sortBy = (orderBy) => {
            let sort = '+';
            let currentOrderBy = this.getSortByFrom(orderBy);
            let currentOrderByIndex = this.state.sorts.indexOf(currentOrderBy);

            if (currentOrderBy) {
                let currentSort = this.getSortByDirectionFrom(orderBy);
                if (currentSort === '-') {
                    this.state.sorts.splice(currentOrderByIndex, 1);
                    return;
                }
                if (currentSort === '+') {
                    sort = '-';
                }
                this.state.sorts.splice(currentOrderByIndex, 1, `${sort}${orderBy}`);
            } else {
                this.state.sorts.push(`${sort}${orderBy}`);
            }
        };

        this.getSortByFrom = (orderBy) => {
            return this.state.sorts.find(sort => sort.substr(1) === orderBy);
        };

        this.getSortByDirectionFrom = (orderBy) => {
            let sortBy = this.getSortByFrom(orderBy);
            return sortBy ? sortBy.slice(0, 1) : '';
        };

        this.suggestionFormatter = (input) => {
            return brUtilsGeneral.isNonEmpty(input) ? `${input}:` : '';
        };
    }