Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove methods no longer in use - especially pagination

ulferts158f3e4e3ac8
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb
index 5411dc51f39..f40fd2e22e3 100644
--- a/app/controllers/members_controller.rb
+++ b/app/controllers/members_controller.rb
@@ -32,11 +32,6 @@ class MembersController < ApplicationController
before_action :find_project_by_project_id, only: [:autocomplete_for_member]
before_action :authorize
- include Pagination::Controller
- paginate_model User
- search_for User, :search_in_project
- search_options_for User, lambda { |*| { project: @project } }
-
def index
set_index_data!
end
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb
index 79dc22db71d..771f91a04d5 100644
--- a/app/controllers/roles_controller.rb
+++ b/app/controllers/roles_controller.rb
@@ -115,20 +115,6 @@ class RolesController < ApplicationController
end
end
- def autocomplete_for_role
- size = params[:page_limit].to_i
- page = params[:page].to_i
-
- @roles = Role.paginated_search(params[:q], page:, page_limit: size)
- # we always get all the items on a page, so just check if we just got the last
- @more = @roles.total_pages > page
- @total = @roles.total_entries
-
- respond_to do |format|
- format.json
- end
- end
-
private
def set_role_attributes(role, create_or_update)
diff --git a/app/models/principal.rb b/app/models/principal.rb
index f18c491ff20..7ff6ce32869 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -181,6 +181,4 @@ class Principal < ApplicationRecord
self.mail ||= ''
true
end
-
- extend Pagination::Model
end
diff --git a/app/models/project.rb b/app/models/project.rb
index eeac6404f01..38c30f42c6f 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -27,7 +27,6 @@
#++
class Project < ApplicationRecord
- extend Pagination::Model
extend FriendlyId
include Projects::Storage
@@ -196,11 +195,6 @@ class Project < ApplicationRecord
Project.visible.select { |p| User.current.member_of? p }.sort_by(&:to_s)
end
- def self.search_scope(query)
- # overwritten from Pagination::Model
- visible.like(query)
- end
-
# Returns all projects the user is allowed to see.
#
# Employs the :view_project permission to perform the
diff --git a/app/models/role.rb b/app/models/role.rb
index 169633a4363..e12bcab80cd 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -27,8 +27,6 @@
#++
class Role < ApplicationRecord
- extend Pagination::Model
-
# Built-in roles
NON_BUILTIN = 0
BUILTIN_NON_MEMBER = 1
@@ -175,10 +173,6 @@ class Role < ApplicationRecord
end
end
- def self.paginated_search(search, options = {})
- paginate_scope! givable.like(search), options
- end
-
def self.in_new_project
givable
.except(:order)
diff --git a/app/models/status.rb b/app/models/status.rb
index 917fce252d4..3b0553d9aed 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -27,8 +27,6 @@
#++
class Status < ApplicationRecord
- extend Pagination::Model
-
default_scope { order_by_position }
before_destroy :check_integrity
has_many :workflows, foreign_key: 'old_status_id'
diff --git a/app/models/type.rb b/app/models/type.rb
index b6a017d9fec..32febae229c 100644
--- a/app/models/type.rb
+++ b/app/models/type.rb
@@ -27,8 +27,6 @@
#++
class ::Type < ApplicationRecord
- extend Pagination::Model
-
# Work Package attributes for this type
# and constraints to specific attributes (by plugins).
include ::Type::Attributes
diff --git a/lib/pagination/controller.rb b/lib/pagination/controller.rb
deleted file mode 100644
index 42e2fd0df8b..00000000000
--- a/lib/pagination/controller.rb
+++ /dev/null
@@ -1,295 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# Extending this module provides some convenience methods for easier setup of pagination inside a controller.
-# It assumes there is just one pagination method to set up per model.
-#
-# To set up basic functions:
-# paginate_model Project
-#
-# This sets up the action #paginate_projects inside the controller.
-#
-# To change this action:
-#
-# action_for Project, :my_own_action
-#
-# or use a block:
-#
-# action_for Project do
-# do_something
-# end
-#
-# To set up multiple models at once:
-# paginate_models Project, User
-#
-# To change the call the model uses for pagination (signature as in Pagination::Model#paginate_scope!):
-# pagination_for Project, :my_own_pagination_method
-# pagination_for Project do |scope, opts|
-# do_something
-# end
-#
-# To change the scope the model uses to search (signature as in Pagination::Model#search_scope):
-# search_for Project, :my_own_pagination_method
-# search_for Project do |query|
-# do_something
-# end
-# Note that this needs to return an actual scope or its corresponding hash.
-#
-# To change the response the action will give:
-# response_for Project, :my_custom_response
-# response_for Project, Proc.new {
-# respond_to do |format|
-# DO SOMETHING
-# end
-# }
-# This needs to return something that can be #instance_eval'ed AND #call'ed, i.e. a Proc.
-# A String containing code will NOT work but a lambda will, if the execution context
-# can be changed accordingly (simply providing an additional parameter will work in most
-# cases).
-#
-# There are several possibilities to add options to the call to #search_method:
-# Procs allow to change behaviour dynamically, as with ActiveRecords scopes.
-# Lambdas will work just as procs, but an additional parameter needs to get passed to
-# change their context.
-# Everything else just gets passed as is.
-# search_options_for Project, proc { @bar.nil? ? @bar : { a: b, c: d } }
-# search_options_for Project, lambda { |self| (@bar.nil? ? @bar : { a: b, c: d }) }
-# search_options_for Project, { a: b, c: d }
-# search_options_for Project, "yeah!"
-#
-#
-module Pagination::Controller
- class Paginator
- attr_accessor :model, :action, :pagination, :search, :controller, :last_action, :block, :response, :search_options
-
- def initialize(controller, model)
- self.controller = controller
- self.model = model
- end
-
- def self.resolve_model(model)
- (model.respond_to?(:constantize) ? model.constantize : model)
- end
-
- def default_action
- model_name = self.class.resolve_model(model).name
- model_name_without_modules = model_name.split('::').last || ''
- :"paginate_#{model_name_without_modules.underscore.downcase.pluralize}"
- end
-
- def default_pagination
- :paginate_scope!
- end
-
- def default_search
- :search_scope
- end
-
- def default_search_options
- {}
- end
-
- def last_action
- @last_action ||= action
- end
-
- def action
- @action ||= default_action
- end
-
- def action=(action)
- @action = action
- refresh_action!
- @action
- end
-
- def search
- @search ||= default_search
- end
-
- def pagination
- @pagination ||= default_pagination
- end
-
- def block
- @block ||= default_block
- end
-
- def response
- @response ||= default_response_block
- end
-
- def search_options
- @search_options ||= default_search_options
- end
-
- def changed?
- last_action != action
- end
-
- def refresh_action!
- undef_action!
- define_action!
- end
-
- def undef_action!
- controller.pagination.delete(last_action)
-
- # remove old
- controller.send(:remove_method, last_action) if controller.respond_to? last_action
- end
-
- def define_action!(block = default_block)
- controller.pagination[action] = self
- raise NameError, "method '#{action}' already defined in #{controller}" if controller.respond_to? action
-
- controller.send(:define_method, action, block)
- end
-
- def default_block
- Proc.new do
- # TODO: less evilness
- paginator = self.class.pagination[__method__]
- size = params[:page_limit].to_i || 10
- page = params[:page]
-
- if page
- page = page.to_i
-
- methods = {}
- %i[pagination search].each do |meth|
- methods[meth] = if paginator.send(meth).respond_to?(:call)
- paginator.send(meth)
- else
- paginator.model.method(paginator.send(meth))
- end
- end
-
- if (options = paginator.search_options).respond_to?(:call)
- options = instance_eval(&options.to_proc)
- end
-
- search_call = (options.presence ? methods[:search].call(params[:q], options) : methods[:search].call(params[:q]))
- @paginated_items = methods[:pagination].call(
- search_call,
- page:, page_limit: size
- )
-
- @more = @paginated_items.total_pages > page
- @total = @paginated_items.total_entries
-
- instance_eval(&paginator.response.to_proc)
- end
- end
- end
-
- def default_response_block
- Proc.new do
- respond_to do |format|
- format.json do
- render json: { results:
- { items: @paginated_items.map { |item| { id: item.id, name: item.name } },
- total: @total || @paginated_items.size,
- more: @more || 0 } }
- end
- end
- end
- end
- end
-
- def self.included(base)
- base.extend self
- end
-
- def self.extended(base)
- base.instance_eval do
- def paginate_models(*args)
- args.each do |arg|
- paginate_model(arg)
- end
- end
-
- def paginate_model(model)
- pagination_class.resolve_model(model)
- pagination[model] = pagination_class.new(self, model)
- pagination[model].refresh_action!
- end
-
- def pagination_class
- @pagination_class ||= Pagination::Controller::Paginator
- end
-
- def pagination_class=(struct)
- @pagination_class = struct
- end
-
- def pagination=(calls)
- @pagination = calls
- end
-
- def pagination
- @pagination ||= {}
- end
-
- # Has to return a method that takes a query as an argument
- # See pagination::Model#paginate_scope!
- def pagination_for(model, call)
- resolve_paginator_for(model).pagination = (call.respond_to?(:call) ? call : call.to_s.to_sym)
- end
-
- def search_for(model, call)
- resolve_paginator_for(model).search = (call.respond_to?(:call) ? call : call.to_s.to_sym)
- end
-
- def action_for(model, call)
- resolve_paginator_for(model).action = (call.respond_to?(:call) ? call : call.to_s.to_sym)
- end
-
- def response_for(model, call)
- resolve_paginator_for(model).response = (call.respond_to?(:call) ? call : call.to_s.to_sym)
- end
-
- def search_options_for(model, options)
- resolve_paginator_for(model).search_options = options
- end
-
- private
-
- def resolve_paginator_for(model)
- model = pagination_class.resolve_model(model)
- inst = pagination.find { |_, pag| pag.model == model }[1]
-
- if inst.nil?
- raise ArgumentError, "Model #{model} is not being paginated. Call #paginate_model(s) first."
- else
- inst
- end
- end
- end
- end
-end
diff --git a/lib/pagination/model.rb b/lib/pagination/model.rb
deleted file mode 100644
index b43edf2bfff..00000000000
--- a/lib/pagination/model.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# This module includes some boilerplate code for pagination using scopes.
-# #search_scope may be overridden by the model to change (restrict) the search scope
-# and MUST return a scope or its corresponding hash.
-
-module Pagination::Model
- def self.included(base)
- base.extend self
- end
-
- def self.extended(base)
- unless base.respond_to? :like
- base.scope :like, ->(q) {
- s = "%#{q.to_s.strip.downcase}%"
- base.where(['LOWER(name) LIKE :s', { s: }])
- .order(Arel.sql('name'))
- }
- end
-
- base.instance_eval do
- def paginate_scope!(scope, options = {})
- limit = options.fetch(:page_limit) || 10
- page = options.fetch(:page) || 1
-
- scope.paginate(per_page: limit, page:)
- end
-
- # ignores options passed in from the controller, overwrite to use 'em
- def search_scope(query, _options = {})
- like(query)
- end
- end
- end
-end