Sha256: 09b1ceb45a5cbbfbe56b857a537643c13821a1f446bdec351ff40e57586e43d7

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module MegaBar
  class FieldsController < ApplicationController
    include MegaBarConcern

    def new
      @default_options[:model_id] = @nested_instance_variables[0]&.id
      @default_options[:tablename] = @nested_instance_variables[0]&.tablename
      super
    end

    def get_options
      blocks = []
      # bad news, if the block doesn't have model_displays it doesnt show up in this menu
      ModelDisplay.select(:block_id).distinct.pluck("block_id, model_id").each do |md|
        blocks << ['id: ' + md[0].to_s + ', model: ' + Model.find(md[1]).name + ' (' + md[1].to_s + '), ' + Block.find(md[0]).name, md[0]]
      end
      # md_ids = {model_display_ids: ModelDisplay.by_model(env[:mega_env][:nested_ids][0]["model_id"])} unless env[:mega_env][:nested_ids].blank
      @options[:mega_bar_fields] =  {
        model_id: Model.all.pluck("name, id"),
        tablename: Model.all.pluck("tablename, tablename"),
        block_id: blocks

      }
      unless env[:mega_env][:nested_ids].blank?
        md_opts = []
        ModelDisplay.by_model(env[:mega_env][:nested_ids][0]["model_id"]).each do | m|
          md_opts << [m[:id].to_s + ": " + m[:header], m[:id]]
        end
        @options[:mega_bar_fields][:model_display_ids] =  md_opts
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mega_bar-0.5.2 app/controllers/mega_bar/fields_controller.rb