Skip to content

Commit

Permalink
fix bug for instances that don't have a label (used by default for so…
Browse files Browse the repository at this point in the history
…rting and search)
  • Loading branch information
syphax-bouazzouni committed Jan 1, 2022
1 parent 83a765e commit c041100
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: a2dea8f73bb9d94b58a5dd4b4acef2cfcf4ac097
revision: 89a8f665f70644989adf70cd132bf0f38ef3414d
branch: master
specs:
goo (0.0.2)
Expand Down Expand Up @@ -356,7 +356,7 @@ GEM
macaddr (~> 1.0)

PLATFORMS
x86_64-linux
x86_64-darwin-21

DEPENDENCIES
activesupport (~> 3.0)
Expand Down
14 changes: 9 additions & 5 deletions controllers/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class InstancesController < ApplicationController
page, size = page_params
attributes = get_attributes_to_include(includes_param)
order_by = get_order_by_from(@params)


page_data = LinkedData::Models::Instance.where(filter_classes_by(cls.id))
.filter(label_regex_filter).in(sub)
.in(sub)
.include(attributes)
.order_by(order_by)
.page(page,size).all
page_data.order_by(order_by) unless (order_by.nil?)
page_data = page_data.page(page,size).all

bring_unmapped_if_needed includes_param, page_data , sub

Expand All @@ -31,11 +33,13 @@ class InstancesController < ApplicationController
page, size = page_params
attributes = get_attributes_to_include(includes_param)
order_by = get_order_by_from(@params)

page_data = LinkedData::Models::Instance.where.filter(label_regex_filter)
.in(sub)
.include(attributes)
.order_by(order_by)
.page(page,size).all
page_data.order_by(order_by) unless (order_by.nil?)
page_data = page_data.page(page,size).all


bring_unmapped_if_needed includes_param, page_data , sub
reply page_data
Expand Down
4 changes: 2 additions & 2 deletions helpers/instances_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module Sinatra
module Helpers
module InstancesHelper
def label_regex_filter
(Goo::Filter.new(:label).regex(@params["search"])) if @params["search"] != ""
(Goo::Filter.new(:label).regex(@params["search"])) if @params["search"] != nil
end

def filter_classes_by(class_uri)
class_uri.nil? ? nil :{types: RDF::URI.new(class_uri.to_s)}
end

def get_order_by_from(params , default_sort = :label , default_order = :asc)
{(params["sortby"] || default_sort).to_sym => params["order"] || default_order}
{(params["sortby"] || default_sort).to_sym => params["order"] || default_order} unless params["sortby"].nil? || params["sortby"] == ""
end

def get_attributes_to_include(includes_param)
Expand Down

0 comments on commit c041100

Please sign in to comment.