mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-09 16:01:30 +08:00
Fix new year problems with activities
Closes SCI-876.
This commit is contained in:
parent
aba12b9b2c
commit
8b01f912a0
3 changed files with 12 additions and 6 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
class ActivitiesController < ApplicationController
|
class ActivitiesController < ApplicationController
|
||||||
|
include ActivityHelper
|
||||||
|
|
||||||
before_filter :load_vars
|
before_filter :load_vars
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
@ -14,8 +16,8 @@ class ActivitiesController < ApplicationController
|
||||||
# Whether to hide date labels
|
# Whether to hide date labels
|
||||||
@hide_today = params.include? :from
|
@hide_today = params.include? :from
|
||||||
@day = @last_activity.present? ?
|
@day = @last_activity.present? ?
|
||||||
@last_activity.created_at.strftime("%j").to_i :
|
days_since_1970(@last_activity.created_at) :
|
||||||
366
|
days_since_1970(DateTime.current + 30.days)
|
||||||
|
|
||||||
more_url = url_for(activities_url(format: :json,
|
more_url = url_for(activities_url(format: :json,
|
||||||
from: @activities.last.id))
|
from: @activities.last.id))
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,8 @@ module ActivityHelper
|
||||||
message = message.gsub(/#{activity_title}/, title )
|
message = message.gsub(/#{activity_title}/, title )
|
||||||
message.html_safe if message
|
message.html_safe if message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def days_since_1970(dt)
|
||||||
|
dt.to_i / 86400
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<%
|
<%
|
||||||
current_day = DateTime.current.strftime('%j').to_i
|
current_day = days_since_1970(DateTime.current)
|
||||||
%>
|
%>
|
||||||
<% if !hide_today and activities.count > 0 and activities[0].created_at.strftime('%j').to_i == current_day %>
|
<% if !hide_today and activities.count > 0 and days_since_1970(activities[0].created_at) == current_day %>
|
||||||
<li class="text-center activity-date-item">
|
<li class="text-center activity-date-item">
|
||||||
<span class="label label-primary">
|
<span class="label label-primary">
|
||||||
<%=t "activities.index.today" %>
|
<%=t "activities.index.today" %>
|
||||||
|
|
@ -9,10 +9,10 @@
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% activities.each do |activity| %>
|
<% activities.each do |activity| %>
|
||||||
<% activity_day = activity.created_at.strftime('%j').to_i %>
|
<% activity_day = days_since_1970(activity.created_at) %>
|
||||||
|
|
||||||
<% if activity_day < current_day and activity_day < day %>
|
<% if activity_day < current_day and activity_day < day %>
|
||||||
<% day = activity.created_at.strftime('%j').to_i %>
|
<% day = days_since_1970(activity.created_at) %>
|
||||||
<li class="text-center activity-date-item">
|
<li class="text-center activity-date-item">
|
||||||
<span class="label label-primary">
|
<span class="label label-primary">
|
||||||
<%= activity.created_at.strftime('%d.%m.%Y') %>
|
<%= activity.created_at.strftime('%d.%m.%Y') %>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue