improve media list view

This commit is contained in:
Dennis Eichhorn 2020-02-02 15:51:25 +01:00
parent 45348609f8
commit 8348b1bb87
8 changed files with 99 additions and 27 deletions

View File

@ -23,7 +23,7 @@ return [
],
[
'dest' => '\Modules\Media\Controller\ApiController:apiMediaUpdate',
'verb' => RouteVerb::POST,
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::CREATE,

View File

@ -22,7 +22,7 @@ jsOMS.Modules.Media = class {
length = e.length;
for (let i = 0; i < length; ++i) {
this.bindElement(e[i]);
//this.bindElement(e[i]);
}
};

View File

@ -26,6 +26,10 @@ use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\System\MimeType;
use Modules\Media\Models\NullCollection;
use phpOMS\Utils\Parser\Markdown\Markdown;
use Modules\Media\Models\Collection;
use Modules\Media\Models\CollectionMapper;
/**
* Media class.
@ -95,20 +99,12 @@ final class ApiController extends Controller
*/
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
/**
* @todo Orange-Management/Modules#202
* Consider to use FormData
* Form data is currently submitted in two steps if it contains media files.
* 1. Upload media data
* 2. Submit form data
* Consider to use `FormData` in order to submit media files and form data at the same time.
*/
$uploads = $this->uploadFiles(
$request->getData('name') ?? '',
$request->getFiles(),
$request->getHeader()->getAccount(),
(string) ($request->getData('path') ?? __DIR__ . '/../../../Modules/Media/Files'),
(string) ($request->getData('virtualPath') ?? '/'),
(string) ($request->getData('virtualPath') ?? ''),
(string) ($request->getData('password') ?? ''),
(string) ($request->getData('encrypt') ?? '')
);
@ -136,7 +132,7 @@ final class ApiController extends Controller
array $files,
int $account,
string $basePath = 'Modules/Media/Files',
string $virtualPath = '/',
string $virtualPath = '',
string $password = '',
string $encryptionKey = ''
) : array
@ -177,7 +173,7 @@ final class ApiController extends Controller
*
* @since 1.0.0
*/
public function createDbEntries(array $status, int $account, string $virtualPath = '/') : array
public function createDbEntries(array $status, int $account, string $virtualPath = '') : array
{
$mediaCreated = [];
@ -215,7 +211,7 @@ final class ApiController extends Controller
*
* @since 1.0.0
*/
public static function createDbEntry(array $status, int $account, string $virtualPath = '/') : ?Media
public static function createDbEntry(array $status, int $account, string $virtualPath = '') : ?Media
{
$media = null;
@ -306,4 +302,43 @@ final class ApiController extends Controller
return $media;
}
/**
* Method to create media collection from request.
*
* @param string $name Collection name
* @param string $description Description
* @param Media[] $media Media files to create the collection from
* @param int $account Account Id
*
* @return Collection
*
* @since 1.0.0
*/
public function createMediaCollectionFromMedia(string $name, string $description, array $media, int $account) : Collection
{
if (empty($media)) {
return new NullCollection();
}
// is allowed to create media file
if (!$this->app->accountManager->get($account)->hasPermission(
PermissionType::CREATE, $this->app->orgId, null, self::MODULE_NAME, PermissionState::COLLECTION, null)
) {
return new NullCollection();
}
/* Create collection */
$mediaCollection = new Collection();
$mediaCollection->setName($name);
$mediaCollection->setDescription(Markdown::parse($description));
$mediaCollection->setDescriptionRaw($description);
$mediaCollection->setCreatedBy($account);
$mediaCollection->setSources($media);
$mediaCollection->setVirtualPath('/Modules/Helper');
CollectionMapper::create($mediaCollection);
return $mediaCollection;
}
}

View File

@ -129,8 +129,11 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Media/Theme/Backend/media-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response));
$media = MediaMapper::getByVirtualPath('/');
$path = (string) ($request->getData('path') ?? '/');
$media = MediaMapper::getByVirtualPath($path);
$view->addData('media', $media);
$view->addData('path', $path);
return $view;
}
@ -160,11 +163,16 @@ final class BackendController extends Controller
$media = MediaMapper::get((int) $request->getData('id'));
if ($media->getExtension() === 'collection') {
//$media = CollectionMapper::get($media->getId());
$media = MediaMapper::getByVirtualPath(
$media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->getName()
);
$collection = CollectionMapper::get((int) $request->getData('id'));
$media = \array_merge($media, $collection->getSources());
$view->addData('path', $collection->getVirtualPath() . '/' . $collection->getName());
$view->setTemplate('/Modules/Media/Theme/Backend/media-list');
}

View File

@ -146,13 +146,6 @@ export class Upload {
*
* @return {void}
*
* @todo Orange-Management/Modules#202
* Consider to use FormData
* Form data is currently submitted in two steps if it contains media files.
* 1. Upload media data
* 2. Submit form data
* Consider to use `FormData` in order to submit media files and form data at the same time.
*
* @since 1.0.0
*/
upload (formId)

View File

@ -52,7 +52,7 @@ class BaseView extends View
{
$this->form = $data[0];
$this->name = $data[1];
$this->virtualPath = $data[2] ?? '/';
$this->virtualPath = $data[2] ?? '';
return parent::render();
}
}

View File

@ -12,17 +12,49 @@
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
include __DIR__ . '/template-functions.php';
/**
* @var \phpOMS\Views\View $this
* @var string $parent
*/
$mediaPath = $this->getData('path') ?? '/';
/**
* @var \Modules\Media\Models\Media[] $media
*/
$media = $this->getData('media');
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<div class="box">
<ul class="crumbs-1">
<li data-href="<?= UriFactory::build('{/prefix}media/list?path=/'); ?>"><a href="<?= UriFactory::build('{/prefix}media/list?path=/'); ?>">/</a></li>
<?php
$subPath = '';
$paths = \explode('/', \ltrim($mediaPath, '/'));
$length = \count($paths);
for ($i = 0; $i < $length; ++$i) :
if ($paths[$i] === '') {
continue;
}
$subPath .= '/' . $paths[$i];
$url = $i === $length - 1 ? UriFactory::build('{%}') : UriFactory::build('{/prefix}media/list?path=' . $subPath);
?>
<li data-href="<?= $url; ?>"><a href="<?= $url; ?>"><?= $this->printHtml($paths[$i]); ?></a></li>
<?php endfor; ?>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="box wf-100">
@ -40,7 +72,7 @@ echo $this->getData('nav')->render(); ?>
<?php $count = 0;
foreach ($media as $key => $value) :
++$count;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}media/single?{?}&id=' . $value->getId());
$url = UriFactory::build('{/prefix}media/single?id=' . $value->getId());
$icon = $fileIconFunction(\phpOMS\System\File\FileUtils::getExtensionType($value->getExtension()));
?>
<tr data-href="<?= $url; ?>">

View File

@ -20,8 +20,8 @@ use \phpOMS\Uri\UriFactory;
include __DIR__ . '/template-functions.php';
/**
* @var \phpOMS\Views\View $this
* @var $media \Modules\Media\Models\Media
* @var \phpOMS\Views\View $this
* @var \Modules\Media\Models\Media $media
*/
$media = $this->getData('media');
echo $this->getData('nav')->render();
@ -124,7 +124,11 @@ echo $this->getData('nav')->render();
<template>
<textarea class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content" name="content"></textarea>
</template>
<pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->getFileContent($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/')); ?></pre>
<pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->printHtml(
$this->getFileContent(
$media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/')
)
); ?></pre>
<?php endif; ?>
<?php endif; ?>
</div>