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

[full-ci] Integration of drag & drop move for personal files #5588

Merged
merged 35 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
950f78d
integration of drag&drop for personal files
lookacat Jul 29, 2021
9b780bf
added unittest
lookacat Aug 2, 2021
0069ab0
fixed linting issues
lookacat Aug 2, 2021
3dad663
removed unused action
lookacat Aug 2, 2021
772d926
upgraded ods version
lookacat Aug 3, 2021
812bb4c
Merge remote-tracking branch 'origin/master' into WEB-154-move-file-d…
lookacat Aug 3, 2021
c9e3262
fixed interfering with file upload drop
lookacat Aug 4, 2021
2f16919
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 6, 2021
379b4af
fixed PR issues
lookacat Aug 12, 2021
fa4b836
Merge branch 'WEB-154-move-file-drag-drop' of https://github.com/ownc…
lookacat Aug 12, 2021
f0056ba
added changelog
lookacat Aug 12, 2021
a4f8117
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 12, 2021
c24f5be
fixed linting
lookacat Aug 12, 2021
d46a4b3
WIP
lookacat Aug 13, 2021
a1b2497
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 13, 2021
bb5c4bf
added removal of file when dragging in searched results
lookacat Aug 16, 2021
7378b3a
fixed linting
lookacat Aug 16, 2021
d137a12
addressed PR issues
lookacat Aug 16, 2021
bc0a5c5
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 16, 2021
085ce5d
changed showDetails to default panel
lookacat Aug 16, 2021
87d6c95
addressed some PR issues
lookacat Aug 16, 2021
90754fd
WIP
lookacat Aug 17, 2021
ff999c5
added unittests
lookacat Aug 17, 2021
5c305aa
fixed linting
lookacat Aug 17, 2021
aca52d9
make dragover more readable
lookacat Aug 17, 2021
2cf5ce4
drone test fail fix
lookacat Aug 17, 2021
81c897d
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 17, 2021
9e49d45
refactored code for PR
lookacat Aug 18, 2021
d8ef1ff
Merge branch 'master' into WEB-154-move-file-drag-drop
lookacat Aug 18, 2021
9d315cd
Use p-queue for moving files
kulmann Aug 18, 2021
8a72edc
Fix sequential move via drag and drop
kulmann Aug 18, 2021
bf6080b
Introduce success message on move
kulmann Aug 18, 2021
3ac9287
Refactor resources to named vars in unit tests
kulmann Aug 18, 2021
d1dcb40
Move mapped action into own mapActions
kulmann Aug 18, 2021
71ba4de
Fix code smells
kulmann Aug 19, 2021
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
99 changes: 85 additions & 14 deletions packages/web-app-files/src/views/Personal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
:target-route="targetRoute"
:highlighted="highlightedFile ? highlightedFile.id : null"
:header-position="headerPosition"
:drag-drop="true"
@fileDropped="fileDropped"
@showDetails="$_mountSideBar_showDetails"
@fileClick="$_fileActions_triggerDefaultAction"
@rowMounted="rowMounted"
Expand Down Expand Up @@ -76,6 +78,8 @@ import NotFoundMessage from '../components/FilesList/NotFoundMessage.vue'
import ListInfo from '../components/FilesList/ListInfo.vue'
import Pagination from '../components/FilesList/Pagination.vue'

import { basename } from 'path'

const visibilityObserver = new VisibilityObserver()

export default {
Expand All @@ -98,6 +102,7 @@ export default {
...mapState(['app']),
...mapState('Files', ['files']),
...mapGetters('Files', [
'files',
'davProperties',
'highlightedFile',
'activeFiles',
Expand Down Expand Up @@ -147,13 +152,16 @@ export default {
$route: {
handler: function(to, from) {
if (isNil(this.$route.params.item)) {
this.$router.push({
name: 'files-personal',
params: {
item: this.homeFolder
}
})

this.$router
.push({
name: 'files-personal',
params: {
item: this.homeFolder
}
})
.catch(error => {
console.log(error)
})
return
}

Expand Down Expand Up @@ -186,7 +194,7 @@ export default {
},

methods: {
...mapActions('Files', ['loadIndicators', 'loadPreview']),
...mapActions('Files', ['loadIndicators', 'loadPreview'], 'showMessage'),
...mapMutations('Files', [
'SELECT_RESOURCES',
'SET_CURRENT_FOLDER',
Expand All @@ -195,6 +203,65 @@ export default {
]),
...mapMutations(['SET_QUOTA']),

async fileDropped(fileIdTarget) {
lookacat marked this conversation as resolved.
Show resolved Hide resolved
lookacat marked this conversation as resolved.
Show resolved Hide resolved
const selected = this.selectedFiles
const targetInfo = this.getFileInfoById(fileIdTarget)
lookacat marked this conversation as resolved.
Show resolved Hide resolved
const targetSelected = selected.some(e => e.id === fileIdTarget)
lookacat marked this conversation as resolved.
Show resolved Hide resolved
if (targetSelected) return
fschade marked this conversation as resolved.
Show resolved Hide resolved
if (targetInfo.type !== 'folder') return

this.loading = true
lookacat marked this conversation as resolved.
Show resolved Hide resolved
const targetPath = targetInfo.path + '/'
lookacat marked this conversation as resolved.
Show resolved Hide resolved
const errors = []
const itemsInTarget = await this.getFolderItems(targetPath)
for (let i = 0; i < selected.length; i++) {
lookacat marked this conversation as resolved.
Show resolved Hide resolved
const current = selected[i]
const exists = itemsInTarget.some(e => basename(e.name) === current.name)
if (exists) {
const message = this.$gettext('Resource with name %{name} already exists')
errors.push({
resource: current.name,
message: this.$gettextInterpolate(message, { name: current.name }, true)
})
continue
}
const promise = this.$client.files.move(current.path, targetPath + current.name)
await promise.catch(error => {
error.resource = current.name
errors.push(error)
})
}
this.loadResources(true)
lookacat marked this conversation as resolved.
Show resolved Hide resolved
this.loading = false
if (errors.length === 0) {
return
}
let title = this.$gettext('An error occurred while moving %{resource}')
lookacat marked this conversation as resolved.
Show resolved Hide resolved
if (errors.length === 1) {
fschade marked this conversation as resolved.
Show resolved Hide resolved
this.showMessage({
title: this.$gettextInterpolate(title, { resource: errors[0].resource }, true),
desc: errors[0].message,
status: 'danger'
})
return
}
title = this.$gettext('An error occurred while moving several resources')
const desc = this.$ngettext(
'%{count} resource could not be moved',
'%{count} resources could not be moved',
errors.length
)
this.showMessage({
title,
desc: this.$gettextInterpolate(desc, { count: errors.length }, false),
status: 'danger'
})
},

getFileInfoById(fileId) {
return this.activeFiles.find(e => e.id === fileId)
},

rowMounted(resource, component) {
if (!this.displayThumbnails) {
return
Expand All @@ -212,17 +279,21 @@ export default {

visibilityObserver.observe(component.$el, { onEnter: debounced, onExit: debounced.cancel })
},

async getFolderItems(path, properties) {
lookacat marked this conversation as resolved.
Show resolved Hide resolved
try {
const resources = await this.$client.files.list(path, 1, properties)
lookacat marked this conversation as resolved.
Show resolved Hide resolved
return resources
} catch (error) {
console.log('im here')
lookacat marked this conversation as resolved.
Show resolved Hide resolved
console.error(error)
}
},
async loadResources(sameRoute) {
this.loading = true
this.CLEAR_CURRENT_FILES_LIST()

try {
let resources = await this.$client.files.list(
this.$route.params.item,
1,
this.davProperties
)
let resources = await this.getFolderItems(this.$route.params.item, this.davProperties)
lookacat marked this conversation as resolved.
Show resolved Hide resolved

resources = resources.map(buildResource)
this.LOAD_FILES({
Expand Down
57 changes: 57 additions & 0 deletions packages/web-app-files/tests/unit/views/Personal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import GetTextPlugin from 'vue-gettext'
import { mount } from '@vue/test-utils'
import Personal from 'packages/web-app-files/src/views/Personal.vue'
import { localVue, getStore } from './views.setup'
import VueRouter from 'vue-router'

localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
})
localVue.use(VueRouter)

const router = new VueRouter({
routes: [
{
path: '/',
name: 'files-personal'
}
]
})

jest.unmock('axios')

const stubs = {
translate: true,
'oc-pagination': true,
'list-loader': true,
'oc-table-files': true,
'not-found-message': true,
'quick-actions': true,
'list-info': true
}

const component = { ...Personal, created: jest.fn(), mounted: jest.fn() }

const spyOnFileDropped = jest.spyOn(Personal.methods, 'fileDropped').mockImplementation()
lookacat marked this conversation as resolved.
Show resolved Hide resolved

const wrapper = mount(component, {
store: getStore(),
localVue,
router,
stubs: stubs,
data: () => ({
loading: false
})
})

describe('Personal component', () => {
lookacat marked this conversation as resolved.
Show resolved Hide resolved
describe('file move with drag & drop', () => {
it('should react to drop event', async () => {
const ocTableFiled = wrapper.find('#files-personal-table')
ocTableFiled.vm.$emit('fileDropped', '123')
await wrapper.vm.$nextTick()
expect(spyOnFileDropped).toBeCalled()
})
})
})
6 changes: 4 additions & 2 deletions packages/web-app-files/tests/unit/views/views.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export const getStore = function({
getters: {
configuration: () => configuration,
getToken: () => '',
isOcis: () => true
isOcis: () => true,
homeFolder: () => '/'
},
modules: {
Files: {
Expand All @@ -57,7 +58,8 @@ export const getStore = function({
activeFilesCount: () => ({ files: 0, folders: 1 }),
inProgress: () => [null],
highlightedFile: () => highlightedFile,
pages: () => pages
pages: () => pages,
currentFolder: () => '/'
},
mutations: {
UPDATE_RESOURCE: (state, resource) => {
Expand Down