Class: Goldencobra::Widget

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/goldencobra/widget.rb

Constant Summary collapse

OfflineDays =
["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
OfflineDaysEN =
["mo", "tu", "we", "th", "fr", "sa", "su"]
ImportDataFunctions =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#offline_time_end_frObject

Returns the value of attribute offline_time_end_fr.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_end_fr
  @offline_time_end_fr
end

#offline_time_end_moObject

Returns the value of attribute offline_time_end_mo.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_end_mo
  @offline_time_end_mo
end

#offline_time_end_saObject

Returns the value of attribute offline_time_end_sa.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_end_sa
  @offline_time_end_sa
end

#offline_time_end_suObject

Returns the value of attribute offline_time_end_su.



44
45
46
# File 'app/models/goldencobra/widget.rb', line 44

def offline_time_end_su
  @offline_time_end_su
end

#offline_time_end_thObject

Returns the value of attribute offline_time_end_th.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_end_th
  @offline_time_end_th
end

#offline_time_end_tuObject

Returns the value of attribute offline_time_end_tu.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_end_tu
  @offline_time_end_tu
end

#offline_time_end_weObject

Returns the value of attribute offline_time_end_we.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_end_we
  @offline_time_end_we
end

#offline_time_start_frObject

Returns the value of attribute offline_time_start_fr.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_start_fr
  @offline_time_start_fr
end

#offline_time_start_moObject

Returns the value of attribute offline_time_start_mo.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_start_mo
  @offline_time_start_mo
end

#offline_time_start_saObject

Returns the value of attribute offline_time_start_sa.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_start_sa
  @offline_time_start_sa
end

#offline_time_start_suObject

Returns the value of attribute offline_time_start_su.



44
45
46
# File 'app/models/goldencobra/widget.rb', line 44

def offline_time_start_su
  @offline_time_start_su
end

#offline_time_start_thObject

Returns the value of attribute offline_time_start_th.



43
44
45
# File 'app/models/goldencobra/widget.rb', line 43

def offline_time_start_th
  @offline_time_start_th
end

#offline_time_start_tuObject

Returns the value of attribute offline_time_start_tu.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_start_tu
  @offline_time_start_tu
end

#offline_time_start_weObject

Returns the value of attribute offline_time_start_we.



42
43
44
# File 'app/models/goldencobra/widget.rb', line 42

def offline_time_start_we
  @offline_time_start_we
end

Class Method Details

.recent(count) ⇒ Object



84
85
86
# File 'app/models/goldencobra/widget.rb', line 84

def self.recent(count)
  Goldencobra::Widget.where("title IS NOT NULL").order("created_at DESC").limit(count)
end

Instance Method Details

#duplicate!Object



183
184
185
186
187
188
189
190
191
192
# File 'app/models/goldencobra/widget.rb', line 183

def duplicate!
  attrs = self.attributes
            .delete_if{ |key| %w(id created_at updated_at).include?(key) }
  attrs["title"] = "#{attrs["title"]} (Kopie)"
  attrs["id_name"] = attrs["id_name"].present? ? "#{attrs["id_name"]}-kopie" : nil
  attrs["active"] = false
  attrs["tag_list"] = tag_list
  new_widget = Goldencobra::Widget.create!(attrs)
  new_widget ? new_widget.id : nil
end

#offline_date_end_displayObject



112
113
114
115
116
117
118
# File 'app/models/goldencobra/widget.rb', line 112

def offline_date_end_display
  if self.offline_date_end.present?
    self.offline_date_end.strftime("%Y%m%d")
  else
    ""
  end
end

#offline_date_start_displayObject

def offline_time_end_display

if self.offline_time_end.present?
  self.offline_time_end.strftime("%H%M")
else
  ""
end

end



104
105
106
107
108
109
110
# File 'app/models/goldencobra/widget.rb', line 104

def offline_date_start_display
  if self.offline_date_start.present?
    self.offline_date_start.strftime("%Y%m%d")
  else
    ""
  end
end

#offline_dayObject



80
81
82
# File 'app/models/goldencobra/widget.rb', line 80

def offline_day
  self.offline_days.split(",").map{|tag| tag.strip} if self.offline_days.present?
end

#offline_day=(wert) ⇒ Object



76
77
78
# File 'app/models/goldencobra/widget.rb', line 76

def offline_day=(wert)
  self.offline_days = wert.flatten.uniq.compact.delete_if{|a|a==""}.join(",")
end

#offline_time_weekObject



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

def offline_time_week
  result = Hash.new
  if self.offline_time_week_start_end.present?
    self.offline_time_week_start_end.each do |key,value|
      result["data-time-day-#{key}"] = value
    end
  end
  return result
end

#set_default_tagObject



72
73
74
# File 'app/models/goldencobra/widget.rb', line 72

def set_default_tag
  self.tag_list = "sidebar" if self.tag_list.blank?
end

#set_week_start_end_timesObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/models/goldencobra/widget.rb', line 145

def set_week_start_end_times
  self.offline_time_week_start_end = Hash.new
  OfflineDays.each_with_index do |day,index|
    if self.offline_day.present? && self.offline_day.include?(day)
      current_day = OfflineDaysEN[index]
      if current_day.present?
        start_time = eval("self.offline_time_start_#{current_day}").to_s.gsub(/\D/, "").strip
        end_time = eval("self.offline_time_end_#{current_day}").to_s.gsub(/\D/, "").strip
        start_time = "0001" if start_time.blank?
        end_time = "2359" if end_time.blank?
        self.offline_time_week_start_end[current_day] = "#{start_time}-#{end_time}"
      end
    end
  end
end

#validate_start_end_timeObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/models/goldencobra/widget.rb', line 162

def validate_start_end_time
  if self.offline_time_active

    # if self.offline_time_start.present? && self.offline_time_end.present?

    #   if self.offline_time_start > self.offline_time_end
    #     errors.add(:offline_time_start, 'Startzeit muss VOR Endzeit liegen')
    #     errors.add(:offline_time_end, 'Startzeit muss VOR Endzeit liegen')
    #   end

    # else
    #   errors.add(:offline_time_start, 'Zeit muss gesetzt werden')
    #   errors.add(:offline_time_end, 'Zeit muss gesetzt werden')
    # end

    if self.offline_days.blank?
      errors.add(:offline_day, 'Mindestens ein Tag muss ausgewählt sein.')
    end
  end
end