Class: Models::Attributes

Inherits:
Components::Base
  • Object
show all
Defined in:
app/components/databasium/models/attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes: nil, models: nil) ⇒ Attributes

Returns a new instance of Attributes.



4
5
6
7
# File 'app/components/databasium/models/attributes.rb', line 4

def initialize(attributes: nil, models: nil)
  @attributes = attributes
  @models = models
end

Instance Method Details

#view_templateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/databasium/models/attributes.rb', line 9

def view_template
  @attributes
    .fetch(:unknown, [])
    .each do |line|
      input(type: "hidden", name: "model[unknown][]", value: line.fetch(:line, line["line"]))
    end
  render_collapsable(
    name: "Pre-filled attributes",
    form: nil,
    class_name: "bg-panel rounded-xl py-2"
  ) do
    div(
      class: "rounded-b-xl border border-border overflow-hidden divide-y divide-border mt-2"
    ) do
      @attributes
        &.fetch(:columns_hash)
        &.each do |name, attribute|
          render Models::Templates::Attribute.new(name: name, params: attribute)
        end
    end
  end
  render_collapsable(
    name: "Pre-filled relations",
    form: nil,
    data_targets: {
      controller: "relation"
    },
    class_name: "bg-panel mt-2 rounded-xl py-2"
  ) do
    div(class: "flex flex-col gap-2 py-2 px-3") do
      @attributes
        &.fetch(:relations)
        &.each do |relation|
          render Models::Templates::Relation.new(relation: relation, models: @models)
        end
    end
  end
end