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

Listen on printing shortcut to open print view for printing #544

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/components/Collective/CollectiveActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<NcActionSeparator v-if="collectiveCanShare(collective) && !isPublic" />
<NcActionLink :close-after-click="true"
:href="printLink"
target="_blank">
target="ncCollectivesPrint">
mejo- marked this conversation as resolved.
Show resolved Hide resolved
{{ t('collectives', 'Export or print') }}
<template #icon>
<DownloadIcon :size="20" />
Expand Down Expand Up @@ -142,6 +142,7 @@ export default {
'isCollectiveAdmin',
'isPublic',
'loading',
'printLink',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a leftover, printLink() is defined as computed property below and not available as getter from the store.

]),

circleLink() {
Expand All @@ -166,6 +167,10 @@ export default {
? generateUrl(`/apps/collectives/p/${this.shareTokenParam}/print/${this.collective.name}`)
: generateUrl(`/apps/collectives/_/print/${this.collective.name}`)
},

unshareIcon() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a leftover or copy/paste error as well. unshareIcon() is not used here.

return this.loading('unshare') ? 'icon-loading-small' : 'icon-public'
},
},

watch: {
Expand Down
15 changes: 12 additions & 3 deletions src/components/CollectivePrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ul>
</template>
</NcEmptyContent>
<div v-for="page in pagesTreeWalk()" v-show="!loading" :key="page.id">
<div v-for="page in pages" v-show="!loading" :key="page.id">
<PagePrint :page="page"
@loading="waitingFor.push(page.id)"
@ready="ready(page.id)" />
Expand Down Expand Up @@ -71,6 +71,7 @@ export default {
computed: {
...mapGetters([
'currentCollective',
'currentPage',
'pagesTreeWalk',
'shareTokenParam',
]),
Expand Down Expand Up @@ -98,6 +99,14 @@ export default {

return parts.join(' - ')
},

/**
* List of all pages, empty if pages not loaded
*/
pages() {
if (!this.currentPage) return []
return this.pagesTreeWalk(this.currentPage.parentId)
},
},

mounted() {
Expand All @@ -110,12 +119,12 @@ export default {
}),

/**
* Get list of all pages
* Fetch list of all pages
*/
async getPages() {
await this.dispatchGetPages()
.catch(displayError('Could not fetch pages'))
this.loadPages.total = this.pagesTreeWalk().length
this.loadPages.total = this.pagesTreeWalk(this.currentPage.parentId).length
},

ready(pageId) {
Expand Down
16 changes: 16 additions & 0 deletions src/components/Page/PageActionMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
</template>
{{ deletePageString }}
</NcActionButton>
<NcActionLink :close-after-click="true"
:href="printLink"
target="ncCollectivesPrint">
{{ t('collectives', 'Export or print') }}
<template #icon>
<DownloadIcon :size="20" />
</template>
</NcActionLink>
<NcActionSeparator v-if="lastUserId && lastUserDisplayName" />
<PageActionLastUser :last-user-id="lastUserId" :last-user-display-name="lastUserDisplayName" :timestamp="timestamp" />
</NcActions>
Expand All @@ -85,6 +93,7 @@ import { NcActions, NcActionButton, NcActionLink, NcActionSeparator } from '@nex
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
import CollectiveActions from '../Collective/CollectiveActions.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
import DownloadIcon from 'vue-material-design-icons/Download.vue'
import EmoticonOutlineIcon from 'vue-material-design-icons/EmoticonOutline.vue'
import FormatListBulletedIcon from 'vue-material-design-icons/FormatListBulleted.vue'
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
Expand All @@ -104,6 +113,7 @@ export default {
NcActionLink,
NcActionSeparator,
DeleteIcon,
DownloadIcon,
EmoticonOutlineIcon,
FormatListBulletedIcon,
PagesTemplateIcon,
Expand Down Expand Up @@ -172,11 +182,17 @@ export default {
'hasSubpages',
'loading',
'pagesTreeWalk',
'pageById',
'pagePrintLink',
'showing',
'showTemplates',
'visibleSubpages',
]),

printLink() {
return this.pagePrintLink(this.pageById(this.pageId))
},

toggleOutlineString() {
return this.showing('outline')
? t('collectives', 'Hide outline')
Expand Down
3 changes: 2 additions & 1 deletion src/components/PagePrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 v-if="page.parentId === 0" id="page-title-collective" class="page-title page-title-collective">
{{ currentCollectiveTitle }}
</h1>
<h1 v-else class="page-title page-title-subpage">
<h1 v-else class="page-title" :class="{'page-title-subpage': currentPage.id !== page.id}">
{{ pageTitleString }}
</h1>
<RichTextReader v-if="pageContent"
Expand Down Expand Up @@ -53,6 +53,7 @@ export default {
computed: {
...mapGetters([
'currentCollectiveTitle',
'currentPage',
'pageDavUrl',
'pageDirectory',
'isPublic',
Expand Down
2 changes: 2 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ const routes = [
path: '/_/print/:collective',
component: CollectivePrintView,
props: (route) => route.params,
children: [{ path: ':page*' }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me a quick hint what you want to achieve here? Maybe I oversaw something, but I don't see where this would be used πŸ€”

},
{
path: '/p/:token/print/:collective',
component: CollectivePrintView,
props: (route) => route.params,
children: [{ path: ':page*' }],
},
{
path: '/p/:token/:collective',
Expand Down
8 changes: 8 additions & 0 deletions src/store/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ export default {
return state.pages.find(p => (p.parentId === parentId && p.title === TEMPLATE_PAGE))
},

pagePrintLink: (state, get) => (page) => {
const path = [page.collectivePath.split('/').at(-1), page.filePath.split('/'), page.fileName]
if (path.at(-1) === 'Readme.md') path.splice(-1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use these one-line if () ... syntax so far, I'd prefer to stick to if () { \n ... \n }` 😬

Same for the following two lines.

if (get.isPublic) path.splice(2, 0, 'print')
else path.splice(0, 0, '_', 'print')
return generateUrl(`/apps/collectives/${path.join('/')}`)
},

currentFileIdPage(state, _getters, rootState) {
const fileId = Number(rootState.route.query.fileId)
return state.pages.find(p => (p.id === fileId))
Expand Down
9 changes: 9 additions & 0 deletions src/views/CollectivePrintView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export default {
height: fit-content;
}

html, body {
background: var(--color-main-background, white)!important;
}

/* hide toast notifications for printing */
.toastify.dialogs {
display: none;
}

#content-vue {
position: static;
overflow: visible;
Expand Down
32 changes: 32 additions & 0 deletions src/views/CollectiveView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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,13 +41,43 @@ export default {
computed: {
...mapGetters([
'currentCollective',
'currentPage',
'loading',
'pagePrintLink',
'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)) {
if (!this.currentPage) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


const handle = window.open(this.pagePrintLink(this.currentPage), 'ncCollectivesPrint')
if (handle === null) {
// This might happen because of popup blockers etc
showWarning(t('collectives', 'Could not open print view, try to disable any popup blockers.'))
} else {
handle.focus()
event.preventDefault()
event.stopImmediatePropagation()
}
}
},
},
}
</script>
Expand Down