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

allow pasting Activities using paste command #5454

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
51 changes: 43 additions & 8 deletions frontend/src/components/program/DialogActivityCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ export default {
watch: {
showDialog: function (showDialog) {
if (showDialog) {
if (!this.scheduleEntry.start) {
this.scheduleEntry.start = this.$date
.utc(this.period.start)
.add(8, 'hour')
.format()
}
if (!this.scheduleEntry.end) {
this.scheduleEntry.end = this.$date
.utc(this.period.start)
.add(9, 'hour')
.format()
}
this.refreshCopyActivitySource()
this.setEntityData({
title: this.entityData?.title,
Expand Down Expand Up @@ -249,6 +261,10 @@ export default {
},
mounted() {
this.api.href(this.api.get(), 'activities').then((url) => (this.entityUri = url))
window.addEventListener('paste', this.pasteHandler)
},
beforeUnmount() {
window.removeEventListener('paste', this.pasteHandler)
},
methods: {
refreshCopyActivitySource() {
Expand Down Expand Up @@ -276,25 +292,44 @@ export default {
}
)
},
isActivitySource(value) {
if (value?.startsWith(window.location.origin)) {
const url = value.substring(window.location.origin.length)
const match = router.matcher.match(url)
return match.name === 'activity'
}
return false
},
async getCopyActivitySource(url) {
if (url?.startsWith(window.location.origin)) {
if (this.isActivitySource(url)) {
url = url.substring(window.location.origin.length)
const match = router.matcher.match(url)
const scheduleEntry = await this.api
.get()
.scheduleEntries({ id: match.params['scheduleEntryId'] })

if (match.name === 'activity') {
const scheduleEntry = await this.api
.get()
.scheduleEntries({ id: match.params['scheduleEntryId'] })

return await scheduleEntry.activity()
}
return await scheduleEntry.activity()
}
return null
},
async clearClipboard() {
await navigator.clipboard.writeText('')
this.refreshCopyActivitySource()
},
/// Handles the Paste event which still can be used if the user doesnt grant permission
async pasteHandler(event) {
const url = (event.clipboardData || window.clipboardData).getData('text')
if (!this.isActivitySource(url) || this.copyActivitySourceUrlShowPopover) return
if (this.copyActivitySource == null) {
const copyActivitySource = await this.getCopyActivitySource(url)
pmattmann marked this conversation as resolved.
Show resolved Hide resolved
this.copyActivitySource = await copyActivitySource?._meta.load
}
if (this.copyActivitySource != null) {
this.showDialog = true // on paste make sure this dialog opens
this.copyContent = true
event.preventDefault()
}
},
cancelCreate() {
this.close()
},
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/components/program/ScheduleEntries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
right
class="fab--bottom_nav float-right"
color="red"
@click.stop="createNewActivity()"
@click.stop="showActivityCreateDialog()"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
Expand Down Expand Up @@ -77,17 +77,6 @@ export default {
},

methods: {
createNewActivity() {
this.newScheduleEntry.start = this.$date
.utc(this.period.start)
.add(8, 'hour')
.format()
this.newScheduleEntry.end = this.$date
.utc(this.period.start)
.add(9, 'hour')
.format()
this.showActivityCreateDialog()
},
showActivityCreateDialog() {
this.$refs.dialogActivityCreate.showDialog = true
},
Expand Down
Loading