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

#1515: Add keywords field to the edit image description slide panel #1605

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
84de736
magento/adobe-stock-integration#1515: Add keywords field to the edit …
Jul 16, 2020
507f503
magento/adobe-stock-integration#1515: Add keywords field to the edit …
Jul 17, 2020
b3baefd
magento/adobe-stock-integration#1515: Add keywords field to the edit …
Jul 17, 2020
69ebfbb
Merge branch '2.0-develop' of github.com:magento/adobe-stock-integrat…
sivaschenko Jul 20, 2020
e91c4be
magento/adobe-stock-integration#1605: Using the default ui-select com…
sivaschenko Jul 20, 2020
9bf8ac6
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Jul 24, 2020
4b670d9
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Jul 26, 2020
837ded8
magento/adobe-stock-integration#1605: Added keywords to submit form data
sivaschenko Jul 26, 2020
daa221f
magento/adobe-stock-integration#1515: MFTF test coverage
sivaschenko Jul 26, 2020
23b5a79
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Jul 27, 2020
f41bee6
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Jul 29, 2020
75940bb
Fixed static tests
sivaschenko Jul 29, 2020
dcd8913
magento/adobe-stock-integration#1605: Added validation
sivaschenko Jul 29, 2020
8282e1e
magento/adobe-stock-integration#1605: Moved generic config to compone…
sivaschenko Jul 30, 2020
2b9f86b
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Jul 30, 2020
5307a5d
Fixed static tests
sivaschenko Aug 2, 2020
50f5d8c
Merge branch '2.0-develop' of github.com:magento/adobe-stock-integrat…
sivaschenko Aug 2, 2020
b9aa0c1
Updated bindings
sivaschenko Aug 2, 2020
2eca30e
Fixed static tests
sivaschenko Aug 2, 2020
2fe992c
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Aug 2, 2020
8c4c01e
Fixed static tests
sivaschenko Aug 2, 2020
d27bfd5
Fixed tests for embedded media gallery
sivaschenko Aug 2, 2020
90c7bec
Merge branch '2.0-develop' into 1515-add-keywords-field-to-edit-image
sivaschenko Aug 2, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<description>Verifies image keywords on the View Details panel</description>
</annotations>
<arguments>
<argument name="keywords" />
<argument name="keywords"/>
</arguments>

<grabTextFrom selector="{{AdminEnhancedMediaGalleryViewDetailsSection.keywords}}" stepKey="grabDescription"/>
<assertStringContainsString stepKey="verifyDescription">
<actualResult type="variable">grabDescription</actualResult>
<grabTextFrom selector="{{AdminEnhancedMediaGalleryViewDetailsSection.keywords}}" stepKey="grabKeywords"/>
<assertStringContainsString stepKey="verifyKeywords">
<actualResult type="variable">grabKeywords</actualResult>
<expectedResult type="string">{{keywords}}</expectedResult>
</assertStringContainsString>
</actionGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminMediaGalleryEditAssetAddKeywordActionGroup">
<annotations>
<description>Set Keywords on the Edit Details panel</description>
</annotations>
<arguments>
<argument name="keyword"/>
</arguments>

<fillField selector="{{AdminEnhancedMediaGalleryEditDetailsSection.newKeyword}}" userInput="{{keyword}}" stepKey="enterKeyword"/>
<click selector="{{AdminEnhancedMediaGalleryEditDetailsSection.addNewKeyword}}" stepKey="addKeyword"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<data key="file">magento.jpg</data>
<data key="fileName">renamed title</data>
<data key="extension">jpg</data>
<data key="keyword">newkeyword</data>
</entity>
<entity name="ImageUploadPng" type="uploadImage">
<data key="title" unique="suffix">Image1</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<element name="title" type="input" selector="#title"/>
<element name="fileName" type="text" selector="#path"/>
<element name="description" type="textarea" selector="#description"/>
<element name="newKeyword" type="input" selector="[data-ui-id='keyword']"/>
<element name="addNewKeyword" type="input" selector="[data-ui-id='add-keyword']"/>
<element name="cancel" type="button" selector="#image-details-action-cancel"/>
<element name="save" type="button" selector="#image-details-action-save"/>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="viewImageDetails"/>
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsEditActionGroup" stepKey="editImage"/>
<actionGroup ref="AdminMediaGalleryEditAssetAddKeywordActionGroup" stepKey="setKeywords">
<argument name="keyword" value="UpdatedImageDetails.keyword"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsSaveActionGroup" stepKey="saveImage">
<argument name="image" value="UpdatedImageDetails"/>
</actionGroup>
Expand All @@ -42,5 +45,11 @@
<actionGroup ref="AdminEnhancedMediaGalleryVerifyImageDescriptionActionGroup" stepKey="verifyImageDescription">
<argument name="description" value="UpdatedImageDetails.description"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryVerifyImageKeywordsActionGroup" stepKey="verifyAddedKeywords">
<argument name="keywords" value="UpdatedImageDetails.keyword"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryVerifyImageKeywordsActionGroup" stepKey="verifyMetadataKeywords">
<argument name="keywords" value="ImageMetadata.keywords"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ use Magento\Backend\Block\Template;
"component": "Magento_MediaGalleryUi/js/image/image-edit",
"imageEditDetailsUrl": "<?= $escaper->escapeJs($block->getData('imageEditDetailsUrl')); ?>",
"saveDetailsUrl": "<?= $escaper->escapeJs($block->getData('saveDetailsUrl')); ?>",
"modalSelector": ".media-gallery-edit-image-details-modal",
"mediaGridMessages": "standalone_media_gallery_listing.standalone_media_gallery_listing.messages"
}
}
},
"Magento_MediaGalleryUi/js/validation/validate-image-title": {},
"Magento_MediaGalleryUi/js/validation/validate-image-description": {}
"Magento_MediaGalleryUi/js/validation/validate-image-description": {},
"Magento_MediaGalleryUi/js/validation/validate-image-keyword": {}
},
"#media-gallery-image-edit-details-messages": {
"Magento_Ui/js/core/app": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ use Magento\Backend\Block\Template;
<div id="media-gallery-image-edit-details-messages" data-bind="scope: 'mediaGalleryEditDetailsMessages'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<div id="media-gallery-image-edit-details" data-bind="scope: 'mediaGalleryEditDetails'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<form data-bind="mageInit:{'validation':{}}" id="image-edit-details-form" method="post" enctype="multipart/form-data">
<div id="media-gallery-image-edit-details" data-bind="scope: 'mediaGalleryEditDetails'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
</form>
</div>

<script type="text/x-magento-init">
Expand All @@ -47,13 +49,13 @@ use Magento\Backend\Block\Template;
"component": "Magento_MediaGalleryUi/js/image/image-edit",
"imageEditDetailsUrl": "<?= $escaper->escapeJs($block->getData('imageEditDetailsUrl')); ?>",
"saveDetailsUrl": "<?= $escaper->escapeJs($block->getData('saveDetailsUrl')); ?>",
"modalSelector": ".media-gallery-edit-image-details-modal",
"mediaGridMessages": "standalone_media_gallery_listing.standalone_media_gallery_listing.messages"
}
}
},
"Magento_MediaGalleryUi/js/validation/validate-image-title": {},
"Magento_MediaGalleryUi/js/validation/validate-image-description": {}
"Magento_MediaGalleryUi/js/validation/validate-image-description": {},
"Magento_MediaGalleryUi/js/validation/validate-image-keyword": {}
},
"#media-gallery-image-edit-details-messages": {
"Magento_Ui/js/core/app": {
Expand Down
10 changes: 10 additions & 0 deletions MediaGalleryUi/view/adminhtml/web/css/source/_module.less
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@
.media-gallery-image-details-modal,
.media-gallery-edit-image-details-modal {

.admin__action-multiselect-crumb {
.action-close {
padding: 0;

&:before {
font-size: .5em;
}
}
}

.edit-image-details {
padding: 50px;
}
Expand Down
8 changes: 3 additions & 5 deletions MediaGalleryUi/view/adminhtml/web/js/action/saveDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ define([
], function ($) {
'use strict';

return function (saveImageDetailsUrl, formElement) {
return function (saveImageDetailsUrl, data) {
var deferred = $.Deferred(),
message,
formData = formElement.serialize();
message;

$.ajax({
type: 'POST',
url: saveImageDetailsUrl,
dataType: 'json',
showLoader: true,
data: formData,
data: data,

/**
* Resolve with image details if success, reject with response message otherwise
Expand All @@ -40,7 +39,6 @@ define([
* @param {Object} response
*/
error: function (response) {

if (typeof response.responseJSON === 'undefined' ||
typeof response.responseJSON.message === 'undefined'
) {
Expand Down
9 changes: 6 additions & 3 deletions MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ define([
saveImageDetailsAction: function () {
var saveDetailsUrl = this.mediaGalleryEditDetails().saveDetailsUrl,
modalElement = $(this.modalSelector),
dataForm = modalElement.find('#image-edit-details-form'),
form = modalElement.find('#image-edit-details-form'),
imageId = this.imageModel().getSelected().id,
keywords = this.mediaGalleryEditDetails().selectedKeywords(),
imageDetails = this.mediaGalleryImageDetails();

if (dataForm.validation('isValid')) {
if (form.validation('isValid')) {
saveDetails(
saveDetailsUrl,
dataForm
[form.serialize(), $.param({
'keywords': keywords
})].join('&')
).then(function () {
this.closeModal();
this.imageModel().reloadGrid();
Expand Down
113 changes: 108 additions & 5 deletions MediaGalleryUi/view/adminhtml/web/js/image/image-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,120 @@ define([
'jquery',
'underscore',
'uiComponent',
'uiLayout',
'Magento_Ui/js/lib/key-codes',
'Magento_MediaGalleryUi/js/action/getDetails'
], function ($, _, Component, keyCodes, getDetails) {
'Magento_MediaGalleryUi/js/action/getDetails',
'mage/validation'
], function ($, _, Component, layout, keyCodes, getDetails) {
'use strict';

return Component.extend({
defaults: {
template: 'Magento_MediaGalleryUi/image/image-edit',
modalSelector: '',
modalSelector: '.media-gallery-edit-image-details-modal',
imageEditDetailsUrl: '/media_gallery/image/details',
saveDetailsUrl: '/media_gallery/image/saveDetails',
images: [],
image: null,
keywordOptions: [],
selectedKeywords: [],
newKeyword: '',
newKeywordSelector: '#keyword',
modules: {
mediaGridMessages: '${ $.mediaGridMessages }'
mediaGridMessages: '${ $.mediaGridMessages }',
keywordsSelect: '${ $.name }_keywords'
},
viewConfig: [
{
component: 'Magento_Ui/js/form/element/ui-select',
name: '${ $.name }_keywords',
template: 'ui/grid/filters/elements/ui-select',
disableLabel: true
}
],
exports: {
keywordOptions: '${ $.name }_keywords:options'
},
links: {
selectedKeywords: '${ $.name }_keywords:value'
}
},

/**
* Initialize the component
*
* @returns {Object}
*/
initialize: function () {
this._super().initView();

return this;
},

/**
* Add a new keyword to select
*/
addKeyword: function () {
var options = this.keywordOptions(),
selected = this.selectedKeywords(),
newKeywordField = $(this.newKeywordSelector);

newKeywordField.validation();

if (!newKeywordField.validation('isValid') || this.newKeyword() === '') {
return;
}

options.push(this.getOptionForKeyword(this.newKeyword()));
selected.push(this.newKeyword());
this.newKeyword('');

this.keywordOptions(options);
this.selectedKeywords(selected);
},

/**
* Create an option object based on keyword string
*
* @param {String} keyword
* @returns {Object}
*/
getOptionForKeyword: function(keyword) {
return {
is_active: 1,
level: 1,
value: keyword,
label: keyword
};
},

/**
* Convert array of keywords to options format
*
* @param {Array} tags
*/
setKeywordOptions: function (tags) {
var options = [];

tags.forEach(function (tag) {
options.push(this.getOptionForKeyword(tag));
}.bind(this));

this.keywordOptions(options);
this.selectedKeywords(tags);
},

/**
* Initialize child components
*
* @returns {Object}
*/
initView: function () {
layout(this.viewConfig);

return this;
},

/**
* Init observable variables
*
Expand All @@ -33,7 +129,10 @@ define([
initObservable: function () {
this._super()
.observe([
'image'
'image',
'keywordOptions',
'selectedKeywords',
'newKeyword'
]);

return this;
Expand Down Expand Up @@ -76,6 +175,10 @@ define([
if (!modalElement.length || _.isUndefined(modalElement.modal)) {
return;
}

this.setKeywordOptions(this.image().tags);
this.newKeyword('');

modalElement.modal('openModal');
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'jquery/validate',
'mage/translate'
], function ($, validate, $t) {
'use strict';

$.validator.addMethod(
'validate-image-keyword', function (value) {
return /^[a-zA-Z0-9\-\_\.\,]+$|^$/i.test(value);

}, $t('Please use only letters (a-z or A-Z), numbers (0-9), dots (.), commas(,), ' +
'underscores (_) and dashes(-) on this field.'));
});
Loading