forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next-10244/slider-images-drag-and-drop' into 'trunk'
NEXT-10244 - Slider images drag and drop See merge request shopware/6/product/platform!10330
- Loading branch information
Showing
13 changed files
with
364 additions
and
6 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
changelog/_unreleased/2023-03-09-slider-images-drag-and-drop.md
This file contains 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,15 @@ | ||
--- | ||
title: Slider Images Drag & Drop | ||
issue: NEXT-10244 | ||
--- | ||
# Administration | ||
* Added `moveItem` method in `/core/service/util.service.ts` to sort when drag and drop item. | ||
* Changed in `app/asyncComponent/media/sw-media-list-selection-v2/index.js` | ||
* Changed `mediaItems` computed to add position index to image. | ||
* Added `onMediaItemDragSort` method to handle drag and drop item. | ||
* Added `v-draggable` and `v-droppable` properties in `/app/asyncComponent/media/sw-media-list-selection-v2/sw-media-list-selection-v2.html.twig` to handle drag and drop item. | ||
* Added `item-sort` event in `module/sw-cms/elements/image-gallery/config/sw-cms-el-config-image-gallery.html.twig` to handle drag and drop item event of Image gallery. | ||
* Added `onItemSort` method in `/module/sw-cms/elements/image-gallery/config/index.js` to handle drag and drop item of Image gallery. | ||
* Added `item-sort` event in `module/sw-cms/elements/image-slider/config/sw-cms-el-config-image-slider.html.twig` to handle drag and drop item event of Image Slider. | ||
* Added `onItemSort` method in `/module/sw-cms/elements/image-slider/config/index.js` to handle drag and drop item of Image Slider. | ||
* Changed `scss` in `/app/asyncComponent/media/sw-media-list-selection-item-v2/sw-media-list-selection-item-v2.scss` to keep the drag item ratio. |
This file contains 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
This file contains 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
This file contains 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
85 changes: 85 additions & 0 deletions
85
...rc/app/asyncComponent/media/sw-media-list-selection-v2/sw-media-list-selection-v2.spec.js
This file contains 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,85 @@ | ||
/** | ||
* @package content | ||
*/ | ||
import { shallowMount } from '@vue/test-utils'; | ||
import SwMediaListSelectionV2 from 'src/app/asyncComponent/media/sw-media-list-selection-v2'; | ||
import swMediaListSelectionItemV2 from 'src/app/asyncComponent/media/sw-media-list-selection-item-v2'; | ||
|
||
Shopware.Component.register('sw-media-list-selection-v2', SwMediaListSelectionV2); | ||
Shopware.Component.register('sw-media-list-selection-item-v2', swMediaListSelectionItemV2); | ||
|
||
const entityMediaItems = [ | ||
{ | ||
id: '1', | ||
url: 'http://shopware.com/image1.jpg', | ||
position: 3, | ||
|
||
}, | ||
{ | ||
id: '2', | ||
url: 'http://shopware.com/image2.jpg', | ||
position: 1, | ||
}, | ||
{ | ||
id: '3', | ||
url: 'http://shopware.com/image3.jpg', | ||
position: 2, | ||
}, | ||
]; | ||
async function createWrapper() { | ||
return shallowMount(await Shopware.Component.build('sw-media-list-selection-v2'), { | ||
|
||
provide: { | ||
mediaService: {}, | ||
}, | ||
stubs: { | ||
'sw-upload-listener': true, | ||
'sw-media-upload-v2': true, | ||
'sw-media-list-selection-item-v2': await Shopware.Component.build('sw-media-list-selection-item-v2'), | ||
'sw-icon': true, | ||
'sw-media-preview-v2': true, | ||
'sw-context-button': true, | ||
'sw-context-menu-item': true, | ||
}, | ||
propsData: { | ||
entity: {}, | ||
entityMediaItems: entityMediaItems, | ||
}, | ||
}); | ||
} | ||
|
||
describe('components/media/sw-media-list-selection-v2', () => { | ||
it('should be a Vue.JS component', async () => { | ||
const wrapper = await createWrapper(); | ||
|
||
expect(wrapper.vm).toBeTruthy(); | ||
}); | ||
|
||
it('should set the position property for each item by index in computed', async () => { | ||
const wrapper = await createWrapper(); | ||
const mediaItems = wrapper.vm.mediaItems; | ||
|
||
mediaItems.forEach((item, index) => { | ||
expect(item.position).toBe(index); | ||
}); | ||
}); | ||
|
||
it('should emit item-sort event when drag and drop item valid', async () => { | ||
const wrapper = await createWrapper(); | ||
|
||
await wrapper.vm.onMediaItemDragSort({ id: 2, position: 1 }, { id: 1, position: 2 }, true); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.emitted()['item-sort']).toBeTruthy(); | ||
expect(wrapper.emitted()['item-sort'][0]).toEqual([{ id: 2, position: 1 }, { id: 1, position: 2 }]); | ||
}); | ||
|
||
it('should not emit item-sort event when drag and drop item valid', async () => { | ||
const wrapper = await createWrapper(); | ||
|
||
await wrapper.vm.onMediaItemDragSort(); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.emitted('item-sort')).not.toBeTruthy(); | ||
}); | ||
}); |
97 changes: 97 additions & 0 deletions
97
src/Administration/Resources/app/administration/src/core/service/util.service.spec.js
This file contains 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,97 @@ | ||
import UtilService from './util.service'; | ||
|
||
describe('src/core/service/util.service.spec.js', () => { | ||
describe('moveItem', () => { | ||
let entity = new MutationObserver(() => {}); | ||
|
||
beforeEach(() => { | ||
entity = [ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
]; | ||
}); | ||
|
||
it('should move the item correctly', () => { | ||
const oldIndex = 1; | ||
const newIndex = 3; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([ | ||
{ id: 1 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
{ id: 2 }, | ||
]); | ||
}); | ||
|
||
it('should not move the item if the new index is null', () => { | ||
const oldIndex = 2; | ||
const newIndex = null; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 4 }, | ||
{ id: 3 }, | ||
]); | ||
}); | ||
|
||
it('should not move the item if the old index is out of bounds', () => { | ||
const oldIndex = -1; | ||
const newIndex = 2; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
]); | ||
}); | ||
|
||
it('should not move the item if the new index is the same as the old index', () => { | ||
const oldIndex = 2; | ||
const newIndex = 2; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
]); | ||
}); | ||
|
||
it('should not move the item if it does not exist', () => { | ||
const oldIndex = 10; | ||
const newIndex = 2; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
]); | ||
}); | ||
|
||
it('should not move the item if entity does not exist', () => { | ||
entity = [null, 1, null]; | ||
const oldIndex = 0; | ||
const newIndex = 1; | ||
|
||
UtilService.moveItem(entity, oldIndex, newIndex); | ||
|
||
expect(entity).toEqual([null, 1, null]); | ||
}); | ||
}); | ||
}); | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.