Skip to content

Commit

Permalink
EZP-30099: Define preferred user date format
Browse files Browse the repository at this point in the history
  • Loading branch information
pawbuj committed Feb 19, 2019
1 parent 3931a61 commit 2b3a5b3
Show file tree
Hide file tree
Showing 48 changed files with 992 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
* default: # configuration per siteaccess or siteaccess group
* user_preferences:
* additional_translations: ['en_US', 'en_GB']
* datetime_format: 'dd/mm/yyy hh:mm'
* allowed_date_formats:
* 'label for dd/MM/yyy' ; 'dd/MM/yyy"
* 'label for MM/dd/yyy' ; 'MM/dd/yyy"
* allowed_time_formats:
* 'label for HH:mm' : 'HH:mm",
* 'label for hh:mm a' : 'hh:mm a'
* ```
*/
class UserPreferences extends AbstractParser
Expand All @@ -40,6 +47,20 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder): void
->example(['en_US', 'en_GB'])
->prototype('scalar')->end()
->end()
->scalarNode('datetime_format')
->info('The default datetime format to display dates in the AdminUI.')
->example('dd/MM/yyy hh:mm')
->end()
->arrayNode('allowed_date_formats')
->info('List of allowed date formats.')
->example(['label dd/MM/yyy' =>'dd/MM/yyy', 'label for mm/dd/yyy' => 'mm/dd/yyy '])
->prototype('scalar')->end()
->end()
->arrayNode('allowed_time_formats')
->info('List of allowed time formats.')
->example(['label hh:mm' => 'hh:mm ', 'label for HH:mm' => 'HH:mm'])
->prototype('scalar')->end()
->end()
->end()
->end();
}
Expand All @@ -59,4 +80,4 @@ public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerIn
$scopeSettings['user_preferences']['additional_translations']
);
}
}
}
16 changes: 14 additions & 2 deletions src/bundle/Resources/config/ezplatform_default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,17 @@ parameters:
# Views
ezsettings.default.content_translate_view: {}

# Additional translations e.g. ['en_US', 'nb_NO']
ezsettings.default.user_preferences.additional_translations: []
# User Preferences
ezsettings.default.user_preferences.additional_translations: [] # e.g. ['en_US', 'nb_NO']
ezsettings.default.user_preferences.datetime_format: 'dd/mm/Y HH:mm'
ezsettings.default.user_preferences.allowed_date_formats:
'mm/dd/yyyy' : 'MM/dd/Y'
'dd/mm/yyyy' : 'dd/MM/Y'
'yy/mm/dd' : 'yy/MM/dd'
'M dd yyyy' : 'LLLL dd Y'
'dd M yyyy' : 'dd LLLL Y'
ezsettings.default.user_preferences.allowed_time_formats:
'none' : ''
'hh:mm AM/PM' : 'hh:mm a'
'hh:mm' : 'HH:mm'

4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ services:
EzSystems\EzPlatformAdminUiBundle\Templating\Twig\PathStringExtension: ~

EzSystems\EzPlatformAdminUiBundle\Templating\Twig\ContentTypeIconExtension: ~

EzSystems\EzPlatformAdminUiBundle\Templating\Twig\DateTime\DateTimeExtension: ~

EzSystems\EzPlatformAdminUiBundle\Templating\Twig\DateTime\DateTimeRuntimeExtension: ~
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/user_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ services:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: language }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: language }

EzSystems\EzPlatformAdminUi\UserSetting\Setting\DateTimeFormat:
tags:
- { name: ezplatform.admin_ui.user_setting.value, identifier: datetime_format }
- { name: ezplatform.admin_ui.user_setting.form_mapper, identifier: datetime_format }
96 changes: 36 additions & 60 deletions src/bundle/Resources/public/js/scripts/admin.format.date.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,42 @@
(function(moment) {
const formatEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g;

const formatEx = /[GdayLqDeEc]+/g;
const formatMap = {
d: 'DD',
D: 'ddd',
j: 'D',
l: 'dddd',
N: 'E',
S: function() {
return '[' + this.format('Do').replace(/\d*/g, '') + ']';
},
w: 'd',
z: function() {
return this.format('DDD') - 1;
},
W: 'W',
F: 'MMMM',
m: 'MM',
M: 'MMM',
n: 'M',
t: function() {
return this.daysInMonth();
},
L: function() {
return this.isLeapYear() ? 1 : 0;
},
o: 'GGGG',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: function() {
var thisUTC = this.clone().utc(),
swatch = ((thisUTC.hours() + 1) % 24) + thisUTC.minutes() / 60 + thisUTC.seconds() / 3600;
return Math.floor((swatch * 1000) / 24);
},
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: '[u]',
e: '[e]',
I: function() {
return this.isDST() ? 1 : 0;
},
O: 'ZZ',
P: 'Z',
T: '[T]',
Z: function() {
return parseInt(this.format('ZZ'), 10) * 36;
},
c: 'YYYY-MM-DD[T]HH:mm:ssZ',
r: 'ddd, DD MMM YYYY HH:mm:ss ZZ',
U: 'X',
dd: 'DD',
d: 'D',
a: 'A',
y: 'Y',
yy: 'YY',
yyyy: 'YYYY',
LLLL: 'MMMM',
LLL: 'MMM',
LL: 'MM',
L: 'M',
q: 'Q',
D: 'DDD',
eeeeee: 'dd',
eeee: 'dddd',
eee: 'ddd',
ee: 'E',
e: 'E',
EEEEEE: 'dd',
EEEE: 'dddd',
EEE: 'ddd',
EE: 'ddd',
E: 'ddd',
cccccc: 'dd',
cccc: 'dddd',
ccc: 'ddd',
cc: 'E',
c: 'E',
};

moment.fn.formatPHP = function(format) {
return this.format(
format.replace(formatEx, (phpStr) => {
return typeof formatMap[phpStr] === 'function' ? formatMap[phpStr].call(this) : formatMap[phpStr];
})
);
moment.fn.formatICU = function(format) {
let form = format.replace(formatEx, (icuStr) => {
return typeof formatMap[icuStr] === 'function' ? formatMap[icuStr].call(this) : formatMap[icuStr];
});

return this.format(form);
};

})(window.moment);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function(global, doc) {

const dateDropdown = doc.querySelector('#user_setting_update_value_date_format');
const timeDropdown = doc.querySelector('#user_setting_update_value_time_format');
const demoContainer = doc.querySelector('#datetime_format_demo');

const updateDemoDateFormat = () => {
let dateFormat = dateDropdown.options[dateDropdown.selectedIndex].value;
let timeFormat = timeDropdown.options[timeDropdown.selectedIndex].value;
let datetimeFormat = dateFormat + ' ' + timeFormat;

demoContainer.innerHTML = global.eZ.helpers.timezone.formatDate(new Date(), datetimeFormat);
};

dateDropdown.addEventListener('change', updateDemoDateFormat, false);
timeDropdown.addEventListener('change', updateDemoDateFormat, false);
updateDemoDateFormat();

})(window, document);
17 changes: 4 additions & 13 deletions src/bundle/Resources/public/js/scripts/helpers/timezone.helper.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
(function(global, doc, eZ, moment) {
const userPreferedTimezone = eZ.adminUiConfig.timezone;
const userPreferedFullDateFormat = eZ.adminUiConfig.dateFormat.full;
const userPreferedShortDateFormat = eZ.adminUiConfig.dateFormat.short;
const userPreferedDateFormat = eZ.adminUiConfig.dateFormat;

const convertDateToTimezone = (date, timezone = userPreferedTimezone) => {
return moment(date).tz(timezone);
};
const formatDate = (date, format = userPreferedFullDateFormat) => {
return moment(date).formatPHP(format);
const formatDate = (date, format = userPreferedDateFormat) => {
return moment(date).formatICU(format);
};
const formatShortDate = (date, format = userPreferedShortDateFormat) => {
return moment(date).formatPHP(format);
};
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedFullDateFormat) => {
return formatDate(convertDateToTimezone(date, timezone), format);
};
const formatShortDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedShortDateFormat) => {
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedDateFormat) => {
return formatDate(convertDateToTimezone(date, timezone), format);
};

eZ.addConfig('helpers.timezone', {
convertDateToTimezone,
formatDate,
formatShortDate,
formatDateWithTimezone,
formatShortDateWithTimezone,
});
})(window, document, window.eZ, window.moment);
25 changes: 25 additions & 0 deletions src/bundle/Resources/translations/user_settings.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@
<target state="new">User setting '%identifier%' updated.</target>
<note>key: user_setting.update.success</note>
</trans-unit>
<trans-unit id="18615263ff1640ffb19435dc88897a658ae7592d" resname="settings.datetime_format.value.description">
<source><![CDATA[Format for displaying Date & Time]]></source>
<target state="new"><![CDATA[Format for displaying Date & Time]]></target>
<note>key: settings.datetime_format.value.description</note>
</trans-unit>
<trans-unit id="106f6833c4af74624ceed3015e658f7298f308f1" resname="settings.datetime_format.value.title">
<source><![CDATA[Date & Time format]]></source>
<target state="new"><![CDATA[Date & Time format]]></target>
<note>key: settings.datetime_format.value.title</note>
</trans-unit>
<trans-unit id="b0b3ec0f464ef6e2113e58e28b47c4d31b7df31d" resname="settings.datetime_format.date.label">
<source>Format for displaying Date</source>
<target state="new">Format for displaying Date</target>
<note>key: settings.datetime_format.date.label</note>
</trans-unit>
<trans-unit id="1d4c72b2f7c87bcdb3cca4f7f43b150b63ee4425" resname="settings.datetime_format.time.label">
<source>Format for displaying Time</source>
<target state="new">Format for displaying Time</target>
<note>key: settings.datetime_format.time.label</note>
</trans-unit>
<trans-unit id="f1fbb4a933439a893696e9c55993d35a741e2f51" resname="settings.datetime_format.additional_info">
<source>Date &amp; Time will be displayed in this format%:</source>
<target state="new">Date &amp; Time will be displayed in this format:</target>
<note>key: settings.datetime_format.additional_info</note>
</trans-unit>
</body>
</file>
</xliff>
1 change: 1 addition & 0 deletions src/bundle/Resources/views/admin/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% block form %}
{% endblock %}
</div>
{% block additional_contnet %}{% endblock %}
</div>
<div class="pt-4 px-0 bg-secondary ez-context-menu">
<div class="ez-sticky-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<td class="ez-table__cell">{{ row.content_type.name }}</td>
<td class="ez-table__cell">{{ admin_ui_config.languages.mappings[row.language].name }}</td>
<td class="ez-table__cell">{{ row.version }}</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-draft-edit"
title="{{ 'drafts.list.action.edit'|trans|desc('Edit Draft') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</td>
<td class="ez-table__cell">{{ content_type.identifier }}</td>
<td class="ez-table__cell">{{ content_type.id }}</td>
<td class="ez-table__cell">{{ content_type.modificationDate|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ content_type.modificationDate|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
{% if can_update %}
{{ macros.content_type_edit(content_type, content_type_group, 'btn btn-icon mx-2') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<td class="ez-table__cell ez-table__cell--after-icon">
<a href="{{ url('_ez_content_view', { 'contentId': row.contentId }) }}">{{ row.name }}</a>
</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell">{{ row.type }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<td><a href="{{ package.homepage }}" target="_blank">{{ package.name }}</a></td>
{% endif %}
<td>{{ package.version }} {{ package.stability }}
<span>({{ package.dateTime|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}
<span>({{ package.dateTime|ez_datetime }}
, {{ package.reference | slice(0, 5) }})
</span>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="small">
{{ contentType.name }} /
{% if creator is not null %}{{ 'created_by'|trans({'%name%': ez_content_name(creator)})|desc('Created by %name%') }} /{% endif %}
{{ content.versionInfo.contentInfo.publishedDate|localizeddate('medium', 'medium', app.request.locale, ez_user_settings['timezone']) }} /
{{ content.versionInfo.contentInfo.publishedDate|ez_datetime }} /
{{ 'content_id'|trans({'%contentId%': content.id})|desc('Content ID: %contentId%') }},
{% if isPublished == false %}
{{ 'parent_location_id'|trans({'%locationId%': parentLocation.id})|desc('Parent Location ID: %locationId%') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="small">
{{ contentType.name }} /
{% if creator is not null %}{{ 'created_by'|trans({'%name%': ez_content_name(creator)})|desc('Created by %name%') }} /{% endif %}
{{ user.versionInfo.contentInfo.publishedDate|localizeddate('medium', 'medium', app.request.locale, ez_user_settings['timezone']) }} /
{{ user.versionInfo.contentInfo.publishedDate|ez_datetime }} /
{{ 'content_id'|trans({'%contentId%': user.id})|desc('Content ID: %contentId%') }}{% if user.versionInfo.contentInfo.mainLocationId %}, {{ 'location_id'|trans({'%locationId%': user.versionInfo.contentInfo.mainLocationId})|desc('Location ID: %locationId%') }}{% endif %}
</div>
<div class="ez-content-item__errors-wrapper" hidden>
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/views/content/tab/details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
{% else %}
{{ 'tab.details.creator.not_found'|trans|desc('Can’t fetch creator') }}
{% endif %}
({{ contentInfo.publishedDate|localizeddate('medium', 'short', app.request.locale, ez_user_settings['timezone']) }})
({{ contentInfo.publishedDate|ez_datetime }})
</td>
<td>
{% if lastContributor is not empty %}
{{ ez_content_name(lastContributor) }}
{% else %}
{{ 'tab.details.last_contributor.not_found'|trans|desc('Can’t fetch last contributor') }}
{% endif %}
({{ versionInfo.modificationDate|localizeddate('medium', 'short', app.request.locale, ez_user_settings['timezone']) }})
({{ versionInfo.modificationDate|ez_datetime }})
</td>
<td>{{ versionInfo.versionNo }}</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
</td>
{% if not is_draft_conflict %}
<td class="ez-table__cell">
{{ version.creationDate|localizeddate('medium', 'short', app.request.locale, ez_user_settings['timezone']) }}
{{ version.creationDate|ez_datetime }}
</td>
{% endif %}
<td class="ez-table__cell">
{{ version.modificationDate|localizeddate('medium', 'short', app.request.locale, ez_user_settings['timezone']) }}
{{ version.modificationDate|ez_datetime }}
</td>
{% if is_draft_conflict %}
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{ 'dashboard.table.contributor.not_found'|trans|desc('Can’t fetch contributor') }}
{% endif %}
</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-edit"
title="{{ 'dashboard.table.all.content.edit'|trans|desc('Edit Content') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{ 'dashboard.table.contributor.not_found'|trans|desc('Can’t fetch contributor') }}
{% endif %}
</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-edit"
title="{{ 'dashboard.table.all.media.edit'|trans|desc('Edit Media') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</td>
<td class="ez-table__cell ez-table__cell--after-icon"><a href="{{ url('_ez_content_view', { 'contentId': row.contentId }) }}">{{ row.name }}</a></td>
<td class="ez-table__cell">{{ row.type }}</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-edit"
title="{{ 'dashboard.table.content.edit'|trans|desc('Edit Content') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<td class="ez-table__cell">{{ row.content_type.name }}</td>
<td class="ez-table__cell">{{ admin_ui_config.languages.mappings[row.language].name }}</td>
<td class="ez-table__cell">{{ row.version }}</td>
<td class="ez-table__cell">{{ row.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ row.modified|ez_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<button class="btn btn-icon mx-2 ez-btn--content-draft-edit"
title="{{ 'dashboard.table.draft.edit'|trans|desc('Edit Draft') }}"
Expand Down
Loading

0 comments on commit 2b3a5b3

Please sign in to comment.