Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.2' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
robertSt7 committed Nov 9, 2023
2 parents a4f807e + c709702 commit e174500
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 103 deletions.
5 changes: 5 additions & 0 deletions public/css/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,11 @@
background: url(/bundles/pimcoreadmin/img/flat-color-icons/focal_point.svg) center center no-repeat !important;
}

.pimcore_icon_focal_point_remove {
background: url(/bundles/pimcoreadmin/img/flat-color-icons/focal_point.svg) center center no-repeat !important;
filter: invert(1);
}

.pimcore_icon_icons {
background: url(/bundles/pimcoreadmin/img/flat-color-icons/library.svg) center center no-repeat !important;
}
Expand Down
75 changes: 56 additions & 19 deletions public/js/pimcore/asset/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pimcore.registerNS("pimcore.asset.image");
* @private
*/
pimcore.asset.image = Class.create(pimcore.asset.asset, {

focalPointCoordinates: {'x': -100,'y': -100},
initialize: function (id, options) {

this.options = options;
Expand Down Expand Up @@ -134,13 +134,25 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {
bodyStyle: "padding: 10px;",
items: [{
xtype: "button",
id: "add_focal_point_" + this.id,
text: t("set_focal_point"),
iconCls: "pimcore_icon_focal_point",
width: "100%",
textAlign: "left",
handler: function () {
this.addFocalPoint();
}.bind(this)
},{
xtype: "button",
id: "remove_focal_point_" + this.id,
text: t("remove_focal_point"),
iconCls: "pimcore_icon_focal_point_remove",
width: "100%",
textAlign: "left",
hidden: this["marker"] !== false,
handler: function () {
this.removeFocalPoint();
}.bind(this)
}, {
xtype: "container",
html: "<hr>"
Expand Down Expand Up @@ -368,6 +380,7 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {
});

this.displayPanel.on('resize', function () {
this.updateFocalPointCoordinates();
this.initPreviewImage();
}.bind(this));
}
Expand All @@ -377,7 +390,7 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {

initPreviewImage: function () {

var html = '<img src="' + this.data.imageInfo['previewUrl'] + '">';
let html = '<img src="' + this.data.imageInfo['previewUrl'] + '">';
Ext.get(this.previewContainerId).setHtml(html);

let area = this.displayPanel.getEl().down('img');
Expand All @@ -386,9 +399,18 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {
area.setStyle('max-height', (this.displayPanel.getHeight() - 40) + "px");
}

if(this.data['customSettings']) {
if (this.data['customSettings']['focalPointX']) {
this.addFocalPoint(this.data['customSettings']['focalPointX'], this.data['customSettings']['focalPointY']);
let focalPointX = this.focalPointCoordinates['x'];
let focalPointY = this.focalPointCoordinates['y'];

//on init, the marker is undefined (on init) or set (on resize), is false when removing focal point
if (this.marker !== false) {
this.marker = false;
if (focalPointX > -100 && focalPointY > -100) {
this.addFocalPoint(focalPointX, focalPointY);
} else if (this.data['customSettings']) {
if (this.data['customSettings']['focalPointX'] && this.data['customSettings']['focalPointY']) {
this.addFocalPoint(this.data['customSettings']['focalPointX'], this.data['customSettings']['focalPointY']);
}
}
}
},
Expand All @@ -410,8 +432,7 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {
text: t("delete"),
iconCls: "pimcore_icon_delete",
handler: function (el) {
marker.remove();
this.marker = false;
this.removeFocalPoint();
}.bind(this)
}));

Expand All @@ -426,30 +447,46 @@ pimcore.asset.image = Class.create(pimcore.asset.asset, {

var markerDD = new Ext.dd.DD(marker);

this.marker = marker;
},
Ext.getCmp('remove_focal_point_' + this.id).setVisible(true);
Ext.getCmp('add_focal_point_' + this.id).setVisible(false);

getSaveData : function ($super, only) {
var parameters = $super(only);
this.marker = marker;

},
removeFocalPoint: function () {
if(this["marker"]) {
this.marker.remove();
this["marker"] = false;
Ext.getCmp('remove_focal_point_' + this.id).setVisible(false);
Ext.getCmp('add_focal_point_' + this.id).setVisible(true);
this.focalPointCoordinates = {x: -100, y: -100};
}
},
updateFocalPointCoordinates: function () {
if (this["marker"]) {
let top = intval(this.marker.getStyle('top'));
let left = intval(this.marker.getStyle('left'));

var top = intval(this.marker.getStyle('top'));
var left = intval(this.marker.getStyle('left'));
let boundingBox = this.marker.up().getSize();

var boundingBox = this.marker.up().getSize();
let x = round(left * 100 / boundingBox.width, 8);
let y = round(top * 100 / boundingBox.height, 8);
this.focalPointCoordinates = {x: x, y: y};
}
},
getSaveData: function ($super, only) {
let parameters = $super(only);

var x = round(left * 100 / boundingBox.width, 8);
var y = round(top * 100 / boundingBox.height, 8);
if (this["marker"]) {
this.updateFocalPointCoordinates();

parameters["image"] = Ext.encode({
"focalPoint": {
"x": x,
"y": y
"x": this.focalPointCoordinates['x'],
"y": this.focalPointCoordinates['y']
}
});
}

return parameters;
}
});
3 changes: 1 addition & 2 deletions public/js/pimcore/document/editables/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ pimcore.document.editables.link = Class.create(pimcore.document.editable, {


getLinkContent: function () {

let text = "[" + t("not_set") + "]";
if (this.data.text) {
text = this.data.text;
Expand All @@ -101,7 +100,7 @@ pimcore.document.editables.link = Class.create(pimcore.document.editable, {
}
let displayHtml = Ext.util.Format.htmlEncode(text);
if (this.data.path || this.data.anchor || this.data.parameters) {
let fullpath = this.data.path + (this.data.parameters ? '?' + Ext.util.Format.htmlEncode(this.data.parameters) : '') + (this.data.anchor ? '#' + Ext.util.Format.htmlEncode(this.data.anchor) : '');
let fullpath = Ext.util.Format.htmlEncode(this.data.path + (this.data.parameters ? '?' + this.data.parameters : '') + (this.data.anchor ? '#' + this.data.anchor : ''));
let displayHtml = Ext.util.Format.htmlEncode(text);

if (this.config.textPrefix !== undefined) {
Expand Down
1 change: 0 additions & 1 deletion public/js/pimcore/object/tags/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pimcore.object.tags.checkbox = Class.create(pimcore.object.tags.abstract, {
getGridColumnConfig:function (field) {
var columnConfig = {
xtype: "checkcolumn",
disabled: field.layout.noteditable,
text: t(field.label),
dataIndex:field.key,
renderer:function (key, value, metaData, record, rowIndex, colIndex, store) {
Expand Down
16 changes: 11 additions & 5 deletions public/js/pimcore/object/tags/localizedfields.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,17 @@ pimcore.object.tags.localizedfields = Class.create(pimcore.object.tags.abstract,
if (oldLanguage == newLanguage) {
return;
}
this.switchLocalizedPanels(oldLanguage, newLanguage);

this.availablePanels[oldLanguage].hide();
this.component.updateLayout();
this.availablePanels[newLanguage].show();
this.currentLanguage = newLanguage;
this.component.updateLayout();
}.bind(this),
pimcoreGlobalLanguageChanged: function (language) {
let globalLanguageIndex = 0;
if (this.frontendLanguages.includes(language)) {
globalLanguageIndex = this.frontendLanguages.indexOf(language);
}
this.countrySelect.setValue(this.frontendLanguages[globalLanguageIndex]);
this.switchLocalizedPanels(this.currentLanguage, language);

}.bind(this)
}
};
Expand Down Expand Up @@ -1004,6 +1002,14 @@ pimcore.object.tags.localizedfields = Class.create(pimcore.object.tags.abstract,
languageTab.setActiveTab(tabLanguage);
}
});
},

switchLocalizedPanels: function (oldLanguage, newLanguage){
this.availablePanels[oldLanguage].hide();
this.component.updateLayout();
this.availablePanels[newLanguage].show();
this.currentLanguage = newLanguage;
this.component.updateLayout();
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ public function replaceAssetAction(Request $request, TranslatorInterface $transl
$stream = fopen($_FILES['Filedata']['tmp_name'], 'r+');
$asset->setStream($stream);
$asset->setCustomSetting('thumbnails', null);
if (method_exists($asset, 'getEmbeddedMetaData')) {
$asset->getEmbeddedMetaData(true);
}
$asset->setUserModification($this->getAdminUser()->getId());

$newFileExt = pathinfo($newFilename, PATHINFO_EXTENSION);
Expand Down
58 changes: 32 additions & 26 deletions src/Controller/Admin/Asset/AssetHelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
use Pimcore\Bundle\AdminBundle\Model\GridConfigShare;
use Pimcore\Bundle\AdminBundle\Tool;
use Pimcore\Db;
use Pimcore\File;
use Pimcore\Loader\ImplementationLoader\Exception\UnsupportedException;
use Pimcore\Localization\LocaleServiceInterface;
use Pimcore\Logger;
use Pimcore\Model\Asset;
use Pimcore\Model\Element;
Expand Down Expand Up @@ -722,17 +722,13 @@ public function getExportJobsAction(Request $request, GridHelperService $gridHel
/**
* @Route("/do-export", name="pimcore_admin_asset_assethelper_doexport", methods={"POST"})
*
* @param Request $request
* @param LocaleServiceInterface $localeService
*
* @return JsonResponse
* @throws FilesystemException
*/
public function doExportAction(Request $request, LocaleServiceInterface $localeService): JsonResponse
public function doExportAction(Request $request): JsonResponse
{
$fileHandle = \Pimcore\File::getValidFilename($request->get('fileHandle'));
$fileHandle = File::getValidFilename($request->get('fileHandle'));
$ids = $request->get('ids');
$settings = $request->get('settings');
$settings = json_decode($settings, true);
$settings = json_decode($request->get('settings'), true);
$delimiter = $settings['delimiter'] ?? ';';
$language = str_replace('default', '', $request->get('language'));

Expand All @@ -752,27 +748,37 @@ public function doExportAction(Request $request, LocaleServiceInterface $localeS

$csv = $this->getCsvData($request, $language, $list, $fields, $addTitles);

$storage = Storage::get('temp');
$csvFile = $this->getCsvFile($fileHandle);
try {
$storage = Storage::get('temp');
$csvFile = $this->getCsvFile($fileHandle);

$fileStream = $storage->readStream($csvFile);
$fileStream = $storage->readStream($csvFile);

$temp = tmpfile();
stream_copy_to_stream($fileStream, $temp, null, 0);
$temp = tmpfile();
stream_copy_to_stream($fileStream, $temp, null, 0);

$firstLine = true;
foreach ($csv as $line) {
if ($addTitles && $firstLine) {
$firstLine = false;
$line = implode($delimiter, $line) . "\r\n";
fwrite($temp, $line);
} else {
fwrite($temp, implode($delimiter, array_map([$this, 'encodeFunc'], $line)) . "\r\n");
$firstLine = true;
foreach ($csv as $line) {
if ($addTitles && $firstLine) {
$firstLine = false;
$line = implode($delimiter, $line) . "\r\n";
fwrite($temp, $line);
} else {
fwrite($temp, implode($delimiter, array_map([$this, 'encodeFunc'], $line)) . "\r\n");
}
}
$storage->writeStream($csvFile, $temp);
} catch (UnableToReadFile $exception) {
Logger::err($exception->getMessage());

return $this->adminJson(
[
'success' => false,
'message' => sprintf('export file not found: %s', $fileHandle),
]
);
}

$storage->writeStream($csvFile, $temp);

return $this->adminJson(['success' => true]);
}

Expand Down Expand Up @@ -860,7 +866,7 @@ protected function getCsvFile(string $fileHandle): string
public function downloadCsvFileAction(Request $request): Response
{
$storage = Storage::get('temp');
$fileHandle = \Pimcore\File::getValidFilename($request->get('fileHandle'));
$fileHandle = File::getValidFilename($request->get('fileHandle'));
$csvFile = $this->getCsvFile($fileHandle);

try {
Expand Down Expand Up @@ -893,7 +899,7 @@ public function downloadCsvFileAction(Request $request): Response
public function downloadXlsxFileAction(Request $request, GridHelperService $gridHelperService): BinaryFileResponse
{
$storage = Storage::get('temp');
$fileHandle = \Pimcore\File::getValidFilename($request->get('fileHandle'));
$fileHandle = File::getValidFilename($request->get('fileHandle'));
$csvFile = $this->getCsvFile($fileHandle);

try {
Expand Down
Loading

0 comments on commit e174500

Please sign in to comment.