Class: Breeze::Section
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, #update_present_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, dir_id, fields, find, find_all, find_by, first, full_path, #id, #id=, #initialize, largest, load_file, next_id, #persisted?, previous_id, primary_key, reload, save_all, set_root_path, the_meta_class
Class Method Details
.fix_cards ⇒ Object
130
131
132
133
134
135
136
137
138
|
# File 'app/models/breeze/section.rb', line 130
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'app/models/breeze/section.rb', line 115
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_fields ⇒ Object
71
72
73
|
# File 'app/models/breeze/section.rb', line 71
def allowed_fields
super + [:page_id]
end
|
#card_template_style ⇒ Object
52
53
54
|
# File 'app/models/breeze/section.rb', line 52
def card_template_style
CardStyle.find_by_template( card_template )
end
|
#cards ⇒ Object
40
41
42
|
# File 'app/models/breeze/section.rb', line 40
def cards
Card.find_all(:section_id, id).sort_by{|obj| obj.index }
end
|
#cards_update ⇒ Object
44
45
46
|
# File 'app/models/breeze/section.rb', line 44
def cards_update
last_update_for( cards )
end
|
#change_name ⇒ Object
14
15
16
|
# File 'app/models/breeze/section.rb', line 14
def change_name
"#{page_name}:#{header}"
end
|
#delete(editor) ⇒ Object
104
105
106
107
|
# File 'app/models/breeze/section.rb', line 104
def delete(editor)
cards.each {|card| card.delete(editor) }
delete_save!(editor)
end
|
#delete_and_reset_index(editor) ⇒ Object
109
110
111
112
113
|
# File 'app/models/breeze/section.rb', line 109
def delete_and_reset_index(editor)
delete(editor)
Page.find(page_id).reset_index
Section.save_all
end
|
#has_cards? ⇒ Boolean
75
76
77
|
# File 'app/models/breeze/section.rb', line 75
def has_cards?
template_style.has_cards?
end
|
#index_name ⇒ Object
18
19
20
|
# File 'app/models/breeze/section.rb', line 18
def index_name
"#{self.index}"
end
|
#missing_translations ⇒ Object
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_down ⇒ Object
83
84
85
|
# File 'app/models/breeze/section.rb', line 83
def move_down
swap_index_with(next_section)
end
|
#move_up ⇒ Object
79
80
81
|
# File 'app/models/breeze/section.rb', line 79
def move_up
swap_index_with(previous_section)
end
|
#new_card ⇒ Object
95
96
97
98
|
# File 'app/models/breeze/section.rb', line 95
def new_card
card = Card.new_card(card_template, self.id , cards.length + 1)
card
end
|
#next_section ⇒ Object
91
92
93
|
# File 'app/models/breeze/section.rb', line 91
def next_section
page.sections.find{|s| s.index == index + 1 }
end
|
#object_type ⇒ Object
22
23
24
|
# File 'app/models/breeze/section.rb', line 22
def object_type
"Section"
end
|
#page_name ⇒ Object
10
11
12
|
# File 'app/models/breeze/section.rb', line 10
def page_name
page ? page.name : "missing page"
end
|
#previous_section ⇒ Object
87
88
89
|
# File 'app/models/breeze/section.rb', line 87
def previous_section
page.sections.find{|s| s.index == index - 1 }
end
|
#reset_index ⇒ Object
100
101
102
|
# File 'app/models/breeze/section.rb', line 100
def reset_index
cards.each_with_index{|card, index| card.index = index + 1}
end
|
#set_card_template(new_template) ⇒ Object
67
68
69
|
# File 'app/models/breeze/section.rb', line 67
def set_card_template(new_template)
self.card_template = new_template
end
|
#set_template(new_template) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'app/models/breeze/section.rb', line 56
def set_template(new_template)
self.template = new_template
new_style = template_style
add_default_options
if(new_style.has_cards?)
if card_template.blank?
self.card_template = CardStyle.first.template
end
end
end
|
#template_style ⇒ Object
48
49
50
|
# File 'app/models/breeze/section.rb', line 48
def template_style
SectionStyle.find_by_template( template )
end
|
#translate(lang, editor) ⇒ Object
35
36
37
38
|
# File 'app/models/breeze/section.rb', line 35
def translate(lang , editor)
super
cards.each{ |s | s.translate(lang, editor) }
end
|