Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24972] Feature/hierarchy mode query #5330

Merged
merged 5 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/contracts/queries/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BaseContract < ::ModelContract
attribute :is_public # => public
attribute :display_sums # => sums
attribute :timeline_visible
attribute :show_hierarchies

attribute :column_names # => columns
attribute :filters
Expand Down
8 changes: 8 additions & 0 deletions app/models/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Query < ActiveRecord::Base
validate :validate_columns
validate :validate_sort_criteria
validate :validate_group_by
validate :validate_show_hierarchies

scope :visible, ->(to:) do
# User can see public queries and his own queries
Expand Down Expand Up @@ -155,6 +156,7 @@ def self.new_default(attributes = nil)
new(attributes).tap do |query|
query.add_default_filter
query.set_default_sort
query.show_hierarchies = true
end
end

Expand Down Expand Up @@ -235,6 +237,12 @@ def validate_group_by
end
end

def validate_show_hierarchies
if show_hierarchies && group_by.present?
errors.add :show_hierarchies, :group_by_hierarchies_exclusive, group_by: group_by
end
end

def editable_by?(user)
return false unless user
# Admin can edit them all and regular users can edit their private queries
Expand Down
2 changes: 2 additions & 0 deletions app/services/api/v3/parse_query_params_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def call(params)

parsed_params[:timeline_visible] = boolearize(params[:timelineVisible])

parsed_params[:show_hierarchies] = boolearize(params[:showHierarchies])

ServiceResult.new(success: true,
result: without_empty(parsed_params, params.keys))
end
Expand Down
18 changes: 16 additions & 2 deletions app/services/update_query_from_params_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def call(params)

apply_timeline(params)

apply_hierarchy(params)

disable_hierarchy_when_only_grouped_by(params)

if query.valid?
ServiceResult.new(success: true,
result: query)
Expand Down Expand Up @@ -77,11 +81,21 @@ def apply_columns(params)
end

def apply_sums(params)
query.display_sums = params[:display_sums] if params[:display_sums]
query.display_sums = params[:display_sums] if params.key?(:display_sums)
end

def apply_timeline(params)
query.timeline_visible = params[:timeline_visible] if params[:timeline_visible]
query.timeline_visible = params[:timeline_visible] if params.key?(:timeline_visible)
end

def apply_hierarchy(params)
query.show_hierarchies = params[:show_hierarchies] if params.key?(:show_hierarchies)
end

def disable_hierarchy_when_only_grouped_by(params)
if params.key?(:group_by) && !params.key?(:show_hierarchies)
query.show_hierarchies = false
end
end

attr_accessor :query,
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ en:
identical_projects: "Dependency cannot be created between one project and itself."
project_association_not_allowed: "does not allow associations."
query:
group_by_hierarchies_exclusive: "is mutually exclusive with group by '%{group_by}'. You cannot activate both."
filters:
custom_fields:
inexistent: "There is no custom field for the filter."
Expand Down
3 changes: 3 additions & 0 deletions config/locales/js-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ en:
column_names: "Columns"
group_by: "Group results by"
group: "Group by"
group_by_disabled_by_hierarchy: "Group by is disabled due to the hierarchy mode being active."
hierarchy_disabled_by_group_by: "Hierarchy mode is disabled due to results being grouped by %{column}."
hierarchy_mode: "Hierarchy mode"
sort_ascending: "Sort ascending"
sort_descending: "Sort descending"
move_column_left: "Move column left"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170407074032_add_hierarchy_to_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHierarchyToQuery < ActiveRecord::Migration[5.0]
def change
add_column :queries, :show_hierarchies, :boolean, default: true
end
end
46 changes: 43 additions & 3 deletions docs/api/apiv3/endpoints/queries.apib
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Please note, that all the properties listed above will also be embedded when ind
| name | Query name | String | | READ |
| filters | A set of QueryFilters which will be applied to the work packages to determine the resulting work packages | []QueryFilterInstance | | READ |
| sums | Should sums (of supported properties) be shown? | Boolean | | READ |
| timelineVisible | Should the timeline mode be shown? | Boolean | | READ |
| showHierarchies | Should the hierarchy mode be enabled? | Boolean | | READ |
| public | Can users besides the owner see the query? | Boolean | | READ |
| starred | Should the query be highlighted to the user? | Boolean | | READ |

Expand Down Expand Up @@ -99,7 +101,7 @@ If the values are nonprimitive (e.g. User, Project), they will be listed as obje

```

## Query [/api/v3/queries/{id}{?offset,pageSize,filters,sortBy,groupBy,showSums}]
## Query [/api/v3/queries/{id}{?offset,pageSize,filters,sortBy,groupBy,showSums,timelineVisible,showHierarchies}]

+ Model
+ Body
Expand Down Expand Up @@ -257,6 +259,8 @@ Retreive an individual query as identified by the id parameter. Then end point a
+ sortBy (optional, string, `[["status", "asc"]]`) ... JSON specifying sort criteria. The sort criteria is applied to the querie's result collection of work packages overriding the query's persisted sort criteria.
+ groupBy (optional, string, `status`) ... The column to group by. The grouping criteria is applied to the to the querie's result collection of work packages overriding the query's persisted group criteria.
+ showSums = `false` (optional, boolean, `true`) ... Indicates whether properties should be summed up if they support it. The showSums parameter is applied to the to the querie's result collection of work packages overriding the query's persisted sums property.
+ timelineVisible = `false` (optional, boolean, `true`) ... Indicates whether the timeline should be shown.
+ showHierarchies = `true` (optional, boolean, `true`) ... Indicates whether the hierarchy mode should be enabled.

+ Response 200 (application/hal+json)

Expand Down Expand Up @@ -398,7 +402,7 @@ Delete the query identified by the id parameter
"message": "The requested resource could not be found."
}

## Default Query [/api/v3/queries/default{?offset,pageSize,filters,sortBy,groupBy,showSums}]
## Default Query [/api/v3/queries/default{?offset,pageSize,filters,sortBy,groupBy,showSums,timelineVisible,showHierarchies}]

+ Model
+ Body
Expand Down Expand Up @@ -428,6 +432,8 @@ Delete the query identified by the id parameter
],
"public": false,
"sums": false,
"timelineVisible": false,
"showHierarchies": true,
"starred": false,
"_embedded": {
"results": {
Expand Down Expand Up @@ -533,6 +539,8 @@ Same as [viewing an existing, persisted Query](#queries-query-get) in its respon
+ sortBy (optional, string, `[["status", "asc"]]`) ... JSON specifying sort criteria. The sort criteria is applied to the querie's result collection of work packages overriding the query's persisted sort criteria.
+ groupBy (optional, string, `status`) ... The column to group by. The grouping criteria is applied to the to the querie's result collection of work packages overriding the query's persisted group criteria.
+ showSums = `false` (optional, boolean, `true`) ... Indicates whether properties should be summed up if they support it. The showSums parameter is applied to the to the querie's result collection of work packages overriding the query's persisted sums property.
+ timelineVisible = `false` (optional, boolean, `true`) ... Indicates whether the timeline should be shown.
+ showHierarchies = `true` (optional, boolean, `true`) ... Indicates whether the hierarchy mode should be enabled.

+ Response 200 (application/hal+json)

Expand All @@ -552,7 +560,7 @@ Same as [viewing an existing, persisted Query](#queries-query-get) in its respon
"message": "You are not authorized to access this resource."
}

## Default Query for Project [/api/v3/projects/{id}/queries/default{?offset,pageSize,filters,sortBy,groupBy,showSums}]
## Default Query for Project [/api/v3/projects/{id}/queries/default{?offset,pageSize,filters,sortBy,groupBy,showSums,timelineVisible,showHierarchies}]

+ Model
+ Body
Expand Down Expand Up @@ -582,6 +590,8 @@ Same as [viewing an existing, persisted Query](#queries-query-get) in its respon
],
"public": false,
"sums": false,
"timelineVisible": false,
"showHierarchies": true,
"starred": false,
"_embedded": {
"results": {
Expand Down Expand Up @@ -690,6 +700,8 @@ Same as [viewing an existing, persisted Query](#queries-query-get) in its respon
+ sortBy (optional, string, `[["status", "asc"]]`) ... JSON specifying sort criteria. The sort criteria is applied to the querie's result collection of work packages overriding the query's persisted sort criteria.
+ groupBy (optional, string, `status`) ... The column to group by. The grouping criteria is applied to the to the querie's result collection of work packages overriding the query's persisted group criteria.
+ showSums = `false` (optional, boolean, `true`) ... Indicates whether properties should be summed up if they support it. The showSums parameter is applied to the to the querie's result collection of work packages overriding the query's persisted sums property.
+ timelineVisible = `false` (optional, boolean, `true`) ... Indicates whether the timeline should be shown.
+ showHierarchies = `true` (optional, boolean, `true`) ... Indicates whether the hierarchy mode should be enabled.

+ Response 200 (application/hal+json)

Expand Down Expand Up @@ -1422,6 +1434,20 @@ For more details and all possible responses see the general specification of [Fo
"hasDefault": true,
"writable": true
},
"timelineVisible": {
"type": "Boolean",
"name": "Timeline visible",
"required": false,
"hasDefault": true,
"writable": true
},
"showHierarchies": {
"type": "Boolean",
"name": "Show hierarchies",
"required": false,
"hasDefault": true,
"writable": true
},
"starred": {
"type": "Boolean",
"name": "Starred",
Expand Down Expand Up @@ -1680,6 +1706,20 @@ Retrieve the schema for global queries, those, that are not assigned to a projec
"hasDefault": true,
"writable": true
},
"timelineVisible": {
"type": "Boolean",
"name": "Timeline visible",
"required": false,
"hasDefault": true,
"writable": true
},
"showHierarchies": {
"type": "Boolean",
"name": "Show hierarchies",
"required": false,
"hasDefault": true,
"writable": true
},
"starred": {
"type": "Boolean",
"name": "Starred",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class QueryResource extends HalResource {
public starred:boolean;
public sums:boolean;
public timelineVisible:boolean;
public showHierarchies:boolean;
public public:boolean;
public project:ProjectResource;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WorkPackageTableHierarchiesService } from './../../wp-fast-table/state/wp-table-hierarchy.service';
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
Expand Down Expand Up @@ -40,18 +41,28 @@ function ColumnContextMenuController($scope:any,
wpTableColumns:WorkPackageTableColumnsService,
wpTableSortBy:WorkPackageTableSortByService,
wpTableGroupBy:WorkPackageTableGroupByService,
wpTableHierarchies:WorkPackageTableHierarchiesService,
I18n:op.I18n,
columnsModal:any) {

$scope.I18n = I18n;
$scope.text = {
group_by: I18n.t('js.work_packages.query.group'),
group_by_disabled_by_hierarchy: I18n.t('js.work_packages.query.group_by_disabled_by_hierarchy')
};

$scope.$watch('column', function () {
// fall back to 'id' column as the default
$scope.column = $scope.column || {name: 'id', sortable: true};
$scope.isGroupable = wpTableGroupBy.isGroupable($scope.column) && !wpTableGroupBy.isCurrentlyGroupedBy($scope.column);
$scope.isGroupableDisabled = wpTableHierarchies.isEnabled;
$scope.isSortable = wpTableSortBy.isSortable($scope.column)
});

wpTableHierarchies.observeOnScope($scope).subscribe(() => {
$scope.isGroupableDisabled = wpTableHierarchies.isEnabled;
});

// context menu actions

$scope.groupBy = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
</li>

<li ng-if="isGroupable">
<a class="menu-item" focus="focusFeature('group')" href="" ng-click="groupBy()">
<a class="menu-item"
ng-class="{'inactive': isGroupableDisabled }"
focus="focusFeature('group')"
href=""
ng-attr-title="{{ isGroupableDisabled ? text.group_by_disabled_by_hierarchy : text.group_by }}"
ng-disabled="isGroupableDisabled"
ng-click="isGroupableDisabled || groupBy()">
<i class="icon-action-menu icon-group-by"></i>
<span ng-bind="I18n.t('js.work_packages.query.group')"/>
<span ng-bind="text.group_by"/>
</a>
</li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import {opWorkPackagesModule} from '../../../angular-modules';
import {ContextMenuService} from '../context-menu.service';
import {WorkPackageTableHierarchyService} from '../../wp-fast-table/state/wp-table-hierarchy.service';
import {WorkPackageTableHierarchiesService} from '../../wp-fast-table/state/wp-table-hierarchy.service';
import {WorkPackageTableSumService} from '../../wp-fast-table/state/wp-table-sum.service';
import {WorkPackageTableGroupByService} from '../../wp-fast-table/state/wp-table-group-by.service';
import {WorkPackagesListService} from '../../wp-list/wp-list.service';
Expand Down Expand Up @@ -70,15 +70,32 @@ function SettingsDropdownMenuController($scope:IMyScope,
sortingModal:any,
groupingModal:any,
contextMenu:ContextMenuService,
wpTableHierarchy:WorkPackageTableHierarchyService,
wpTableHierarchies:WorkPackageTableHierarchiesService,
wpTableSum:WorkPackageTableSumService,
wpTableGroupBy:WorkPackageTableGroupByService,
wpListService:WorkPackagesListService,
states:States,
AuthorisationService:any,
NotificationsService:any) {

$scope.displayHierarchies = wpTableHierarchy.isEnabled;
$scope.text = {
group_by_title: () => {
if ($scope.displayHierarchies) {
return I18n.t('js.work_packages.query.group_by_disabled_by_hierarchy');
} else {
return I18n.t('js.work_packages.query.hierarchy_mode');
}
},
hierarchy_title: () => {
if (wpTableGroupBy.current) {
return I18n.t('js.work_packages.query.hierarchy_disabled_by_group_by', { column: wpTableGroupBy.current.id! });
} else {
return I18n.t('js.work_packages.query.group_by');
}
}
};

$scope.displayHierarchies = wpTableHierarchies.isEnabled;
$scope.displaySums = wpTableSum.isEnabled;
$scope.isGrouped = wpTableGroupBy.isEnabled;

Expand Down Expand Up @@ -170,8 +187,8 @@ function SettingsDropdownMenuController($scope:IMyScope,
return;
}

const isEnabled = wpTableHierarchy.isEnabled;
wpTableHierarchy.setEnabled(!isEnabled);
const isEnabled = wpTableHierarchies.isEnabled;
wpTableHierarchies.setEnabled(!isEnabled);
};

$scope.toggleDisplaySums = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
href
ng-disabled="displayHierarchies"
ng-class="{'inactive': displayHierarchies}"
ng-attr-title="{{ text.group_by_title() }}"
ng-click="showGroupingModal($event)">
<i class="icon-action-menu icon-group-by"></i>
{{ I18n.t('js.toolbar.settings.group_by') }}
Expand All @@ -33,6 +34,7 @@
<a ng-disabled="isGrouped"
ng-class="{'inactive': !!isGrouped}"
ng-if="!displayHierarchies"
ng-attr-title="{{ text.hierarchy_title() }}"
class="menu-item"
href
ng-click="toggleHierarchies($event)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {WorkPackageTablePaginationService} from "../../wp-fast-table/state/wp-ta
import {WorkPackageTableSortByService} from "../../wp-fast-table/state/wp-table-sort-by.service";
import {WorkPackageTableSumService} from "../../wp-fast-table/state/wp-table-sum.service";
import {WorkPackageTablePagination} from "../../wp-fast-table/wp-table-pagination";
import {WorkPackageTableHierarchiesService} from './../../wp-fast-table/state/wp-table-hierarchy.service';
import {WorkPackagesListChecksumService} from "../../wp-list/wp-list-checksum.service";
import {WorkPackagesListService} from "../../wp-list/wp-list.service";
import {WorkPackageTableTimelineService} from "../../wp-fast-table/state/wp-table-timeline.service";
Expand All @@ -52,7 +53,8 @@ function WorkPackagesListController($scope:any,
wpTableGroupBy:WorkPackageTableGroupByService,
wpTableFilters:WorkPackageTableFiltersService,
wpTableSum:WorkPackageTableSumService,
wpTableTimeline: WorkPackageTableTimelineService,
wpTableTimeline:WorkPackageTableTimelineService,
wpTableHierarchies:WorkPackageTableHierarchiesService,
wpTablePagination:WorkPackageTablePaginationService,
wpListService:WorkPackagesListService,
wpListChecksumService:WorkPackagesListChecksumService,
Expand Down Expand Up @@ -116,6 +118,10 @@ function WorkPackagesListController($scope:any,
updateAndExecuteIfAltered(timeline.current, "timelineVisible");
});

wpTableHierarchies.observeOnScope($scope).subscribe(hierarchies => {
updateAndExecuteIfAltered(hierarchies.current, 'showHierarchies');
});

wpTableColumns.observeOnScope($scope).subscribe(columns => {
updateAndExecuteIfAltered(columns.current, "columns");
});
Expand Down Expand Up @@ -218,6 +224,7 @@ function WorkPackagesListController($scope:any,
!states.table.sortBy.value ||
!states.table.groupBy.value ||
!states.table.timelineVisible.value ||
!states.table.hierarchies.value ||
!states.table.sum.value;
}

Expand Down
Loading