Sha256: 56273e38c68207f1287945f325db82ca9bb8e6fdae0470bb8b3a6360e15540cd

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'ditty/controllers/component_controller'
require 'ditty/models/user_login_trait'
require 'ditty/policies/user_login_trait_policy'

module Ditty
  class UserLoginTraitsController < ::Ditty::ComponentController
    SEARCHABLE = %i[platform device browser ip_address].freeze
    FILTERS = [
      { name: :user, field: 'user.email' },
      { name: :platform },
      { name: :device },
      { name: :browser }
    ].freeze

    set base_path: '/login-traits'
    set model_class: UserLoginTrait
    set heading: 'Login'
    # set track_actions: true

    helpers do
      def user_options
        policy_scope(::Ditty::User).as_hash(:email, :email)
      end

      def platform_options
        policy_scope(::Ditty::UserLoginTrait).select(:platform).distinct.as_hash(:platform, :platform)
      end

      def device_options
        policy_scope(::Ditty::UserLoginTrait).select(:device).distinct.as_hash(:device, :device)
      end

      def browser_options
        policy_scope(::Ditty::UserLoginTrait).select(:browser).distinct.as_hash(:browser, :browser)
      end
    end

    def list
      return super if params[:sort]

      super.order(:updated_at).reverse
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ditty-0.11.1 lib/ditty/controllers/user_login_traits_controller.rb
ditty-0.10.2 lib/ditty/controllers/user_login_traits_controller.rb
ditty-0.10.1 lib/ditty/controllers/user_login_traits_controller.rb