Skip to content

Commit

Permalink
fix: Listen on printing shortcut to open print view for printing
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Apr 16, 2023
1 parent 1a6ad95 commit 297d574
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Collective/CollectiveActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<NcActionSeparator v-if="collectiveCanShare(collective) && !isPublic" />
<NcActionLink :close-after-click="true"
:href="printLink"
target="_blank">
target="ncCollectivesPrint">
{{ t('collectives', 'Export or print') }}
<template #icon>
<DownloadIcon :size="20" />
Expand Down Expand Up @@ -142,6 +142,7 @@ export default {
'isCollectiveAdmin',
'isPublic',
'loading',
'printLink',
]),
isContactsInstalled() {
Expand Down Expand Up @@ -174,6 +175,10 @@ export default {
? generateUrl(`/apps/collectives/p/${this.shareTokenParam}/print/${this.collective.name}`)
: generateUrl(`/apps/collectives/_/print/${this.collective.name}`)
},
unshareIcon() {
return this.loading('unshare') ? 'icon-loading-small' : 'icon-public'
},
},
watch: {
Expand Down
5 changes: 5 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateUrl } from '@nextcloud/router'
import Vue, { set } from 'vue'
import Vuex, { Store } from 'vuex'

Expand Down Expand Up @@ -53,6 +54,10 @@ export default new Store({

isTextEdit: (state) => state.textMode === pageModes.MODE_EDIT,
isTextView: (state) => state.textMode === pageModes.MODE_VIEW,

printLink: (_state, get) => get.isPublic
? generateUrl(`/apps/collectives/p/${get.shareTokenParam}/print/${get.currentCollective.name}`)
: generateUrl(`/apps/collectives/_/print/${get.currentCollective.name}`),
},

mutations: {
Expand Down
29 changes: 29 additions & 0 deletions src/views/CollectiveView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<script>
import { mapGetters, mapMutations } from 'vuex'
import { showWarning } from '@nextcloud/dialogs'
import { NcAppContent, NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import Collective from '../components/Collective.vue'
import CollectiveNotFound from '../components/CollectiveNotFound.vue'
import PageList from '../components/PageList.vue'
Expand All @@ -39,12 +41,39 @@ export default {
...mapGetters([
'currentCollective',
'loading',
'printLink',
'showing',
]),
},
mounted() {
window.addEventListener('keydown', this.printKeyHandler)
},
beforeDestroy() {
window.removeEventListener('keydown', this.printKeyHandler)
},
methods: {
...mapMutations(['hide']),
/**
* @param {KeyboardEvent} event the keydown event
*/
printKeyHandler(event) {
// Handle `CTRL+P` or `CMD+P` but ensure ALT or SHIFT are NOT pressed (e.g. CTRL+SHIFT+P is new private tab on firefox)
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'p' && !(event.altKey || event.shiftKey)) {
const handle = window.open(this.printLink, 'ncCollectivesPrint')
if (handle === null) {
// This might happen because of popup blockers etc
showWarning(t('collectives', 'Could not open print view, document might be formatted incorrectly.'))
} else {
handle.focus()
event.preventDefault()
event.stopImmediatePropagation()
}
}
},
},
}
</script>
Expand Down

0 comments on commit 297d574

Please sign in to comment.