Implemented issue #645 - Alternative pretty date format.

This commit is contained in:
Martin Edenhofer 2017-04-21 11:25:28 +02:00
parent 5239515096
commit 131d360c75
3 changed files with 100 additions and 2 deletions

View file

@ -1,7 +1,7 @@
class App.PrettyDate class App.PrettyDate
# human readable time # human readable time
@humanTime: ( time, escalation, long = true ) -> @humanTime: (time, escalation, long = true, type = undefined) ->
return '' if !time return '' if !time
current = new Date() current = new Date()
created = new Date(time) created = new Date(time)
@ -29,6 +29,26 @@ class App.PrettyDate
if diff < 60 if diff < 60
return App.i18n.translateInline('just now') return App.i18n.translateInline('just now')
if type is undefined && window.App && window.App.Config
type = window.App.Config.get('pretty_date_format')
if type is 'absolute' && direction is 'past'
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
weekday = weekdays[created.getDay()]
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
month = months[created.getMonth()]
# for less than 7 days
if diff < (60 * 60 * 24 * 7)
string = "#{App.i18n.translateInline(weekday)} #{created.getHours()}:#{@s(created.getMinutes(), 2)}"
else if diff < (60 * 60 * 24 * 7) * 365
string = "#{App.i18n.translateInline(weekday)} #{created.getDate()}. #{App.i18n.translateInline(month)} #{created.getHours()}:#{@s(created.getMinutes(), 2)}"
else
string = "#{App.i18n.translateInline(weekday)} #{App.i18n.translateTimestamp(time)}"
if escalation
string = "<span #{style}>#{string}</b>"
return string
if direction is 'past' && !escalation && diff > ( 60 * 60 * 24 * 7 ) if direction is 'past' && !escalation && diff > ( 60 * 60 * 24 * 7 )
return App.i18n.translateDate(time) return App.i18n.translateDate(time)
@ -99,3 +119,8 @@ class App.PrettyDate
if escalation if escalation
string = "<span #{style}>#{string}</b>" string = "<span #{style}>#{string}</b>"
return string return string
@s: (num, digits) ->
while num.toString().length < digits
num = '0' + num
num

View file

@ -0,0 +1,46 @@
class PrettyDateOptionsAdded < ActiveRecord::Migration
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_or_update(
title: 'Pretty Date',
name: 'pretty_date_format',
area: 'System::Branding',
description: 'Defines pretty date format.',
options: {
form: [
{
display: '',
null: false,
name: 'pretty_date_format',
tag: 'select',
options: {
'relative': 'relative - e. g. "2 hours ago" or "2 days and 15 minutes ago"',
'absolute': 'absolute - e. g. "Monday 09:30" or "Tuesday 23. Feb 14:20"',
},
},
],
},
preferences: {
render: true,
prio: 10,
permission: ['admin.branding'],
},
state: 'relative',
frontend: true
)
Scheduler.create_or_update(
name: 'Import Jobs',
method: 'ImportJob.start_registered',
period: 1.hour,
prio: 1,
active: true,
updated_by_id: 1,
created_by_id: 1
)
end
end

View file

@ -168,6 +168,33 @@ Setting.create_if_not_exists(
}, },
frontend: true frontend: true
) )
Setting.create_or_update(
title: 'Pretty Date',
name: 'pretty_date_format',
area: 'System::Branding',
description: 'Defines pretty date format.',
options: {
form: [
{
display: '',
null: false,
name: 'pretty_date_format',
tag: 'select',
options: {
'relative': 'relative - e. g. "2 hours ago" or "2 days and 15 minutes ago"',
'absolute': 'absolute - e. g. "Monday 09:30" or "Tuesday 23. Feb 14:20"',
},
},
],
},
preferences: {
render: true,
prio: 10,
permission: ['admin.branding'],
},
state: 'relative',
frontend: true
)
options = {} options = {}
(10..99).each { |item| (10..99).each { |item|
options[item] = item options[item] = item
@ -5553,7 +5580,7 @@ Scheduler.create_if_not_exists(
) )
Scheduler.create_if_not_exists( Scheduler.create_if_not_exists(
name: 'Import Jobs', name: 'Import Jobs',
method: 'ImportJob.start', method: 'ImportJob.start_registered',
period: 1.hour, period: 1.hour,
prio: 1, prio: 1,
active: true, active: true,