Skip to content

Commit

Permalink
Add bulk actions
Browse files Browse the repository at this point in the history
  • Loading branch information
JanAckermann committed Jan 31, 2022
1 parent fe7e21a commit d80ece5
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/web-app-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "AGPL-3.0",
"dependencies": {
"copy-to-clipboard": "^3.3.1",
"semver": "^6.1.0",
"semver": "^7.3.5",
"vue2-dropzone": "^3.6.0"
},
"devDependencies": {
Expand Down
28 changes: 20 additions & 8 deletions packages/web-app-files/src/mixins/actions/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
isEnabled: ({ resources }) => {
if (
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files') &&
!isLocationCommonActive(this.$router, 'files-common-favorites')
) {
Expand All @@ -43,22 +44,33 @@ export default {
},
methods: {
$_copy_trigger({ resources }) {
const context = isLocationPublicActive(this.$router, 'files-public-files')
? 'public'
: 'private'
let context = 'private'

const query = {
resource: resources.map((resource) => {
return resource.path
})
}

if (isLocationPublicActive(this.$router, 'files-public-files')) {
context = 'public'
}

if (isLocationSpacesActive(this.$router, 'files-spaces-project')) {
context = 'space'
query.spaceId = this.$route.params.spaceId
}

const item = this.currentFolder.path || this.homeFolder

return this.$router.push(
createLocationOperations('files-operations-location-picker', {
params: {
context,
item,
action: 'copy'
},
query: {
resource: resources.map((resource) => {
return resource.path
})
}
query
})
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/mixins/actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
isEnabled: ({ resources }) => {
if (
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files')
) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
isEnabled: ({ resources }) => {
if (
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files') &&
!isLocationCommonActive(this.$router, 'files-common-favorites')
) {
Expand Down
28 changes: 20 additions & 8 deletions packages/web-app-files/src/mixins/actions/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
isEnabled: ({ resources }) => {
if (
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files') &&
!isLocationCommonActive(this.$router, 'files-common-favorites')
) {
Expand All @@ -45,22 +46,33 @@ export default {
},
methods: {
$_move_trigger({ resources }) {
const context = isLocationPublicActive(this.$router, 'files-public-files')
? 'public'
: 'private'
let context = 'private'

const query = {
resource: resources.map((resource) => {
return resource.path
})
}

if (isLocationPublicActive(this.$router, 'files-public-files')) {
context = 'public'
}

if (isLocationSpacesActive(this.$router, 'files-spaces-project')) {
context = 'space'
query.spaceId = this.$route.params.spaceId
}

const item = this.currentFolder.path || this.homeFolder

return this.$router.push(
createLocationOperations('files-operations-location-picker', {
params: {
context,
item,
action: 'move'
},
query: {
resource: resources.map((resource) => {
return resource.path
})
}
query
})
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/router/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [
component: components.Spaces.Project,
meta: {
hasBulkActions: true,
patchCleanPath: true,
title: $gettext('Space')
}
},
Expand Down
112 changes: 96 additions & 16 deletions packages/web-app-files/src/views/LocationPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,32 @@ export default {
target = ref.target
}
const resources = ref.isPublicContext
? yield ref.$client.publicFiles.list(target, ref.publicLinkPassword, DavProperties.Default)
: yield ref.$client.files.list(`/files/${ref.user.id}/${target}`, 1, DavProperties.Default)
const { context } = ref.$route.params
let resources
switch (context) {
case 'public':
resources = yield ref.$client.publicFiles.list(
target,
ref.publicLinkPassword,
DavProperties.Default
)
break
case 'space':
resources = yield ref.$client.files.list(
`/spaces/${ref.$route.query.spaceId}/${target}`,
1,
DavProperties.Default
)
break
default:
resources = yield ref.$client.files.list(
`/files/${ref.user.id}/${target}`,
1,
DavProperties.Default
)
}
ref.loadFiles({ currentFolder: resources[0], files: resources.slice(1) })
ref.loadIndicators({
Expand Down Expand Up @@ -276,7 +299,7 @@ export default {
},
targetRoute() {
return {
const route = {
name: this.$route.name,
query: {
resource: this.resources
Expand All @@ -285,6 +308,12 @@ export default {
action: this.currentAction
}
}
if (this.$route.query.spaceId) {
route.query.spaceId = this.$route.query.spaceId
}
return route
},
currentHint() {
Expand Down Expand Up @@ -346,11 +375,26 @@ export default {
},
leaveLocationPicker(target) {
this.$router.push(
this.isPublicContext
? createLocationPublic('files-public-files', { params: { item: target } })
: createLocationSpaces('files-spaces-personal-home', { params: { item: target || '/' } })
)
console.log(this.$route.query.spaceId)
switch (this.$route.params.context) {
case 'public':
this.$router.push(
createLocationPublic('files-public-files', { params: { item: target } })
)
break
case 'space':
this.$router.push(
createLocationSpaces('files-spaces-project', {
params: { spaceId: this.$route.query.spaceId, item: target || '/' }
})
)
break
default:
this.$router.push(
createLocationSpaces('files-spaces-personal-home', { params: { item: target || '/' } })
)
}
},
isRowDisabled(resource) {
Expand All @@ -367,7 +411,7 @@ export default {
// Execute move or copy
for (const resource of this.resources) {
let targetPath = `files/${this.user.id}/${this.target || '/'}`
const resourceName = basename(resource)
let resourceName = basename(resource)
targetPath += `/${resourceName}`
const exists = this.paginatedResources.some((item) => {
return basename(item.name) === resourceName
Expand All @@ -384,15 +428,51 @@ export default {
switch (this.currentAction) {
case batchActions.move: {
promise = this.isPublicContext
? this.$client.publicFiles.move(resource, targetPath, this.publicLinkPassword)
: this.$client.files.move(`files/${this.user.id}/${resource}`, targetPath)
switch (this.$route.params.context) {
case 'public':
promise = this.$client.publicFiles.move(
resource,
targetPath,
this.publicLinkPassword
)
break
case 'space':
targetPath = `spaces/${this.$route.query.spaceId}/${this.target || '/'}`
resourceName = basename(resource)
targetPath += `/${resourceName}`
promise = this.$client.files.move(
`spaces/${this.$route.query.spaceId}/${resource}`,
targetPath
)
break
default:
promise = this.$client.files.move(`files/${this.user.id}/${resource}`, targetPath)
}
break
}
case batchActions.copy: {
promise = this.isPublicContext
? this.$client.publicFiles.copy(resource, targetPath, this.publicLinkPassword)
: this.$client.files.copy(`files/${this.user.id}/${resource}`, targetPath)
switch (this.$route.params.context) {
case 'public':
promise = this.$client.publicFiles.copy(
resource,
targetPath,
this.publicLinkPassword
)
break
case 'space':
targetPath = `spaces/${this.$route.query.spaceId}/${this.target || '/'}`
resourceName = basename(resource)
targetPath += `/${resourceName}`
promise = this.$client.files.copy(
`spaces/${this.$route.query.spaceId}/${resource}`,
targetPath
)
break
default:
promise = this.$client.files.copy(`files/${this.user.id}/${resource}`, targetPath)
}
break
}
default:
Expand Down
9 changes: 6 additions & 3 deletions packages/web-app-files/src/views/spaces/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import { mapActions, mapGetters, mapMutations } from 'vuex'
import ListInfo from '../../components/FilesList/ListInfo.vue'
import Pagination from '../../components/FilesList/Pagination.vue'
import ContextActions from '../../components/FilesList/ContextActions.vue'
import QuickActions from '../../components/FilesList/QuickActions.vue'
import MixinFileActions from '../../mixins/fileActions'
export default {
Expand All @@ -97,6 +96,8 @@ export default {
const store = useStore()
const spaceId = router.currentRoute.params.spaceId
console.log(spaceId)
const space = ref({})
const markdownContent = ref('')
const imageContent = ref('')
Expand Down Expand Up @@ -165,7 +166,9 @@ export default {
const loadFilesListTask = useTask(function* (signal, ref, sameRoute, path = null) {
ref.CLEAR_CURRENT_FILES_LIST()
const response = yield ref.$client.files.list(`spaces/${space.value.id}/${path || ''}`)
const response = yield ref.$client.files.list(
`spaces/${ref.$route.params.spaceId}/${path || ''}`
)
const resources = response.map(buildResource)
const currentFolder = resources.shift()
Expand Down Expand Up @@ -260,7 +263,7 @@ export default {
}
},
async mounted() {
await this.loadResourcesTask.perform(this)
await this.loadResourcesTask.perform(this, false, this.$route.params.item || '')
document.title = `${this.space.name} - ${this.$route.meta.title}`
this.$route.params.name = this.space.name
Expand Down

0 comments on commit d80ece5

Please sign in to comment.