Skip to content

Commit

Permalink
Merge branch 'main' into fix/check_tab_visibility_on_header
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Jul 5, 2023
2 parents 1783804 + 1cf596c commit 486c3e1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
14 changes: 11 additions & 3 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,24 @@ def order

def save_model
perform_action_and_record_errors do
@model.save!
save_model_action
end
end

def save_model_action
@model.save!
end

def destroy_model
perform_action_and_record_errors do
@model.destroy!
destroy_model_action
end
end

def destroy_model_action
@model.destroy!
end

def perform_action_and_record_errors(&block)
begin
succeeded = block.call
Expand Down Expand Up @@ -253,7 +261,7 @@ def model_params
end

def permitted_params
@resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param).concat extra_params
@resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param).concat(extra_params).uniq
end

def extra_params
Expand Down
6 changes: 5 additions & 1 deletion lib/avo/concerns/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def fields(only_root: false)
if item.is_field?
fields << item
end

if item.is_row?
fields << extract_fields_from_items(tab)
end
end

fields.flatten
Expand All @@ -117,7 +121,7 @@ def extract_fields_from_items(thing)
thing.items.each do |item|
if item.is_field?
fields << item
elsif item.is_panel?
elsif item.is_panel? || item.is_row?
fields << extract_fields_from_items(item)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ActiveRecordAttachmentResource < Avo::BaseResource
self.title = :filename
self.model_class = "ActiveStorage::Attachment"

field :id, as: :id
field :filename, as: :text
field :service_url, as: :external_image, name: "Image"
field :created_at, as: :date_time
end
2 changes: 2 additions & 0 deletions spec/dummy/app/avo/resources/post_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class PostResource < Avo::BaseResource
extract_excerpt model.body
end

field :cover_photo_attachment, as: :has_one

field :is_featured, as: :boolean, visible: ->(resource:) { context[:user].is_admin? }
field :is_published, as: :boolean do |model|
model.published_at.present?
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/avo/resources/project_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ProjectResource < Avo::BaseResource
field :comments, as: :has_many, searchable: true
field :reviews, as: :has_many

field :files_attachments, as: :has_many

action ExportCsv

# filter PeopleFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::ActiveRecordAttachmentsController < Avo::ResourcesController
end

0 comments on commit 486c3e1

Please sign in to comment.