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] Search all files with ocis backend #6841

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-enable-search-all-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Enable search all files for ocis backend

We've enabled the search all files feature for ocis backend:
* Find files in sub directories
* Find files in other places like project spaces

https://github.com/owncloud/web/pull/6841
34 changes: 28 additions & 6 deletions packages/web-app-files/src/components/FilesList/ResourceTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
:key="`${item.path}-${resourceDomSelector(item)}-${item.thumbnail}`"
:resource="item"
:is-path-displayed="arePathsDisplayed"
:parent-folder-name-default="defaultParentFolderName"
:parent-folder-name-default="getDefaultParentFolderName(item)"
:is-thumbnail-displayed="areThumbnailsDisplayed"
:is-extension-displayed="areFileExtensionsShown"
:is-resource-clickable="isResourceClickable(item.id)"
Expand Down Expand Up @@ -176,6 +176,7 @@ import Rename from '../../mixins/actions/rename'
import { defineComponent, PropType } from '@vue/composition-api'
import { extractDomSelector, Resource } from '../../helpers/resource'
import { ShareTypes } from '../../helpers/share'
import { createLocationSpaces } from '../../router'

export default defineComponent({
mixins: [Rename],
Expand Down Expand Up @@ -353,7 +354,7 @@ export default defineComponent({
},
computed: {
...mapGetters(['configuration']),
...mapState('Files', ['areFileExtensionsShown']),
...mapState('Files', ['areFileExtensionsShown', 'spaces']),
popperOptions() {
return {
modifiers: [
Expand Down Expand Up @@ -512,9 +513,6 @@ export default defineComponent({
},
currentLanguage() {
return (this.$language?.current || '').split('_')[0]
},
defaultParentFolderName() {
return this.hasSpaces ? this.$gettext('Personal') : this.$gettext('All files and folders')
}
},
methods: {
Expand Down Expand Up @@ -543,11 +541,20 @@ export default defineComponent({
if (this.targetRoute === null) {
return {}
}

const matchingSpace = this.getMatchingSpace(storageId)

if (matchingSpace && matchingSpace?.driveType === 'project') {
return createLocationSpaces('files-spaces-project', {
params: { storageId, item: path.replace(/^\//, '') || undefined }
})
}

return {
name: this.targetRoute.name,
query: this.targetRoute.query,
params: {
item: path.replace(/^\//, ''),
item: path.replace(/^\//, '') || undefined,
...this.targetRoute.params,
...(storageId && { storageId })
}
Expand Down Expand Up @@ -693,6 +700,21 @@ export default defineComponent({
resourceType,
ownerName: resource.owner[0].displayName
})
},
getMatchingSpace(storageId) {
return this.spaces.find((space) => space.id === storageId)
},
getDefaultParentFolderName(resource) {
if (!this.hasSpaces) {
return this.$gettext('All files and folders')
}
const matchingSpace = this.getMatchingSpace(resource.storageId)

if (matchingSpace && matchingSpace?.driveType === 'project') {
AlexAndBear marked this conversation as resolved.
Show resolved Hide resolved
return matchingSpace.name
}

return this.$gettext('Personal')
}
}
})
Expand Down
34 changes: 27 additions & 7 deletions packages/web-app-files/src/components/Search/Preview.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<div class="files-search-preview" @click="$_fileActions_triggerDefaultAction(resource)">
<div class="files-search-preview">
<oc-resource
:resource="resource"
:is-path-displayed="true"
:folder-link="folderLink(resource)"
:parent-folder-link="parentFolderLink(resource)"
:parent-folder-name-default="defaultParentFolderName"
@click="$_fileActions_triggerDefaultAction(resource)"
/>
</div>
</template>
Expand All @@ -17,7 +18,7 @@ import { ImageDimension } from '../../constants'
import { loadPreview } from '../../helpers/resource'
import debounce from 'lodash-es/debounce'
import Vue from 'vue'
import { mapGetters } from 'vuex'
import { mapGetters, mapState } from 'vuex'
import { createLocationSpaces } from '../../router'
import path from 'path'
import { useCapabilitySpacesEnabled } from 'web-pkg/src/composables'
Expand All @@ -43,7 +44,8 @@ export default {
setup() {
return {
hasSpaces: useCapabilitySpacesEnabled(),
resourceTargetLocation: createLocationSpaces('files-spaces-personal-home')
resourceTargetLocation: createLocationSpaces('files-spaces-personal-home'),
resourceTargetLocationSpace: createLocationSpaces('files-spaces-project')
}
},
data() {
Expand All @@ -53,9 +55,21 @@ export default {
},
computed: {
...mapGetters(['configuration', 'user', 'getToken']),
...mapState('Files', ['spaces']),

matchingSpace() {
return this.spaces.find((space) => space.id === this.resource.storageId)
},
defaultParentFolderName() {
return this.hasSpaces ? this.$gettext('Personal') : this.$gettext('All files and folders')
if (!this.hasSpaces) {
return this.$gettext('All files and folders')
}

if (this.matchingSpace?.driveType === 'project') {
return this.matchingSpace.name
}

return this.$gettext('Personal')
}
},
beforeMount() {
Expand Down Expand Up @@ -91,14 +105,20 @@ export default {
return this.createFolderLink(path.dirname(file.path), file.storageId)
},
createFolderLink(path, storageId) {
if (this.resourceTargetLocation === null) {
if (this.resourceTargetLocation === null || this.resourceTargetLocationSpace === null) {
return {}
}

if (this.matchingSpace?.driveType === 'project') {
return createLocationSpaces('files-spaces-project', {
params: { storageId, item: path.replace(/^\//, '') || undefined }
})
}

return {
name: this.resourceTargetLocation.name,
query: this.resourceTargetLocation.query,
params: {
item: path.replace(/^\//, ''),
item: path.replace(/^\//, '') || undefined,
...this.resourceTargetLocation.params,
...(storageId && { storageId })
}
Expand Down
5 changes: 3 additions & 2 deletions packages/web-app-files/src/helpers/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function buildSpace(space) {
spaceReadmeData = space.special.find((el) => el.specialFolder.name === 'readme')
}

if (space.root) {
if (space.root?.permissions) {
for (const permission of space.root.permissions) {
for (const role of SpacePeopleShareRoles.list()) {
if (permission.roles.includes(role.name)) {
Expand All @@ -146,6 +146,7 @@ export function buildSpace(space) {
extension: '',
path: '',
webDavPath: '',
driveType: space.driveType,
type: 'space',
isFolder: true,
mdate: space.lastModifiedDateTime,
Expand All @@ -161,7 +162,7 @@ export function buildSpace(space) {
privateLink: '',
downloadURL: '',
ownerDisplayName: '',
ownerId: '',
ownerId: space.owner?.user?.id,
disabled,
spaceQuota: space.quota,
spaceRoles,
Expand Down
4 changes: 4 additions & 0 deletions packages/web-app-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { archiverService, thumbnailService, Registry } from './services'
import fileSideBars from './fileSideBars'
import { buildRoutes } from './router'
import get from 'lodash-es/get'
import { clientService } from 'web-pkg/src/services'

// dirty: importing view from other extension within project
import SearchResults from '../../web-app-search/src/views/List.vue'
Expand Down Expand Up @@ -125,6 +126,9 @@ export default {
bus.publish('app.search.register.provider', Registry.sdkSearch)
},
userReady({ store }) {
// Load spaces to make them available across the application
store.dispatch('Files/loadSpaces', { clientService })

archiverService.initialize(
store.getters.configuration.server || window.location.origin,
get(store, 'getters.capabilities.files.archivers', [
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/search/sdk/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export default class List implements SearchList {
)

return plainResources.map((plainResource) => {
const resource = buildResource(plainResource)
let resourceName = decodeURIComponent(plainResource.name)
if (resourceName.startsWith('/dav')) {
resourceName = resourceName.slice(4)
}

const resource = buildResource({ ...plainResource, name: resourceName })
return { id: resource.id, data: resource }
})
}
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/search/sdk/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export default class Preview implements SearchPreview {
return this.cache.set(
term,
plainResources.map((plainResource) => {
const resource = buildResource(plainResource)
let resourceName = decodeURIComponent(plainResource.name)
if (resourceName.startsWith('/dav')) {
resourceName = resourceName.slice(4)
}

const resource = buildResource({ ...plainResource, name: resourceName })
return { id: resource.id, data: resource }
})
)
Expand Down
15 changes: 15 additions & 0 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,21 @@ export default {
})
},

async loadSpaces(context, { clientService }) {
const graphClient = clientService.graphAuthenticated(
context.rootGetters.configuration.server,
context.rootGetters.getToken
)
const graphResponse = await graphClient.drives.listMyDrives()

if (!graphResponse.data) {
return
}

const spaces = graphResponse.data.value.map((space) => buildSpace(space))
context.commit('LOAD_SPACES', spaces)
},

async loadPreview({ commit, rootGetters }, { resource, isPublic, dimensions, type }) {
if (
rootGetters.previewFileExtensions.length &&
Expand Down
6 changes: 6 additions & 0 deletions packages/web-app-files/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { renameResource } from '../helpers/resources'
import { ShareTypes } from '../helpers/share'

export default {
LOAD_SPACES(state, spaces) {
state.spaces = spaces
},
CLEAR_SPACES(state) {
state.spaces = []
},
LOAD_FILES(state, { currentFolder, files }) {
state.currentFolder = currentFolder
state.files = files
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/store/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
inProgress: [],
shareOpen: null,
versions: [],
spaces: [],

/**
* Outgoing shares and links from currently highlighted element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ function getMountedWrapper(options = {}) {
},
modules: {
Files: {
namespaced: true
namespaced: true,
state: {
spaces: []
}
}
}
}),
Expand Down
Loading