From 53701a6a623db8e9b7c5c921f8d24e2fe2c551c8 Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Sun, 23 Aug 2015 11:59:36 +0300 Subject: [PATCH 001/206] PV-5: Create video config with Helper for getting params from it --- .../Magento/ProductVideo/Helper/Media.php | 106 ++++++++++++++++++ app/code/Magento/ProductVideo/etc/view.xml | 14 +++ 2 files changed, 120 insertions(+) create mode 100644 app/code/Magento/ProductVideo/Helper/Media.php create mode 100644 app/code/Magento/ProductVideo/etc/view.xml diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php new file mode 100644 index 0000000000000..10608f2f5795a --- /dev/null +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -0,0 +1,106 @@ +viewConfig = $configInterface; + $this->currentTheme = $designInterface->getDesignTheme(); + } + + /** + * Get video config from view.xml + * + * @return $this + */ + public function getVideoConfig() + { + $this->videoConfig = $this->viewConfig->getViewConfig([ + 'area' => Area::AREA_FRONTEND, + 'themeModel' => $this->currentTheme + ]); + + return $this; + } + + /** + * Get video play params for player + * + * @return mixed + */ + public function getVideoPlayAttribute() + { + if (!isset($this->videoConfig) || empty($this->videoConfig)) { + $this->getVideoConfig(); + } + return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_play'); + } + + /** + * Get video stop params for player + * + * @return mixed + */ + public function getVideoStopAttribute() + { + if (!isset($this->videoConfig) || empty($this->videoConfig)) { + $this->getVideoConfig(); + } + return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_stop'); + } + + /** + * Get video color params for player + * + * @return mixed + */ + public function getVideoColorAttribute() + { + if (!isset($this->videoConfig) || empty($this->videoConfig)) { + $this->getVideoConfig(); + } + return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_color'); + } + +} diff --git a/app/code/Magento/ProductVideo/etc/view.xml b/app/code/Magento/ProductVideo/etc/view.xml new file mode 100644 index 0000000000000..84268b368e98a --- /dev/null +++ b/app/code/Magento/ProductVideo/etc/view.xml @@ -0,0 +1,14 @@ + + + + + 1 + 1 + 000000 + + From 3967ac13882d50e388503ac0fb343811a9df3000 Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Mon, 24 Aug 2015 10:46:27 +0300 Subject: [PATCH 002/206] PV-5: Variable's names changed --- app/code/Magento/ProductVideo/Helper/Media.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php index 10608f2f5795a..ce9eb93d0b7f8 100644 --- a/app/code/Magento/ProductVideo/Helper/Media.php +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -35,7 +35,7 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper /* * Cached video config */ - protected $videoConfig; + protected $cachedVideoConfig; /** * @param \Magento\Framework\View\ConfigInterface $configInterface @@ -56,7 +56,7 @@ public function __construct( */ public function getVideoConfig() { - $this->videoConfig = $this->viewConfig->getViewConfig([ + $this->cachedVideoConfig = $this->viewConfig->getViewConfig([ 'area' => Area::AREA_FRONTEND, 'themeModel' => $this->currentTheme ]); @@ -71,10 +71,10 @@ public function getVideoConfig() */ public function getVideoPlayAttribute() { - if (!isset($this->videoConfig) || empty($this->videoConfig)) { + if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { $this->getVideoConfig(); } - return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_play'); + return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_play'); } /** @@ -84,10 +84,10 @@ public function getVideoPlayAttribute() */ public function getVideoStopAttribute() { - if (!isset($this->videoConfig) || empty($this->videoConfig)) { + if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { $this->getVideoConfig(); } - return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_stop'); + return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_stop'); } /** @@ -97,10 +97,10 @@ public function getVideoStopAttribute() */ public function getVideoColorAttribute() { - if (!isset($this->videoConfig) || empty($this->videoConfig)) { + if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { $this->getVideoConfig(); } - return $this->videoConfig->getVarValue(self::MODULE_NAME, 'video_color'); + return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_color'); } } From a7c441a8b800e895eb0b84d4a728075764f5cc7e Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Tue, 25 Aug 2015 19:46:18 +0300 Subject: [PATCH 003/206] PV-5: Video config with helper to get attributes. Helper include unit test --- .../Magento/ProductVideo/Helper/Media.php | 49 +++--- .../Test/Unit/Helper/MediaTest.php | 143 ++++++++++++++++++ app/code/Magento/ProductVideo/etc/view.xml | 16 +- .../Magento/Framework/Config/View.php | 30 +++- .../Magento/Framework/Config/etc/view.xsd | 31 ++++ 5 files changed, 243 insertions(+), 26 deletions(-) create mode 100644 app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php index ce9eb93d0b7f8..549e0581ca321 100644 --- a/app/code/Magento/ProductVideo/Helper/Media.php +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -9,7 +9,7 @@ use Magento\Framework\App\Area; /** - * Helper to move images from tmp to catalog directory + * Helper to get attributes for video * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -20,6 +20,21 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper */ const MODULE_NAME = 'Magento_ProductVideo'; + /* + * Video play attribute + */ + const VIDEO_PLAY = 'video_play'; + + /* + * Video stop attribute + */ + const VIDEO_STOP = 'video_stop'; + + /* + * Video color attribute + */ + const VIDEO_BACKGROUND = 'video_background'; + /** * @var \Magento\Framework\View\ConfigInterface */ @@ -47,19 +62,22 @@ public function __construct( ) { $this->viewConfig = $configInterface; $this->currentTheme = $designInterface->getDesignTheme(); + $this->initConfig(); } /** - * Get video config from view.xml + * Cached video config * * @return $this */ - public function getVideoConfig() + public function initConfig() { - $this->cachedVideoConfig = $this->viewConfig->getViewConfig([ - 'area' => Area::AREA_FRONTEND, - 'themeModel' => $this->currentTheme - ]); + if($this->cachedVideoConfig === null) { + $this->cachedVideoConfig = $this->viewConfig->getViewConfig([ + 'area' => Area::AREA_FRONTEND, + 'themeModel' => $this->currentTheme + ]); + } return $this; } @@ -71,10 +89,7 @@ public function getVideoConfig() */ public function getVideoPlayAttribute() { - if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { - $this->getVideoConfig(); - } - return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_play'); + return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_PLAY); } /** @@ -84,10 +99,7 @@ public function getVideoPlayAttribute() */ public function getVideoStopAttribute() { - if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { - $this->getVideoConfig(); - } - return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_stop'); + return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_STOP); } /** @@ -95,12 +107,9 @@ public function getVideoStopAttribute() * * @return mixed */ - public function getVideoColorAttribute() + public function getVideoBackgroundAttribute() { - if (!isset($this->cachedVideoConfig) || empty($this->cachedVideoConfig)) { - $this->getVideoConfig(); - } - return $this->cachedVideoConfig->getVarValue(self::MODULE_NAME, 'video_color'); + return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_BACKGROUND); } } diff --git a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php new file mode 100644 index 0000000000000..675432104ba16 --- /dev/null +++ b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php @@ -0,0 +1,143 @@ +viewConfigMock = $this->getMock( + '\Magento\Framework\View\Config', + [], + [], + '', + false + ); + + $this->themeCustomization = $this->getMock( + 'Magento\Framework\View\Design\Theme\Customization', + [], + [], + '', + false + ); + $themeMock = $this->getMock( + 'Magento\Theme\Model\Theme', + ['__wakeup', 'getCustomization'], + [], + '', + false + ); + $themeMock->expects( + $this->any() + )->method( + 'getCustomization' + )->will( + $this->returnValue($this->themeCustomization) + ); + + $this->currentThemeMock = $this->getMock('Magento\Framework\View\DesignInterface'); + $this->currentThemeMock->expects($this->any())->method('getDesignTheme')->will($this->returnValue($themeMock)); + + $this->mediaHelperObject = $objectManager->getObject( + '\Magento\ProductVideo\Helper\Media', + [ + 'configInterface' => $this->viewConfigMock, + 'designInterface' => $this->currentThemeMock, + ] + ); + + } + + public function dataForVideoPlay() + { + return [ + [ + 1, + ], + [ + 0, + ], + ]; + } + + public function dataForVideoStop() + { + return [ + [ + 1, + ], + [ + 0, + ], + ]; + } + + public function dataForVideoBackground() + { + return [ + [ + '[255, 255, 255]', + ], + [ + '[0, 0, 0]', + ], + ]; + } + + public function testInitConfig() + { + $configMock = $this->getMock('\Magento\Framework\Config\View', [], [], '', false); + + $this->viewConfigMock + ->expects($this->atLeastOnce()) + ->method('getViewConfig') + ->willReturn($configMock); + + $this->mediaHelperObject->initConfig(); + } + + /** + * @dataProvider dataForVideoPlay + */ + public function testGetVideoPlayAttribute($expectedResult) + { + $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + } + + /** + * @dataProvider dataForVideoStop + */ + public function testGetVideoStopAttribute($expectedResult) + { + $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + } + + /** + * @dataProvider dataForVideoBackground + */ + public function testGetVideoBackgroundAttribute($expectedResult) + { + $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + } + +} diff --git a/app/code/Magento/ProductVideo/etc/view.xml b/app/code/Magento/ProductVideo/etc/view.xml index 84268b368e98a..abcce7c52a32a 100644 --- a/app/code/Magento/ProductVideo/etc/view.xml +++ b/app/code/Magento/ProductVideo/etc/view.xml @@ -6,9 +6,15 @@ */ --> - - 1 - 1 - 000000 - + + + 1 + + + 1 + + + [255, 255, 255] + + diff --git a/lib/internal/Magento/Framework/Config/View.php b/lib/internal/Magento/Framework/Config/View.php index 3221b201c9953..d0334c2982483 100644 --- a/lib/internal/Magento/Framework/Config/View.php +++ b/lib/internal/Magento/Framework/Config/View.php @@ -58,6 +58,21 @@ protected function _extractData(\DOMDocument $dom) } } break; + case 'media': + $moduleName = $childNode->getAttribute('module'); + /** @var \DOMElement $node */ + foreach ($childNode->getElementsByTagName('mediaItem') as $node) { + $imageId = $node->getAttribute('id'); + $result[$childNode->tagName][$moduleName][$imageId]['type'] = $node->getAttribute('type'); + foreach ($node->childNodes as $attribute) { + if ($attribute->nodeType != XML_ELEMENT_NODE) { + continue; + } + $nodeValue = $attribute->nodeValue; + $result[$childNode->tagName][$moduleName][$imageId][$attribute->tagName] = $nodeValue; + } + } + break; case 'exclude': /** @var $itemNode \DOMElement */ foreach ($childNode->getElementsByTagName('item') as $itemNode) { @@ -106,6 +121,17 @@ public function getImages($module) return isset($this->_data['images'][$module]) ? $this->_data['images'][$module] : []; } + /** + * Retrieve a list images attributes in scope of specified module + * + * @param string $module + * @return array + */ + public function getMediaValue($module, $var) + { + return isset($this->_data['media'][$module][$var][$var]) ? $this->_data['media'][$module][$var][$var] : []; + } + /** * Retrieve array of image attributes * @@ -152,8 +178,10 @@ protected function _getIdAttributes() '/view/vars' => 'module', '/view/vars/var' => 'name', '/view/exclude/item' => ['type', 'item'], - '/view/images' => 'modulle', + '/view/images' => 'module', '/view/images/image' => ['id', 'type'], + '/view/media' => 'module', + '/view/media/mediaItem' => ['id', 'mediaItem'], ]; } diff --git a/lib/internal/Magento/Framework/Config/etc/view.xsd b/lib/internal/Magento/Framework/Config/etc/view.xsd index a9fb9593b2531..017e5c510b339 100644 --- a/lib/internal/Magento/Framework/Config/etc/view.xsd +++ b/lib/internal/Magento/Framework/Config/etc/view.xsd @@ -30,6 +30,7 @@ + @@ -74,6 +75,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a9147db501373bf7d137fbeba7f09e4d19253ffd Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Wed, 26 Aug 2015 18:01:37 +0300 Subject: [PATCH 004/206] PV-5: Refactoring XSD-schema, added global root "media" --- .../Magento/ProductVideo/Helper/Media.php | 8 ++-- .../Test/Unit/Helper/MediaTest.php | 30 ++++++------ app/code/Magento/ProductVideo/etc/view.xml | 12 ++--- app/code/Magento/Swatches/etc/view.xml | 20 ++++---- .../adminhtml/Magento/backend/etc/view.xml | 4 +- .../frontend/Magento/blank/etc/view.xml | 4 +- app/design/frontend/Magento/luma/etc/view.xml | 4 +- .../Magento/Framework/Config/View.php | 46 +++++++++++-------- .../Magento/Framework/Config/etc/view.xsd | 12 ++--- 9 files changed, 70 insertions(+), 70 deletions(-) diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php index 549e0581ca321..11c546322ebb2 100644 --- a/app/code/Magento/ProductVideo/Helper/Media.php +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -70,7 +70,7 @@ public function __construct( * * @return $this */ - public function initConfig() + protected function initConfig() { if($this->cachedVideoConfig === null) { $this->cachedVideoConfig = $this->viewConfig->getViewConfig([ @@ -89,7 +89,7 @@ public function initConfig() */ public function getVideoPlayAttribute() { - return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_PLAY); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_PLAY); } /** @@ -99,7 +99,7 @@ public function getVideoPlayAttribute() */ public function getVideoStopAttribute() { - return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_STOP); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_STOP); } /** @@ -109,7 +109,7 @@ public function getVideoStopAttribute() */ public function getVideoBackgroundAttribute() { - return $this->cachedVideoConfig->getMediaValue(self::MODULE_NAME, self::VIDEO_BACKGROUND); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_BACKGROUND); } } diff --git a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php index 675432104ba16..6912613f0f205 100644 --- a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php +++ b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php @@ -16,6 +16,8 @@ class MediaTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\DesignInterface */ protected $currentThemeMock; + protected $mediaHelperObject; + /** * @var array */ @@ -27,12 +29,17 @@ public function setUp() $this->viewConfigMock = $this->getMock( '\Magento\Framework\View\Config', - [], + ['getMediaValue', 'getViewConfig'], [], '', false ); + $this->viewConfigMock + ->expects($this->atLeastOnce()) + ->method('getViewConfig') + ->willReturn($this->viewConfigMock); + $this->themeCustomization = $this->getMock( 'Magento\Framework\View\Design\Theme\Customization', [], @@ -104,24 +111,13 @@ public function dataForVideoBackground() ]; } - public function testInitConfig() - { - $configMock = $this->getMock('\Magento\Framework\Config\View', [], [], '', false); - - $this->viewConfigMock - ->expects($this->atLeastOnce()) - ->method('getViewConfig') - ->willReturn($configMock); - - $this->mediaHelperObject->initConfig(); - } - /** * @dataProvider dataForVideoPlay */ public function testGetVideoPlayAttribute($expectedResult) { - $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->mediaHelperObject->getVideoPlayAttribute(); } /** @@ -129,7 +125,8 @@ public function testGetVideoPlayAttribute($expectedResult) */ public function testGetVideoStopAttribute($expectedResult) { - $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->mediaHelperObject->getVideoStopAttribute(); } /** @@ -137,7 +134,8 @@ public function testGetVideoStopAttribute($expectedResult) */ public function testGetVideoBackgroundAttribute($expectedResult) { - $this->viewConfigMock->expects($this->any())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->mediaHelperObject->getVideoBackgroundAttribute(); } } diff --git a/app/code/Magento/ProductVideo/etc/view.xml b/app/code/Magento/ProductVideo/etc/view.xml index abcce7c52a32a..6c5e0250f47b4 100644 --- a/app/code/Magento/ProductVideo/etc/view.xml +++ b/app/code/Magento/ProductVideo/etc/view.xml @@ -7,14 +7,14 @@ --> - + - + + - + + + diff --git a/app/code/Magento/Swatches/etc/view.xml b/app/code/Magento/Swatches/etc/view.xml index e32865f4ce668..84435d932943c 100644 --- a/app/code/Magento/Swatches/etc/view.xml +++ b/app/code/Magento/Swatches/etc/view.xml @@ -6,22 +6,22 @@ */ --> - + - 30 - 20 + 1 + 1 - 110 - 90 + 1 + 1 - 30 - 20 + 1 + 1 - 110 - 90 + 1 + 1 - + diff --git a/app/design/adminhtml/Magento/backend/etc/view.xml b/app/design/adminhtml/Magento/backend/etc/view.xml index 8e6953e5faf01..7771b2b27f9f1 100644 --- a/app/design/adminhtml/Magento/backend/etc/view.xml +++ b/app/design/adminhtml/Magento/backend/etc/view.xml @@ -9,7 +9,7 @@ 1MB - + 75 75 @@ -19,7 +19,7 @@ 75 75 - + Lib::mage/common.js Lib::mage/cookies.js diff --git a/app/design/frontend/Magento/blank/etc/view.xml b/app/design/frontend/Magento/blank/etc/view.xml index 21b576c7da5db..6a2e6fee1e9f3 100644 --- a/app/design/frontend/Magento/blank/etc/view.xml +++ b/app/design/frontend/Magento/blank/etc/view.xml @@ -6,7 +6,7 @@ */ --> - + 140 140 @@ -176,7 +176,7 @@ 240 300 - + 0 diff --git a/app/design/frontend/Magento/luma/etc/view.xml b/app/design/frontend/Magento/luma/etc/view.xml index caa64aaf48140..b0357367d95aa 100644 --- a/app/design/frontend/Magento/luma/etc/view.xml +++ b/app/design/frontend/Magento/luma/etc/view.xml @@ -6,7 +6,7 @@ */ --> - + 140 140 @@ -180,7 +180,7 @@ 240 300 - + 0 diff --git a/lib/internal/Magento/Framework/Config/View.php b/lib/internal/Magento/Framework/Config/View.php index d0334c2982483..2720ddbc41041 100644 --- a/lib/internal/Magento/Framework/Config/View.php +++ b/lib/internal/Magento/Framework/Config/View.php @@ -43,33 +43,30 @@ protected function _extractData(\DOMDocument $dom) $result[$childNode->tagName][$moduleName][$varName] = $varValue; } break; - case 'images': + break; + case 'media': $moduleName = $childNode->getAttribute('module'); /** @var \DOMElement $node */ foreach ($childNode->getElementsByTagName('image') as $node) { $imageId = $node->getAttribute('id'); - $result[$childNode->tagName][$moduleName][$imageId]['type'] = $node->getAttribute('type'); + $result[$childNode->tagName][$moduleName]['images'][$imageId]['type'] = $node->getAttribute('type'); foreach ($node->childNodes as $attribute) { if ($attribute->nodeType != XML_ELEMENT_NODE) { continue; } $nodeValue = $attribute->nodeValue; - $result[$childNode->tagName][$moduleName][$imageId][$attribute->tagName] = $nodeValue; + $result[$childNode->tagName][$moduleName]['images'][$imageId][$attribute->tagName] = $nodeValue; } } - break; - case 'media': - $moduleName = $childNode->getAttribute('module'); - /** @var \DOMElement $node */ - foreach ($childNode->getElementsByTagName('mediaItem') as $node) { + foreach ($childNode->getElementsByTagName('video') as $node) { $imageId = $node->getAttribute('id'); - $result[$childNode->tagName][$moduleName][$imageId]['type'] = $node->getAttribute('type'); + $result[$childNode->tagName][$moduleName]['videos'][$imageId]['type'] = $node->getAttribute('type'); foreach ($node->childNodes as $attribute) { if ($attribute->nodeType != XML_ELEMENT_NODE) { continue; } $nodeValue = $attribute->nodeValue; - $result[$childNode->tagName][$moduleName][$imageId][$attribute->tagName] = $nodeValue; + $result[$childNode->tagName][$moduleName]['videos'][$imageId][$attribute->tagName] = $nodeValue; } } break; @@ -110,6 +107,18 @@ public function getVarValue($module, $var) return isset($this->_data['vars'][$module][$var]) ? $this->_data['vars'][$module][$var] : false; } + /** + * Retrieve a list videos attributes in scope of specified module + * + * @param $module + * @param $var + * @return bool + */ + public function getVideoAttributeValue($module, $var) + { + return isset($this->_data['media'][$module]['videos'][$var][$var]) ? $this->_data['media'][$module]['videos'][$var][$var] : false; + } + /** * Retrieve a list images attributes in scope of specified module * @@ -118,18 +127,18 @@ public function getVarValue($module, $var) */ public function getImages($module) { - return isset($this->_data['images'][$module]) ? $this->_data['images'][$module] : []; + return isset($this->_data['media'][$module]['images']) ? $this->_data['media'][$module]['images'] : []; } /** - * Retrieve a list images attributes in scope of specified module + * Retrieve a list media attributes in scope of specified module * * @param string $module * @return array */ - public function getMediaValue($module, $var) + public function getMedia($module) { - return isset($this->_data['media'][$module][$var][$var]) ? $this->_data['media'][$module][$var][$var] : []; + return isset($this->_data['media'][$module]) ? $this->_data['media'][$module] : []; } /** @@ -141,8 +150,8 @@ public function getMediaValue($module, $var) */ public function getImageAttributes($module, $imageId) { - return isset($this->_data['images'][$module][$imageId]) - ? $this->_data['images'][$module][$imageId] + return isset($this->_data['media'][$module]['images'][$imageId]) + ? $this->_data['media'][$module]['images'][$imageId] : []; } @@ -178,10 +187,9 @@ protected function _getIdAttributes() '/view/vars' => 'module', '/view/vars/var' => 'name', '/view/exclude/item' => ['type', 'item'], - '/view/images' => 'module', - '/view/images/image' => ['id', 'type'], '/view/media' => 'module', - '/view/media/mediaItem' => ['id', 'mediaItem'], + '/view/media/image' => ['id', 'type'], + '/view/media/video' => ['id', 'type'], ]; } diff --git a/lib/internal/Magento/Framework/Config/etc/view.xsd b/lib/internal/Magento/Framework/Config/etc/view.xsd index 017e5c510b339..db70f652ae2b1 100644 --- a/lib/internal/Magento/Framework/Config/etc/view.xsd +++ b/lib/internal/Magento/Framework/Config/etc/view.xsd @@ -29,7 +29,6 @@ - @@ -39,9 +38,9 @@ - + - + @@ -72,12 +71,7 @@ - - - - - - + From 0db0433bdddaeb6064f7392105de430d0dbcc5ab Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 10:45:53 +0300 Subject: [PATCH 005/206] PV-5: Correct Unit test --- .../Magento/ProductVideo/Test/Unit/Helper/MediaTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php index 6912613f0f205..bfe1075dfa226 100644 --- a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php +++ b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php @@ -29,7 +29,7 @@ public function setUp() $this->viewConfigMock = $this->getMock( '\Magento\Framework\View\Config', - ['getMediaValue', 'getViewConfig'], + ['getVideoAttributeValue', 'getViewConfig'], [], '', false @@ -116,7 +116,7 @@ public function dataForVideoBackground() */ public function testGetVideoPlayAttribute($expectedResult) { - $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getVideoAttributeValue')->willReturn($expectedResult); $this->mediaHelperObject->getVideoPlayAttribute(); } @@ -125,7 +125,7 @@ public function testGetVideoPlayAttribute($expectedResult) */ public function testGetVideoStopAttribute($expectedResult) { - $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getVideoAttributeValue')->willReturn($expectedResult); $this->mediaHelperObject->getVideoStopAttribute(); } @@ -134,7 +134,7 @@ public function testGetVideoStopAttribute($expectedResult) */ public function testGetVideoBackgroundAttribute($expectedResult) { - $this->viewConfigMock->expects($this->once())->method('getMediaValue')->willReturn($expectedResult); + $this->viewConfigMock->expects($this->once())->method('getVideoAttributeValue')->willReturn($expectedResult); $this->mediaHelperObject->getVideoBackgroundAttribute(); } From 9d5deb7c59c477adf98cf42565e598ab5898fc3c Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 12:33:58 +0300 Subject: [PATCH 006/206] PV-5: PhpDoc --- .../ProductVideo/Test/Unit/Helper/MediaTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php index bfe1075dfa226..b68063d0b689a 100644 --- a/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php +++ b/app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php @@ -10,12 +10,19 @@ */ class MediaTest extends \PHPUnit_Framework_TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Config */ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Config + */ protected $viewConfigMock; - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\DesignInterface */ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\DesignInterface + */ protected $currentThemeMock; + /** + * @var \Magento\Swatches\Helper\Media|\Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ protected $mediaHelperObject; /** From ece0b1e3aa0ff0671328a33abeca10af8478cd6d Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 15:16:07 +0300 Subject: [PATCH 007/206] PV-5: phpcs and phpmd --- app/code/Magento/ProductVideo/Helper/Media.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php index 11c546322ebb2..8e427436ac051 100644 --- a/app/code/Magento/ProductVideo/Helper/Media.php +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -11,7 +11,6 @@ /** * Helper to get attributes for video * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Media extends \Magento\Framework\App\Helper\AbstractHelper { @@ -72,11 +71,13 @@ public function __construct( */ protected function initConfig() { - if($this->cachedVideoConfig === null) { - $this->cachedVideoConfig = $this->viewConfig->getViewConfig([ - 'area' => Area::AREA_FRONTEND, - 'themeModel' => $this->currentTheme - ]); + if ($this->cachedVideoConfig === null) { + $this->cachedVideoConfig = $this->viewConfig->getViewConfig( + [ + 'area' => Area::AREA_FRONTEND, + 'themeModel' => $this->currentTheme + ] + ); } return $this; From fa7ee5ccbeee5cf1207f575429d3c2d424e84e12 Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 15:21:36 +0300 Subject: [PATCH 008/206] PV-5: changed constant's names --- app/code/Magento/ProductVideo/Helper/Media.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/ProductVideo/Helper/Media.php b/app/code/Magento/ProductVideo/Helper/Media.php index 8e427436ac051..cb8a9014e87a9 100644 --- a/app/code/Magento/ProductVideo/Helper/Media.php +++ b/app/code/Magento/ProductVideo/Helper/Media.php @@ -22,17 +22,17 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper /* * Video play attribute */ - const VIDEO_PLAY = 'video_play'; + const NODE_CONFIG_NAME_VIDEO_PLAY = 'video_play'; /* * Video stop attribute */ - const VIDEO_STOP = 'video_stop'; + const NODE_CONFIG_NAME_VIDEO_STOP = 'video_stop'; /* * Video color attribute */ - const VIDEO_BACKGROUND = 'video_background'; + const NODE_CONFIG_NAME_VIDEO_BACKGROUND = 'video_background'; /** * @var \Magento\Framework\View\ConfigInterface @@ -90,7 +90,7 @@ protected function initConfig() */ public function getVideoPlayAttribute() { - return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_PLAY); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::NODE_CONFIG_NAME_VIDEO_PLAY); } /** @@ -100,7 +100,7 @@ public function getVideoPlayAttribute() */ public function getVideoStopAttribute() { - return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_STOP); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::NODE_CONFIG_NAME_VIDEO_STOP); } /** @@ -110,7 +110,7 @@ public function getVideoStopAttribute() */ public function getVideoBackgroundAttribute() { - return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::VIDEO_BACKGROUND); + return $this->cachedVideoConfig->getVideoAttributeValue(self::MODULE_NAME, self::NODE_CONFIG_NAME_VIDEO_BACKGROUND); } } From 78321c82f9ecccc80ca77b72fd85a7b8baba52c6 Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 16:29:42 +0300 Subject: [PATCH 009/206] PV-5: Right view.xml for swatches --- app/code/Magento/Swatches/etc/view.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Swatches/etc/view.xml b/app/code/Magento/Swatches/etc/view.xml index 84435d932943c..c70a0c3f9d099 100644 --- a/app/code/Magento/Swatches/etc/view.xml +++ b/app/code/Magento/Swatches/etc/view.xml @@ -8,20 +8,20 @@ - 1 - 1 + 30 + 20 - 1 - 1 + 110 + 90 - 1 - 1 + 30 + 20 - 1 - 1 + 110 + 90 From 24b0e07e6ad5a75e3af2be679b7646103c0c1b2d Mon Sep 17 00:00:00 2001 From: Dmitry Kologrivov Date: Thu, 27 Aug 2015 17:01:05 +0300 Subject: [PATCH 010/206] PV-5: pattern for video background --- app/code/Magento/ProductVideo/etc/view.xml | 2 +- lib/internal/Magento/Framework/Config/etc/view.xsd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ProductVideo/etc/view.xml b/app/code/Magento/ProductVideo/etc/view.xml index 6c5e0250f47b4..6eda58f7123e1 100644 --- a/app/code/Magento/ProductVideo/etc/view.xml +++ b/app/code/Magento/ProductVideo/etc/view.xml @@ -14,7 +14,7 @@ 1 diff --git a/lib/internal/Magento/Framework/Config/etc/view.xsd b/lib/internal/Magento/Framework/Config/etc/view.xsd index db70f652ae2b1..10b659beb8ad4 100644 --- a/lib/internal/Magento/Framework/Config/etc/view.xsd +++ b/lib/internal/Magento/Framework/Config/etc/view.xsd @@ -79,7 +79,7 @@ - + From abc3baa028726819042fe2a40f81dce580e33345 Mon Sep 17 00:00:00 2001 From: Stanislau komar Date: Thu, 3 Sep 2015 10:48:34 +0300 Subject: [PATCH 011/206] Fix 7upload images in IE --- .../ProductVideo/view/adminhtml/web/js/new-video-dialog.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js index 53a9e252427e4..84b4efad581e2 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js @@ -367,10 +367,11 @@ define([ }, _onImageInputChange: function() { - var file = document.getElementById('new_video_screenshot').files[0]; - if(!file) { + var file = document.getElementById('new_video_screenshot'); + if(!file || !file.files || !file.files.length) { return; } + file = file.files[0]; this._onPreview(null, file, true); }, From 438182f8a1788682969518da8917698ae365cbc4 Mon Sep 17 00:00:00 2001 From: Stanislau komar Date: Thu, 3 Sep 2015 13:06:06 +0300 Subject: [PATCH 012/206] tmp --- .../adminhtml/web/js/edit-image-dialog.js | 3 ++ .../view/adminhtml/web/js/product-gallery.js | 41 ++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 app/code/Magento/Catalog/view/adminhtml/web/js/edit-image-dialog.js diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/edit-image-dialog.js b/app/code/Magento/Catalog/view/adminhtml/web/js/edit-image-dialog.js new file mode 100644 index 0000000000000..d4402241e8073 --- /dev/null +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/edit-image-dialog.js @@ -0,0 +1,3 @@ +/** + * Created by kost on 3.9.15. + */ diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js b/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js index d7f63593aa71c..acf013147aa78 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js @@ -324,10 +324,10 @@ define([ var dialogElement = $imageContainer.data('dialog'); - if ($imageContainer.is('.removed') || (dialogElement && dialogElement.is(':visible'))) { - return; - } - this.element.find('[data-role=dialog]').trigger('close'); + //if ($imageContainer.is('.removed') || (dialogElement && dialogElement.is(':visible'))) { + // return; + // } + //this.element.find('[data-role=dialog]').trigger('close'); if (!dialogElement && this.dialogTmpl) { var $template = this.dialogTmpl({ @@ -337,9 +337,22 @@ define([ dialogElement = $($template); + dialogElement.modal({ + type: 'slide', + title: $.mage.__('Edit Image'), + modalClass: 'mage-edit-image-dialog form-inline', + buttons: [{ + 'text': $.mage.__('Return'), + 'class': ' action-primary image-edit-button', + click: function (e) { + dialogElement.trigger('closeModal') + } + }] + }); + dialogElement - .data('imageContainer', $imageContainer) - .on('open', $.proxy(function (event) { + //.data('imageContainer', $imageContainer) + .on('showModal', $.proxy(function (event) { var imagesList = this.element.find(this.options.imageSelector + ':not(.removed), .image-placeholder'); var index = imagesList.index($imageContainer); var positionIndex = Math.floor(index / imageCountInRow + 1) * imageCountInRow - 1; @@ -367,18 +380,18 @@ define([ }, this)); this._setImagePointerPosition($imageContainer, dialogElement); - }, this)) - .on('close', $.proxy(function (event) { - $imageContainer.removeClass('active'); - $(event.target) - .slideUp(400); }, this)); + //.on('closeModal', $.proxy(function (event) { + // $imageContainer.removeClass('active'); + // $(event.target) + // .slideUp(400); + //}, this)); $imageContainer.data('dialog', dialogElement); } - if (dialogElement) { - dialogElement.trigger('open'); - } + //if (dialogElement) { + dialogElement.trigger('openModal'); + //} }, /** From 789ce772555a7605b7efefdde29db250ddcd4cd7 Mon Sep 17 00:00:00 2001 From: Stanislau komar Date: Thu, 3 Sep 2015 18:52:10 +0300 Subject: [PATCH 013/206] PV-34 --- .../view/adminhtml/web/js/product-gallery.js | 172 ++++++++---------- .../view/adminhtml/web/product/product.css | 4 - .../adminhtml/templates/helper/gallery.phtml | 105 +++++------ .../view/adminhtml/web/js/new-video-dialog.js | 56 ++++-- .../view/adminhtml/web/js/video-modal.js | 11 +- 5 files changed, 172 insertions(+), 176 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js b/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js index acf013147aa78..78c4d7effe1ae 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js @@ -46,6 +46,7 @@ define([ */ _bind: function () { var events = { + openDialog: '_onOpenDialog', addItem: '_addItem', removeItem: '_removeItem', setImageType: '_setImageType', @@ -140,9 +141,6 @@ define([ }); element = $(element).data('imageData', imageData); - if(imageData.subclass) { - element.addClass(imageData.subclass); - } if (count === 0) { element.prependTo(this.element); } else { @@ -261,11 +259,7 @@ define([ */ _bind: function () { this._super(); - var events = { - 'change [data-role=visibility-trigger]': '_changeVisibility', - 'change [data-role=type-selector]': '_changeType' - }; - + var events = {}; events['click [data-role=close-panel]'] = $.proxy(function () { this.element.find('[data-role=dialog]').trigger('close'); }, this); @@ -274,39 +268,28 @@ define([ $(event.currentTarget).addClass('active'); var itemId = $(event.currentTarget).find('input')[0].name.match(/\[([^\]]*)\]/g)[2]; $('#item_id').val(itemId); - this._showDialog($(event.currentTarget).data('imageData')); + this.element.trigger('openDialog', [$(event.currentTarget).data('imageData')]); } }; this._on(events); this.element.on('sortstart', $.proxy(function () { this.element.find('[data-role=dialog]').trigger('close'); }, this)); - - this.element.on('change', '[data-role=type-selector]', function () { - var parent = $(this).closest('.item'), - selectedClass = 'selected'; - parent.toggleClass(selectedClass, $(this).prop('checked')); - }); }, /** - * Set Position of Image Pointer - * @param image - * @param panel + * + * Click by image handler + * + * @param e + * @param imageData * @private */ - _setImagePointerPosition: function (image, panel) { - var position = image.position(), - posX = position.left, - imageWidth = image.width(), - pointer = $('.image-pointer', panel), - pointerWidth = pointer.width(), - padding = -3, - pointerOffset = posX + padding + pointerWidth / 2 + imageWidth / 2; - - pointer.css({ - left: pointerOffset - }); + _onOpenDialog: function(e, imageData) { + if(imageData.media_type) { + return; + } + this._showDialog(imageData); }, /** @@ -316,82 +299,71 @@ define([ */ _showDialog: function (imageData) { var $imageContainer = this.findElement(imageData); + var dialogElement = $imageContainer.data('dialog'); - if ($imageContainer.find('input[name*="media_type"]').val() == 'external-video') { - $('#new-video').modal('openModal'); + if ($imageContainer.is('.removed') || (dialogElement && dialogElement.is(':visible'))) { return; } - var dialogElement = $imageContainer.data('dialog'); + if(!this.dialogTmpl) { + alert('System problem!'); + return; + } - //if ($imageContainer.is('.removed') || (dialogElement && dialogElement.is(':visible'))) { - // return; - // } - //this.element.find('[data-role=dialog]').trigger('close'); - - if (!dialogElement && this.dialogTmpl) { - var $template = this.dialogTmpl({ - data: imageData - }), - imageCountInRow = 5; - - dialogElement = $($template); - - dialogElement.modal({ - type: 'slide', - title: $.mage.__('Edit Image'), - modalClass: 'mage-edit-image-dialog form-inline', - buttons: [{ - 'text': $.mage.__('Return'), - 'class': ' action-primary image-edit-button', - click: function (e) { - dialogElement.trigger('closeModal') - } - }] - }); + var $template = this.dialogTmpl({ data: imageData }); + dialogElement = $($template); + dialogElement.modal({ + 'type': 'slide', + title: $.mage.__('Edit Image'), + buttons: [], + opened: function() { + dialogElement.trigger('open'); + }, + closed: function(e) { + dialogElement.trigger('close'); + } + }); + dialogElement + .data('imageContainer', $imageContainer) + .on('open', $.proxy(function (event) { + $(event.target) + .find('[data-role=type-selector]') + .each($.proxy(function (index, checkbox) { + var $checkbox = $(checkbox), + parent = $checkbox.closest('.item'), + selectedClass = 'selected', + isChecked = this.options.types[$checkbox.val()].value == imageData.file; + $checkbox.prop( + 'checked', + isChecked + ); + parent.toggleClass(selectedClass, isChecked); + }, this)); + + }, this)) + .on('close', $.proxy(function (event) { + $imageContainer.removeClass('active'); + $imageContainer.data('dialog', null); + }, this)); + + $imageContainer.data('dialog', dialogElement); + + + var _changeDescription = function(e) { + var target = jQuery(e.target); + var targetName = target.attr('name'); + jQuery('input[type="hidden"][name="'+ targetName + '"]').val(target.val()); + }; - dialogElement - //.data('imageContainer', $imageContainer) - .on('showModal', $.proxy(function (event) { - var imagesList = this.element.find(this.options.imageSelector + ':not(.removed), .image-placeholder'); - var index = imagesList.index($imageContainer); - var positionIndex = Math.floor(index / imageCountInRow + 1) * imageCountInRow - 1; - if (positionIndex > imagesList.length - 1) { - positionIndex = imagesList.length - 1; - } - var afterElement = imagesList.get(positionIndex); - - $(event.target) - .insertAfter(afterElement) - .slideDown(400); - - $(event.target) - .find('[data-role=type-selector]') - .each($.proxy(function (index, checkbox) { - var $checkbox = $(checkbox), - parent = $checkbox.closest('.item'), - selectedClass = 'selected', - isChecked = this.options.types[$checkbox.val()].value == imageData.file; - $checkbox.prop( - 'checked', - isChecked - ); - parent.toggleClass(selectedClass, isChecked); - }, this)); - this._setImagePointerPosition($imageContainer, dialogElement); - - }, this)); - //.on('closeModal', $.proxy(function (event) { - // $imageContainer.removeClass('active'); - // $(event.target) - // .slideUp(400); - //}, this)); - - $imageContainer.data('dialog', dialogElement); - } - //if (dialogElement) { - dialogElement.trigger('openModal'); - //} + dialogElement.on('change', '[data-role=type-selector]', function () { + var parent = $(this).closest('.item'), + selectedClass = 'selected'; + parent.toggleClass(selectedClass, $(this).prop('checked')); + }); + dialogElement.on('change', '[data-role=type-selector]', $.proxy(this._changeType, this)); + dialogElement.on('change', '[data-role=visibility-trigger]', $.proxy(this._changeVisibility, this)); + dialogElement.on('change', '#image-description', _changeDescription); + dialogElement.modal('openModal'); }, /** diff --git a/app/code/Magento/Catalog/view/adminhtml/web/product/product.css b/app/code/Magento/Catalog/view/adminhtml/web/product/product.css index fce4af6f57f8f..b91f81aadb8bf 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/product/product.css +++ b/app/code/Magento/Catalog/view/adminhtml/web/product/product.css @@ -149,15 +149,11 @@ /* Gallery image panel */ .admin__scope-old .image-panel { - display: none; position: relative; top: 5px; clear: both; background: #fff; - margin: 0 -2px 15px; padding: 20px 15px; - box-shadow: 0 1px 3px #aaa inset; - border-bottom: 1px solid #cfd0cb; } .admin__scope-old .image .file-row { diff --git a/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml b/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml index 2b52d882bad6b..01e4df97fcc4b 100755 --- a/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml +++ b/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml @@ -87,67 +87,62 @@ $elementName = $block->getElement()->getName() . '[images]'; diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js index 84b4efad581e2..56d5f0b1357be 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js @@ -24,14 +24,7 @@ define([ _images: {}, - _imageTypes: [ - 'image/jpeg', - 'image/pjpeg', - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/gif' - ], + _imageTypes: ['.jpeg', '.pjpeg', '.jpeg', '.jpg', '.pjpeg', '.png', '.gif'], _bind: function() { var events = { @@ -213,10 +206,10 @@ define([ this._bind(); var widget = this; var uploader = jQuery('#new_video_screenshot'); - uploader.on('change', this._onImageInputChange.bind(this)); - this.toggleButtons(); uploader.attr('accept', this._imageTypes.join(',')); + + this.toggleButtons(); this.element.modal({ type: 'slide', modalClass: 'mage-new-video-dialog form-inline', @@ -294,10 +287,13 @@ define([ $('[name*="' + $('#item_id').val() + '"]').siblings('.image-fade').css('visibility', 'hidden'); } var imageData = widget._getImage($('#file_name').val()); - - var fileName = $('#new_video_screenshot').get(0).files[0]; uploader.replaceWith(inputFile); + var fileName = $('#new_video_screenshot').get(0).files; + if(!fileName || !fileName.length) { + fileName = null; + } + var callback = function(code, data) { widget._onClose(); }; @@ -366,15 +362,43 @@ define([ fr.readAsDataURL(file); }, + /** + * Image file input handler + * @private + */ _onImageInputChange: function() { var file = document.getElementById('new_video_screenshot'); - if(!file || !file.files || !file.files.length) { + var val = file.value; + var jFile = jQuery(file); + var prev = this._getPreviewImage(); + + if(!val) { return; } + var ext = '.' + val.split('.').pop(); + if( + ext.length < 2 || + this._imageTypes.indexOf(ext) == -1 || + !file.files || + !file.files.length + + ) { + jFile.val(''); + prev.remove(); + this._previewImage = null; + return; + } // end if file = file.files[0]; this._onPreview(null, file, true); }, + /** + * Change Preview + * @param error + * @param src + * @param local + * @private + */ _onPreview: function(error, src, local) { var img = this._getPreviewImage(); if(error) { @@ -404,6 +428,10 @@ define([ return this._previewImage; }, + /** + * Close dialog wrap + * @private + */ _onClose: function() { $('#new-video').modal('closeModal'); }, @@ -460,13 +488,11 @@ define([ $('.video-create-button').show(); $('.video-delete-button').hide(); $('.video-edit').hide(); - $('.modal-title').html('New video'); }); $(document).on('click', '.item.image', function() { $('.video-create-button').hide(); $('.video-delete-button').show(); $('.video-edit').show(); - $('.modal-title').html('Edit video'); }); $(document).on('click', '.item.image', function() { var formFields = $('#new_video_form').find('.edited-data'); diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/video-modal.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/video-modal.js index 25bcfca4238cc..bc886be507983 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/video-modal.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/video-modal.js @@ -16,13 +16,20 @@ define([ { _create: function() { this._bind(); + jQuery('#media_gallery_content').on('openDialog', $.proxy(this._onOpenDialog, this)); }, - _bind: function() - { + _bind: function() { $(this.element).on('click', this.showModal.bind(this)); }, + _onOpenDialog: function(e, imageData) { + if(imageData.media_type != 'external-video') { + return; + } + this.showModal(); + }, + showModal: function(e) { $('#new-video').modal('openModal'); From a255a1efcf69d708d8ebd49683c1aa3269a720da Mon Sep 17 00:00:00 2001 From: Mikalai_Eutsikhieu Date: Fri, 4 Sep 2015 14:17:45 +0300 Subject: [PATCH 014/206] PV-24: Implement Retrieve meta data form external video service. Main functionality ready --- .../adminhtml/layout/catalog_product_new.xml | 1 + .../product/edit/slideout/form.phtml | 8 + .../view/adminhtml/web/css/productvideo.css | 66 ++- .../view/adminhtml/web/images/camera.png | Bin 0 -> 1384 bytes .../adminhtml/web/js/get-video-information.js | 548 ++++++++++++++++++ .../view/adminhtml/web/js/new-video-dialog.js | 3 - 6 files changed, 622 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/ProductVideo/view/adminhtml/web/images/camera.png create mode 100644 app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js diff --git a/app/code/Magento/ProductVideo/view/adminhtml/layout/catalog_product_new.xml b/app/code/Magento/ProductVideo/view/adminhtml/layout/catalog_product_new.xml index a214672c79e7c..e2362f9473219 100755 --- a/app/code/Magento/ProductVideo/view/adminhtml/layout/catalog_product_new.xml +++ b/app/code/Magento/ProductVideo/view/adminhtml/layout/catalog_product_new.xml @@ -8,6 +8,7 @@ + diff --git a/app/code/Magento/ProductVideo/view/adminhtml/templates/product/edit/slideout/form.phtml b/app/code/Magento/ProductVideo/view/adminhtml/templates/product/edit/slideout/form.phtml index d4cb76cc42e30..e5d3eb0fef34c 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/templates/product/edit/slideout/form.phtml +++ b/app/code/Magento/ProductVideo/view/adminhtml/templates/product/edit/slideout/form.phtml @@ -8,4 +8,12 @@ + diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/css/productvideo.css b/app/code/Magento/ProductVideo/view/adminhtml/web/css/productvideo.css index e11dfb3a76a9d..ee1f46366fe57 100755 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/css/productvideo.css +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/css/productvideo.css @@ -108,7 +108,71 @@ position: absolute; bottom: 0; right: 9px; - background: url(../img/luma-gallery-sprite.png) bottom left; + background: url(../images/gallery-sprite.png) bottom left; width: 49px; height: 40px; + z-index: 1; +} +.mage-new-video-dialog #new_video_form { + width: 65%; + float: left; +} +.mage-new-video-dialog #video-player-preview-location { + width: 34.99999%; + float: left; +} +.video-player-container { + width: 100%; + height: 200px; + margin-bottom: 30px; + border: 1px solid #e3e3e3; + position: relative; +} +.video-player-container:after { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + margin: auto; + width: 93px; + height: 60px; + background: url(../images/camera.png) no-repeat center; + z-index: 1; +} +.video-information { + margin-bottom: 7px; + display: none; +} +.video-information:after { + content: " "; /* Older browser do not support empty content */ + visibility: hidden; + display: block; + height: 0; + clear: both; +} +.video-information label { + font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 1.4rem; + font-weight: 600; + display: block; + width: 25%; + float: left; + text-align: right; +} +.video-information span { + font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 1.4rem; + font-weight: 300; + display: block; + width: 74.9999%; + float: left; + padding-left: 20px; +} +.product-video { + width: 100%; + z-index: 20; + height: 100%; + position: relative; } \ No newline at end of file diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/images/camera.png b/app/code/Magento/ProductVideo/view/adminhtml/web/images/camera.png new file mode 100644 index 0000000000000000000000000000000000000000..468f922ecb12dbd5b1980421a504de4eedf1bc00 GIT binary patch literal 1384 zcmeAS@N?(olHy`uVBq!ia0vp^u|RCY!2~3`cPnNCDajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_cg49rTIArU1JzCKpT`MG+DAT@dwxdlMoK*Q`S3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxSU1_g&``n5OwZ87 z)XdCKN5ROz&`93^h|F{iO{`4Ktc=VRpg;*|TTx1yRgjAt)Gi>;Rw<*Tq`*pFzr4I$ zuiRKKzbIYb(9+TpWQLKEE>MMTab;dfVufyAu`f(~1RD^r68eAMwS&*t9 zlvv ztM~P_^2{qPNz6-5^>ndS0-B(gnVDi`VrpSv;B4q>YUJu@2&9~h%}rd*EsR`DO)SkF zU7cWhUGkGlb5rw5V0u#!dfjm91to>t0-((aHV7#JAuc)B=-RNQ(q zyEebcK;W3B?)qt3X?6e4uTap<-*tP|i$^kiOK;w~_nBW&<-(sG)m7KGJgKo`Uy+{_ zpFd@a*UCbf|GGL}nUho^=LtLY)OBRAEWfGr-$b3$AwnxGxIxxL$6x!ywDGCZBaJ;{FRc>^_ z&t8W3LE`4&3m~%`0qsHD6X#T z7_oQD1J@NAZlBWmu_3{n*R6Hw=6_oa!=|O~i?ZDtdoT6=+0Qae>V3&iinP5}MyziY zDE@n+yYd&O{kNrcGhZLCyIOjyKYWh;mt^_ZcXdw7{o1(v_uj4Y|F`hlefU#z;7I58 zfa*zm^RhPNw=CFXF3VFCx#Z%n$*Yd!>{${i<~lJpU_sr}Inp)z_lY<~w78vDdnRVs qeEMgmF6$(r^Hc8^ImUj`JHT+h^Bl{%>C*#2WuK?3pUXO@geCwPs|4`? literal 0 HcmV?d00001 diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js new file mode 100644 index 0000000000000..fe6eb8ee01399 --- /dev/null +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js @@ -0,0 +1,548 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +/*jshint browser:true jquery:true*/ +/*global FORM_KEY*/ +require(["jquery", "jquery/ui"], function ($) { + 'use strict'; + var videoRegister = { + _register: {}, + + /** + * Checks, if api is already registered + * + * @param api + * @returns {boolean} + */ + isRegistered: function (api) { + return this._register[api] !== undefined; + }, + + /** + * Checks, if api is loaded + * + * @param api + * @returns {boolean} + */ + isLoaded: function (api) { + return this._register[api] !== undefined && this._register[api] === true; + }, + + /** + * Register new video api + * @param api + * @param loaded + */ + register: function (api, loaded) { + loaded = loaded || false; + this._register[api] = loaded; + } + }; + + $.widget('mage.productVideoLoader', { + _create: function () { + switch (this.element.data('type')) { + case 'youtube': + this.element.videoYoutube(); + this._player = this.element.data('mageVideoYoutube'); + break; + case 'vimeo': + this.element.videoVimeo(); + this._player = this.element.data('mageVideoVimeo'); + break; + default: + throw { + name: 'Video Error', + message: 'Unknown video type', + toString: function () { + return this.name + ": " + this.message; + } + }; + } + }, + /** + * Initializes variables + * @private + */ + _initialize: function () { + this._params = this.element.data('params') || {}; + this._code = this.element.data('code'); + this._width = this.element.data('width'); + this._height = this.element.data('height'); + this._autoplay = !!this.element.data('autoplay'); + this._playing = this._autoplay || false; + + this._responsive = true; + + if (this.element.data('responsive') === false) { + this._responsive = false; + } + + if (this._responsive === true) { + this.element.addClass('responsive'); + } + + this._calculateRatio(); + }, + /** + * Abstract play command + */ + play: function () { + this._player.play(); + }, + + /** + * Abstract pause command + */ + pause: function () { + this._player.pause(); + }, + + /** + * Abstract stop command + */ + stop: function () { + this._player.stop(); + }, + + /** + * Abstract playing command + */ + playing: function () { + return this._player.playing(); + }, + + destroy: function () { + this._player.destroy(); + }, + + /** + * Calculates ratio for responsive videos + * @private + */ + _calculateRatio: function () { + if (!this._responsive) { + return; + } + this.element.css('paddingBottom', (this._height / this._width * 100) + '%'); + } + }); + + $.widget('mage.videoYoutube', $.mage.productVideoLoader, { + /** + * Initialization of the Youtube widget + * @private + */ + _create: function () { + var self = this; + var duration; + var done = false; + this._initialize(); + + this.element.append('
'); + + this._on(window, { + 'youtubeapiready': function () { + if (self._player !== undefined) { + return; + } + if (self._autoplay) { + self._params.autoplay = 1; + } + self._params.rel = 0; + + self._player = new YT.Player(self.element.children(':first')[0], { + height: self._height, + width: self._width, + videoId: self._code, + playerVars: self._params, + events: { + 'onReady': function onPlayerReady(event) { + duration = self._player.getDuration(); + }, + onStateChange: function (data) { + switch (window.parseInt(data.data, 10)) { + case 1: + self._playing = true; + break; + default: + self._playing = false; + break; + } + + self._trigger('statechange', {}, data); + } + } + + }); + } + }); + + this._loadApi(); + }, + + /** + * Loads Youtube API and triggers event, when loaded + * @private + */ + _loadApi: function () { + if (videoRegister.isRegistered('youtube')) { + if (videoRegister.isLoaded('youtube')) { + $(window).trigger('youtubeapiready'); + } + return; + } + videoRegister.register('youtube'); + + var element = document.createElement('script'), + scriptTag = document.getElementsByTagName('script')[0]; + + element.async = true; + element.src = "http://www.youtube.com/iframe_api"; + scriptTag.parentNode.insertBefore(element, scriptTag); + + window.onYouTubeIframeAPIReady = function () { + $(window).trigger('youtubeapiready'); + videoRegister.register('youtube', true); + }; + }, + + /** + * Play command for Youtube + */ + play: function () { + this._player.playVideo(); + this._playing = true; + }, + + /** + * Pause command for Youtube + */ + pause: function () { + this._player.pauseVideo(); + this._playing = false; + }, + + /** + * Stop command for Youtube + */ + stop: function () { + this._player.stopVideo(); + this._playing = false; + }, + + /** + * Playing command for Youtube + */ + playing: function () { + return this._playing; + }, + + /** + * stops and unloads player + * @private + */ + destroy: function () { + this.stop(); + this._player.destroy(); + } + }); + + $.widget('mage.videoVimeo', $.mage.productVideoLoader, { + /** + * Initialize the Vimeo widget + * @private + */ + _create: function () { + this._initialize(); + var timestamp = new Date().getTime(), + additionalParams = ''; + + if (this._autoplay) { + additionalParams += '&autoplay=1'; + } + + this.element.append( + $('