Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the user's timezone in the version preview and in CSV exports #548

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion public/js/pimcore/asset/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ pimcore.asset.versions = Class.create({
var data = grid.getStore().getAt(rowIndex).data;

var versionId = data.id;
var url = Routing.generate('pimcore_admin_asset_showversion', {id: versionId});
var url = Routing.generate('pimcore_admin_asset_showversion', {
id: versionId,
userTimezone: getUserTimezone()
});
Ext.get(this.frameId).dom.src = url;
},

Expand Down
1 change: 1 addition & 0 deletions public/js/pimcore/element/helpers/gridColumnConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ pimcore.element.helpers.gridColumnConfig = {
this.exportParameters.initial = initial ? 1 : 0;
this.exportParameters.language = this.gridLanguage;
this.exportParameters.context = Ext.encode(this.context);
this.exportParameters.userTimezone = getUserTimezone();

Ext.Ajax.request({
url: this.exportProcessUrl,
Expand Down
4 changes: 4 additions & 0 deletions public/js/pimcore/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,10 @@ function htmlspecialchars (string, quoteStyle, charset, doubleEncode) {
return string
}

function getUserTimezone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}

function dateToServerTimezone(date) {

let utcDate = new Date(date.toLocaleString('en-US', {
Expand Down
12 changes: 9 additions & 3 deletions public/js/pimcore/object/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ pimcore.object.versions = Class.create({

var selections = grid.getSelectionModel().getSelection();

var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', {from: selections[0].data.id, to: selections[1].data.id});
var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', {
from: selections[0].data.id,
to: selections[1].data.id,
userTimezone: getUserTimezone()
});
Ext.get(this.iframeId).dom.src = url;
}
},
Expand All @@ -212,8 +216,10 @@ pimcore.object.versions = Class.create({
var store = grid.getStore();
var data = store.getAt(rowIndex).data;
var versionId = data.id;

var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', {id: versionId});
var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', {
id: versionId,
userTimezone: getUserTimezone()
});
Ext.get(this.iframeId).dom.src = url;
},

Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ public function showVersionAction(Request $request): Response
}
}

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

$loader = \Pimcore::getContainer()->get('pimcore.implementation_loader.asset.metadata.data');

return $this->render(
Expand Down
5 changes: 5 additions & 0 deletions src/Controller/Admin/DataObject/DataObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,9 @@ public function previewVersionAction(Request $request): Response
$object = $version?->loadData();

if ($object) {

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

if (method_exists($object, 'getLocalizedFields')) {
/** @var DataObject\Localizedfield $localizedFields */
$localizedFields = $object->getLocalizedFields();
Expand Down Expand Up @@ -1651,6 +1654,8 @@ public function diffVersionsAction(Request $request, int $from, int $to): Respon
throw $this->createNotFoundException('Version with id [' . $id2 . "] doesn't exist");
}

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

if (method_exists($object2, 'getLocalizedFields')) {
/** @var DataObject\Localizedfield $localizedFields2 */
$localizedFields2 = $object2->getLocalizedFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ public function doExportAction(
$settings = json_decode($request->get('settings'), true);
$delimiter = $settings['delimiter'] ?? ';';
$header = $settings['header'] ?? 'title';
Tool\UserTimezone::setUserTimezone($request->request->get('userTimezone'));

$allParams = array_merge($request->request->all(), $request->query->all());

Expand Down
Loading