From 6787465f21ec1426b67a6f715fb9383201c8afb5 Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 27 Apr 2023 12:07:50 +0200 Subject: [PATCH 01/26] WIP --- .../components/FilesList/ContextActions.vue | 6 +- .../src/composables/actions/files/index.ts | 1 + .../files/useFileActionsCreateNewFolder.ts | 193 ++++++++++++++++++ 3 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts diff --git a/packages/web-app-files/src/components/FilesList/ContextActions.vue b/packages/web-app-files/src/components/FilesList/ContextActions.vue index 0e72e1ac978..9634ebe1f32 100644 --- a/packages/web-app-files/src/components/FilesList/ContextActions.vue +++ b/packages/web-app-files/src/components/FilesList/ContextActions.vue @@ -31,9 +31,11 @@ import { useFileActionsShowEditTags, useFileActionsNavigate, useFileActionsFavorite, - useFileActionsCreateSpaceFromResource + useFileActionsCreateSpaceFromResource, + useFileActionsCreateNewFolder } from '../../composables/actions/files' import { FileActionOptions } from 'web-pkg/src/composables/actions' +import { create } from 'domain' export default defineComponent({ name: 'ContextActions', @@ -49,6 +51,7 @@ export default defineComponent({ const { editorActions, loadExternalAppActions } = useFileActions() + const { actions: createNewFolder } = useFileActionsCreateNewFolder({ store }) const { actions: acceptShareActions } = useFileActionsAcceptShare({ store }) const { actions: copyActions } = useFileActionsCopy({ store }) const { actions: createQuickLinkActions } = useFileActionsCreateQuickLink({ store }) @@ -107,6 +110,7 @@ export default defineComponent({ const menuItemsActions = computed(() => { return [ + ...unref(createNewFolder), ...unref(downloadArchiveActions), ...unref(downloadFileActions), ...unref(deleteActions), diff --git a/packages/web-app-files/src/composables/actions/files/index.ts b/packages/web-app-files/src/composables/actions/files/index.ts index 1203708d328..9580c8a7628 100644 --- a/packages/web-app-files/src/composables/actions/files/index.ts +++ b/packages/web-app-files/src/composables/actions/files/index.ts @@ -19,3 +19,4 @@ export * from './useFileActionsShowDetails' export * from './useFileActionsShowEditTags' export * from './useFileActionsShowShares' export * from './useFileActionsCreateSpaceFromResource' +export * from './useFileActionsCreateNewFolder' diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts new file mode 100644 index 00000000000..f01f7e7293c --- /dev/null +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts @@ -0,0 +1,193 @@ +import { Resource, extractNameWithoutExtension } from 'web-client/src/helpers' +import { Store } from 'vuex' +import { computed, unref } from 'vue' +import { useStore } from 'web-pkg/src/composables' +import { FileAction, FileActionOptions } from 'web-pkg/src/composables/actions' +import { useGettext } from 'vue3-gettext' +import { resolveFileNameDuplicate } from 'web-app-files/src/helpers/resource' + +export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } = {}) => { + store = store || useStore() + const { $gettext } = useGettext() + + const files = computed((): Array => store.getters['Files/files']) + const areFileExtensionsShown = computed( + (): boolean => store.getters['Files/areFileExtensionsShown'] + ) + + const checkNewFolderName = (folderName) => { + if (folderName.trim() === '') { + return $gettext('Folder name cannot be empty') + } + + if (/[/]/.test(folderName)) { + return $gettext('Folder name cannot contain "/"') + } + + if (folderName === '.') { + return $gettext('Folder name cannot be equal to "."') + } + + if (folderName === '..') { + return $gettext('Folder name cannot be equal to ".."') + } + + const exists = unref(files).find((file) => file.name === folderName) + + if (exists) { + const translated = $gettext('%{name} already exists') + return $gettext(translated, { name: folderName }, true) + } + + return null + } + + const checkNewFileName = (fileName) => { + if (fileName === '') { + return $gettext('File name cannot be empty') + } + + if (/[/]/.test(fileName)) { + return $gettext('File name cannot contain "/"') + } + + if (fileName === '.') { + return $gettext('File name cannot be equal to "."') + } + + if (fileName === '..') { + return $gettext('File name cannot be equal to ".."') + } + + if (/\s+$/.test(fileName)) { + return $gettext('File name cannot end with whitespace') + } + + const exists = unref(files).find((file) => file.name === fileName) + + if (exists) { + const translated = $gettext('%{name} already exists') + return $gettext(translated, { name: fileName }, true) + } + + return null + } + + const addAppProviderFileFunc = async (fileName) => {} + + const addNewFolder = async (folderName) => { + /*folderName = folderName.trimEnd() + + try { + const path = join(this.item, folderName) + const resource = await (clientService.webdav as WebDAV).createFolder(this.space, { + path + }) + + if (this.loadIndicatorsForNewFile) { + resource.indicators = getIndicators({ resource, ancestorMetaData: this.ancestorMetaData }) + } + + this.UPSERT_RESOURCE(resource) + this.hideModal() + + this.showMessage({ + title: this.$gettextInterpolate( + this.$gettext('"%{folderName}" was created successfully'), + { + folderName + } + ) + }) + } catch (error) { + console.error(error) + this.showMessage({ + title: this.$gettext('Failed to create folder'), + status: 'danger' + }) + }*/ + // TODO + } + + const handler = ({ space, resources }: FileActionOptions) => { + const checkInputValue = (value) => { + /*this.setModalInputErrorMessage( + isFolder + ? this.checkNewFolderName(value) + : this.checkNewFileName(this.areFileExtensionsShown ? value : `${value}.${ext}`) //TODO + )*/ + } + const addAppProviderFile = false + const isFolder = true + const ext = '' + let defaultName = isFolder ? $gettext('New folder') : $gettext('New file') + `.${ext}` + + if (unref(files).some((f) => f.name === defaultName)) { + defaultName = resolveFileNameDuplicate(defaultName, isFolder ? '' : ext, files) + } + + if (!areFileExtensionsShown) { + defaultName = extractNameWithoutExtension({ name: defaultName, extension: ext } as any) + } + + // Sets action to be executed after creation of the file + if (!isFolder) { + //this.newFileAction = openAction // TODO + } + + const inputSelectionRange = + isFolder || !areFileExtensionsShown ? null : [0, defaultName.length - (ext.length + 1)] + + const modal = { + variation: 'passive', + title: isFolder ? $gettext('Create a new folder') : $gettext('Create a new file'), + cancelText: $gettext('Cancel'), + confirmText: $gettext('Create'), + hasInput: true, + inputValue: defaultName, + inputLabel: isFolder ? $gettext('Folder name') : $gettext('File name'), + inputError: isFolder + ? checkNewFolderName(defaultName) + : checkNewFileName(areFileExtensionsShown ? defaultName : `${defaultName}.${ext}`), + inputSelectionRange, + onCancel: store.dispatch('hideModal'), + onConfirm: isFolder + ? addNewFolder + : addAppProviderFile + ? addAppProviderFileFunc + : (fileName) => { + /*if (!this.areFileExtensionsShown) { + fileName = `${fileName}.${ext}` + } + this.addNewFile(fileName)*/ + //TODO + }, + onInput: checkInputValue + } + + store.dispatch('createModal', modal) + } + + const actions = computed((): FileAction[] => { + return [ + { + name: 'create-folder', + icon: 'add', + handler, + label: () => { + return $gettext('Create new Folder') + }, + isEnabled: ({ resources }) => { + return true + }, + canBeDefault: true, + componentType: 'button', + class: 'oc-files-actions-download-archive-trigger' + } + ] + }) + + return { + actions + } +} From 667e727b6a754e538c03a3949e8a27b40cf1749d Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 27 Apr 2023 12:30:40 +0200 Subject: [PATCH 02/26] Make createFolder work --- .../files/useFileActionsCreateNewFolder.ts | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts index f01f7e7293c..d8df4234e6a 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts @@ -1,20 +1,33 @@ import { Resource, extractNameWithoutExtension } from 'web-client/src/helpers' import { Store } from 'vuex' import { computed, unref } from 'vue' -import { useStore } from 'web-pkg/src/composables' +import { useClientService, useRouter, useStore } from 'web-pkg/src/composables' import { FileAction, FileActionOptions } from 'web-pkg/src/composables/actions' import { useGettext } from 'vue3-gettext' import { resolveFileNameDuplicate } from 'web-app-files/src/helpers/resource' +import { join } from 'path' +import { WebDAV } from 'web-client/src/webdav' +import { isLocationSpacesActive } from 'web-app-files/src/router' +import { getIndicators } from 'web-app-files/src/helpers/statusIndicators' export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } = {}) => { store = store || useStore() + const router = useRouter() const { $gettext } = useGettext() + const clientService = useClientService() + const currentFolder = computed((): Resource => store.getters['Files/currentFolder']) const files = computed((): Array => store.getters['Files/files']) + const ancestorMetaData = computed(() => store.getters['Files/ancestorMetaData']) const areFileExtensionsShown = computed( (): boolean => store.getters['Files/areFileExtensionsShown'] ) + const storageId = unref(currentFolder).storageId + const currentSpace = store.getters['runtime/spaces/spaces'].find( + (space) => space.id === storageId + ) //TODO is this the way to replace this.space ( ͡° ͜ʖ ͡°)? + const checkNewFolderName = (folderName) => { if (folderName.trim() === '') { return $gettext('Folder name cannot be empty') @@ -75,38 +88,38 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } const addAppProviderFileFunc = async (fileName) => {} + const loadIndicatorsForNewFile = computed(() => { + return ( + isLocationSpacesActive(router, 'files-spaces-projects') && currentSpace.driveType !== 'share' + ) + }) + const addNewFolder = async (folderName) => { - /*folderName = folderName.trimEnd() + folderName = folderName.trimEnd() try { - const path = join(this.item, folderName) - const resource = await (clientService.webdav as WebDAV).createFolder(this.space, { + const path = join(unref(currentFolder).path, folderName) // TODO: Why was this.item used here isn't it just the currentFolderPath? + const resource = await (clientService.webdav as WebDAV).createFolder(currentSpace, { path }) - if (this.loadIndicatorsForNewFile) { - resource.indicators = getIndicators({ resource, ancestorMetaData: this.ancestorMetaData }) + if (unref(loadIndicatorsForNewFile)) { + resource.indicators = getIndicators({ resource, ancestorMetaData: unref(ancestorMetaData) }) } - this.UPSERT_RESOURCE(resource) - this.hideModal() + store.commit('Files/UPSERT_RESOURCE', resource) + store.dispatch('hideModal') - this.showMessage({ - title: this.$gettextInterpolate( - this.$gettext('"%{folderName}" was created successfully'), - { - folderName - } - ) + store.dispatch('showMessage', { + title: $gettext('"%{folderName}" was created successfully', { folderName }) }) } catch (error) { console.error(error) - this.showMessage({ - title: this.$gettext('Failed to create folder'), + store.dispatch('showMessage', { + title: $gettext('Failed to create folder'), status: 'danger' }) - }*/ - // TODO + } } const handler = ({ space, resources }: FileActionOptions) => { @@ -150,7 +163,7 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } ? checkNewFolderName(defaultName) : checkNewFileName(areFileExtensionsShown ? defaultName : `${defaultName}.${ext}`), inputSelectionRange, - onCancel: store.dispatch('hideModal'), + onCancel: () => store.dispatch('hideModal'), onConfirm: isFolder ? addNewFolder : addAppProviderFile From 2a685cdab3c7fa9b1cd9b4346ba969d2d937d430 Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 27 Apr 2023 12:42:47 +0200 Subject: [PATCH 03/26] Fix unref files --- .../composables/actions/files/useFileActionsCreateNewFolder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts index d8df4234e6a..0cfd2ed0b7a 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts @@ -136,7 +136,7 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } let defaultName = isFolder ? $gettext('New folder') : $gettext('New file') + `.${ext}` if (unref(files).some((f) => f.name === defaultName)) { - defaultName = resolveFileNameDuplicate(defaultName, isFolder ? '' : ext, files) + defaultName = resolveFileNameDuplicate(defaultName, isFolder ? '' : ext, unref(files)) } if (!areFileExtensionsShown) { From a98ff9afa7e73352d5e1610a2736a8696a9563df Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 27 Apr 2023 14:38:19 +0200 Subject: [PATCH 04/26] Refactor useFileCreateNewFolder, implement useFileCreateNewFile --- .../components/FilesList/ContextActions.vue | 11 +- .../src/composables/actions/files/index.ts | 1 + .../files/useFileActionsCreateNewFile.ts | 198 ++++++++++++++++++ .../files/useFileActionsCreateNewFolder.ts | 93 ++------ 4 files changed, 222 insertions(+), 81 deletions(-) create mode 100644 packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts diff --git a/packages/web-app-files/src/components/FilesList/ContextActions.vue b/packages/web-app-files/src/components/FilesList/ContextActions.vue index 9634ebe1f32..65dd39c8005 100644 --- a/packages/web-app-files/src/components/FilesList/ContextActions.vue +++ b/packages/web-app-files/src/components/FilesList/ContextActions.vue @@ -32,10 +32,10 @@ import { useFileActionsNavigate, useFileActionsFavorite, useFileActionsCreateSpaceFromResource, - useFileActionsCreateNewFolder + useFileActionsCreateNewFolder, + useFileActionsCreateNewFile } from '../../composables/actions/files' import { FileActionOptions } from 'web-pkg/src/composables/actions' -import { create } from 'domain' export default defineComponent({ name: 'ContextActions', @@ -51,6 +51,12 @@ export default defineComponent({ const { editorActions, loadExternalAppActions } = useFileActions() + const { actions: createNewFile } = useFileActionsCreateNewFile({ + store, + openAction: null, + addAppProviderFile: false, + extension: 'txt' + }) const { actions: createNewFolder } = useFileActionsCreateNewFolder({ store }) const { actions: acceptShareActions } = useFileActionsAcceptShare({ store }) const { actions: copyActions } = useFileActionsCopy({ store }) @@ -110,6 +116,7 @@ export default defineComponent({ const menuItemsActions = computed(() => { return [ + ...unref(createNewFile), ...unref(createNewFolder), ...unref(downloadArchiveActions), ...unref(downloadFileActions), diff --git a/packages/web-app-files/src/composables/actions/files/index.ts b/packages/web-app-files/src/composables/actions/files/index.ts index 9580c8a7628..4b2f09f7364 100644 --- a/packages/web-app-files/src/composables/actions/files/index.ts +++ b/packages/web-app-files/src/composables/actions/files/index.ts @@ -20,3 +20,4 @@ export * from './useFileActionsShowEditTags' export * from './useFileActionsShowShares' export * from './useFileActionsCreateSpaceFromResource' export * from './useFileActionsCreateNewFolder' +export * from './useFileActionsCreateNewFile' diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts new file mode 100644 index 00000000000..5a59489a4cc --- /dev/null +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts @@ -0,0 +1,198 @@ +import { Resource, extractNameWithoutExtension } from 'web-client/src/helpers' +import { Store } from 'vuex' +import { computed, ref, unref } from 'vue' +import { useClientService, useRouter, useStore } from 'web-pkg/src/composables' +import { FileAction } from 'web-pkg/src/composables/actions' +import { useGettext } from 'vue3-gettext' +import { resolveFileNameDuplicate } from 'web-app-files/src/helpers/resource' +import { join } from 'path' +import { WebDAV } from 'web-client/src/webdav' +import { isLocationSpacesActive } from 'web-app-files/src/router' +import { getIndicators } from 'web-app-files/src/helpers/statusIndicators' +import { EDITOR_MODE_CREATE, useFileActions } from './useFileActions' + +export const useFileActionsCreateNewFile = ({ + store, + openAction, + addAppProviderFile, + extension +}: { + store?: Store + openAction?: any + addAppProviderFile?: boolean + extension?: string +} = {}) => { + store = store || useStore() + const router = useRouter() + const { $gettext } = useGettext() + + const { openEditor } = useFileActions() + const clientService = useClientService() + const currentFolder = computed((): Resource => store.getters['Files/currentFolder']) + const files = computed((): Array => store.getters['Files/files']) + const ancestorMetaData = computed(() => store.getters['Files/ancestorMetaData']) + const areFileExtensionsShown = computed( + (): boolean => store.getters['Files/areFileExtensionsShown'] + ) + const storageId = unref(currentFolder).storageId + const currentSpace = store.getters['runtime/spaces/spaces'].find( + (space) => space.id === storageId + ) + const newFileAction = ref(null) + + const checkNewFileName = (fileName) => { + if (fileName === '') { + return $gettext('File name cannot be empty') + } + + if (/[/]/.test(fileName)) { + return $gettext('File name cannot contain "/"') + } + + if (fileName === '.') { + return $gettext('File name cannot be equal to "."') + } + + if (fileName === '..') { + return $gettext('File name cannot be equal to ".."') + } + + if (/\s+$/.test(fileName)) { + return $gettext('File name cannot end with whitespace') + } + + const exists = unref(files).find((file) => file.name === fileName) + + if (exists) { + const translated = $gettext('%{name} already exists') + return $gettext(translated, { name: fileName }, true) + } + + return null + } + + const addAppProviderFileFunc = async (fileName) => {} + + const loadIndicatorsForNewFile = computed(() => { + return ( + isLocationSpacesActive(router, 'files-spaces-projects') && currentSpace.driveType !== 'share' + ) + }) + + const addNewFile = async (fileName) => { + if (fileName === '') { + return + } + + try { + const path = join(unref(currentFolder).path, fileName) + const resource = await (clientService.webdav as WebDAV).putFileContents(currentSpace, { + path + }) + + if (loadIndicatorsForNewFile) { + resource.indicators = getIndicators({ resource, ancestorMetaData: unref(ancestorMetaData) }) + } + + store.commit('Files/UPSERT_RESOURCE', resource) + + if (unref(newFileAction)) { + openEditor( + unref(newFileAction), + unref(currentSpace).getDriveAliasAndItem(resource), + resource.webDavPath, + resource.fileId, + EDITOR_MODE_CREATE + ) + store.dispatch('hideModal') + + return + } + + store.dispatch('hideModal') + store.dispatch('showMessage', { + title: $gettext('"%{fileName}" was created successfully', { fileName }) + }) + } catch (error) { + console.error(error) + store.dispatch('showMessage', { + title: $gettext('Failed to create file'), + status: 'danger' + }) + } + } + + const handler = () => { + const checkInputValue = (value) => { + store.dispatch( + 'setModalInputErrorMessage', + checkNewFileName(areFileExtensionsShown ? value : `${value}.${extension}`) + ) + } + let defaultName = $gettext('New file') + `.${extension}` + + if (unref(files).some((f) => f.name === defaultName)) { + defaultName = resolveFileNameDuplicate(defaultName, extension, unref(files)) + } + + if (!areFileExtensionsShown) { + defaultName = extractNameWithoutExtension({ name: defaultName, extension } as any) + } + + // Sets action to be executed after creation of the file + newFileAction.value = openAction + + const inputSelectionRange = !areFileExtensionsShown + ? null + : [0, defaultName.length - (extension.length + 1)] + + const modal = { + variation: 'passive', + title: $gettext('Create a new file'), + cancelText: $gettext('Cancel'), + confirmText: $gettext('Create'), + hasInput: true, + inputValue: defaultName, + inputLabel: $gettext('File name'), + inputError: checkNewFileName( + areFileExtensionsShown ? defaultName : `${defaultName}.${extension}` + ), + inputSelectionRange, + onCancel: () => store.dispatch('hideModal'), + onConfirm: addAppProviderFile + ? addAppProviderFileFunc + : (fileName) => { + if (!areFileExtensionsShown) { + fileName = `${fileName}.${extension}` + } + addNewFile(fileName) + }, + onInput: checkInputValue + } + + store.dispatch('createModal', modal) + } + + const actions = computed((): FileAction[] => { + return [ + { + name: 'create-new-file', + icon: 'add', + handler, + label: () => { + return $gettext('Create new File') + }, + isEnabled: ({ resources }) => { + return true + }, + canBeDefault: true, + componentType: 'button', + class: 'oc-files-actions-create-new-file' + } + ] + }) + + return { + actions + } +} diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts index 0cfd2ed0b7a..b36a4321811 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts @@ -1,8 +1,8 @@ -import { Resource, extractNameWithoutExtension } from 'web-client/src/helpers' +import { Resource } from 'web-client/src/helpers' import { Store } from 'vuex' import { computed, unref } from 'vue' import { useClientService, useRouter, useStore } from 'web-pkg/src/composables' -import { FileAction, FileActionOptions } from 'web-pkg/src/composables/actions' +import { FileAction } from 'web-pkg/src/composables/actions' import { useGettext } from 'vue3-gettext' import { resolveFileNameDuplicate } from 'web-app-files/src/helpers/resource' import { join } from 'path' @@ -19,14 +19,11 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } const currentFolder = computed((): Resource => store.getters['Files/currentFolder']) const files = computed((): Array => store.getters['Files/files']) const ancestorMetaData = computed(() => store.getters['Files/ancestorMetaData']) - const areFileExtensionsShown = computed( - (): boolean => store.getters['Files/areFileExtensionsShown'] - ) const storageId = unref(currentFolder).storageId const currentSpace = store.getters['runtime/spaces/spaces'].find( (space) => space.id === storageId - ) //TODO is this the way to replace this.space ( ͡° ͜ʖ ͡°)? + ) const checkNewFolderName = (folderName) => { if (folderName.trim() === '') { @@ -55,39 +52,6 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } return null } - const checkNewFileName = (fileName) => { - if (fileName === '') { - return $gettext('File name cannot be empty') - } - - if (/[/]/.test(fileName)) { - return $gettext('File name cannot contain "/"') - } - - if (fileName === '.') { - return $gettext('File name cannot be equal to "."') - } - - if (fileName === '..') { - return $gettext('File name cannot be equal to ".."') - } - - if (/\s+$/.test(fileName)) { - return $gettext('File name cannot end with whitespace') - } - - const exists = unref(files).find((file) => file.name === fileName) - - if (exists) { - const translated = $gettext('%{name} already exists') - return $gettext(translated, { name: fileName }, true) - } - - return null - } - - const addAppProviderFileFunc = async (fileName) => {} - const loadIndicatorsForNewFile = computed(() => { return ( isLocationSpacesActive(router, 'files-spaces-projects') && currentSpace.driveType !== 'share' @@ -98,7 +62,7 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } folderName = folderName.trimEnd() try { - const path = join(unref(currentFolder).path, folderName) // TODO: Why was this.item used here isn't it just the currentFolderPath? + const path = join(unref(currentFolder).path, folderName) const resource = await (clientService.webdav as WebDAV).createFolder(currentSpace, { path }) @@ -122,59 +86,30 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } } } - const handler = ({ space, resources }: FileActionOptions) => { + const handler = () => { const checkInputValue = (value) => { - /*this.setModalInputErrorMessage( - isFolder - ? this.checkNewFolderName(value) - : this.checkNewFileName(this.areFileExtensionsShown ? value : `${value}.${ext}`) //TODO - )*/ + store.dispatch('setModalInputErrorMessage', checkNewFolderName(value)) } - const addAppProviderFile = false - const isFolder = true - const ext = '' - let defaultName = isFolder ? $gettext('New folder') : $gettext('New file') + `.${ext}` + let defaultName = $gettext('New folder') if (unref(files).some((f) => f.name === defaultName)) { - defaultName = resolveFileNameDuplicate(defaultName, isFolder ? '' : ext, unref(files)) - } - - if (!areFileExtensionsShown) { - defaultName = extractNameWithoutExtension({ name: defaultName, extension: ext } as any) - } - - // Sets action to be executed after creation of the file - if (!isFolder) { - //this.newFileAction = openAction // TODO + defaultName = resolveFileNameDuplicate(defaultName, '', unref(files)) } - const inputSelectionRange = - isFolder || !areFileExtensionsShown ? null : [0, defaultName.length - (ext.length + 1)] + const inputSelectionRange = null const modal = { variation: 'passive', - title: isFolder ? $gettext('Create a new folder') : $gettext('Create a new file'), + title: $gettext('Create a new folder'), cancelText: $gettext('Cancel'), confirmText: $gettext('Create'), hasInput: true, inputValue: defaultName, - inputLabel: isFolder ? $gettext('Folder name') : $gettext('File name'), - inputError: isFolder - ? checkNewFolderName(defaultName) - : checkNewFileName(areFileExtensionsShown ? defaultName : `${defaultName}.${ext}`), + inputLabel: $gettext('Folder name'), + inputError: checkNewFolderName(defaultName), inputSelectionRange, onCancel: () => store.dispatch('hideModal'), - onConfirm: isFolder - ? addNewFolder - : addAppProviderFile - ? addAppProviderFileFunc - : (fileName) => { - /*if (!this.areFileExtensionsShown) { - fileName = `${fileName}.${ext}` - } - this.addNewFile(fileName)*/ - //TODO - }, + onConfirm: addNewFolder, onInput: checkInputValue } @@ -195,7 +130,7 @@ export const useFileActionsCreateNewFolder = ({ store }: { store?: Store } }, canBeDefault: true, componentType: 'button', - class: 'oc-files-actions-download-archive-trigger' + class: 'oc-files-actions-create-new-folder' } ] }) From f41a535a2dfc593caea6faa67dfdac7d108285a7 Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 27 Apr 2023 15:11:28 +0200 Subject: [PATCH 05/26] Implement composables into CreateAndUpload --- .../src/components/AppBar/CreateAndUpload.vue | 44 +++++++++++++++---- .../components/FilesList/ContextActions.vue | 9 ---- .../files/useFileActionsCreateNewFile.ts | 11 ++--- .../files/useFileActionsCreateNewFolder.ts | 11 ++--- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 61f376ddec0..9917211dd5d 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -25,23 +25,23 @@ >
  • - +
  • - - {{ newFileHandler.menuTitle($gettext) }} + + {{ fileAction.title }}