compact fix

This commit is contained in:
2015-03-30 11:23:49 +02:00
parent 7000870853
commit 32f9e010f8
2 changed files with 11 additions and 8 deletions

View File

@@ -107,18 +107,21 @@ class Neuigkeit < ActiveRecord::Base
def is_event?
self.has_calentries?
end
def relevant_calentry
self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)}
end
def update_cache
if self.has_meeting? && !self.meeting.calentry.nil?
self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs)
self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs * 2)
self.update_column(:cache_relevant_date, self.meeting.calentry.start.to_date)
else
if self.is_event?
c = self.calentries.min{|c| c.days_to_today * ((c.is_past?)? 2:1)}
self.update_column(:cache_order, c.days_to_today * ((c.is_past?)? 2:1))
c = self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)}
self.update_column(:cache_order, c.days_to_today * 2 * ((c.is_past?)? 2:1))
self.update_column(:cache_relevant_date, (c.is_past?) ? c.ende.to_date : c.start.to_date)
else
unless self.datum.nil?
self.update_column(:cache_order, (((self.datum.to_date - Date.today).to_i)/3).abs-1)
self.update_column(:cache_order, (((self.datum.to_date - Date.today).to_i)).abs)
self.update_column(:cache_relevant_date, self.datum.to_date)
else
self.update_column(:cache_order,0)

View File

@@ -8,9 +8,9 @@
<div>
<small><%= ff_icon(neuigkeit.rubrik.icon) unless neuigkeit.rubrik.icon.nil? or neuigkeit.rubrik.icon.empty? %>&nbsp;<span><%= neuigkeit.rubrik.name %></span></small>
<% unless neuigkeit.has_calentries? %> <small class="pull-right"><% unless neuigkeit.try(:datum).try(:to_date).nil? %>
<%= I18n.t("neuigkeit.am") %>
<span datetime="<%= neuigkeit.try(:datum).to_formatted_s(:iso8601) unless neuigkeit.try(:datum).nil? %>"> <%= I18n.l(neuigkeit.try(:datum).try(:to_date))%> </span>
<% end %> </small> <% else %> <% end %>
<%= I18n.t("neuigkeit.am") %>
<span datetime="<%= neuigkeit.try(:datum).to_formatted_s(:iso8601) unless neuigkeit.try(:datum).nil? %>"> <%= I18n.l(neuigkeit.try(:datum).try(:to_date))%> </span>
<% end %> </small> <% else %> <% end %>
</div>
<h1 >
<%= neuigkeit.title%>
@@ -20,7 +20,7 @@
<% if neuigkeit.has_calentries? %>
<div class="pull-right" href="#">
<%= fa_icon("calendar 2x") %>
<%= neuigkeit.calentries.min{|c| c.days_to_today * ((c.is_past?)? 2:1)}.text %>
<%= neuigkeit.relevant_calentry.text %>
</div>
<% end %>