Refactored group by watching into directive to get clear filter working.

pull/997/head
Richard 11 years ago
parent 860ccda74d
commit 9927409522
  1. 12
      app/assets/javascripts/angular/controllers/work-packages-controller.js
  2. 4
      app/assets/javascripts/angular/directives/work_packages/filter-clear-directive.js
  3. 2
      app/assets/javascripts/angular/directives/work_packages/query-form-directive.js
  4. 8
      app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js
  5. 8
      app/assets/javascripts/angular/models/query.js
  6. 2
      app/views/work_packages/_list.html.erb
  7. 2
      public/templates/work_packages/filter_clear.html
  8. 2
      public/templates/work_packages/work_packages_options.html

@ -2,15 +2,6 @@ angular.module('openproject.workPackages.controllers')
.controller('WorkPackagesController', ['$scope', 'WorkPackagesTableHelper', 'Query', 'Sortation', 'WorkPackageService', function($scope, WorkPackagesTableHelper, Query, Sortation, WorkPackageService) {
$scope.$watch('groupBy', function() {
var groupByColumnIndex = $scope.columns.map(function(column){
return column.name;
}).indexOf($scope.groupBy);
$scope.groupByColumn = $scope.columns[groupByColumnIndex];
$scope.query.group_by = $scope.groupBy; // keep the query in sync
});
function initialSetup() {
$scope.projectIdentifier = gon.project_identifier;
$scope.operatorsAndLabelsByFilterType = gon.operators_and_labels_by_filter_type;
@ -27,7 +18,6 @@ angular.module('openproject.workPackages.controllers')
$scope.columns = gon.columns;
$scope.availableColumns = WorkPackagesTableHelper.getColumnDifference(gon.available_columns, $scope.columns);
$scope.groupBy = $scope.query.group_by || '';
$scope.currentSortation = gon.sort_criteria;
angular.extend($scope.query, {
@ -51,7 +41,7 @@ angular.module('openproject.workPackages.controllers')
$scope.setupWorkPackagesTable = function(json) {
$scope.workPackageCountByGroup = json.work_package_count_by_group;
$scope.rows = WorkPackagesTableHelper.getRows(json.work_packages, $scope.groupBy);
$scope.rows = WorkPackagesTableHelper.getRows(json.work_packages, $scope.query.group_by);
$scope.totalSums = json.sums;
$scope.groupSums = json.group_sums;
$scope.totalEntries = json.total_entries;

@ -6,8 +6,8 @@ angular.module('openproject.workPackages.directives')
templateUrl: '/templates/work_packages/filter_clear.html',
scope: true,
link: function(scope, element, attributes) {
scope.clearFilter = function(){
scope.query.clearFilters();
scope.clearQuery = function(){
scope.query.clearAll();
}
}
};

@ -10,7 +10,7 @@ angular.module('openproject.workPackages.directives')
pre: function(scope) {
scope.showQueryOptions = false;
scope.$watch('groupBy', function(oldValue, newValue) {
scope.$watch('query.group_by', function(oldValue, newValue) {
if (newValue !== oldValue) {
scope.updateResults();
}

@ -5,6 +5,14 @@ angular.module('openproject.workPackages.directives')
restrict: 'E',
templateUrl: '/templates/work_packages/work_packages_options.html',
link: function(scope, element, attributes) {
scope.$watch('query.group_by', function() {
var groupByColumnIndex = scope.columns.map(function(column){
return column.name;
}).indexOf(scope.query.group_by);
scope.groupByColumn = scope.columns[groupByColumnIndex];
// $scope.query.group_by = $scope.groupBy; // keep the query in sync
});
}
};
}]);

@ -4,6 +4,7 @@ angular.module('openproject.models')
Query = function (data, options) {
angular.extend(this, data, options);
this.group_by = this.group_by || '';
if (this.filters === undefined) this.filters = [];
};
@ -75,6 +76,13 @@ angular.module('openproject.models')
});
},
clearAll: function(){
this.group_by = '';
this.display_sums = false;
this.id = null;
this.clearFilters();
},
clearFilters: function(){
this.filters.map(function(filter){
filter.deactivated = true;

@ -36,7 +36,7 @@ See doc/COPYRIGHT.rdoc for more details.
columns="columns"
rows="rows"
query="query"
group-by="groupBy"
group-by="query.group_by"
group-by-column="groupByColumn"
count-by-group="workPackageCountByGroup"
display-sums="query.display_sums"

@ -1,3 +1,3 @@
<span>
<a href="" class="icon icon-undo" ng-click="clearFilter()">Clear</a>
<a href="" class="icon icon-undo" ng-click="clearQuery()">Clear</a>
</span>

@ -30,7 +30,7 @@
<div class="horizontal_margin">
<select id="group_by"
name="group_by"
ng-model="groupBy">
ng-model="query.group_by">
<option value=""></option>
<option ng-repeat="column in columns" value="{{ column.name }}">{{ column.title }}</option>
</select>

Loading…
Cancel
Save