Class: Breeze::Section

Inherits:
ViewBase show all
Defined in:
app/models/breeze/section.rb

Instance Attribute Summary

Attributes inherited from ActiveYaml

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ViewBase

#add_default_options, #get_translation, #has_option?, #header_text, #image_old, #last_update_for, #option, #option_definitions, #safe_options, #set_option, #swap_index_with, #text_text, #type_id, #update, #update_options

Methods inherited from ActiveBase

#add_save, #add_save!, #delete_save!, #edit_save, #edit_save!

Methods inherited from ActiveYaml

all, append, define_access, define_association, delete, fields, find, find_all, find_by, first, full_path, #id, #id=, #initialize, load_file, #persisted?, primary_key, reload, save_all, set_root_path, the_meta_class

Constructor Details

This class inherits a constructor from Breeze::ActiveYaml

Class Method Details

.fix_cardsObject



120
121
122
123
124
125
126
127
128
# File 'app/models/breeze/section.rb', line 120

def self.fix_cards
  Section.all.each do |section|
    next if section.template_style.has_cards?
    puts "#{section.id}: #{section.card_template}"
    section.card_template = nil if section.card_template
  end
  Section.save_all
  nil
end

.new_section(template, page_id, index) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/models/breeze/section.rb', line 105

def self.new_section(template , page_id , index)
  data = { template: template , index: index , page_id: page_id}
  style = SectionStyle.find_by_template( template)
  style.fields.each do |key|
    data[key.to_sym] = key.upcase
  end unless style.fields.blank?
  if(style.has_cards?)
    data[:card_template] = CardStyle.first.template
  end
  new_id = Section.append(data)
  s = Section.new(data)
  s.add_default_options
  s
end

Instance Method Details

#allowed_fieldsObject



61
62
63
# File 'app/models/breeze/section.rb', line 61

def allowed_fields
  super + [:page_id]
end

#card_template_styleObject



47
48
49
# File 'app/models/breeze/section.rb', line 47

def card_template_style
  CardStyle.find_by_template( card_template )
end

#cardsObject



35
36
37
# File 'app/models/breeze/section.rb', line 35

def cards
  Card.find_all(:section_id, id).sort_by{|obj| obj.index }
end

#cards_updateObject



39
40
41
# File 'app/models/breeze/section.rb', line 39

def cards_update
  last_update_for( cards )
end

#change_nameObject



14
15
16
# File 'app/models/breeze/section.rb', line 14

def change_name
  "#{page_name}:#{header}"
end

#delete(editor) ⇒ Object



94
95
96
97
# File 'app/models/breeze/section.rb', line 94

def delete(editor)
  cards.each {|card| card.delete(editor) }
  delete_save!(editor)
end

#delete_and_reset_index(editor) ⇒ Object



99
100
101
102
103
# File 'app/models/breeze/section.rb', line 99

def delete_and_reset_index(editor)
  delete(editor)
  Page.find(page_id).reset_index
  Section.save_all
end

#has_cards?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/breeze/section.rb', line 65

def has_cards?
  template_style.has_cards?
end

#index_nameObject



18
19
20
# File 'app/models/breeze/section.rb', line 18

def index_name
  "#{self.index}"
end

#missing_translationsObject



26
27
28
29
30
31
32
33
# File 'app/models/breeze/section.rb', line 26

def missing_translations
  sum = 0
  cards.collect{ |s | sum += s.missing_translations }
  Breeze.language_strings.each do |lang|
    sum += 1 if get_translation(lang)&.is_old?
  end
  sum
end

#move_downObject



73
74
75
# File 'app/models/breeze/section.rb', line 73

def move_down
  swap_index_with(next_section)
end

#move_upObject



69
70
71
# File 'app/models/breeze/section.rb', line 69

def move_up
  swap_index_with(previous_section)
end

#new_cardObject



85
86
87
88
# File 'app/models/breeze/section.rb', line 85

def new_card
  card = Card.new_card(card_template, self.id , cards.length + 1)
  card
end

#next_sectionObject



81
82
83
# File 'app/models/breeze/section.rb', line 81

def next_section
  page.sections.find{|s|  s.index == index + 1 }
end

#object_typeObject



22
23
24
# File 'app/models/breeze/section.rb', line 22

def object_type
  "Section"
end

#page_nameObject



10
11
12
# File 'app/models/breeze/section.rb', line 10

def page_name
  page ? page.name : "missing page"
end

#previous_sectionObject



77
78
79
# File 'app/models/breeze/section.rb', line 77

def previous_section
  page.sections.find{|s|  s.index == index - 1 }
end

#reset_indexObject



90
91
92
# File 'app/models/breeze/section.rb', line 90

def reset_index
  cards.each_with_index{|card, index| card.index = index + 1}
end

#set_template(new_template) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/models/breeze/section.rb', line 51

def set_template(new_template)
  self.template = new_template
  new_style = template_style
  if(new_style.has_cards?)
    if card_template.blank?
      self.card_template = CardStyle.first.template
    end
  end
end

#template_styleObject



43
44
45
# File 'app/models/breeze/section.rb', line 43

def template_style
  SectionStyle.find_by_template( template )
end