-
Notifications
You must be signed in to change notification settings - Fork 155
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
Create and open shortcut #9890
Merged
Merged
Create and open shortcut #9890
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c048cf
The greatest technican that ever lived
AlexAndBear dac527d
Base
AlexAndBear 54979bd
More base
AlexAndBear ffe14e8
Prevent xss attacks
AlexAndBear bcb208c
Add handler
AlexAndBear fbddc5c
Improve ui
AlexAndBear 25812a4
use location instead of window location
AlexAndBear 4995d80
Add unit test
AlexAndBear 9ca8459
Add unit test
AlexAndBear 955cca4
change icon
AlexAndBear 78e6987
Open in new tab
AlexAndBear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be done in a followup but just a blank text |
||
<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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the
create-list-shortcut
used anywhere?