Sha256: e5fa9b64288110a7824451d41af7cde46caea3258b4651c5fdc50fa76549b17c

Contents?: true

Size: 635 Bytes

Versions: 27

Compression:

Stored size: 635 Bytes

Contents

# frozen_string_literal: true

module Renalware
  module System
    class UsersPresenter
      def list_for_dropdown(user_to_promote_to_top: nil)
        return users if user_to_promote_to_top.blank?

        matching_user = users.detect{ |user| user.id == user_to_promote_to_top.id }
        make_user_first_in_list(matching_user) if matching_user.present?
        users
      end

      private

      def make_user_first_in_list(user)
        users.delete(user)
        users.unshift(user)
      end

      def users
        @users ||= Renalware::User.select(:id, :family_name, :given_name).ordered.to_a
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.77 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.76 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.75 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.74 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.73 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.72 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.71 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.70 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.69 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.68 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.67 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.64 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.63 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.62 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.61 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.60 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.58 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.57 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.56 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.55 app/presenters/renalware/system/users_presenter.rb