Skip to content

Commit

Permalink
Merge pull request #3725 from LibreSign/backport/3718/stable28
Browse files Browse the repository at this point in the history
[stable28] feat: use Viewer to open pdf
  • Loading branch information
vitormattos authored Sep 17, 2024
2 parents 60f8aaa + c4befd1 commit 03b6c5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCA\Libresign\Service\SessionService;
use OCA\Libresign\Service\SignerElementsService;
use OCA\Libresign\Service\SignFileService;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
Expand All @@ -52,6 +53,7 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand All @@ -73,6 +75,7 @@ public function __construct(
private IAppConfig $appConfig,
private FileService $fileService,
private ValidateHelper $validateHelper,
private IEventDispatcher $eventDispatcher,
private IURLGenerator $url
) {
parent::__construct(
Expand Down Expand Up @@ -111,6 +114,10 @@ public function index(): TemplateResponse {

Util::addScript(Application::APP_ID, 'libresign-main');

if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
}

$response = new TemplateResponse(Application::APP_ID, 'main');

$policy = new ContentSecurityPolicy();
Expand Down Expand Up @@ -530,6 +537,9 @@ public function validationFile(string $uuid): TemplateResponse {
$this->initialState->provideInitialState('file_info', $this->fileService->formatFile());

Util::addScript(Application::APP_ID, 'libresign-validation');
if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
}
$response = new TemplateResponse(Application::APP_ID, 'validation', [], TemplateResponse::RENDER_AS_BASE);

return $response;
Expand Down
16 changes: 13 additions & 3 deletions src/views/Validation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
:use-markdown="true" />

<NcButton type="primary"
@click="viewDocument(document.file)">
@click="viewDocument()">
<template #icon>
<NcLoadingIcon v-if="hasLoading" :size="20" />
</template>
Expand Down Expand Up @@ -194,8 +194,18 @@ export default {
return 'None'
},
viewDocument(val) {
window.open(`${val}?_t=${Date.now()}`)
viewDocument() {
if (OCA?.Viewer !== undefined) {
OCA.Viewer.open({
fileInfo: {
source: this.document.file,
basename: this.document.name,
mime: 'application/pdf',
},
})
} else {
window.open(`${this.document.file}?_t=${Date.now()}`)
}
},
goBack() {
// Redirect if have path to go back
Expand Down

0 comments on commit 03b6c5e

Please sign in to comment.