fix default sorting by parent

pull/4159/head
Jens Ulferts 9 years ago
parent 761fc11717
commit 9c6b7f4981
  1. 9
      app/controllers/api/experimental/concerns/query_loading.rb
  2. 1
      app/controllers/api/experimental/work_packages_controller.rb
  3. 2
      frontend/app/components/api/api-work-packages/api-work-packages.service.ts
  4. 3
      lib/api/v3/work_packages/work_package_list_helpers.rb

@ -30,6 +30,7 @@
# Differences being that it's not looking to the session and also existing
# queries will be augmented with the params data passed with them.
module Api::Experimental::Concerns::QueryLoading
DEFAULT_SORT_ORDER = 'parent:desc'
private
def init_query
@ -72,7 +73,7 @@ module Api::Experimental::Concerns::QueryLoading
end
@query.group_by = params[:group_by]
@query.sort_criteria = prepare_sort_criteria if params[:sort]
@query.sort_criteria = prepare_sort_criteria
@query.display_sums = params[:display_sums] if params[:display_sums].present?
@query.column_names = params[:c] if params[:c]
@query.column_names = nil if params[:default_columns]
@ -83,11 +84,13 @@ module Api::Experimental::Concerns::QueryLoading
def prepare_sort_criteria
# Note: There was a convention to have sortation strings in the form "type:desc,status:asc".
# For the sake of not breaking from convention we encoding/decoding the sortation.
params[:sort].split(',').map { |p| [p.split(':')[0], p.split(':')[1] || 'asc'] }
(params[:sort] || DEFAULT_SORT_ORDER)
.split(',')
.map { |p| [p.split(':')[0], p.split(':')[1] || 'asc'] }
end
def no_query_params_provided?
(params.keys & %w(group_by c fields f sort is_public name display_sums)).empty?
(params.keys & %w(groupBy c fields f sort isPublic name displaySums)).empty?
end
def allowed_links_on_query(query, user)

@ -29,7 +29,6 @@
module Api
module Experimental
class WorkPackagesController < ApplicationController
DEFAULT_SORT_ORDER = ['parent', 'desc']
include ApiController
include ::Api::Experimental::Concerns::GrapeRouting

@ -68,7 +68,7 @@ export class ApiWorkPackagesService {
params.showSums = query.displaySums;
}
if (query.sortCriteria) {
if (query.sortCriteria && query.sortCriteria.length > 0) {
params.sortBy = [query.sortCriteria];
}

@ -107,6 +107,9 @@ module API
if params[:sortBy]
query.sort_criteria = parse_sorting_from_json(params[:sortBy])
query_params[:sortBy] = params[:sortBy]
else
query.sort_criteria = [['parent', 'desc']]
query_params[:sortBy] = 'parent:desc'
end
end

Loading…
Cancel
Save