Skip to content

Commit

Permalink
feat(docs): corct aud/img preview, hide report btn
Browse files Browse the repository at this point in the history
when doc is yours.
  • Loading branch information
mrilyew committed Jan 27, 2025
1 parent 9ea67ac commit 0fb18e3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
10 changes: 10 additions & 0 deletions Web/Models/Entities/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ function isImage(): bool
return in_array($this->getVKAPIType(), [3, 4]);
}

function isBook(): bool
{
return in_array($this->getFileExtension(), ["pdf"]);
}

function isAudio(): bool
{
return in_array($this->getVKAPIType(), [Document::VKAPI_TYPE_AUDIO]);
}

function isGif(): bool
{
return $this->getVKAPIType() == 3;
Expand Down
2 changes: 1 addition & 1 deletion Web/Presenters/DocumentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function renderUpload()
} 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);
$this->flashFail("err", tr("forbidden"), "corrupted file", null, $isAjax);
} catch(\ValueError $e) {
$this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax);
} catch(\ImagickException $e) {
Expand Down
10 changes: 7 additions & 3 deletions Web/Presenters/templates/Documents/Page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

<div class='media-page-wrapper photo-page-wrapper'>
<div class='photo-page-wrapper-photo'>
{if $is_image}
<img alt="doc image" src="{$doc->getURL()}" />
{if $doc->isGif()}
<img class="main_doc_block" alt="doc image" src="{$doc->getURL()}" />
{elseif $doc->isImage()}
<img class="main_doc_block" alt="doc image" src="{$doc->getPreview()->getURLBySizeId('original')}" />
{elseif $doc->isAudio()}
<audio src="{$doc->getURL()}" controls></audio>
{else}
<a href="{$doc->getURL()}" download="{downloadable_name($doc->getName())}">
<input class="button" type="button" value="{_download_file}">
Expand Down Expand Up @@ -63,7 +67,7 @@

{if isset($thisUser)}
<a n:if="$modifiable" class="profile_link" style="display:block;width:96%;" id="edit_icon">{_edit}</a>
<a n:if="$modifiable" class="profile_link" style="display:block;width:96%;" id="report_icon">{_report}</a>
<a n:if="!$modifiable" class="profile_link" style="display:block;width:96%;" id="report_icon">{_report}</a>
<a n:if="!$copied || $copied && $copyImportance" class="profile_link" style="display:block;width:96%;" id="add_icon">{_add}</a>
<a n:if="$copied && !$copyImportance" class="profile_link" style="display:block;width:96%;" id="remove_icon">{_remove}</a>
{/if}
Expand Down
5 changes: 5 additions & 0 deletions Web/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,11 @@ a.poll-retract-vote {
user-select: none;
}

.ovk-photo-view iframe {
width: 90vw;
height: 100vh;
}

.photo_com_title {
font-weight: bold;
padding-bottom: 16px;
Expand Down
36 changes: 19 additions & 17 deletions Web/static/js/al_docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,26 @@ u(document).on('click', '.docMainItem #report_icon', (e) => {
const item = target.closest('.docMainItem')
const id = item.nodes[0].dataset.id.split("_")

MessageBox(tr("report_question"), `
const msg = new CMessageBox({
title: tr("report_question"),
unique_name: "report_doc",
body: `
${tr("going_to_report_doc")}
<br/>${tr("report_question_text")}
<br/><br/><b> ${tr("report_reason")}</b>: <input type='text' id='uReportMsgInput' placeholder='${tr("reason")}' />`, [tr("confirm_m"), tr("cancel")], [(function() {

res = document.querySelector("#uReportMsgInput").value;
xhr = new XMLHttpRequest();
xhr.open("GET", "/report/" + id[1] + "?reason=" + res + "&type=doc", true);
xhr.onload = (function() {
if(xhr.responseText.indexOf("reason") === -1)
MessageBox(tr("error"), tr("error_sending_report"), ["OK"], [Function.noop]);
else
MessageBox(tr("action_successfully"), tr("will_be_watched"), ["OK"], [Function.noop]);
});
xhr.send(null)
}),

Function.noop])
<br/><br/><b> ${tr("report_reason")}</b>: <input type='text' id='uReportMsgInput' placeholder='${tr("reason")}' />`,
buttons: [tr("confirm_m"), tr("cancel")],
callbacks: [(function() {
res = document.querySelector("#uReportMsgInput").value;
xhr = new XMLHttpRequest();
xhr.open("GET", "/report/" + id[1] + "?reason=" + res + "&type=doc", true);
xhr.onload = (function() {
if(xhr.responseText.indexOf("reason") === -1)
MessageBox(tr("error"), tr("error_sending_report"), ["OK"], [Function.noop]);
else
MessageBox(tr("action_successfully"), tr("will_be_watched"), ["OK"], [Function.noop]);
});
xhr.send(null)
}), Function.noop]})
})

u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", async (e) => {
Expand Down Expand Up @@ -287,7 +289,7 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy
const preview = body.querySelector('.photo-page-wrapper-photo')
const details = body.querySelector('.ovk-photo-details')

u(preview.querySelector('img')).attr('id', 'ovk-photo-img')
u(preview.querySelector('.main_doc_block')).attr('id', 'ovk-photo-img')

const photo_viewer = new CMessageBox({
title: '',
Expand Down

0 comments on commit 0fb18e3

Please sign in to comment.