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

.tree_view(parent_id) ⇒ Object



32
33
34
35
36
37
# File 'app/models/flexite/config.rb', line 32

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}.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")
end

Instance Method Details

#entry_idObject



43
44
45
# File 'app/models/flexite/config.rb', line 43

def entry_id
  self[:entry_id]
end

#nodesObject



47
48
49
50
51
52
53
# File 'app/models/flexite/config.rb', line 47

def nodes
  if selectable
    return nil
  end

  nodes_count > 0 ? [] : nil
end

#nodes_countObject



39
40
41
# File 'app/models/flexite/config.rb', line 39

def nodes_count
  self[:nodes_count].to_i
end

#to_tree_nodeObject



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

def to_tree_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: name,
    dataHref: selectable ? entry_href : configs_href,
    nodes: nodes,
    selectable: true,
    ajaxOnSelect: selectable
  }
end