mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 09:18:42 +00:00
improve media list view
This commit is contained in:
parent
45348609f8
commit
8348b1bb87
|
|
@ -23,7 +23,7 @@ return [
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Media\Controller\ApiController:apiMediaUpdate',
|
'dest' => '\Modules\Media\Controller\ApiController:apiMediaUpdate',
|
||||||
'verb' => RouteVerb::POST,
|
'verb' => RouteVerb::SET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => ApiController::MODULE_NAME,
|
'module' => ApiController::MODULE_NAME,
|
||||||
'type' => PermissionType::CREATE,
|
'type' => PermissionType::CREATE,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ jsOMS.Modules.Media = class {
|
||||||
length = e.length;
|
length = e.length;
|
||||||
|
|
||||||
for (let i = 0; i < length; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
this.bindElement(e[i]);
|
//this.bindElement(e[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ use phpOMS\Message\NotificationLevel;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\System\MimeType;
|
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.
|
* Media class.
|
||||||
|
|
@ -95,20 +99,12 @@ final class ApiController extends Controller
|
||||||
*/
|
*/
|
||||||
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
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(
|
$uploads = $this->uploadFiles(
|
||||||
$request->getData('name') ?? '',
|
$request->getData('name') ?? '',
|
||||||
$request->getFiles(),
|
$request->getFiles(),
|
||||||
$request->getHeader()->getAccount(),
|
$request->getHeader()->getAccount(),
|
||||||
(string) ($request->getData('path') ?? __DIR__ . '/../../../Modules/Media/Files'),
|
(string) ($request->getData('path') ?? __DIR__ . '/../../../Modules/Media/Files'),
|
||||||
(string) ($request->getData('virtualPath') ?? '/'),
|
(string) ($request->getData('virtualPath') ?? ''),
|
||||||
(string) ($request->getData('password') ?? ''),
|
(string) ($request->getData('password') ?? ''),
|
||||||
(string) ($request->getData('encrypt') ?? '')
|
(string) ($request->getData('encrypt') ?? '')
|
||||||
);
|
);
|
||||||
|
|
@ -136,7 +132,7 @@ final class ApiController extends Controller
|
||||||
array $files,
|
array $files,
|
||||||
int $account,
|
int $account,
|
||||||
string $basePath = 'Modules/Media/Files',
|
string $basePath = 'Modules/Media/Files',
|
||||||
string $virtualPath = '/',
|
string $virtualPath = '',
|
||||||
string $password = '',
|
string $password = '',
|
||||||
string $encryptionKey = ''
|
string $encryptionKey = ''
|
||||||
) : array
|
) : array
|
||||||
|
|
@ -177,7 +173,7 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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 = [];
|
$mediaCreated = [];
|
||||||
|
|
||||||
|
|
@ -215,7 +211,7 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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;
|
$media = null;
|
||||||
|
|
||||||
|
|
@ -306,4 +302,43 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
return $media;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,8 +129,11 @@ final class BackendController extends Controller
|
||||||
$view->setTemplate('/Modules/Media/Theme/Backend/media-list');
|
$view->setTemplate('/Modules/Media/Theme/Backend/media-list');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response));
|
$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('media', $media);
|
||||||
|
$view->addData('path', $path);
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
@ -160,11 +163,16 @@ final class BackendController extends Controller
|
||||||
|
|
||||||
$media = MediaMapper::get((int) $request->getData('id'));
|
$media = MediaMapper::get((int) $request->getData('id'));
|
||||||
if ($media->getExtension() === 'collection') {
|
if ($media->getExtension() === 'collection') {
|
||||||
|
|
||||||
//$media = CollectionMapper::get($media->getId());
|
//$media = CollectionMapper::get($media->getId());
|
||||||
$media = MediaMapper::getByVirtualPath(
|
$media = MediaMapper::getByVirtualPath(
|
||||||
$media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->getName()
|
$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->setTemplate('/Modules/Media/Theme/Backend/media-list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,13 +146,6 @@ export class Upload {
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @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
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
upload (formId)
|
upload (formId)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class BaseView extends View
|
||||||
{
|
{
|
||||||
$this->form = $data[0];
|
$this->form = $data[0];
|
||||||
$this->name = $data[1];
|
$this->name = $data[1];
|
||||||
$this->virtualPath = $data[2] ?? '/';
|
$this->virtualPath = $data[2] ?? '';
|
||||||
return parent::render();
|
return parent::render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,49 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
|
||||||
include __DIR__ . '/template-functions.php';
|
include __DIR__ . '/template-functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \phpOMS\Views\View $this
|
* @var \phpOMS\Views\View $this
|
||||||
|
* @var string $parent
|
||||||
*/
|
*/
|
||||||
|
$mediaPath = $this->getData('path') ?? '/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Modules\Media\Models\Media[] $media
|
||||||
|
*/
|
||||||
$media = $this->getData('media');
|
$media = $this->getData('media');
|
||||||
|
|
||||||
echo $this->getData('nav')->render(); ?>
|
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="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="box wf-100">
|
<div class="box wf-100">
|
||||||
|
|
@ -40,7 +72,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<?php $count = 0;
|
<?php $count = 0;
|
||||||
foreach ($media as $key => $value) :
|
foreach ($media as $key => $value) :
|
||||||
++$count;
|
++$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()));
|
$icon = $fileIconFunction(\phpOMS\System\File\FileUtils::getExtensionType($value->getExtension()));
|
||||||
?>
|
?>
|
||||||
<tr data-href="<?= $url; ?>">
|
<tr data-href="<?= $url; ?>">
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ use \phpOMS\Uri\UriFactory;
|
||||||
include __DIR__ . '/template-functions.php';
|
include __DIR__ . '/template-functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \phpOMS\Views\View $this
|
* @var \phpOMS\Views\View $this
|
||||||
* @var $media \Modules\Media\Models\Media
|
* @var \Modules\Media\Models\Media $media
|
||||||
*/
|
*/
|
||||||
$media = $this->getData('media');
|
$media = $this->getData('media');
|
||||||
echo $this->getData('nav')->render();
|
echo $this->getData('nav')->render();
|
||||||
|
|
@ -124,7 +124,11 @@ echo $this->getData('nav')->render();
|
||||||
<template>
|
<template>
|
||||||
<textarea class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content" name="content"></textarea>
|
<textarea class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content" name="content"></textarea>
|
||||||
</template>
|
</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; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user