Sha256: 242b4834ca02bbb162a3f81fe482f1566eaa5c3f1701f87bd0887f5260e7fdd0

Contents?: true

Size: 1.17 KB

Versions: 62

Compression:

Stored size: 1.17 KB

Contents

module Workarea
  module Admin
    module Visiting
      extend ActiveSupport::Concern

      included do
        helper_method :most_visited
        after_action :save_visit
      end

      def most_visited
        @most_visited ||= User::AdminVisit.most_visited(current_user.id)
      end

      private

      def save_visit
        return unless save_visit?

        User::AdminVisit.create!(
          name: response_title,
          path: request.path,
          user_id: current_user.id
        )
      end

      def save_visit?
        !request.xhr? &&
          request.get? &&
          !response.redirect? &&
          !request.path.in?(excluded_paths) &&
          response_title.present?
      end

      def excluded_paths
        Workarea.config.admin_visit_excluded_paths.map do |path_method|
          send(path_method)
        end
      end

      def response_title
        @response_title ||= Nokogiri::XML(response.body)
                              .css('title')
                              .try(:text)
                              .to_s
                              .gsub(/\[#{Rails.env.upcase}\]/, '')
                              .strip
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/visiting.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/visiting.rb