From 6bb92aed3cdf04a87e5d2379de5651e8e2ea9946 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Sun, 29 Dec 2024 19:26:47 +0300 Subject: [PATCH] add viewer and gallery --- Web/Models/Entities/Document.php | 5 + Web/Presenters/DocumentsPresenter.php | 28 ++++++ Web/Presenters/templates/Documents/List.xml | 16 ++-- Web/Presenters/templates/Documents/Page.xml | 74 ++++++++++++++ Web/Presenters/templates/Documents/Upload.xml | 5 +- .../templates/Documents/components/doc.xml | 6 +- .../templates/Documents/components/image.xml | 19 ++++ Web/routes.yml | 2 + Web/static/css/main.css | 73 +++++++++++++- Web/static/js/al_docs.js | 96 ++++++++++++++++--- bootstrap.php | 5 + locales/ru.strings | 4 + 12 files changed, 309 insertions(+), 24 deletions(-) create mode 100644 Web/Presenters/templates/Documents/Page.xml create mode 100644 Web/Presenters/templates/Documents/components/image.xml diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php index 05e44a58..7093e1ed 100644 --- a/Web/Models/Entities/Document.php +++ b/Web/Models/Entities/Document.php @@ -156,6 +156,11 @@ class Document extends Media return false; } + function isImage(): bool + { + return in_array($this->getVKAPIType(), [3, 4]); + } + function isCopiedBy(User $user): bool { if($user->getId() === $this->getOwnerID()) diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index f95a3242..6fd827d7 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -2,6 +2,7 @@ namespace openvk\Web\Presenters; use openvk\Web\Models\Repositories\{Documents, Clubs}; use openvk\Web\Models\Entities\Document; +use Nette\InvalidStateException as ISE; final class DocumentsPresenter extends OpenVKPresenter { @@ -10,6 +11,8 @@ final class DocumentsPresenter extends OpenVKPresenter function renderList(?int $owner_id = NULL): void { + $this->assertUserLoggedIn(); + $this->template->_template = "Documents/List.xml"; if($owner_id > 0) $this->notFound(); @@ -110,6 +113,10 @@ final class DocumentsPresenter extends OpenVKPresenter $document->save(); } catch(\TypeError $e) { $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); + } catch(ISE $e) { + $this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax); + } catch(\ValueError $e) { + $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); } if(!$isAjax) { @@ -121,4 +128,25 @@ final class DocumentsPresenter extends OpenVKPresenter ]); } } + + function renderPage(int $virtual_id, int $real_id): void + { + $this->assertUserLoggedIn(); + + $access_key = $this->queryParam("key"); + $doc = (new Documents)->getDocumentById((int)$virtual_id, (int)$real_id); + if(!$doc || $doc->isDeleted()) + $this->notFound(); + + if(!$doc->checkAccessKey($access_key)) + $this->notFound(); + + $this->template->doc = $doc; + $this->template->type = $doc->getVKAPIType(); + $this->template->is_image = $doc->isImage(); + $this->template->tags = $doc->getTags(); + $this->template->copied = $doc->isCopiedBy($this->user->identity); + $this->template->copyImportance = true; + $this->template->modifiable = $doc->canBeModifiedBy($this->user->identity); + } } diff --git a/Web/Presenters/templates/Documents/List.xml b/Web/Presenters/templates/Documents/List.xml index ea38f865..cd662aff 100644 --- a/Web/Presenters/templates/Documents/List.xml +++ b/Web/Presenters/templates/Documents/List.xml @@ -18,6 +18,7 @@ {/block} {block content} + {var $is_gallery = $current_tab == 3 || $current_tab == 4}
+ {foreach $tags as $tag} + + {$tag}{if $tag != $tags[sizeof($tags) - 1]},{/if} + + {/foreach} +
+