170 lines
4.9 KiB
PHP
170 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace rosavox\renderings;
|
|
|
|
require_once('helpers/list.php');
|
|
require_once('helpers/string.php');
|
|
require_once('helpers/misc.php');
|
|
require_once('entities/doc.php');
|
|
require_once('services/doc.php');
|
|
require_once('nav.php');
|
|
|
|
|
|
/**
|
|
*/
|
|
function doc_list() : string
|
|
{
|
|
return \rosavox\helpers\misc\render(
|
|
'docs-list',
|
|
[
|
|
'label_make' => \rosavox\helpers\misc\translate('action.make'),
|
|
'link_make' => \rosavox\make_link('make', []),
|
|
'entries' => \implode(
|
|
"\n",
|
|
\rosavox\helpers\list_\map(
|
|
\rosavox\services\doc\dump(),
|
|
fn ($entry) => \rosavox\helpers\misc\render(
|
|
'docs-list-entry',
|
|
[
|
|
'label_read' => \rosavox\helpers\misc\translate('action.read'),
|
|
'value_text' => $entry['value']->title,
|
|
'value_link_open' => \rosavox\make_link('edit', ['id' => \sprintf('%u', $entry['id'])]),
|
|
'value_link_read' => \rosavox\services\doc\readable_path($entry['id']),
|
|
'area_download_readable' => (
|
|
(fn ($name, $path) => (
|
|
(! \file_exists($path))
|
|
?
|
|
\rosavox\helpers\misc\render(
|
|
'state-waiting',
|
|
[
|
|
'info' => \rosavox\helpers\misc\translate('state.generating'),
|
|
]
|
|
)
|
|
:
|
|
\rosavox\helpers\misc\render(
|
|
'download',
|
|
[
|
|
'text' => \rosavox\helpers\misc\translate('item.readable.short'),
|
|
'tooltip' => \rosavox\helpers\string_\coin(
|
|
'{{item}} {{action}}',
|
|
[
|
|
'action' => \rosavox\helpers\misc\translate('action.download'),
|
|
'item' => \rosavox\helpers\misc\translate('item.readable.long'),
|
|
]
|
|
),
|
|
'link' => $path,
|
|
'name' => \rosavox\helpers\string_\coin(
|
|
'{{name}}.md',
|
|
[
|
|
'name' => $name,
|
|
]
|
|
),
|
|
'type' => 'text/markdown',
|
|
]
|
|
)
|
|
)) (
|
|
\rosavox\services\doc\name($entry['id']),
|
|
\rosavox\services\doc\readable_path($entry['id'])
|
|
)
|
|
),
|
|
'area_download_audible' => (
|
|
(fn ($name, $path) => (
|
|
(! \file_exists($path))
|
|
?
|
|
\rosavox\helpers\misc\render(
|
|
'state-waiting',
|
|
[
|
|
'info' => \rosavox\helpers\misc\translate('state.generating'),
|
|
]
|
|
)
|
|
:
|
|
\rosavox\helpers\misc\render(
|
|
'download',
|
|
[
|
|
'text' => \rosavox\helpers\misc\translate('item.audible.short'),
|
|
'tooltip' => \rosavox\helpers\string_\coin(
|
|
'{{item}} {{action}}',
|
|
[
|
|
'action' => \rosavox\helpers\misc\translate('action.download'),
|
|
'item' => \rosavox\helpers\misc\translate('item.audible.long'),
|
|
]
|
|
),
|
|
'link' => $path,
|
|
'name' => \rosavox\helpers\string_\coin(
|
|
'{{name}}.oga',
|
|
[
|
|
'name' => $name,
|
|
]
|
|
),
|
|
'type' => 'audio/ogg',
|
|
]
|
|
)
|
|
)) (
|
|
\rosavox\services\doc\name($entry['id']),
|
|
\rosavox\services\doc\audible_path($entry['id'])
|
|
)
|
|
),
|
|
'area_hear' => (
|
|
(fn ($name, $path) => (
|
|
(! \file_exists($path))
|
|
?
|
|
\rosavox\helpers\misc\render(
|
|
'state-waiting',
|
|
[
|
|
'info' => \rosavox\helpers\misc\translate('state.generating'),
|
|
]
|
|
)
|
|
:
|
|
\rosavox\helpers\misc\render(
|
|
'player',
|
|
[
|
|
'source_path' => $path,
|
|
]
|
|
)
|
|
)) (
|
|
\rosavox\services\doc\name($entry['id']),
|
|
\rosavox\services\doc\audible_path($entry['id'])
|
|
)
|
|
),
|
|
]
|
|
)
|
|
)
|
|
),
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function doc_edit(?int $id) : string
|
|
{
|
|
$doc = (
|
|
($id === null)
|
|
?
|
|
\rosavox\entities\doc\empty_()
|
|
:
|
|
\rosavox\services\doc\get($id)
|
|
);
|
|
return \rosavox\helpers\misc\render(
|
|
'docs-edit',
|
|
[
|
|
'label_action_back' => \rosavox\helpers\misc\translate('action.back'),
|
|
'label_action_save' => \rosavox\helpers\misc\translate('action.save'),
|
|
'label_action_delete' => \rosavox\helpers\misc\translate('action.delete'),
|
|
'label_doc_title' => \rosavox\helpers\misc\translate('domain.doc.title'),
|
|
'label_doc_authors' => \rosavox\helpers\misc\translate('domain.doc.authors'),
|
|
'label_doc_content' => \rosavox\helpers\misc\translate('domain.doc.content'),
|
|
'label_doc_reasoning' => \rosavox\helpers\misc\translate('domain.doc.reasoning'),
|
|
'value_action_back' => \rosavox\make_link('list', []),
|
|
'value_action_save' => \rosavox\make_link('save', (($id === null) ? [] : ['id' => \strval($id)])),
|
|
'value_action_delete' => \rosavox\make_link('delete', (($id === null) ? [] : ['id' => \strval($id)])),
|
|
'value_doc_title' => $doc->title,
|
|
'value_doc_authors' => \implode(', ', $doc->authors),
|
|
'value_doc_content' => $doc->content,
|
|
'value_doc_reasoning' => ($doc->reasoning ?? ''),
|
|
]
|
|
);
|
|
}
|
|
|
|
?>
|