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 authored and adamwojs committed Mar 5, 2019
1 parent 23707c9 commit ef673a1
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 41 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ezsystems/ezplatform-admin-ui-modules": "^1.4@dev",
"ezsystems/ez-support-tools": "^1.0@dev",
"ezsystems/ezplatform-design-engine": "^2.0@dev",
"ezsystems/ezplatform-user": "^1.0@dev",
"white-october/pagerfanta-bundle": "^1.1",
"knplabs/knp-menu-bundle": "^2.1",
"mck89/peast": "^1.8",
Expand Down
49 changes: 45 additions & 4 deletions src/bundle/Resources/public/js/scripts/admin.format.date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
(function(moment) {
const formatEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g;
const formatMap = {
const formatICUEx = /[GdayLqDeEc]+/g;
const formatICUMap = {
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',
};
const formatPHPEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g;
const formatPHPMap = {
d: 'DD',
D: 'ddd',
j: 'D',
Expand Down Expand Up @@ -57,10 +87,21 @@
};

moment.fn.formatPHP = function(format) {
console.warn('[DEPRECATED] formatPHP function is deprecated');
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui 2.0');
console.warn('[DEPRECATED] use formatICU instead');
return this.format(
format.replace(formatEx, (phpStr) => {
return typeof formatMap[phpStr] === 'function' ? formatMap[phpStr].call(this) : formatMap[phpStr];
format.replace(formatPHPEx, (phpStr) => {
return typeof formatPHPMap[phpStr] === 'function' ? formatPHPMap[phpStr].call(this) : formatPHPMap[phpStr];
})
);
};

moment.fn.formatICU = function(format) {
const form = format.replace(formatICUEx, (icuStr) => {
return typeof formatICUMap[icuStr] === 'function' ? formatICUMap[icuStr].call(this) : formatICUMap[icuStr];
});

return this.format(form);
};
})(window.moment);
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
return moment(date).tz(timezone);
};
const formatDate = (date, format = userPreferedFullDateFormat) => {
return moment(date).formatPHP(format);
};
const formatShortDate = (date, format = userPreferedShortDateFormat) => {
return moment(date).formatPHP(format);
return moment(date).formatICU(format);
};
const formatDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedFullDateFormat) => {
return formatDate(convertDateToTimezone(date, timezone), format);
};
const formatShortDate = (date, format = userPreferedShortDateFormat) => {
return formatDate(date, format);
};
const formatShortDateWithTimezone = (date, timezone = userPreferedTimezone, format = userPreferedShortDateFormat) => {
return formatDate(convertDateToTimezone(date, timezone), format);
return formatDateWithTimezone(date, timezone, format);
};

eZ.addConfig('helpers.timezone', {
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_full_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_full_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_full_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_full_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_full_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_full_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 @@ -22,15 +22,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_full_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_full_datetime }})
</td>
<td>{{ versionInfo.versionNo }}</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,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_full_datetime }}
</td>
{% endif %}
<td class="ez-table__cell">
{{ version.modificationDate|localizeddate('medium', 'short', app.request.locale, ez_user_settings['timezone']) }}
{{ version.modificationDate|ez_full_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_full_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_full_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_full_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_full_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
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_full_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.media.edit'|trans|desc('Edit Media') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<td><input type="checkbox" value="{{ relation.contentInfo.id }}" /></td>
<td class="ez-relations__item-name">{{ relation.contentInfo.name }}</td>
<td>{{ relation.contentType.name }}</td>
<td>{{ relation.contentInfo.publishedDate|localizeddate('short', 'medium', null, ez_user_settings['timezone']) }}</td>
<td>{{ relation.contentInfo.publishedDate|ez_short_datetime }}</td>
<td colspan="2"><input class="ez-relations__order-input" type="number" value="{{ loop.index }}" /></td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
{{ contentType.getName() }}
</td>
<td>
{{ content.versionInfo.creationDate|localizeddate( 'short', 'medium', null, ez_user_settings['timezone'] ) }}
{{ content.versionInfo.creationDate|ez_short_datetime }}
</td>
5 changes: 5 additions & 0 deletions src/bundle/Resources/views/form_fields.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends 'bootstrap_4_layout.html.twig' %}

{% block form_label -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ez-label')|trim}) -%}
{{ parent() }}
{%- endblock form_label %}

{% block ezsystems_ezplatform_type_udw_widget %}
{{ form_widget(form.location) }}
{{ form_widget(form.select_content) }}
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/views/link_manager/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
<td class="ez-table__cell">{{ url.isValid ? 'url.status.valid'|trans : 'url.status.invalid'|trans }}</td>
<td class="ez-table__cell">
{% if url.lastChecked %}
{{ url.lastChecked|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}
{{ url.lastChecked|ez_full_datetime }}
{% else %}
Never
{% endif %}
</td>
<td class="ez-table__cell">{{ url.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ url.modified|ez_full_datetime }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
{% if can_edit %}
<a href="{{ edit_url }}" class="btn btn-icon mx-2" title="{{ 'url.action.edit'|trans|desc('Edit URL') }}">
Expand Down
6 changes: 3 additions & 3 deletions src/bundle/Resources/views/link_manager/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@
<td class="ez-table__cell">{{ 'url.label.last_checked'|trans }}</td>
<td class="ez-table__cell">
{% if url.lastChecked %}
{{ url.lastChecked|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}
{{ url.lastChecked|ez_full_datetime }}
{% else %}
{{ 'url.label.last_checked.never'|trans|desc('This URL has not been checked') }}
{% endif %}
</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'url.label.created'|trans }}</td>
<td class="ez-table__cell">{{ url.created|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ url.created|ez_full_datetime }}</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'url.label.modified'|trans }}</td>
<td class="ez-table__cell">{{ url.modified|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}</td>
<td class="ez-table__cell">{{ url.modified|ez_full_datetime }}</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{% endblock %}
{% block date %}
<td class="ez-notifications-modal__time">
{{ notification.created|localizeddate('medium', 'short', null, ez_user_settings['timezone']) }}
{{ notification.created|ez_full_datetime }}
</td>
{% endblock %}
</tr>
2 changes: 1 addition & 1 deletion src/bundle/Resources/views/user/settings/update.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="ez-table-header__headline">{{ user_setting.name }}</div>
</div>
<div class="bg-white p-4">
{{ form_row(form.value, {'label_attr': {'class': 'ez-label'}}) }}
{{ form_row(form.value) }}
</div>
{{ form_widget(form.update, {'attr': {'hidden': 'hidden'}}) }}
{{ form_end(form) }}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Pagination/Pagerfanta/UserSettingsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace EzSystems\EzPlatformAdminUi\Pagination\Pagerfanta;

use EzSystems\EzPlatformAdminUi\UserSetting\UserSettingService;
use EzSystems\EzPlatformUser\UserSetting\UserSettingService;
use Pagerfanta\Adapter\AdapterInterface;

/**
Expand Down
37 changes: 30 additions & 7 deletions src/lib/UI/Config/Provider/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,45 @@
namespace EzSystems\EzPlatformAdminUi\UI\Config\Provider;

use EzSystems\EzPlatformAdminUi\UI\Config\ProviderInterface;
use EzSystems\EzPlatformAdminUi\UserSetting\UserSettingService;
use EzSystems\EzPlatformUser\UserSetting\Setting\DateTimeFormatSerializer;

/**
* @todo Will be refactored once DateFormat becomes a User Setting in 2.4
*/
class DateFormat implements ProviderInterface
{
/** @var \EzSystems\EzPlatformAdminUi\UserSetting\UserSettingService */
protected $userSettingService;

/** @var \EzSystems\EzPlatformUser\UserSetting\Setting\DateTimeFormatSerializer */
protected $dateTimeFormatSerializer;

/**
* @param \EzSystems\EzPlatformAdminUi\UserSetting\UserSettingService $userSettingService
* @param \EzSystems\EzPlatformUser\UserSetting\Setting\DateTimeFormatSerializer $dateTimeFormatSerializer
*/
public function __construct(UserSettingService $userSettingService, DateTimeFormatSerializer $dateTimeFormatSerializer)
{
$this->userSettingService = $userSettingService;
$this->dateTimeFormatSerializer = $dateTimeFormatSerializer;
}

/**
* {@inheritdoc}
*
* @return mixed
* @return array
*/
public function getConfig()
public function getConfig(): array
{
$fullDateTimeFormat = $this->dateTimeFormatSerializer->deserialize(
$this->userSettingService->getUserSetting('full_datetime_format')->value
);

$shortDateTimeFormat = $this->dateTimeFormatSerializer->deserialize(
$this->userSettingService->getUserSetting('short_datetime_format')->value
);

return [
'full' => 'M j, Y g:i A',
'short' => 'd.m.Y g:i A',
'full' => (string)$fullDateTimeFormat,
'short' => (string)$shortDateTimeFormat,
];
}
}

0 comments on commit ef673a1

Please sign in to comment.