Skip to content

Commit

Permalink
feat: Allow to export or print single pages or pages with subpages
Browse files Browse the repository at this point in the history
* Listen on printing shortcut to open print view for printing
* Hide toastify dialogs when printing
* Make sure background is removed

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jul 28, 2023
1 parent 2475b0f commit 50d77bc
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
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">
{{ t('collectives', 'Export or print') }}
<template #icon>
<DownloadIcon :size="20" />
Expand Down Expand Up @@ -142,6 +142,7 @@ export default {
'isCollectiveAdmin',
'isPublic',
'loading',
'printLink',
]),
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() {
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*' }],
},
{
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)
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
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

0 comments on commit 50d77bc

Please sign in to comment.