-
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.
- Loading branch information
1 parent
06249f7
commit 2ab337a
Showing
15 changed files
with
536 additions
and
11 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/design-system/src/assets/icons/resource-type-url-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<portal to="app.runtime.modal"> | ||
<oc-modal | ||
:title="$gettext('Create a Shortcut')" | ||
:button-cancel-text="$gettext('Cancel')" | ||
:button-confirm-text="$gettext('Create')" | ||
:button-confirm-disabled="confirmButtonDisabled" | ||
@cancel="cancel" | ||
@confirm="createShortcut" | ||
> | ||
<template #content> | ||
url | ||
<oc-text-input v-model="inputUrl" /> | ||
<div class="oc-flex oc-flex-bottom oc-width-1-1 oc-mt-m"> | ||
<oc-text-input | ||
v-model="inputFilename" | ||
class="oc-width-1-1" | ||
:label="$gettext('Shortcut name')" | ||
/> | ||
<span class="oc-ml-s">.url</span> | ||
</div> | ||
</template> | ||
</oc-modal> | ||
</portal> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType, ref, unref, computed } from 'vue' | ||
import { SpaceResource } from '@ownclouders/web-client' | ||
import { useClientService, useStore } from '../composables' | ||
import { urlJoin } from '@ownclouders/web-client/src/utils' | ||
import { useGettext } from 'vue3-gettext' | ||
import DOMPurify from 'dompurify' | ||
export default defineComponent({ | ||
name: 'CreateShortcutModal', | ||
props: { | ||
space: { | ||
type: Object as PropType<SpaceResource>, | ||
required: true | ||
}, | ||
cancel: { | ||
type: Function as PropType<(...args: any) => unknown>, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const clientService = useClientService() | ||
const { $gettext } = useGettext() | ||
const store = useStore() | ||
const inputUrl = ref('') | ||
const inputFilename = ref('') | ||
const confirmButtonDisabled = computed(() => !(unref(inputUrl) && unref(inputFilename))) | ||
const currentFolder = computed(() => { | ||
return store.getters['Files/currentFolder'] | ||
}) | ||
const createShortcut = async () => { | ||
// Closes the modal | ||
props.cancel() | ||
try { | ||
// Omit possible xss code | ||
const sanitizedUrl = DOMPurify.sanitize(unref(inputUrl), { USE_PROFILES: { html: true } }) | ||
const content = `[InternetShortcut]\nURL=${unref(sanitizedUrl)}` | ||
const path = urlJoin(unref(currentFolder).path, `${unref(inputFilename)}.url`) | ||
const resource = await clientService.webdav.putFileContents(props.space, { | ||
path, | ||
content | ||
}) | ||
store.commit('Files/UPSERT_RESOURCE', resource) | ||
store.dispatch('showMessage', { | ||
title: $gettext('Shortcut was created successfully') | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
store.dispatch('showErrorMessage', { | ||
title: $gettext('Failed to create shortcut'), | ||
error: e | ||
}) | ||
} | ||
} | ||
return { | ||
confirmButtonDisabled, | ||
createShortcut, | ||
inputUrl, | ||
inputFilename | ||
} | ||
} | ||
}) | ||
</script> |
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
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
46 changes: 46 additions & 0 deletions
46
packages/web-pkg/src/composables/actions/files/useFileActionsCreateNewShortcut.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,46 @@ | ||
import { Resource } from '@ownclouders/web-client/src/helpers' | ||
import { Store } from 'vuex' | ||
import { computed, unref, ref } from 'vue' | ||
import { useStore } from '../../store' | ||
import { FileAction } from '../../../' | ||
import { useGettext } from 'vue3-gettext' | ||
|
||
export const useFileActionsCreateNewShortcut = ({ store }: { store?: Store<any> } = {}) => { | ||
store = store || useStore() | ||
const { $gettext } = useGettext() | ||
const currentFolder = computed((): Resource => store.getters['Files/currentFolder']) | ||
|
||
const modalOpen = ref(false) | ||
|
||
const closeModal = () => { | ||
modalOpen.value = false | ||
} | ||
|
||
const handler = () => { | ||
modalOpen.value = true | ||
} | ||
|
||
const actions = computed((): FileAction[] => { | ||
return [ | ||
{ | ||
name: 'create-shortcut', | ||
icon: 'external-link', | ||
handler, | ||
label: () => { | ||
return $gettext('New Shortcut') | ||
}, | ||
isEnabled: () => { | ||
return unref(currentFolder)?.canCreate() | ||
}, | ||
componentType: 'button', | ||
class: 'oc-files-actions-create-new-shortcut' | ||
} | ||
] | ||
}) | ||
|
||
return { | ||
actions, | ||
modalOpen, | ||
closeModal | ||
} | ||
} |
Oops, something went wrong.