-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Added masonry grid and columns components #25464
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
Merged
magento-engcom-team
merged 12 commits into
magento:2.3-develop
from
sivaschenko:masonry-overlay
Nov 8, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81d2758
Added masonry grid and columns components
sivaschenko c0119d9
magento/magento2#25464: Added unsanitized html suffix to the error me…
sivaschenko c657fb2
magento/magento2#25464: Applied code review suggestions
sivaschenko 5aebbc0
magento/magento2#25464: Applied code review suggestions
sivaschenko 02dfa0d
magento/magento2#25464: Corrected annotation
sivaschenko f7784b5
magento/magento2#25464: Removed relative path
sivaschenko c3f8623
magento/magento2#25464: Adjusted template
sivaschenko 0e5eaaf
magento/magento2#25464: Applied code review suggestions
sivaschenko 4787165
Visible record should not be stateful
sivaschenko 2c0f863
magento/magento2#25464: Fixed static tests
sivaschenko ea18bd7
magento/magento2#25464: Single quotes are redundant for object keys
sivaschenko 6023ac7
Added raf untility for window resizing
sivaschenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
179 changes: 179 additions & 0 deletions
179
app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
define([ | ||
'jquery', | ||
'Magento_Ui/js/grid/columns/column' | ||
], function ($, Column) { | ||
'use strict'; | ||
|
||
return Column.extend({ | ||
defaults: { | ||
previewImageSelector: '[data-image-preview]', | ||
visibleRecord: null, | ||
height: 0, | ||
displayedRecord: {}, | ||
lastOpenedImage: null, | ||
modules: { | ||
masonry: '${ $.parentName }', | ||
thumbnailComponent: '${ $.parentName }.thumbnail_url' | ||
}, | ||
statefull: { | ||
sorting: true, | ||
lastOpenedImage: true | ||
}, | ||
listens: { | ||
'${ $.provider }:params.filters': 'hide', | ||
'${ $.provider }:params.search': 'hide' | ||
}, | ||
exports: { | ||
height: '${ $.parentName }.thumbnail_url:previewHeight' | ||
} | ||
}, | ||
|
||
/** | ||
* Init observable variables | ||
* @return {Object} | ||
*/ | ||
initObservable: function () { | ||
this._super() | ||
.observe([ | ||
'visibleRecord', | ||
'height', | ||
'displayedRecord', | ||
'lastOpenedImage' | ||
]); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
* Next image preview | ||
* | ||
* @param {Object} record | ||
*/ | ||
next: function (record) { | ||
var recordToShow = this.getRecord(record._rowIndex + 1); | ||
|
||
recordToShow.rowNumber = record.lastInRow ? record.rowNumber + 1 : record.rowNumber; | ||
this.show(recordToShow); | ||
}, | ||
|
||
/** | ||
* Previous image preview | ||
* | ||
* @param {Object} record | ||
*/ | ||
prev: function (record) { | ||
var recordToShow = this.getRecord(record._rowIndex - 1); | ||
|
||
recordToShow.rowNumber = record.firstInRow ? record.rowNumber - 1 : record.rowNumber; | ||
this.show(recordToShow); | ||
}, | ||
|
||
/** | ||
* Get record | ||
* | ||
* @param {Integer} recordIndex | ||
* | ||
* @return {Object} | ||
*/ | ||
getRecord: function (recordIndex) { | ||
return this.masonry().rows()[recordIndex]; | ||
}, | ||
|
||
/** | ||
* Set selected row id | ||
* | ||
* @param {Number} rowId | ||
* @private | ||
*/ | ||
_selectRow: function (rowId) { | ||
this.thumbnailComponent().previewRowId(rowId); | ||
}, | ||
|
||
/** | ||
* Show image preview | ||
* | ||
* @param {Object} record | ||
*/ | ||
show: function (record) { | ||
var img; | ||
|
||
this.hide(); | ||
this.displayedRecord(record); | ||
this._selectRow(record.rowNumber || null); | ||
this.visibleRecord(record._rowIndex); | ||
|
||
img = $(this.previewImageSelector + ' img'); | ||
|
||
if (img.get(0).complete) { | ||
this.updateHeight(); | ||
this.scrollToPreview(); | ||
} else { | ||
img.load(function () { | ||
this.updateHeight(); | ||
this.scrollToPreview(); | ||
}.bind(this)); | ||
} | ||
|
||
this.lastOpenedImage(record._rowIndex); | ||
}, | ||
|
||
/** | ||
* Update image preview section height | ||
*/ | ||
updateHeight: function () { | ||
this.height($(this.previewImageSelector).height() + 'px'); | ||
}, | ||
|
||
/** | ||
* Close image preview | ||
*/ | ||
hide: function () { | ||
this.lastOpenedImage(null); | ||
this.visibleRecord(null); | ||
this.height(0); | ||
this._selectRow(null); | ||
}, | ||
|
||
/** | ||
* Returns visibility for given record. | ||
* | ||
* @param {Object} record | ||
* @return {*|bool} | ||
*/ | ||
isVisible: function (record) { | ||
if (this.lastOpenedImage() === record._rowIndex && | ||
this.visibleRecord() === null | ||
) { | ||
this.show(record); | ||
} | ||
|
||
return this.visibleRecord() === record._rowIndex || false; | ||
}, | ||
|
||
/** | ||
* Get styles for preview | ||
* | ||
* @returns {Object} | ||
*/ | ||
getStyles: function () { | ||
return { | ||
'margin-top': '-' + this.height() | ||
}; | ||
}, | ||
|
||
/** | ||
* Scroll to preview window | ||
*/ | ||
scrollToPreview: function () { | ||
$(this.previewImageSelector).get(0).scrollIntoView({ | ||
behavior: 'smooth', | ||
block: 'center', | ||
inline: 'nearest' | ||
}); | ||
} | ||
}); | ||
}); |
89 changes: 89 additions & 0 deletions
89
app/code/Magento/Ui/view/base/web/js/grid/columns/image.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
define([ | ||
'Magento_Ui/js/grid/columns/column' | ||
], function (Column) { | ||
'use strict'; | ||
|
||
return Column.extend({ | ||
defaults: { | ||
modules: { | ||
previewComponent: '${ $.parentName }.preview' | ||
}, | ||
previewRowId: null, | ||
previewHeight: 0, | ||
fields: { | ||
id: 'id', | ||
url: 'url' | ||
} | ||
}, | ||
|
||
/** | ||
* Init observable variables | ||
* @return {Object} | ||
*/ | ||
initObservable: function () { | ||
this._super() | ||
.observe([ | ||
'previewRowId', | ||
'previewHeight' | ||
]); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
* Returns url to given record. | ||
* | ||
* @param {Object} record - Data to be preprocessed. | ||
* @returns {String} | ||
*/ | ||
getUrl: function (record) { | ||
return record[this.fields.url]; | ||
}, | ||
|
||
/** | ||
* Returns id to given record. | ||
* | ||
* @param {Object} record - Data to be preprocessed. | ||
* @returns {Number} | ||
*/ | ||
getId: function (record) { | ||
return record[this.fields.id]; | ||
}, | ||
|
||
/** | ||
* Returns container styles to given record. | ||
* | ||
* @param {Object} record - Data to be preprocessed. | ||
* @returns {Object} | ||
*/ | ||
getStyles: function (record) { | ||
var styles = record.styles(); | ||
|
||
styles['margin-bottom'] = this.previewRowId() === record.rowNumber ? this.previewHeight : 0; | ||
record.styles(styles); | ||
|
||
return record.styles; | ||
}, | ||
|
||
/** | ||
* Returns class list to given record. | ||
* | ||
* @param {Object} record - Data to be preprocessed. | ||
* @returns {Object} | ||
*/ | ||
getClasses: function (record) { | ||
return record.css || {}; | ||
}, | ||
|
||
/** | ||
* Expand image preview | ||
*/ | ||
expandPreview: function (record) { | ||
this.previewComponent().show(record); | ||
} | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
app/code/Magento/Ui/view/base/web/js/grid/columns/overlay.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
define([ | ||
'Magento_Ui/js/grid/columns/column' | ||
], function (Column) { | ||
'use strict'; | ||
|
||
return Column.extend({ | ||
/** | ||
* If overlay should be visible | ||
* | ||
* @param {Object} row | ||
* @returns {Boolean} | ||
*/ | ||
isVisible: function (row) { | ||
return !!row[this.index]; | ||
}, | ||
|
||
/** | ||
* Get overlay label | ||
* | ||
* @param {Object} row | ||
* @returns {String} | ||
*/ | ||
getLabel: function (row) { | ||
return row[this.index]; | ||
} | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.