Skip to content

Commit

Permalink
Introduce personal space resource loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Mar 17, 2022
1 parent e035192 commit 6da3154
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 19 deletions.
9 changes: 6 additions & 3 deletions packages/web-app-files/src/services/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
FolderLoaderSpacesProject,
FolderLoaderSpacesShare,
FolderLoaderFavorites,
FolderLoaderPersonal,
FolderLoaderLegacyPersonal,
FolderLoaderPublicFiles,
FolderLoaderSharedViaLink,
FolderLoaderSharedWithMe,
FolderLoaderSharedWithOthers,
FolderLoaderTrashbin
FolderLoaderTrashbin,
FolderLoaderSpacesPersonal
} from './folder/'

export * from './folder/util'
Expand All @@ -38,12 +39,14 @@ export class FolderService {

constructor() {
this.loaders = [
// legacy loaders
new FolderLoaderLegacyPersonal(),
// spaces loaders
new FolderLoaderSpacesPersonal(),
new FolderLoaderSpacesProject(),
new FolderLoaderSpacesShare(),
// generic loaders
new FolderLoaderFavorites(),
new FolderLoaderPersonal(),
new FolderLoaderPublicFiles(),
new FolderLoaderSharedViaLink(),
new FolderLoaderSharedWithMe(),
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-files/src/services/folder/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * from './legacy/loaderPersonal'
export * from './spaces/loaderPersonal'
export * from './spaces/loaderProject'
export * from './spaces/loaderShare'
export * from './loaderFavorites'
export * from './loaderPersonal'
export * from './loaderPublicFiles'
export * from './loaderSharedViaLink'
export * from './loaderSharedWithMe'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder'
import { FolderLoader, FolderLoaderTask, TaskContext } from '../../folder'
import Router from 'vue-router'
import { useTask } from 'vue-concurrency'
import { DavProperties } from 'web-pkg/src/constants'
import { buildResource, buildWebDavFilesPath } from '../../helpers/resources'
import { isLocationSpacesActive } from '../../router'
import { buildResource, buildWebDavFilesPath } from '../../../helpers/resources'
import { isLocationSpacesActive } from '../../../router'
import { Store } from 'vuex'
import { fetchResources } from './util'
import { fetchResources } from '../util'
import get from 'lodash-es/get'

export class FolderLoaderPersonal implements FolderLoader {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class FolderLoaderLegacyPersonal implements FolderLoader {
public isEnabled(store: Store<any>): boolean {
return true
return !get(store, 'getters.capabilities.spaces.enabled', false)
}

public isActive(router: Router): boolean {
Expand Down Expand Up @@ -42,16 +42,17 @@ export class FolderLoaderPersonal implements FolderLoader {
files: resources
})

store.dispatch('Files/loadIndicators', {
client: client,
currentFolder: currentFolder.path
})
// load indicators
;(() => {
store.dispatch('Files/loadIndicators', {
client: client,
currentFolder: currentFolder.path
})
})()

// Load quota
const promiseUser = client.users.getUser(ref.user.id)
// The semicolon is important to separate from the previous statement
// fetch user quota
;(async () => {
const user = await promiseUser
const user = await client.users.getUser(ref.user.id)
store.commit('SET_QUOTA', user.quota)
})()
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { FolderLoader, FolderLoaderTask, TaskContext } from '../../folder'
import Router from 'vue-router'
import { useTask } from 'vue-concurrency'
import { DavProperties } from 'web-pkg/src/constants'
import {
buildResource,
buildWebDavFilesPath,
buildWebDavSpacesPath
} from '../../../helpers/resources'
import { isLocationSpacesActive } from '../../../router'
import { Store } from 'vuex'
import { fetchResources } from '../util'
import get from 'lodash-es/get'

export class FolderLoaderSpacesPersonal implements FolderLoader {
public isEnabled(store: Store<any>): boolean {
return get(store, 'getters.capabilities.spaces.enabled', false)
}

public isActive(router: Router): boolean {
return isLocationSpacesActive(router, 'files-spaces-personal-home')
}

public getTask(context: TaskContext): FolderLoaderTask {
const { store, router, clientService } = context

const graphClient = clientService.graphAuthenticated(
store.getters.configuration.server,
store.getters.getToken
)

return useTask(function* (signal1, signal2, ref, sameRoute, path = null) {
try {
store.commit('Files/CLEAR_CURRENT_FILES_LIST')

const userResponse = yield graphClient.users.getMe()
if (!userResponse.data) {
throw new Error('graph.user.getMe() has no data')
}

const drivesResponse = yield graphClient.drives.listMyDrives('', 'driveType eq personal')
if (!drivesResponse.data) {
throw new Error('graph.drives.listMyDrives has no data')
}
const personalDrive = drivesResponse.data.value.find(
(drive) => drive.id === userResponse.data.id
)
if (!personalDrive) {
throw new Error(`no personal drive found for user id ${userResponse.data.id}`)
}

let resources = yield fetchResources(
clientService.owncloudSdk,
buildWebDavSpacesPath(
personalDrive.root.id,
path || router.currentRoute.params.item || ''
),
DavProperties.Default
)
resources = resources.map(buildResource)

const currentFolder = resources.shift()

store.commit('Files/LOAD_FILES', {
currentFolder,
files: resources
})

// load indicators
;(() => {
store.dispatch('Files/loadIndicators', {
client: clientService.owncloudSdk,
currentFolder: currentFolder.path
})
})()

// fetch user quota
;(async () => {
const user = await clientService.owncloudSdk.users.getUser(ref.user.id)
store.commit('SET_QUOTA', user.quota)
})()
} catch (error) {
store.commit('Files/SET_CURRENT_FOLDER', null)
console.error(error)
}

ref.refreshFileListHeaderPosition()

ref.accessibleBreadcrumb_focusAndAnnounceBreadcrumb(sameRoute)
ref.scrollToResourceFromRoute()
}).restartable()
}
}

0 comments on commit 6da3154

Please sign in to comment.