Implemented issue #645 - Alternative pretty date format.
This commit is contained in:
parent
5239515096
commit
131d360c75
3 changed files with 100 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
class App.PrettyDate
|
||||
|
||||
# human readable time
|
||||
@humanTime: ( time, escalation, long = true ) ->
|
||||
@humanTime: (time, escalation, long = true, type = undefined) ->
|
||||
return '' if !time
|
||||
current = new Date()
|
||||
created = new Date(time)
|
||||
|
@ -29,6 +29,26 @@ class App.PrettyDate
|
|||
if diff < 60
|
||||
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 )
|
||||
return App.i18n.translateDate(time)
|
||||
|
||||
|
@ -99,3 +119,8 @@ class App.PrettyDate
|
|||
if escalation
|
||||
string = "<span #{style}>#{string}</b>"
|
||||
return string
|
||||
|
||||
@s: (num, digits) ->
|
||||
while num.toString().length < digits
|
||||
num = '0' + num
|
||||
num
|
46
db/migrate/20170421000001_pretty_date_options_added.rb
Normal file
46
db/migrate/20170421000001_pretty_date_options_added.rb
Normal 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
|
29
db/seeds.rb
29
db/seeds.rb
|
@ -168,6 +168,33 @@ Setting.create_if_not_exists(
|
|||
},
|
||||
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 = {}
|
||||
(10..99).each { |item|
|
||||
options[item] = item
|
||||
|
@ -5553,7 +5580,7 @@ Scheduler.create_if_not_exists(
|
|||
)
|
||||
Scheduler.create_if_not_exists(
|
||||
name: 'Import Jobs',
|
||||
method: 'ImportJob.start',
|
||||
method: 'ImportJob.start_registered',
|
||||
period: 1.hour,
|
||||
prio: 1,
|
||||
active: true,
|
||||
|
|
Loading…
Reference in a new issue