//-- copyright // OpenProject is a project management system. // Copyright (C) 2012-2015 the OpenProject Foundation (OPF) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General License version 3. // // OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: // Copyright (C) 2006-2013 Jean-Philippe Lang // Copyright (C) 2010-2013 the ChiliProject Team // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // See doc/COPYRIGHT.rdoc for more details. //++ import {opUiComponentsModule} from "../../../angular-modules"; export class interactiveTableController { // Width of the table and container last applied by this directive private lastWidthSet; // Width of the scrollbar to account for private scrollBarWidth = 16; constructor(protected $element, protected $timeout, protected $interval, protected $scope, protected $window) { 'ngInject'; // Initialize the interactive table $timeout(() => { this.cloneSpacer(); this.setTableWidths(); }); // Watch for global resize events // (e.g., table should expand to full width of window) angular.element($window).on('resize', _.debounce(() => this.setTableWidths(), 50)); // Watch for changes in state // (e.g., detail view opening) $scope.$on('$stateChangeSuccess', () => { $timeout(() => this.setTableWidths(), 200); }); // Watch for changes in the project navigation menu $scope.$on('openproject.layout.navigationToggled', () => { $timeout(() => this.setTableWidths(), 200); }); // Watch for updates not coming through the above methods // e.g., attributes in the table inititally rendering such as the progress bar // will cause the table width to expand var stopInterval = $interval(() => this.refreshWhenNeeded(), 1000, false); $scope.$on('$destroy', () => { $interval.cancel(stopInterval); }); } private get table() { return this.$element; } private get visible() { return this.table.is(':visible'); } private getInnerContainer() { return this.table.parent('.generic-table--results-container'); } private getOuterContainer() { return this.table.closest('.generic-table--container'); } private isWorkPackagesTable () { return this.table.closest('.work-package-table--container').length !== 0; } private getBackgrounds() { return this.getInnerContainer() .find('.generic-table--header-background,.generic-table--footer-background'); } private getHeadersFooters() { return this.table.find( '.generic-table--sort-header-outer,' + '.generic-table--header-outer,' + '.generic-table--footer-outer' ); } private cloneSpacer() { this.getHeadersFooters().each((i, el) => { var element = angular.element(this); var html = element.text(); var hiddenForSighted = element.find('.hidden-for-sighted').text(); html = html.replace(hiddenForSighted, ''); var spacerHtml = '