Skip to content
Open
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
12 changes: 9 additions & 3 deletions lib/Controller/PublicStartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function showAuthFailed(): TemplateResponse {
#[PublicPage]
#[NoCSRFRequired]
#[AnonRateLimit(limit: 10, period: 60)]
public function showShare(): PublicTemplateResponse {
public function showShare(string $path = ''): PublicTemplateResponse {
if ($appsMissing = $this->checkDependencies()) {
return new PublicTemplateResponse('collectives', 'error', ['appsMissing' => $appsMissing]); // templates/error.php
}
Expand All @@ -132,11 +132,14 @@ public function showShare(): PublicTemplateResponse {
'token' => $this->getToken(),
]);
$response->setFooterVisible(false);
$this->setHeader($response);
$this->setHeader($response, str_starts_with($path, 'print/'));
return $response;
}

private function setHeader(PublicTemplateResponse $response): void {
/**
* @param bool $isPrintView The print view has its own export button, so it gets no header actions
*/
private function setHeader(PublicTemplateResponse $response, bool $isPrintView): void {
try {
$share = $this->collectiveShareMapper->findOneByToken($this->getToken());
$collective = $this->collectiveService->getCollective($share->getCollectiveId(), $share->getOwner());
Expand All @@ -146,6 +149,9 @@ private function setHeader(PublicTemplateResponse $response): void {

$emoji = $collective->getEmoji();
$response->setHeaderTitle($emoji ? $emoji . ' ' . $collective->getName() : $collective->getName());
if ($isPrintView) {
return;
}
$response->setHeaderActions([
new SimpleMenuAction(
'print',
Expand Down
114 changes: 103 additions & 11 deletions playwright/e2e/collective-print.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,40 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { expect } from '@playwright/test'
import { test } from '../support/fixtures/create-collectives.ts'
import type { Page } from '@playwright/test'

import { expect, mergeTests } from '@playwright/test'
import { test as createCollectiveTest } from '../support/fixtures/create-collectives.ts'
import { test as navigationTest } from '../support/fixtures/navigation.ts'

const test = mergeTests(createCollectiveTest, navigationTest)

type PrintWindow = Window & { __printCalls?: number }

/**
* Stub window.print in all pages of the browser context, so the real print dialog doesn't block the test
*
* Counts the calls in `window.__printCalls`.
*
* @param page Playwright page of the browser context
*/
async function stubPrint(page: Page) {
await page.context().addInitScript(() => {
(window as PrintWindow).__printCalls = 0
window.print = () => {
(window as PrintWindow).__printCalls! += 1
}
})
}

/**
* Number of window.print calls in a page with `stubPrint`
*
* @param page Playwright page
*/
function printCalls(page: Page) {
return page.evaluate(() => (window as PrintWindow).__printCalls)
}

test.describe('Collective print view', () => {
test('loads all images before opening print dialog', async ({ user, page, collective }) => {
Expand All @@ -27,13 +59,7 @@ test.describe('Collective print view', () => {
})
}

// Stub window.print so the real print dialog doesn't block the test
await page.addInitScript(() => {
(window as Window & { __printCalls?: number }).__printCalls = 0
window.print = () => {
(window as Window & { __printCalls?: number }).__printCalls! += 1
}
})
await stubPrint(page)

await page.goto(`/index.php/apps/collectives/_/print/${collective.getCollectiveUrlPart()}`)

Expand All @@ -42,8 +68,10 @@ test.describe('Collective print view', () => {
await expect(page.getByText('Preparing collective for exporting or printing'))
.toBeHidden({ timeout: 30000 })

const printCalls = await page.evaluate(() => (window as Window & { __printCalls?: number }).__printCalls)
expect(printCalls).toBeGreaterThan(0)
// The print dialog only opens on request
expect(await printCalls(page)).toBe(0)
await page.getByRole('button', { name: 'Export or print' }).click()
await expect.poll(() => printCalls(page), { timeout: 20000 }).toBe(1)

const imgs = page.locator('div.ProseMirror figure.image img.image__main')
const count = await imgs.count()
Expand All @@ -53,4 +81,68 @@ test.describe('Collective print view', () => {
expect(naturalWidth, `image ${i} should have loaded`).toBeGreaterThan(0)
}
})

test('selects the pages to export in the page list', async ({ user, page, collective, navigation }) => {
const parent = await collective.createPage({ title: 'Parent', user, page })
await collective.createPage({ title: 'Child', parentId: parent.data.id, user, page })
await collective.createPage({ title: 'Other', user, page })
await stubPrint(page)

await collective.openCollective()
const popupPromise = page.waitForEvent('popup')
await navigation.clickCollectiveMenu(collective.data.name, 'Export or print')
const printPage = await popupPromise

await expect(printPage.getByText('Preparing collective for exporting or printing'))
.toBeHidden({ timeout: 30000 })
const pageList = printPage.getByRole('navigation', { name: 'Pages to export or print' })
const checkbox = (name: string) => pageList.getByRole('checkbox', { name, exact: true })
await expect(printPage.locator('.print-page:visible h2.page-title-collective'))
.toContainText(collective.data.name)
// Titles of the shown subpages, sorted as sibling order depends on the creation time
const subpageTitles = () => expect.poll(async () => (await printPage
.locator('.print-page:visible h2.page-title:not(.page-title-collective)')
.allTextContents()).map((title) => title.trim()).sort())
await subpageTitles().toEqual(['Child', 'Other', 'Parent'])

// Subpages are listed nested in their parent page
await expect(pageList.getByRole('listitem')
// `has` locators are resolved within the list item, so they must not start at `pageList`
.filter({ has: printPage.getByRole('checkbox', { name: 'Parent', exact: true }) })
.getByRole('list')
.getByRole('checkbox', { name: 'Child', exact: true })).toBeChecked()

// Unselecting a page unselects its subpages and hides them from the print view
await pageList.getByText('Parent', { exact: true }).click()
await expect(checkbox('Parent')).not.toBeChecked()
await expect(checkbox('Child')).not.toBeChecked()
await subpageTitles().toEqual(['Other'])

// Subpages can still be selected individually
await pageList.getByText('Child', { exact: true }).click()
await subpageTitles().toEqual(['Child', 'Other'])

await pageList.getByText('Other', { exact: true }).click()
await subpageTitles().toEqual(['Child'])

// The selection is kept in the URL
await expect(printPage).toHaveURL(/[?&](pages|exclude)=/)
await printPage.reload()
await expect(printPage.getByText('Preparing collective for exporting or printing'))
.toBeHidden({ timeout: 30000 })
await subpageTitles().toEqual(['Child'])
await expect(checkbox('Other')).not.toBeChecked()

await printPage.getByRole('button', { name: 'Export or print' }).click()
await expect.poll(() => printCalls(printPage)).toBe(1)
await printPage.close()
})

test('shows an empty state if no requested page exists', async ({ page, collective }) => {
await stubPrint(page)
await page.goto(`/index.php/apps/collectives/_/print/${collective.getCollectiveUrlPart()}?pages=999999999`)

await expect(page.getByText('No pages to export or print')).toBeVisible()
await expect(page.getByText('Preparing collective for exporting or printing')).toBeHidden()
})
})
9 changes: 8 additions & 1 deletion playwright/e2e/collective-share.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ test.describe('Collective share', () => {
await expect(sharePage.locator('#header .header-title')).toContainText(collective.data.name)
await expect(sharePage.locator('.collective-selector')).toHaveCount(0)
// Older Nextcloud versions expose the header action link with role "button"
await expect(sharePage.locator('#header a', { hasText: 'Export or print' }))
const exportLink = sharePage.locator('#header a', { hasText: 'Export or print' })
await expect(exportLink)
.toHaveAttribute('href', new RegExp(`/p/${shares[0].data.token}/print/`))

// Allows to filter pages
await expect(sharePageList.el).toBeVisible()
await expect(sharePageList.pageListItems.filter({ visible: true })).toHaveCount(2)
await sharePageList.filter.fill('page')
await expect(sharePageList.pageListItems.filter({ visible: true })).toHaveCount(1)

// The print view has its own export button instead of the header action
await sharePage.goto(await exportLink.getAttribute('href') as string)
await expect(sharePage.getByRole('navigation', { name: 'Pages to export or print' }).getByRole('button', { name: 'Export or print' })).toBeVisible()
await expect(sharePage.locator('#header .header-title')).toContainText(collective.data.name)
await expect(exportLink).toHaveCount(0)
})

test('Create read-write share and open share unauthenticated', async ({ page, collective, pageSidebar, sharePage, shareEditor, sharePageList, shareTitleBar }) => {
Expand Down
6 changes: 4 additions & 2 deletions playwright/support/sections/NavigationSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ export class NavigationSection {
await this.page.getByRole('button', { name: 'Collective actions' })
.click()
// The extra `.action-item__popover` locator is needed to not conflict with other button with same name in DOM
await this.page.locator('.action-item__popper:visible')
.getByRole('button', { name: action, exact: true })
const popover = this.page.locator('.action-item__popper:visible')
// Actions are either buttons or links (e.g. "Export or print")
await popover.getByRole('button', { name: action, exact: true })
.or(popover.getByRole('link', { name: action, exact: true }))
.click()
}

Expand Down
142 changes: 142 additions & 0 deletions src/components/Collective/CollectivePrintPageTree.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<ul class="print-page-tree">
<li v-for="node in nodes" :key="node.page.id">
<NcCheckboxRadioSwitch
class="print-page-tree__checkbox"
:modelValue="selectedIds.has(node.page.id)"
@update:modelValue="$emit('toggle', node, $event)">
<span class="print-page-tree__label">
<span class="print-page-tree__icon">
<template v-if="pageEmoji(node.page)">{{ pageEmoji(node.page) }}</template>
<PageIcon v-else :size="22" fillColor="var(--color-background-maxcontrast)" />
</span>
<span class="print-page-tree__title">{{ pageTitle(node.page) }}</span>
</span>
</NcCheckboxRadioSwitch>
<CollectivePrintPageTree
v-if="node.children.length"
:nodes="node.children"
:selectedIds
:collective
@toggle="(child: PageTreeNode<PageInfo>, checked: boolean) => $emit('toggle', child, checked)" />
</li>
</ul>
</template>

<script lang="ts">
import type { PropType } from 'vue'
import type { Collective, PageInfo } from '../../types.ts'
import type { PageTreeNode } from '../../util/pageTree.ts'

import { defineComponent } from 'vue'
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
import PageIcon from '../Icon/PageIcon.vue'

export default defineComponent({
name: 'CollectivePrintPageTree',

components: {
NcCheckboxRadioSwitch,
PageIcon,
},

props: {
nodes: {
type: Array as PropType<PageTreeNode<PageInfo>[]>,
required: true,
},

selectedIds: {
type: Set as PropType<Set<number>>,
required: true,
},

collective: {
type: Object as PropType<Collective>,
required: true,
},
},

emits: {
toggle: (node: PageTreeNode<PageInfo>, checked: boolean) => typeof node === 'object' && typeof checked === 'boolean',
},

methods: {
pageTitle(page: PageInfo): string {
return page.parentId === 0 ? this.collective.name : page.title
},

pageEmoji(page: PageInfo): string | undefined {
return (page.parentId === 0 ? this.collective.emoji : page.emoji) || undefined
},
},
})
</script>

<style scoped lang="scss">
.print-page-tree {
display: flex;
flex-direction: column;
padding: 0 var(--default-grid-baseline);

.print-page-tree {
padding: 0;
}

.print-page-tree .print-page-tree {
padding-inline-start: 10px;
}
}

.print-page-tree__checkbox {
min-width: 0;

:deep(.checkbox-radio-switch__content) {
width: 100%;
max-width: 100%;
min-width: 0;
padding-block: 0;
padding-inline-start: calc((var(--default-clickable-area) - 22px) / 2);
}

&:focus-within :deep(.checkbox-radio-switch__content),
:deep(.checkbox-radio-switch__content:hover) {
background-color: color-mix(in srgb, var(--color-primary-element) 8%, transparent) !important;
}

:deep(.checkbox-content__wrapper),
:deep(.checkbox-content__text) {
flex-shrink: 1;
min-width: 0;
}

.print-page-tree__label {
display: flex;
align-items: center;
min-width: 0;
}

.print-page-tree__icon {
display: flex;
flex: 0 0 auto;
align-items: center;
justify-content: center;
min-width: 22px;
height: var(--default-clickable-area);
margin-inline-end: calc((var(--default-clickable-area) - 22px) / 2);
}

.print-page-tree__title {
flex-shrink: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
</style>
Loading
Loading