Git Product home page Git Product logo

administrate-field-jsonb's People

Contributors

jameswilliamiii avatar jankeesvw avatar kayhide avatar oldharlem avatar volkov-sergey 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

administrate-field-jsonb's Issues

JSON editor is not present when creating nested resources

I have a Post which has_many Post::Translations, which themselves have a JSON tags property. When creating the post with its nested resource(s), the tag editor does not appear (http://localhost:3000/admin/posts/new):

Screenshot 2019-10-28 at 21 38 41

However it does appear when creating the translation sub-resource directly (http://localhost:3000/admin/post/translations/new):

Screenshot 2019-10-28 at 21 42 44

Also, the editor does appear when editing an existing post:

Screenshot 2019-10-28 at 21 57 15

The dashboard is configured as follows:

# app/dashboards/post_dashboard.rb
class PostDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    translations: NestedHasMany.with_options(class_name: "Post::Translation"),
    ...
  }.freeze
  FORM_ATTRIBUTES = %i[
  translations
  ...
  ].freeze
end

# app/dashboards/post/translation_dashboard.rb
class Post::TranslationDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    ...
    tags: Field::JSONB,
    ...
  }.freeze
end

# app/fields/nested_has_many.rb
require "administrate/field/base"

class NestedHasMany < Administrate::Field::NestedHasMany
  def self.permitted_attribute(associated_resource, _options = nil)
    {
      "#{associated_resource}_attributes".to_sym =>
        associated_attributes(associated_resource, _options),
    }
  end

  def self.associated_attributes(associated_resource, _options)
    dashboard_class = dashboard_for_resource(associated_resource, _options)
    DEFAULT_ATTRIBUTES + dashboard_class.new.permitted_attributes
  end

  # Hack: reimplement Administrate::Field::NestedHasMany.dashboard_for_resource to preserve namespace
  def self.dashboard_for_resource(resource, _options)
    class_name = _options && _options[:class_name] || resource.to_s.classify
    "#{class_name}Dashboard".constantize
  end

  def association_name
    options.fetch(
      :association_name,
      associated_class_name.underscore.pluralize[/([^\/]*)$/, 1],
    )
  end
end

As my tags cannot be nil (as enforced by DB schema), this issue prevents creating new posts and is therefore quite blocking.

Using Rails 5.2.3, Administrate 0.12.0, administrate-field-jsonb 0.4.0, and administrate-field-nested_has_many 1.1.0 although it's mostly overridden; code is included for reference above but in principle unrelated to this issue.

Displays/assigns null when showing/editing empty object

There are 3 related issues when a JSONB field contains a non-null but empty object ([] or {}).

1/ It is rendered as - on show view:
Screenshot 2019-10-31 at 14 01 59
2/ It is rendered as null on edit view:
Screenshot 2019-10-31 at 14 02 06
3/ When saving the form, even though I have not modified anything, instead of keeping the original value it tries to assign the value null, which breaks my non-null DB constraint and throws an error.

Instead, it should render the empty array or empty object, as below:
Screenshot 2019-10-31 at 14 05 28
Screenshot 2019-10-31 at 14 08 33

My code:

# db/schema.rb
  create_table "post_translations", force: :cascade do |t|
    ...
    t.jsonb "tags", default: [], null: false
end

# app/dashboards/post/translation_dashboard.rb
class Post::TranslationDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    ...
    tags: Field::JSONB,
    ...
  }.freeze
  ...
end

(+ using workaround described in #1 (comment))

Using administrate-field-jsonb 0.4.1.

Empty array shows `null` not `[]`

My jsonb column default is [], yet when the JSON editor loads it shows this:

image

This fails when saving, it should look like this by default:

image

example of DB data:

image

JSON editor icons are invisible in production

As reported in eddietejeda/administrate-field-json#8, icons don't show up in production because /assets/jsoneditor-icons.svg doesn't exist on the server.

Here is how it looks in development:
Screenshot 2019-11-15 at 11 14 42

And in production:
Screenshot 2019-11-15 at 11 16 08

The location of the icons can only be guessed by hovering the mouse until a tooltip shows up.

Is there any solution or workaround to this?

Tested with Rails 5.2.3, Administrate 0.12.0, administrate-field-jsonb 0.4.1.

Storing as Hash doesn't work in Rails 6.1.4 with the README documentation

Hi guys,

This code in the model would throw the error bellow:
def phone=(value) self[:phone] = value.is_a?(String) ? JSON.parse(value) : value end

Whereas this one would work:

before_save :set_phone_json
...
def set_phone_json
self.phone = phone.is_a?(String) ? JSON.parse(phone) : phone
end

Any idea why? Would it be worth to add it in the README?

Would throw an error:

{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] ActiveModel::UnknownAttributeError (unknown attribute 'phone' for Customer.):\n","stream":"stdout","time":"2023-05-31T14:23:40.382174213Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activemodel (6.1.7) lib/active_model/attribute_assignment.rb:51:in _assign_attribute'\n","stream":"stdout","time":"2023-05-31T14:23:40.382183584Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/attribute_assignment.rb:21:in block in _assign_attributes'\n","stream":"stdout","time":"2023-05-31T14:23:40.382187467Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/attribute_assignment.rb:13:in each'\n","stream":"stdout","time":"2023-05-31T14:23:40.382191608Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/attribute_assignment.rb:13:in _assign_attributes'\n","stream":"stdout","time":"2023-05-31T14:23:40.382195366Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activemodel (6.1.7) lib/active_model/attribute_assignment.rb:34:in assign_attributes'\n","stream":"stdout","time":"2023-05-31T14:23:40.382198982Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/persistence.rb:627:in block in update'\n","stream":"stdout","time":"2023-05-31T14:23:40.382202526Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/transactions.rb:354:in block in with_transaction_returning_status'\n","stream":"stdout","time":"2023-05-31T14:23:40.38220660
6Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/connection_adapters/abstract/database_statements.rb:320:in block in transaction'\n","stream":"stdout","time":"2023-05-31T14:
23:40.382210406Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/connection_adapters/abstract/transaction.rb:319:in block in within_new_transaction'\n","stream":"stdout","time":"2023-05-31T
14:23:40.382214063Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in block (2 levels) in synchronize'\n","stream":"stdout","time":"2023-05-31
T14:23:40.382217697Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in handle_interrupt'\n","stream":"stdout","time":"2023-05-31T14:23:40.38222
1448Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in block in synchronize'\n","stream":"stdout","time":"2023-05-31T14:23:40.3
82225036Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in handle_interrupt'\n","stream":"stdout","time":"2023-05-31T14:23:40.38222
987Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in synchronize'\n","stream":"stdout","time":"2023-05-31T14:23:40.382233693Z
"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/connection_adapters/abstract/transaction.rb:317:in within_new_transaction'\n","stream":"stdout","time":"2023-05-31T14:23:40.
382237281Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/connection_adapters/abstract/database_statements.rb:320:in transaction'\n","stream":"stdout","time":"2023-05-31T14:23:40.382
27025Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/transactions.rb:350:in with_transaction_returning_status'\n","stream":"stdout","time":"2023-05-31T14:23:40.382274126Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/persistence.rb:626:in update'\n","stream":"stdout","time":"2023-05-31T14:23:40.382277727Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] administrate (0.18.0) app/controllers/administrate/application_controller.rb:59:in update'\n","stream":"stdout","time":"2023-05-31T14:23:40.382281364Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/basic_implicit_render.rb:6:in send_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382284973Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/abstract_controller/base.rb:228:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382288552Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/rendering.rb:30:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382292105Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/abstract_controller/callbacks.rb:42:in block in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382295647Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:117:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382299221Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] audited (5.0.2) lib/audited/sweeper.rb:16:in around'\n","stream":"stdout","time":"2023-05-31T14:23:40.382302781Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382306295Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] audited (5.0.2) lib/audited/sweeper.rb:16:in around'\n","stream":"stdout","time":"2023-05-31T14:23:40.382309967Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382313537Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actiontext (6.1.7) lib/action_text/rendering.rb:20:in with_renderer'\n","stream":"stdout","time":"2023-05-31T14:23:40.382317089Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actiontext (6.1.7) lib/action_text/engine.rb:59:in block (4 levels) in \u003cclass:Engine\u003e'\n","stream":"stdout","time":"2023-05-31T14:23:40.382320917Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in instance_exec'\n","stream":"stdout","time":"2023-05-31T14:23:40.382325159Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.38232873Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382306295Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] audited (5.0.2) lib/audited/sweeper.rb:16:in around'\n","stream":"stdout","time":"2023-05-31T14:23:40.382309967Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382313537Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actiontext (6.1.7) lib/action_text/rendering.rb:20:in with_renderer'\n","stream":"stdout","time":"2023-05-31T14:23:40.382317089Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actiontext (6.1.7) lib/action_text/engine.rb:59:in block (4 levels) in \u003cclass:Engine\u003e'\n","stream":"stdout","time":"2023-05-31T14:23:40.382320917Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in instance_exec'\n","stream":"stdout","time":"2023-05-31T14:23:40.382325159Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:126:in block in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.38232873Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:137:in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382332295Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/abstract_controller/callbacks.rb:41:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382335823Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/rescue.rb:22:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382339488Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/instrumentation.rb:34:in block in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382343058Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/notifications.rb:203:in block in instrument'\n","stream":"stdout","time":"2023-05-31T14:23:40.382351313Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/notifications/instrumenter.rb:24:in instrument'\n","stream":"stdout","time":"2023-05-31T14:23:40.382355129Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-rails (5.4.2) lib/sentry/rails/tracing.rb:54:in instrument'\n","stream":"stdout","time":"2023-05-31T14:23:40.382358697Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/notifications.rb:203:in instrument'\n","stream":"stdout","time":"2023-05-31T14:23:40.382362291Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/instrumentation.rb:33:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382365899Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal/params_wrapper.rb:249:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.382369456Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activerecord (6.1.7) lib/active_record/railties/controller_runtime.rb:27:in process_action'\n","stream":"stdout","time":"2023-05-31T14:23:40.38237313Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/abstract_controller/base.rb:165:in process'\n","stream":"stdout","time":"2023-05-31T14:23:40.382376734Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionview (6.1.7) lib/action_view/rendering.rb:39:in process'\n","stream":"stdout","time":"2023-05-31T14:23:40.382380251Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal.rb:190:in dispatch'\n","stream":"stdout","time":"2023-05-31T14:23:40.382383772Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_controller/metal.rb:254:in dispatch'\n","stream":"stdout","time":"2023-05-31T14:23:40.382387606Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/routing/route_set.rb:50:in dispatch'\n","stream":"stdout","time":"2023-05-31T14:23:40.382391205Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/routing/route_set.rb:33:in serve'\n","stream":"stdout","time":"2023-05-31T14:23:40.382394823Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/journey/router.rb:50:in block in serve'\n","stream":"stdout","time":"2023-05-31T14:23:40.382398345Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/journey/router.rb:32:in each'\n","stream":"stdout","time":"2023-05-31T14:23:40.382402022Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/journey/router.rb:32:in serve'\n","stream":"stdout","time":"2023-05-31T14:23:40.38240554Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/routing/route_set.rb:842:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382409066Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rswag-ui (2.6.0) lib/rswag/ui/basic_auth.rb:12:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382412619Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] warden (1.2.9) lib/warden/manager.rb:36:in block in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38241609Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] warden (1.2.9) lib/warden/manager.rb:34:in catch'\n","stream":"stdout","time":"2023-05-31T14:23:40.382419632Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] warden (1.2.9) lib/warden/manager.rb:34:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382423144Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/tempfile_reaper.rb:15:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382426662Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/etag.rb:27:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382434269Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/conditional_get.rb:40:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38243793Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/head.rb:12:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382441453Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/http/permissions_policy.rb:22:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382444951Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/http/content_security_policy.rb:19:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382448517Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/session/abstract/id.rb:266:in context'\n","stream":"stdout","time":"2023-05-31T14:23:40.382452074Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/session/abstract/id.rb:260:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38245567Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/cookies.rb:689:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382460024Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/callbacks.rb:27:in block in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382470182Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/callbacks.rb:98:in run_callbacks'\n","stream":"stdout","time":"2023-05-31T14:23:40.382476423Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/callbacks.rb:26:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382481478Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382486499Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-rails (5.4.2) lib/sentry/rails/rescued_exception_interceptor.rb:12:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38249139Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:29:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38249622Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry/rack/capture_exceptions.rb:28:in block (2 levels) in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382501457Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry/hub.rb:199:in with_session_tracking'\n","stream":"stdout","time":"2023-05-31T14:23:40.38250647Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry-ruby.rb:372:in with_session_tracking'\n","stream":"stdout","time":"2023-05-31T14:23:40.382511579Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry/rack/capture_exceptions.rb:19:in block in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38251656Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry/hub.rb:59:in with_scope'\n","stream":"stdout","time":"2023-05-31T14:23:40.382521561Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry-ruby.rb:352:in with_scope'\n","stream":"stdout","time":"2023-05-31T14:23:40.38252663Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] sentry-ruby (5.4.2) lib/sentry/rack/capture_exceptions.rb:18:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382531395Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/show_exceptions.rb:33:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382535655Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] railties (6.1.7) lib/rails/rack/logger.rb:26:in block in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382555218Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/tagged_logging.rb:99:in block in tagged'\n","stream":"stdout","time":"2023-05-31T14:23:40.382559135Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/tagged_logging.rb:37:in tagged'\n","stream":"stdout","time":"2023-05-31T14:23:40.382562695Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/tagged_logging.rb:99:in tagged'\n","stream":"stdout","time":"2023-05-31T14:23:40.382567147Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] railties (6.1.7) lib/rails/rack/logger.rb:26:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382570721Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/remote_ip.rb:81:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382574231Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/request_id.rb:26:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382577768Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/method_override.rb:24:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382581331Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/runtime.rb:22:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382584836Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] activesupport (6.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382588476Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/executor.rb:14:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382592085Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/static.rb:24:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382595689Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack (2.2.4) lib/rack/sendfile.rb:110:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38259924Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] actionpack (6.1.7) lib/action_dispatch/middleware/host_authorization.rb:142:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382602752Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] rack-cors (1.1.1) lib/rack/cors.rb:100:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382606326Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] railties (6.1.7) lib/rails/engine.rb:539:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.382609846Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/configuration.rb:252:in call'\n","stream":"stdout","time":"2023-05-31T14:23:40.38261334Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/request.rb:77:in block in handle_request'\n","stream":"stdout","time":"2023-05-31T14:23:40.382616979Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/thread_pool.rb:340:in with_force_shutdown'\n","stream":"stdout","time":"2023-05-31T14:23:40.382620481Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/request.rb:76:in handle_request'\n","stream":"stdout","time":"2023-05-31T14:23:40.382624004Z"}
{"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/server.rb:443:in process_client'\n","stream":"stdout","time":"2023-05-31T14:23:40.382627509Z"} {"log":"[4e1d2e46-1a56-40a5-8e02-5ddcf8c4a826] puma (5.6.5) lib/puma/thread_pool.rb:147:in block in spawn_thread'\n","stream":"stdout","time":"2023-05-31T14:23:40.382631024Z"}
{"log":"I, [2023-05-31T14:23:40.403997 #1] INFO -- sentry: [Transport] Sending envelope with items [event, client_report] eb298f35ff07484ea74afefc2b68c71a to Sentry\n","stream":"stdout","time":"2023-05-31T14:23:40.40425645Z"}
{"log":"E, [2023-05-31T14:23:41.406923 #1] ERROR -- sentry: Event sending failed: execution expired\n","stream":"stdout","time":"2023-05-31T14:23:41.407154165Z"}
{"log":"I, [2023-05-31T14:23:41.410229 #1] INFO -- sentry: Unreported Event: ActiveModel::UnknownAttributeError: unknown attribute 'phone' for Customer.\n","stream":"stdout","time":"2023-05-31T14:23:41.410481629Z"}

advanced_view with Field::Select

Hey, i was wondering if you could add support for Field::Select in advanced view likeso:

image_details: Field::JSONB.with_options(advanced_view: {
  'width' => Field::Select.with_options(collection: ['half', 'full']),
}),

Advanced View List Header Labels

Hello!

I'm investigating adding support for specifying the label to display in the advanced view list's collapsible header. For example, in the image below, I might like to replace "SKILL - 1" with "Ruby."

advanced_view_object

I'm planning to open a PR with the changes I make, so I want to try to make a change that you might merge upstream.

While investigating how I might add support for this, I noticed in this file app/views/fields/jsonb/_hash.html.erb:

<% structure.each do |sk, sv| %>
  <% if sv.is_a?(Hash) %>
    <dt class='attribute-label administrate-field-jsonb-accordion'><%= sk.to_s.titleize %></dt>
    <dd class='administrate-field-jsonb-panel'>
      <dl class='administrate-field-jsonb-box'>
        <% if data[sk].is_a?(Array) %> <% # <------------------ when is this branch triggered? %>
          <%= render field.to_partial_path('array'),
            field: field, structure: structure[sk], data: data[sk], label: sk.to_s.singularize.titleize %>
        <% else %>
          <% # ... %>
        <% end %>
      <dl>
    </dd>
  <% else %>
    <% # ... %>
  <% end %>
<% end %>

While iterating over the hash attributes, you check if sv.is_a?(Hash), then later in that same block you check if data[sk].is_a?(Array). It's not clear to me how this branch of code gets executed.

I don't see any examples in the README that have a hash value in the structure, and I don't see any tests at all. Would it be possible for you to provide an example configuration which would exercise this branch?

If I extend the API to support array header labels, I want to try my best to do it in a backwards compatible way. ๐Ÿ‘

Thank you!

Rails 7 compatibility

The version 0.4.5 has a dependency on rails >= 4.2, < 7, which means it is not working for Rails 7.

Could you increase the Rails version dependency to include Rails 7?

Duplicated JSONEditor elements with Turbolinks

Hi,

I encountered an issue when using this gem. I'm building a project with Rails 6 and Turbolinks 5.2.1, which I sadly can't share at the moment. When I enter a page with an .administrate-jsoneditor or .administrate-jsoneditor-viewer element, the editor would load correctly, but ends up generating multiple copies once I leave and revisit the page.

I suspect that Turbolinks triggers the turbolinks:load event every time I visit the page, but also keeps the modified DOM between visits, generating multiple copies of the editor after repeated visits.

image

Sorry for not preparing an example showcasing the problem, but I'm short on time. I hacked together a workaround on this fork, which solves the problem by stopping the creation of a new editor if there's already one present. My solution is not robust at all and the commits were written on a hurry, so it would be better to consider an alternative fix.

Thanks!

Generator does not set field as Field::JSONB

When generating a dashboard (with rails generate administrate:dashboard) while this gem is used, it would be nice if JSON fields were automatically set as Field::JSONB instead of Field::String.with_options(searchable: false). Currently this change needs to be done manually for each field.

Advanced_view does not work with JSON arrays

Currently it is not possible to use the advanced_view option for displaying JSON arrays as the code is defined as follows:

      def advanced_view?
        advanced_view.present? && advanced_view.is_a?(Hash)
      end

E.g if the JSON value is ["one", "two", "three"], it would be nice to be able to just display one, two, three instead of the heavy-looking jsoneditor, and also this advanced_view is necessary to enforce the structure of the data (e.g ensuring the editor won't enter a hash when an array should be provided).

save field results in to_s version all the time

Hey guys

Awesome that you put this together! It comes at the right time :)

When I edit the form in correct json (text/tree), and then save the field, it always results in the to string version "{\"key\": ...

This is my schema:

    create_table :grammatical_forms do |t|
      t.json :translations
      t.string :identifier, index: true
      t.timestamps
    end

I use it in the dashboard as described

  ATTRIBUTE_TYPES = {
    meanings: Field::HasMany,
    id: Field::Number,
    identifier: Field::String.with_options(searchable: false),
    translations: Field::JSONB,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
  }.freeze

Any ideas right away? I haven't debugged yet, but I might do in the next days.

Thanks again

Advanced View, but with user-defined keys

First of all, I love this gem โ€” amazing that it just works perfectly.

Perhaps I'm misunderstanding the documentation, but is there a way to use advanced view but allow for custom key objects?

For example:

      "user_defined_key_here": {  
        table: "2018",
        sources: [
          {name: "lcgms", version: '2018-12-19', minYear: 2018, maxYear: 2019},
          {name: "bluebook", minYear: 2017, maxYear: 2018}
        ]
      },

With advanced view, I find it can enforce an up-front structure of the JSON schema. Is this possible? For now, I can just use the jsoneditor, but I find your advanced view to be much simpler.

That said, this may be a sign that I need to use some other kinds of objects in Rails (read: models), but this is great for now.

Validations with JsonEditor

The jsoneditor library handles front end validation passing a configuration object to : .

I dont think the gem handles passing validations to the jsoneditor lib.

What would be the best workaround ? Is there a way to get the jsoneditor javascript object and add validations after it is initialized by the gem on the page ?

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.