-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce personal space resource loader
- Loading branch information
Showing
4 changed files
with
106 additions
and
19 deletions.
There are no files selected for viewing
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
82 changes: 82 additions & 0 deletions
82
packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts
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,82 @@ | ||
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') | ||
} | ||
|
||
let resources = yield fetchResources( | ||
clientService.owncloudSdk, | ||
buildWebDavSpacesPath( | ||
userResponse.data.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() | ||
} | ||
} |