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

Fix styling and move towards standard TemplateResponse #202

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
globals: {
appName: true,
PDFViewerApplicationOptions: true,
PDFViewerApplication: true,
pdfjsLib: true,
},
extends: [
'@nextcloud',
]
],
}
15 changes: 0 additions & 15 deletions css/style.css

This file was deleted.

37 changes: 37 additions & 0 deletions css/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Prevent printing from the browser when the download of a share is hidden
@media print {
.pdfViewer.disabledTextSelection {
visibility: hidden;
display: none;
}
}

// Prevent text selection when the download of a share is hidden
.pdfViewer.disabledTextSelection .textLayer {
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}

// Override text cursor in descendants
.pdfViewer.disabledTextSelection .textLayer * {
cursor: default;
}

// Hide unwanted toolbar actions
#secondaryOpenFile,
#openFile,
#sidebarResizer {
display: none !important;
}

// Override default styling
#content {
height: 100%;
width: 100%;
#sidebarContent *,
#viewer * {
box-sizing: content-box;
}
}
20 changes: 0 additions & 20 deletions css/viewer.css

This file was deleted.

39 changes: 31 additions & 8 deletions lib/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,62 @@
use OCA\Files_PDFViewer\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Util;

class DisplayController extends Controller {

/** @var IURLGenerator */
private $urlGenerator;

/** @var IInitialStateService */
private $initialStateService;

/**
* @param IRequest $request
* @param IURLGenerator $urlGenerator
*/
public function __construct(IRequest $request,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
IInitialStateService $initialStateService) {
parent::__construct(Application::APP_ID, $request);

$this->urlGenerator = $urlGenerator;
$this->initialStateService = $initialStateService;
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @param bool $minmode
* @return TemplateResponse
* @return StandaloneTemplateResponse
*/
public function showPdfViewer(bool $minmode = false): TemplateResponse {
$params = [
'urlGenerator' => $this->urlGenerator,
'minmode' => $minmode
];
public function showPdfViewer(bool $minmode = false): StandaloneTemplateResponse {
if ($minmode) {
Util::addStyle(Application::APP_ID, 'minmode');
}

Util::addScript(Application::APP_ID, 'files_pdfviewer-workersrc');
Util::addScript(Application::APP_ID, 'pdfjs/build/pdf');
Util::addScript(Application::APP_ID, 'pdfjs/web/viewer');

Util::addStyle(Application::APP_ID, 'style');
Util::addStyle(Application::APP_ID, '../js/pdfjs/web/viewer');

$workerSrc = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.worker.js');
$cmapUrl = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/cmaps/');
$localeUrl = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/locale/locale.properties');

$this->initialStateService->provideInitialState(Application::APP_ID, 'workerSrc', $workerSrc);
$this->initialStateService->provideInitialState(Application::APP_ID, 'cmapUrl', $cmapUrl);
Util::addHeader('link', ['rel' => 'resource', 'type' => 'application/l10n', 'href' => $localeUrl]);

$response = new TemplateResponse(Application::APP_ID, 'viewer', $params, 'blank');
$response = new StandaloneTemplateResponse(Application::APP_ID, 'viewer', [], TemplateResponse::RENDER_AS_BASE);

$policy = new ContentSecurityPolicy();
$policy->addAllowedChildSrcDomain('\'self\'');
Expand Down
Loading