Class: Flexite::Config

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
WithHistory
Defined in:
app/models/flexite/config.rb,
app/services/flexite/config/update_service.rb

Defined Under Namespace

Classes: CreateService, Form, UpdateService

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithHistory

#restore

Class Method Details

.t_nodesObject



64
65
66
# File 'app/models/flexite/config.rb', line 64

def self.t_nodes
  roots.includes(:configs, :entry).order_by_name.map(&:t_node)
end

.tree_view(parent_id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/flexite/config.rb', line 34

def self.tree_view(parent_id)
  joins("LEFT JOIN #{table_name} AS configs_#{table_name} ON configs_#{table_name}.config_id = #{table_name}.id")
    .joins("LEFT JOIN #{Entry.table_name} ON #{Entry.table_name}.parent_id = #{table_name}.id AND #{Entry.table_name}.parent_type = '#{model_name}'")
    .select(["#{table_name}.id",
             "#{table_name}.selectable",
             "#{table_name}.description",
             "#{table_name}.name",
             "#{table_name}.updated_at",
             "COUNT(configs_#{table_name}.id) AS nodes_count",
             "#{Entry.table_name}.id AS entry_id"])
    .where(config_id: parent_id).group("#{table_name}.id")
    .order_by_name
end

Instance Method Details

#dig(level) ⇒ Object



86
87
88
89
90
91
92
# File 'app/models/flexite/config.rb', line 86

def dig(level)
  if level.to_sym == :configs
    return send(level).order_by_name
  end

  send(level)
end

#entry_idObject



52
53
54
# File 'app/models/flexite/config.rb', line 52

def entry_id
  self[:entry_id]
end

#nodesObject



56
57
58
59
60
61
62
# File 'app/models/flexite/config.rb', line 56

def nodes
  if selectable
    return nil
  end

  nodes_count > 0 ? [] : nil
end

#nodes_countObject



48
49
50
# File 'app/models/flexite/config.rb', line 48

def nodes_count
  self[:nodes_count].to_i
end

#t_nodeObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/flexite/config.rb', line 68

def t_node
  node = {
    'name' => name,
    'description' => description,
    'class' => self.class.name
  }

  if configs.any?
    node.merge!('configs' => configs.includes(:configs, :entry).order_by_name.map(&:t_node))
  end

  if entry.present?
    node.merge!('entry' => entry.t_node)
  end

  node
end

#tv_nodeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/flexite/config.rb', line 20

def tv_node
  {
    id: id,
    editHref: Engine.routes.url_helpers.edit_config_path(self),
    selfHref: Engine.routes.url_helpers.config_path(self),
    newHref: Engine.routes.url_helpers.new_config_config_path(self),
    text: description,
    dataHref: selectable ? entry_href : configs_href,
    nodes: nodes,
    selectable: true,
    ajaxOnSelect: selectable
  }
end