Set default value at backend side

This commit is contained in:
François Turbelin
2020-02-04 22:04:09 +01:00
parent 7100111f93
commit 89d2750fc4
2 changed files with 6 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
'q[name_cont]': $scope.query,
'q[supplier_id_eq]': $scope.producerFilter,
'q[primary_taxon_id_eq]': $scope.categoryFilter,
'q[s]': $scope.sorting || 'created_at asc',
'q[s]': $scope.sorting,
import_date: $scope.importDateFilter,
page: $scope.page,
per_page: $scope.per_page

View File

@@ -60,7 +60,7 @@ module Api
end
@products = product_query.
ransack(params[:q]).
ransack(query_params_with_defaults).
result.
page(params[:page] || DEFAULT_PAGE).
per(params[:per_page] || DEFAULT_PER_PAGE)
@@ -142,6 +142,10 @@ module Api
}.to_json
end
def query_params_with_defaults
params[:q].to_h.reverse_merge!({ 's' => 'created_at DESC' })
end
def pagination_data(results)
{
results: results.total_count,