Skip to content

Commit

Permalink
WIP: introduce generic space view
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Sep 8, 2022
1 parent a6128ed commit 056a3c3
Show file tree
Hide file tree
Showing 44 changed files with 412 additions and 552 deletions.
92 changes: 38 additions & 54 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,19 @@ import {
useStore,
usePublicLinkPassword,
useUserContext,
usePublicLinkContext
usePublicLinkContext,
useDriveResolver
} from 'web-pkg/src/composables'
import { DavProperties, DavProperty } from 'web-pkg/src/constants'
import ResourceUpload from './Upload/ResourceUpload.vue'
import { defineComponent, getCurrentInstance, onMounted } from '@vue/composition-api'
import { defineComponent, getCurrentInstance, onMounted, ref, unref } from '@vue/composition-api'
import { UppyResource, useUpload } from 'web-runtime/src/composables/upload'
import { useUploadHelpers } from '../../composables/upload'
import { SHARE_JAIL_ID } from '../../services/folder'
import { bus } from 'web-pkg/src/instance'
import { buildWebDavSpacesPath } from 'web-client/src/helpers'
import { buildWebDavSpacesPath, Resource } from 'web-client/src/helpers'
import { resolveFileNameDuplicate, extractNameWithoutExtension } from '../../helpers/resource'
export default defineComponent({
Expand All @@ -163,6 +164,7 @@ export default defineComponent({
},
mixins: [MixinFileActions],
props: {
space: { type: Object, required: false, default: null },
limitedScreenSpace: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -190,29 +192,32 @@ export default defineComponent({
})
})
const getSpaceByDriveAliasAndItem = (driveAliasAndItem: string): Resource => {
const { space } = useDriveResolver({ store, driveAliasAndItem: ref(driveAliasAndItem) })
return unref(space)
}
return {
...useUpload({
uppyService
}),
...useUploadHelpers(),
...useRequest(),
...useGraphClient(),
isPersonalLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-personal'),
isPublicLocation: useActiveLocation(isLocationPublicActive, 'files-public-files'),
isSpacesProjectsLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-projects'),
isSpacesProjectLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-project'),
isSpacesShareLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-share'),
isSpacesGenericLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-generic'),
hasShareJail: useCapabilityShareJailEnabled(),
hasSpaces: useCapabilitySpacesEnabled(),
publicLinkPassword: usePublicLinkPassword({ store }),
isUserContext: useUserContext({ store }),
isPublicLinkContext: usePublicLinkContext({ store })
isPublicLinkContext: usePublicLinkContext({ store }),
getSpaceByDriveAliasAndItem
}
},
data: () => ({
newFileAction: null,
path: '',
fileFolderCreationLoading: false
path: ''
}),
computed: {
...mapGetters(['capabilities', 'configuration', 'newFileHandlers', 'user']),
Expand Down Expand Up @@ -328,7 +333,7 @@ export default defineComponent({
return
}
if (this.isSpacesProjectLocation || this.isPersonalLocation) {
if (this.isSpacesGenericLocation) {
if (this.hasSpaces) {
const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId)
this.UPDATE_SPACE_FIELD({
Expand Down Expand Up @@ -418,28 +423,22 @@ export default defineComponent({
return
}
this.fileFolderCreationLoading = true
try {
let path = pathUtil.join(this.currentPath, folderName)
let resource
if (this.isPersonalLocation) {
if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
await this.$client.files.createFolder(path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesGenericLocation) {
if (this.hasShareJail) {
path = buildWebDavSpacesPath(this.personalDriveId, path || '')
path = buildWebDavSpacesPath(this.space.id, path || '')
} else {
path = buildWebDavFilesPath(this.user.id, path)
}
await this.$client.files.createFolder(path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesProjectLocation) {
path = buildWebDavSpacesPath(this.$route.params.storageId, path)
await this.$client.files.createFolder(path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
await this.$client.files.createFolder(path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else {
await this.$client.publicFiles.createFolder(path, null, this.publicLinkPassword)
resource = await this.$client.publicFiles.getFileInfo(
Expand All @@ -453,7 +452,7 @@ export default defineComponent({
this.UPSERT_RESOURCE(resource)
this.hideModal()
if (this.isPersonalLocation) {
if (this.isSpacesGenericLocation) {
this.loadIndicators({
client: this.$client,
currentFolder: this.currentFolder.path
Expand All @@ -475,8 +474,6 @@ export default defineComponent({
status: 'danger'
})
}
this.fileFolderCreationLoading = false
},
checkNewFolderName(folderName) {
Expand Down Expand Up @@ -515,28 +512,22 @@ export default defineComponent({
return
}
this.fileFolderCreationLoading = true
try {
let resource
let path = pathUtil.join(this.currentPath, fileName)
if (this.isPersonalLocation) {
if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
await this.$client.files.putFileContents(path, '')
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesGenericLocation) {
if (this.hasShareJail) {
path = buildWebDavSpacesPath(this.personalDriveId, path || '')
path = buildWebDavSpacesPath(this.space.id, path || '')
} else {
path = buildWebDavFilesPath(this.user.id, path)
}
await this.$client.files.putFileContents(path, '')
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesProjectLocation) {
path = buildWebDavSpacesPath(this.$route.params.storageId, path)
await this.$client.files.putFileContents(path, '')
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
await this.$client.files.putFileContents(path, '')
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else {
await this.$client.publicFiles.putFileContents('', path, this.publicLinkPassword, '')
resource = await this.$client.publicFiles.getFileInfo(
Expand All @@ -559,7 +550,7 @@ export default defineComponent({
this.hideModal()
if (this.isPersonalLocation) {
if (this.isSpacesGenericLocation) {
this.loadIndicators({
client: this.$client,
currentFolder: this.currentFolder.path
Expand All @@ -578,8 +569,6 @@ export default defineComponent({
status: 'danger'
})
}
this.fileFolderCreationLoading = false
},
async addAppProviderFile(fileName) {
// FIXME: this belongs in web-app-external, but the app provider handles file creation differently than other editor extensions. Needs more refactoring.
Expand All @@ -603,19 +592,16 @@ export default defineComponent({
let resource
let path = pathUtil.join(this.currentPath, fileName)
if (this.isPersonalLocation) {
if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesGenericLocation) {
if (this.hasShareJail) {
path = buildWebDavSpacesPath(this.personalDriveId, path || '')
path = buildWebDavSpacesPath(this.space.id, path || '')
} else {
path = buildWebDavFilesPath(this.user.id, path)
}
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesProjectLocation) {
path = buildWebDavSpacesPath(this.$route.params.storageId, path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else if (this.isSpacesShareLocation) {
path = buildWebDavSpacesPath([SHARE_JAIL_ID, this.$route.query.shareId].join('!'), path)
resource = await this.$client.files.fileInfo(path, DavProperties.Default)
} else {
resource = await this.$client.publicFiles.getFileInfo(
path,
Expand All @@ -628,7 +614,7 @@ export default defineComponent({
this.UPSERT_RESOURCE(resource)
this.hideModal()
if (this.isPersonalLocation) {
if (this.isSpacesGenericLocation) {
this.loadIndicators({
client: this.$client,
currentFolder: this.currentFolder.path
Expand Down Expand Up @@ -733,11 +719,9 @@ export default defineComponent({
return acc
}
if (uppyResource.meta.routeName === 'files-spaces-personal') {
targetUploadSpace = this.spaces.find((space) => space.driveType === 'personal')
} else {
targetUploadSpace = this.spaces.find(
(space) => space.id === uppyResource.meta.routeStorageId
if (uppyResource.meta.routeName === 'files-spaces-generic') {
targetUploadSpace = this.getSpaceByDriveAliasAndItem(
uppyResource.meta.routeDriveAliasAndItem
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,27 @@ import { useRouter, useStore } from 'web-pkg/src/composables'
export default {
name: 'NotFoundMessage',
setup() {
props: {
space: {
type: Object,
required: false,
default: null
}
},
setup(props) {
const router = useRouter()
const store = useStore()
return {
showPublicLinkButton: isLocationPublicActive(router, 'files-public-files'),
showHomeButton: isLocationSpacesActive(router, 'files-spaces-personal'),
showSpacesButton: isLocationSpacesActive(router, 'files-spaces-project'),
homeRoute: createLocationSpaces('files-spaces-personal', {
params: { item: store.getters.homeFolder }
showHomeButton:
isLocationSpacesActive(router, 'files-spaces-generic') &&
props.space?.driveType !== 'project',
showSpacesButton:
isLocationSpacesActive(router, 'files-spaces-generic') &&
props.space?.driveType === 'project',
homeRoute: createLocationSpaces('files-spaces-generic', {
params: { driveAliasAndItem: 'personal' + store.getters.homeFolder }
}),
publicLinkRoute: createLocationPublic('files-public-files', {
params: { item: router.currentRoute.params?.item?.split('/')[0] }
Expand Down
68 changes: 11 additions & 57 deletions packages/web-app-files/src/components/FilesList/ResourceTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,39 +265,12 @@ export default defineComponent({
default: true
},
/**
* Target route path used to build the link when navigating into a resource
* Accepts a `path` and a `resource` param and returns a corresponding route object.
*/
targetRoute: {
type: Object,
required: false,
default: null
},
/**
* Maps resource values to route params. Use `{ resourceFieldName: 'routeParamName' }` as format.
*
* An example would be `{ id: 'fileId' }` to map the value of the `id` field of a resource
* to the `fileId` param of the target route.
*
* Defaults to `{ storageId: 'storageId' } to map the value of the `storageId` field of a resource
* to the `storageId` param of the target route.
*/
targetRouteParamMapping: {
type: Object,
required: false,
default: () => ({ storageId: 'storageId' })
},
/**
* Maps resource values to route query options. Use `{ resourceFieldName: 'routeQueryName' }` as format.
*
* An example would be `{ id: 'fileId' }` to map the value of the `id` field of a resource
* to the `fileId` query option of the target route.
*
* Defaults to an empty object because no query options are expected as default.
*/
targetRouteQueryMapping: {
type: Object,
targetRouteCallback: {
type: Function,
required: false,
default: () => ({})
default: undefined
},
/**
* Asserts whether clicking on the resource name triggers any action
Expand Down Expand Up @@ -596,36 +569,17 @@ export default defineComponent({
return this.createFolderLink(path.dirname(file.path), file)
},
createFolderLink(path, resource) {
if (this.targetRoute === null) {
return {}
}
const params = {
item: path.replace(/^\//, '') || '/',
...mapResourceFields(resource, this.targetRouteParamMapping),
...this.targetRoute.params
}
const query = {
...mapResourceFields(resource, this.targetRouteQueryMapping),
...this.targetRoute.query
if (this.targetRouteCallback) {
return this.targetRouteCallback(path, resource)
}
const matchingSpace = this.getMatchingSpace(resource.storageId)
if (this.hasProjectSpaces) {
if (matchingSpace?.driveType === 'project') {
return createLocationSpaces('files-spaces-project', {
params: { ...params, storageId: matchingSpace?.id || params.storageId },
query
})
}
}
return {
name: this.targetRoute.name,
params: { ...params, storageId: matchingSpace?.id || params.storageId },
query
if (!matchingSpace) {
return {}
}
return createLocationSpaces('files-spaces-generic', {
params: { driveAliasAndItem: matchingSpace.driveAlias + path }
})
},
fileDragged(file) {
this.addSelectedResource(file)
Expand Down
8 changes: 1 addition & 7 deletions packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class="files-table"
:class="{ 'files-table-squashed': false }"
:resources="paginatedResources"
:target-route="resourceTargetLocation"
:are-paths-displayed="true"
:are-thumbnails-displayed="displayThumbnails"
:has-actions="true"
Expand Down Expand Up @@ -56,7 +55,6 @@ import { useResourcesViewDefaults } from '../../composables'
import AppLoadingSpinner from 'web-pkg/src/components/AppLoadingSpinner.vue'
import { VisibilityObserver } from 'web-pkg/src/observer'
import { ImageType, ImageDimension } from '../../constants'
import { createLocationSpaces } from '../../router'
import NoContentMessage from 'web-pkg/src/components/NoContentMessage.vue'
import ResourceTable from '../FilesList/ResourceTable.vue'
import ContextActions from '../FilesList/ContextActions.vue'
Expand Down Expand Up @@ -105,11 +103,7 @@ export default defineComponent({
setup() {
const store = useStore()
return {
...useResourcesViewDefaults<Resource, any, any[]>(),
resourceTargetLocation: createLocationSpaces('files-spaces-personal', {
params: { storageId: store.getters.user.id }
})
...useResourcesViewDefaults<Resource, any, any[]>()
}
},
computed: {
Expand Down
Loading

0 comments on commit 056a3c3

Please sign in to comment.