Sha256: df771997fff02e01e065bab5b43ef4dc25e5236a610521a94ddc84a3ea522c4f
Contents?: true
Size: 1.83 KB
Versions: 34
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true class Avo::Views::ResourceShowComponent < Avo::ResourceComponent include Avo::ResourcesHelper include Avo::ApplicationHelper attr_reader :fields_by_panel, :has_one_panels, :has_many_panels, :has_as_belongs_to_many_panels def initialize(resource: nil, reflection: nil, parent_model: nil) @resource = resource @reflection = reflection split_panel_fields end def back_path if via_resource? helpers.resource_path(params[:via_resource_class].safe_constantize, resource_id: params[:via_resource_id]) else helpers.resources_path(@resource.model) end end def edit_path if via_resource? helpers.edit_resource_path(@resource.model, via_resource_class: params[:via_resource_class], via_resource_id: params[:via_resource_id]) else helpers.edit_resource_path(@resource.model) end end def detach_path helpers.resource_detach_path(params[:resource_name], params[:id], @reflection.name.to_s, @resource.model.id) end def destroy_path helpers.resource_path(@resource.model) end def can_detach? authorize_association_for('detach') end private def via_resource? params[:via_resource_class].present? && params[:via_resource_id].present? end def split_panel_fields @fields_by_panel = {} @has_one_panels = [] @has_many_panels = [] @has_as_belongs_to_many_panels = [] @resource.get_fields.each do |field| case field.class.to_s when "Avo::Fields::HasOneField" @has_one_panels << field when "Avo::Fields::HasManyField" @has_many_panels << field when "Avo::Fields::HasAndBelongsToManyField" @has_as_belongs_to_many_panels << field else @fields_by_panel[field.panel_name] ||= [] @fields_by_panel[field.panel_name] << field end end end end
Version data entries
34 entries across 34 versions & 1 rubygems