Merge pull request #3982 from furinvader/refactoring/sort-header-directive

Refactor sort header directive
pull/3984/head
Alex Dik 9 years ago
commit 4859bd186f
  1. 15
      frontend/app/components/context-menus/column-context-menu/column-context-menu.controller.js
  2. 40
      frontend/app/components/context-menus/column-context-menu/column-context-menu.service.js
  3. 17
      frontend/app/components/context-menus/column-context-menu/column-context-menu.service.test.js
  4. 0
      frontend/app/components/context-menus/column-context-menu/column-context-menu.template.html
  5. 4
      frontend/app/components/context-menus/types-drop-down-menu/types-drop-down-menu.service.js
  6. 0
      frontend/app/components/context-menus/types-drop-down-menu/types-drop-down-menu.template.html
  7. 0
      frontend/app/components/wp-table/directives/sort-header/sort-header.directive.html
  8. 21
      frontend/app/components/wp-table/directives/sort-header/sort-header.directive.js
  9. 13
      frontend/app/components/wp-table/directives/sort-header/sort-header.directive.test.js
  10. 2
      frontend/app/components/wp-table/directives/wp-table/wp-table.directive.html
  11. 21
      frontend/app/work_packages/controllers/menus/index.js
  12. 3
      frontend/app/work_packages/directives/index.js

@ -1,4 +1,4 @@
//-- copyright
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
@ -24,9 +24,14 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
// ++
module.exports = function($scope, ColumnContextMenu, I18n, QueryService, WorkPackagesTableHelper, WorkPackagesTableService, columnsModal) {
angular
.module('openproject.workPackages')
.controller('ColumnContextMenuController', ColumnContextMenuController);
function ColumnContextMenuController($scope, columnContextMenu, QueryService,
WorkPackagesTableHelper, WorkPackagesTableService, columnsModal) {
$scope.I18n = I18n;
@ -64,7 +69,7 @@ module.exports = function($scope, ColumnContextMenu, I18n, QueryService, WorkPac
};
$scope.hideColumn = function(columnName) {
ColumnContextMenu.close();
columnContextMenu.close();
QueryService.hideColumns(new Array(columnName));
QueryService.getQuery().dirty = true;
};
@ -110,4 +115,4 @@ module.exports = function($scope, ColumnContextMenu, I18n, QueryService, WorkPac
return focus;
};
};
}

@ -0,0 +1,40 @@
// -- 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 Public 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.
// ++
angular
.module('openproject.workPackages')
.factory('columnContextMenu', columnContextMenu);
function columnContextMenu(ngContextMenu) {
return ngContextMenu({
controller: 'ColumnContextMenuController',
controllerAs: 'contextMenu',
templateUrl: '/components/context-menus/column-context-menu/column-context-menu.template.html',
container: '.work-packages--list-table-area'
});
}

@ -1,4 +1,4 @@
//-- copyright
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
@ -24,15 +24,13 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
/*jshint expr: true*/
// ++
describe('columnContextMenu', function() {
var container, contextMenu, $rootScope, scope, stateParams, ngContextMenu;
stateParams = {};
beforeEach(module('ng-context-menu',
beforeEach(angular.mock.module('ng-context-menu',
'openproject.workPackages',
'openproject.workPackages.controllers',
'openproject.models',
@ -41,7 +39,7 @@ describe('columnContextMenu', function() {
'openproject.services',
'openproject.templates'));
beforeEach(module('openproject.templates', function($provide) {
beforeEach(angular.mock.module('openproject.templates', function($provide) {
var configurationService = {};
configurationService.isTimezoneSet = sinon.stub().returns(false);
@ -60,7 +58,9 @@ describe('columnContextMenu', function() {
$rootScope = _$rootScope_;
ngContextMenu = _ngContextMenu_;
var template = $templateCache.get('/templates/work_packages/menus/column_context_menu.html');
var template = $templateCache.get(
'/components/context-menus/column-context-menu/column-context-menu.template.html');
$templateCache.put('column_context_menu.html', [200, template, {}]);
contextMenu = ngContextMenu({
@ -74,12 +74,11 @@ describe('columnContextMenu', function() {
}));
describe('when the context menu handler of a column is clicked', function() {
var I18n, QueryService;
var QueryService;
var column = { name: 'status', title: 'Status' },
anotherColumn = { name: 'subject', title: 'Subject' },
columns = [column, anotherColumn],
query = Factory.build('Query', { columns: columns });
var directiveScope;
beforeEach(inject(function(_QueryService_) {
QueryService = _QueryService_;

@ -33,7 +33,9 @@ angular
function typesDropDownMenu(ngContextMenu) {
return ngContextMenu({
templateUrl: '/components/wp-buttons/wp-create-button/types-drop-down-menu.template.html',
templateUrl: '/components/context-menus/types-drop-down-menu/' +
'types-drop-down-menu.template.html',
container: '.wp-create-button'
});
}

@ -1,4 +1,4 @@
//-- copyright
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
@ -24,13 +24,17 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
// ++
module.exports = function(I18n){
angular
.module('openproject.workPackages.directives')
.directive('sortHeader', sortHeader);
function sortHeader(){
return {
restrict: 'A',
templateUrl: '/templates/work_packages/sort_header.html',
templateUrl: '/components/wp-table/directives/sort-header/sort-header.directive.html',
scope: {
query: '=',
headerName: '=',
@ -38,6 +42,7 @@ module.exports = function(I18n){
sortable: '=',
locale: '='
},
link: function(scope, element) {
scope.$watch('query.sortation.sortElements', function(sortElements){
var latestSortElement = sortElements[0];
@ -51,6 +56,8 @@ module.exports = function(I18n){
setFullTitle();
}, true);
scope.$watch('currentSortDirection', setActiveColumnClass);
function setFullTitle() {
if(!scope.sortable) scope.fullTitle = '';
@ -62,13 +69,9 @@ module.exports = function(I18n){
}
}
// active-column class setting
function setActiveColumnClass() {
element.toggleClass('active-column', !!scope.currentSortDirection);
}
scope.$watch('currentSortDirection', setActiveColumnClass);
}
};
};
}

@ -1,4 +1,4 @@
//-- copyright
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
@ -24,7 +24,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
// ++
/*jshint expr: true*/
@ -32,20 +32,17 @@ describe('sortHeader Directive', function() {
var compile, element1, element2, rootScope, scope;
beforeEach(angular.mock.module('openproject.workPackages.directives'));
beforeEach(module('openproject.templates', 'openproject.models'));
beforeEach(angular.mock.module('openproject.templates', 'openproject.models'));
beforeEach(inject(function($rootScope, $compile) {
var header1Html;
header1Html = '<th sort-header sortable="true" query="query" header-name="headerName1" header-title="headerTitle1"></th>';
var header2Html;
header2Html = '<th sort-header sortable="true" query="query" header-name="headerName2" header-title="headerTitle2"></th>';
var header1Html = '<th sort-header sortable="true" query="query" header-name="headerName1" header-title="headerTitle1"></th>';
var header2Html = '<th sort-header sortable="true" query="query" header-name="headerName2" header-title="headerTitle2"></th>';
element1 = angular.element(header1Html);
element2 = angular.element(header2Html);
rootScope = $rootScope;
scope = $rootScope.$new();
// Mock hasDropdownManu controller
var dropdownMenuController = function() {
this.open = function() {
return true;

@ -24,7 +24,7 @@
<th sort-header ng-repeat="column in columns"
has-dropdown-menu
position-relative-to=".generic-table--sort-header-outer"
target="ColumnContextMenu"
target="columnContextMenu"
locals="columns, column"
locale="column.custom_field && columns.custom_field.name_locale || I18n.locale"
header-name="column.name"

@ -28,27 +28,6 @@
angular.module('openproject.workPackages')
.factory('ColumnContextMenu', [
'ngContextMenu',
function(ngContextMenu) {
return ngContextMenu({
controller: 'ColumnContextMenuController',
controllerAs: 'contextMenu',
templateUrl: '/templates/work_packages/menus/column_context_menu.html',
container: '.work-packages--list-table-area'
});
}
])
.controller('ColumnContextMenuController', [
'$scope',
'ColumnContextMenu',
'I18n',
'QueryService',
'WorkPackagesTableHelper',
'WorkPackagesTableService',
'columnsModal',
require('./column-context-menu-controller')
])
.factory('ShowMoreDropdownMenu', [
'ngContextMenu',
function(ngContextMenu) {

@ -51,9 +51,6 @@ angular.module('openproject.workPackages.directives')
'ADD_FILTER_SELECT_INDEX', require('./query-filters-directive')
])
.directive('queryForm', require('./query-form-directive'))
.directive('sortHeader', [
'I18n', require('./sort-header-directive')
])
.constant('PERMITTED_MORE_MENU_ACTIONS', [
'log_time',
'move',

Loading…
Cancel
Save