Git Product home page Git Product logo

administrate-field-belongs_to_search's Introduction

Administrate::Field::BelongsToSearch

Build Status Gem Version Coverage Status

A plugin to search through belongs_to associations in thoughtbot's Administrate Rails engine.

Usage

Add it to your Gemfile:

gem 'administrate-field-belongs_to_search'

Run bundler to install:

bundle install

Add it to your Administrate dashboard, for instance:

class PostDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    author: Field::BelongsToSearch.with_options(class_name: 'User')
  }
# ...

With this, you should be good to go!

Develop and Contribute

Fork and clone the repo. Install dependencies and run test using:

bundle install
bundle exec rake

Then, implement your feature/fix, write a good commit message and submit a pull request to this repository. If you only have some feedback or are unsure about how to do something, you're welcome to submit an issue.

This is meant to be an welcoming and friendly place for collaboration. Therefore, all contributors are expected to adhere to the Contributor Covenant Code of Conduct.

License

This plugin is Copyright © 2017 Fishbrain AB. It is licensed under the MIT license. See LICENSE for details.

Screenshot

Screenshot

========

Fishbrain AB

This plugin is maintained by Fishbrain AB.

At Fishbrain, we're passionate about the outdoors and conservation. Together, we work to bring you the best app for fishing, hands down.

If you love working with amazing and talented people in tight-knit teams, join us!

administrate-field-belongs_to_search's People

Contributors

alexceder avatar dalen avatar dan-ding avatar dependabot-preview[bot] avatar fishbrain-terraform[bot] avatar klaseskilson avatar mrjaco12 avatar phishalot avatar redrick avatar rmachielse avatar tim-heighes-fishbrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

administrate-field-belongs_to_search's Issues

Javascript error: "SyntaxError: Unexpected token 'export'" and "TypeError: $element.selectize is not a function"

I'm getting the following two errors in the JS console in Brave (Chromium based):
image
Note: I tried Firefox 96.0.1 (64-bit) as well, which resulted in the same exception on the console.

This is the line it highlights:
image

I followed the Readme with SHA fc8eed4 and added the attribute to one dashboard. These are all my changes to my app:

diff --git a/StekkerWeb/Gemfile b/StekkerWeb/Gemfile
index c78f42f34..86f373ac5 100644
--- a/StekkerWeb/Gemfile
+++ b/StekkerWeb/Gemfile
@@ -6,6 +6,7 @@ ruby "3.0.2"
 gem "rails"

 gem "aasm"
+gem "administrate-field-belongs_to_search"
 gem "appsignal"
 gem "attr_encrypted", "~> 3.1.0"
diff --git a/StekkerWeb/Gemfile.lock b/StekkerWeb/Gemfile.lock
index c8c4a544e..cef95c67c 100644
--- a/StekkerWeb/Gemfile.lock
+++ b/StekkerWeb/Gemfile.lock
@@ -122,6 +122,11 @@ GEM
     administrate-field-active_storage (0.3.8)
       administrate (>= 0.2.2)
       rails (>= 6.0)
+    administrate-field-belongs_to_search (0.7.0)
+      administrate (>= 0.3, < 1.0)
+      jbuilder (~> 2)
+      rails (>= 4.2, < 7.0)
+      selectize-rails (~> 0.6)
     administrate-field-enum (0.0.9)
       administrate (~> 0.12)
@@ -673,6 +678,7 @@ DEPENDENCIES
   aasm
   administrate (= 0.16.0)
   administrate-field-active_storage
+  administrate-field-belongs_to_search
   administrate-field-enum
diff --git a/StekkerWeb/app/dashboards/charging_preference_dashboard.rb b/StekkerWeb/app/dashboards/charging_preference_dashboard.rb
index 163ddfc42..419abba3e 100644
--- a/StekkerWeb/app/dashboards/charging_preference_dashboard.rb
+++ b/StekkerWeb/app/dashboards/charging_preference_dashboard.rb
@@ -8,7 +8,7 @@ class ChargingPreferenceDashboard < Administrate::BaseDashboard
   # which determines how the attribute is displayed
   # on pages throughout the dashboard.
   ATTRIBUTE_TYPES = {
-    account: Field::BelongsTo,
+    account: Field::BelongsToSearch,

If you have any pointers or solution, that would be really helpful. Thanks!

Missing template for search

Hi folks, I'm having some trouble getting this plugin working. My resource_dashboard.rb includes this under ATTRIBUTE_TYPES:

address: Field::BelongsToSearch.with_options(
  class_name: "Address"
),

But when I type into the search bar, nothing happens and I get this error in the logs:

ActionView::MissingTemplate - Missing template admin/addresses/index, admin/application/index, administrate/application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :arb, :coffee, :haml]}. Searched in:
  * "/Users/nate-r-a/my-org/my-project/app/views"
  * "/Users/nate-r-a/.rvm/gems/ruby-2.3.8/gems/administrate-field-belongs_to_search-0.6.0/app/views"
  * "/Users/nate-r-a/.rvm/gems/ruby-2.3.8/gems/administrate-0.11.0/app/views"

, etc.

Did I miss a part of the setup, or maybe misunderstanding how this is to be used? Thanks in advance!

Show dropdown options on focus

Currently one has to either start typing or make a space in the input field for items to be shown. Focusing on the field should be enough to show some items. Also, clicking on the dropdown arrow initially shows nothing. Which is a bit confusing.

However, after the items are generated, if I click outside of field, clicking inside it works as expected, as does the dropdown arrow.

So it would be ideal I think to preload the boxes on page load.

jbuilder should be listed in dependencies

Hello,
Thanks a lot for your plugin!
I think jbuilder should be listed as a dependency since it's used in the administrate/application/index.json.jbuilder template. If the rails project does not use jbuilder then the template is not found and it results in a Missing template error.

jbuilder requirement should be listed in README

Howdy,

Following the example in the README, I got an error about a missing ActionView template. It turns out that I needed to have jbuilder in my Gemfile. The README should probably list that as a requirement.

Partial Population for Belongs to Search

Describe the bug

The search field is not populating all of the Users. Instead it's only showing a small percentage of Users available for a belongs_to association.

To Reproduce

Steps to reproduce the behaviour:

Click on new record and start typing in the belongs_to field and view the pre-populated records (in my case, Users). Many (or most) of the records are missing.

If I type out a user is ex (User #287), if it was not one of the pre-populated users, it will fail to create the record, even while the User # 287 does exist in the database is is findable via the User administrate dashboard.

Environment

ruby "2.5.1"
rails "5.2.2.1"

Gemfile:
gem "administrate", "~> 0.11"
gem "administrate_exportable"

Expected behavior

I would expect a pre-populated list containing all of the records and if the record is not showing up, I should still be able to type it in and find it.

Additional context**

Dashboard Configuration:

ATTRIBUTE_TYPES = {
    user:          Field::BelongsToSearch.with_options(class_name: "User"),
    tos_agreement: Field::BelongsTo,
    id:            Field::Number.with_options(searchable: true),
    created_at:    Field::DateTime,
    updated_at:    Field::DateTime
  }.freeze

Screen Shots:

Search finds incomplete list of users. Should be sequential users:
Screen Shot 2019-06-28 at 2 39 52 PM

Error when User #287 which wasn't showing up in the list manually written in and then searched.
Screen Shot 2019-06-28 at 2 45 34 PM

Add BelongsToSearch in Nested form

Hello guys! I hope everybody is doing great.
I'm facing problem to add belongs_to search from "administrate-field-belongs_to_search" in dropdown of nested forms.
As you can see in attachment, order_items is nested form for new order and I need to add search on its product dropdown.
Waiting for your help.

image

Search by belongs_to record attribute

Hi there!
I'm trying to use this gem for my case:
I have a projects, users and many-to-many project_users. When I'm on the Project Users admin page I want to be able to search project_user by its project title (or user email, for example).
In project_dashboard I changed display_resource to use the title and added this to project_user_dashboard:

ATTRIBUTE_TYPES = {
  ...
  project: Field::BelongsToSearch.with_options(class_name: 'Project', searchable: true),
  ...

As you might guess, I got

PG::UndefinedColumn: ERROR:  column project_users.project does not exist 
. . . 
WHERE (lower("project_users"."project") LIKE '%something%')
. . .

Could you give me any advise how to change this ATTRIBUTE_TYPES key (project) to search by its title?
Is it exactly that this gem should provide, or I use it wrong?
Thanks

Support for Rails 7

The gem appears to work fine with Rails 7. Is there any reason for the restriction of less than rails 7?

Search records gives cached 304 response

My rails 5.2 app, I am using acts_as_taggable_on and have following

ATTRIBUTE_TYPES = {
      tag:        Field::BelongsToSearch.with_options(class_name: '::ActsAsTaggableOn::Tag', searchable: true, searchable_field: :name),
      taggable:   Field::Polymorphic,
      tagger:     Field::Polymorphic,
      id:         Field::Number,
      tag_id:     Field::Number.with_options(searchable: false),
      context:    Field::Select.with_options(collection: ActsAsTaggableOn::Tagging.select(:context).uniq.map(&:context).uniq),
      created_at: Field::DateTime
    }.freeze

And I have following form

FORM_ATTRIBUTES = %i[
      tag
      context
    ].freeze

And it doesn't search and returns the cached response. In the network tab of chrome, I see only 304 responses no matter what the query is and it doesn't give the result from the search.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.