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.54 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.53 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.52 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.51 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.50 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.48 app/presenters/renalware/system/users_presenter.rb
renalware-core-2.0.47 app/presenters/renalware/system/users_presenter.rb