Files
proton/resources/views/notes/show.php
T

114 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* Карточка заметки.
*
* @var \App\Models\Note $note
* @var \Rsgrinko\Proton\Models\User|null $author
* @var array<int, \Rsgrinko\Proton\Files\Attachment> $attachments
*/
use Rsgrinko\Proton\Support\SignedUrl;
use Rsgrinko\Proton\View\View;
?>
<div class="row">
<h1 style="margin: 0;"><?= View::e((string) $note->title) ?></h1>
<span class="spacer"></span>
<?php if (View::can('note.edit', $note)) { ?>
<a class="btn" href="<?= View::e(View::route('notes.edit', ['id' => $note->id()])) ?>">Править</a>
<?php } ?>
<?php if (View::can('note.delete', $note)) { ?>
<form method="post" action="<?= View::e(View::route('notes.delete', ['id' => $note->id()])) ?>">
<?= View::csrf() ?>
<button type="submit" class="danger">Удалить</button>
</form>
<?php } ?>
</div>
<div class="grid cols-2" style="margin-top: 16px;">
<div class="card">
<h2>Текст</h2>
<?php if (trim((string) $note->body) === '') { ?>
<p class="muted">Пусто.</p>
<?php } else { ?>
<pre class="break"><?= View::e((string) $note->body) ?></pre>
<?php } ?>
</div>
<div class="card">
<h2>Свойства</h2>
<dl class="props">
<dt>Автор</dt>
<dd><?= View::e($author === null ? '—' : (string) $author->login) ?></dd>
<dt>Адресная часть</dt>
<dd class="mono"><?= View::e((string) $note->raw('slug')) ?></dd>
<dt>Закреплена</dt>
<dd><?= $note->pinned ? 'да' : 'нет' ?></dd>
<dt>Создана</dt>
<dd><?= View::e(View::date((string) $note->raw('created_at'))) ?></dd>
<dt>Изменена</dt>
<dd><?= View::e(View::date((string) $note->raw('updated_at'))) ?></dd>
<dt>Файл</dt>
<dd>
<?php if ($note->hasFile()) { ?>
<a href="<?= View::e(View::route('notes.file', ['id' => $note->id()])) ?>"><?= View::e((string) $note->raw('file_name')) ?></a>
<?php $shared = SignedUrl::absolute('notes.file.shared', ['id' => $note->id()], 86400); ?>
<div class="muted small" style="margin-top: 6px;">
Ссылка на сутки, вход по ней не нужен:
<?= View::copy($shared, 'скопировать') ?>
</div>
<?php } else { ?>
—
<?php } ?>
</dd>
</dl>
</div>
</div>
<?php if ($attachments !== []) { ?>
<div class="card">
<h2>Вложения (<?= count($attachments) ?>)</h2>
<div class="attachments">
<?php foreach ($attachments as $attachment) { ?>
<?php $url = View::route('notes.attachment', ['id' => $note->id(), 'attachment' => $attachment->id()]); ?>
<div class="attachment">
<a href="<?= View::e($url) ?>">
<?php if ($attachment->isImage()) { ?>
<img src="<?= View::e($url) ?>" alt="<?= View::e((string) $attachment->raw('name')) ?>">
<?php } else { ?>
<span class="file-icon"><?= View::e(strtoupper(pathinfo((string) $attachment->raw('name'), PATHINFO_EXTENSION)) ?: 'файл') ?></span>
<?php } ?>
</a>
<div class="small break"><?= View::e((string) $attachment->raw('name')) ?></div>
<div class="muted small"><?= View::e($attachment->readableSize()) ?></div>
<?php if (View::can('note.edit', $note)) { ?>
<form method="post" action="<?= View::e(View::route('notes.detach', ['id' => $note->id()])) ?>">
<?= View::csrf() ?>
<input type="hidden" name="attachment" value="<?= $attachment->id() ?>">
<button type="submit" class="small danger" data-confirm="Убрать вложение? Файл удалится.">Убрать</button>
</form>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<?= View::partial('history', ['entity' => 'note', 'id' => $note->id()]) ?>
<p><a href="<?= View::e(View::route('notes.index')) ?>">← ко всем заметкам</a></p>