mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
Load metadata tab content when tab activate
This commit is contained in:
@@ -55,6 +55,7 @@ class RouteLoader
|
|||||||
'/prod/records/property' => Providers\Prod\Property::class,
|
'/prod/records/property' => Providers\Prod\Property::class,
|
||||||
'/prod/share/' => Providers\Prod\Share::class,
|
'/prod/share/' => Providers\Prod\Share::class,
|
||||||
'/prod/story' => Providers\Prod\Story::class,
|
'/prod/story' => Providers\Prod\Story::class,
|
||||||
|
'/prod/subdefs' => Providers\Prod\Subdefs::class,
|
||||||
'/prod/tools/' => Providers\Prod\Tools::class,
|
'/prod/tools/' => Providers\Prod\Tools::class,
|
||||||
'/prod/tooltip' => Providers\Prod\Tooltip::class,
|
'/prod/tooltip' => Providers\Prod\Tooltip::class,
|
||||||
'/prod/TOU/' => Providers\Prod\TOU::class,
|
'/prod/TOU/' => Providers\Prod\TOU::class,
|
||||||
|
61
lib/Alchemy/Phrasea/Controller/Prod/SubdefsController.php
Normal file
61
lib/Alchemy/Phrasea/Controller/Prod/SubdefsController.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2016 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
namespace Alchemy\Phrasea\Controller\Prod;
|
||||||
|
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Controller\Controller;
|
||||||
|
use PHPExiftool\Driver\Metadata\Metadata;
|
||||||
|
use PHPExiftool\Driver\Metadata\MetadataBag;
|
||||||
|
use PHPExiftool\Driver\TagFactory;
|
||||||
|
use PHPExiftool\Driver\Value\Mono;
|
||||||
|
use PHPExiftool\Reader;
|
||||||
|
|
||||||
|
class SubdefsController extends Controller
|
||||||
|
{
|
||||||
|
public function metadataAction($databox_id, $record_id, $subdef_name)
|
||||||
|
{
|
||||||
|
$record = new \record_adapter($this->app, (int) $databox_id, (int) $record_id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$metadataBag = new MetadataBag();
|
||||||
|
$fileEntity = $this->getExifToolReader()
|
||||||
|
->files($record->get_subdef($subdef_name)->getRealPath())
|
||||||
|
->first();
|
||||||
|
$metadatas = $fileEntity->getMetadatas();
|
||||||
|
foreach($metadatas as $metadata){
|
||||||
|
$valuedata = $fileEntity->executeQuery($metadata->getTag()->getTagname()."[not(@rdf:datatype = 'http://www.w3.org/2001/XMLSchema#base64Binary')]");
|
||||||
|
if(empty($valuedata)){
|
||||||
|
$valuedata = new Mono($this->app->trans('Binary data'));
|
||||||
|
$tag = TagFactory::getFromRDFTagname($metadata->getTag()->getTagname());
|
||||||
|
$metadataBagElement = new Metadata($tag, $valuedata);
|
||||||
|
$metadataBag->set($metadata->getTag()->getTagname(), $metadataBagElement);
|
||||||
|
}else{
|
||||||
|
$metadataBag->set($metadata->getTag()->getTagname(), $metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (PHPExiftoolException $e) {
|
||||||
|
// ignore
|
||||||
|
} catch (\Exception_Media_SubdefNotFound $e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('prod/actions/Tools/metadata.html.twig', [
|
||||||
|
'record' => $record,
|
||||||
|
'metadatas' => $metadataBag,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return Reader
|
||||||
|
*/
|
||||||
|
private function getExifToolReader()
|
||||||
|
{
|
||||||
|
return $this->app['exiftool.reader'];
|
||||||
|
}
|
||||||
|
}
|
@@ -23,11 +23,6 @@ use Alchemy\Phrasea\Record\RecordWasRotated;
|
|||||||
use DataURI\Parser;
|
use DataURI\Parser;
|
||||||
use MediaAlchemyst\Alchemyst;
|
use MediaAlchemyst\Alchemyst;
|
||||||
use MediaVorus\MediaVorus;
|
use MediaVorus\MediaVorus;
|
||||||
use PHPExiftool\Driver\Metadata\Metadata;
|
|
||||||
use PHPExiftool\Driver\Metadata\MetadataBag;
|
|
||||||
use PHPExiftool\Driver\TagFactory;
|
|
||||||
use PHPExiftool\Driver\Value\Mono;
|
|
||||||
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
|
|
||||||
use PHPExiftool\Reader;
|
use PHPExiftool\Reader;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
@@ -87,13 +82,7 @@ class ToolsController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$record->isStory()) {
|
if (!$record->isStory()) {
|
||||||
try {
|
$metadatas = true;
|
||||||
$metadatas = $this->getMetadatas($record);
|
|
||||||
} catch (PHPExiftoolException $e) {
|
|
||||||
// ignore
|
|
||||||
} catch (\Exception_Media_SubdefNotFound $e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$conf = $this->getConf();
|
$conf = $this->getConf();
|
||||||
@@ -434,30 +423,4 @@ class ToolsController extends Controller
|
|||||||
unset($media);
|
unset($media);
|
||||||
$this->getFilesystem()->remove($fileName);
|
$this->getFilesystem()->remove($fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $record
|
|
||||||
* @return MetadataBag
|
|
||||||
*/
|
|
||||||
private function getMetadatas($record)
|
|
||||||
{
|
|
||||||
$metadataBag = new MetadataBag();
|
|
||||||
$fileEntity = $this->getExifToolReader()
|
|
||||||
->files($record->get_subdef('document')->getRealPath())
|
|
||||||
->first();
|
|
||||||
$metadatas = $fileEntity->getMetadatas();
|
|
||||||
foreach($metadatas as $metadata){
|
|
||||||
$valuedata = $fileEntity->executeQuery($metadata->getTag()->getTagname()."[not(@rdf:datatype = 'http://www.w3.org/2001/XMLSchema#base64Binary')]");
|
|
||||||
if(empty($valuedata)){
|
|
||||||
$valuedata = new Mono($this->app->trans('Binary data'));
|
|
||||||
$tag = TagFactory::getFromRDFTagname($metadata->getTag()->getTagname());
|
|
||||||
$metadataBagElement = new Metadata($tag, $valuedata);
|
|
||||||
$metadataBag->set($metadata->getTag()->getTagname(), $metadataBagElement);
|
|
||||||
}else{
|
|
||||||
$metadataBag->set($metadata->getTag()->getTagname(), $metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $metadataBag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -80,6 +80,7 @@ class ControllerProviderServiceProvider implements ServiceProviderInterface
|
|||||||
Prod\Root::class => [],
|
Prod\Root::class => [],
|
||||||
Prod\Share::class => [],
|
Prod\Share::class => [],
|
||||||
Prod\Story::class => [],
|
Prod\Story::class => [],
|
||||||
|
Prod\Subdefs::class => [],
|
||||||
Prod\Tools::class => [],
|
Prod\Tools::class => [],
|
||||||
Prod\Tooltip::class => [],
|
Prod\Tooltip::class => [],
|
||||||
Prod\TOU::class => [],
|
Prod\TOU::class => [],
|
||||||
|
45
lib/Alchemy/Phrasea/ControllerProvider/Prod/Subdefs.php
Normal file
45
lib/Alchemy/Phrasea/ControllerProvider/Prod/Subdefs.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2016 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\ControllerProvider\Prod;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Controller\Prod\SubdefsController;
|
||||||
|
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||||
|
use Silex\ControllerProviderInterface;
|
||||||
|
use Silex\ServiceProviderInterface;
|
||||||
|
use Silex\Application;
|
||||||
|
|
||||||
|
class Subdefs implements ControllerProviderInterface, ServiceProviderInterface
|
||||||
|
{
|
||||||
|
use ControllerProviderTrait;
|
||||||
|
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['controller.prod.subdefs'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
return (new SubdefsController($app));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
public function connect(Application $app)
|
||||||
|
{
|
||||||
|
$controllers = $this->createAuthenticatedCollection($app);
|
||||||
|
|
||||||
|
$controllers->get('/{databox_id}/{record_id}/metadatas/{subdef_name}/', 'controller.prod.subdefs:metadataAction')
|
||||||
|
->bind('prod_subdefs_metadata');
|
||||||
|
|
||||||
|
return $controllers;
|
||||||
|
}
|
||||||
|
}
|
@@ -59,7 +59,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if metadatas %}
|
{% if metadatas %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#exiftool">
|
<a class="tool-metadata" href="#exiftool">
|
||||||
{{ "meta-datas" | trans }}
|
{{ "meta-datas" | trans }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -311,52 +311,10 @@
|
|||||||
|
|
||||||
{# exiftool section #}
|
{# exiftool section #}
|
||||||
{% if metadatas %}
|
{% if metadatas %}
|
||||||
{% for record in records %}
|
|
||||||
<div id="exiftool" class="tabBox">
|
<div id="exiftool" class="tabBox">
|
||||||
{% set thumbnail = record.get_thumbnail() %}
|
<div id="metadata-load" style="height: 100%"></div>
|
||||||
|
<div id="metadata-content"></div>
|
||||||
<img style='float:left; margin-right:15px'
|
|
||||||
src="{{thumbnail.get_url()}}"
|
|
||||||
width="{{thumbnail.get_width()}}"
|
|
||||||
height="{{thumbnail.get_height()}}" />
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h1><b>Metadatas</b></h1>
|
|
||||||
<hr>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
{% if app.getAclForUser(app.getAuthenticatedUser()).is_admin() %}
|
|
||||||
{% for metadata in metadatas %}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{{ metadata.getTag().getTagname() }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ metadata.getValue().asString() }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% else %}
|
|
||||||
{% for metadata in metadatas if 'System' not in metadata.getTag().getTagname() %}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{{ metadata.getTag().getTagname() }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ metadata.getValue().asString() }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if selectionLength == 1 and recordSubdefs is not empty %}
|
{% if selectionLength == 1 and recordSubdefs is not empty %}
|
||||||
<div id="tools-sharing" class="tabBox">
|
<div id="tools-sharing" class="tabBox">
|
||||||
@@ -448,4 +406,21 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('.tool-metadata').click(function(e){
|
||||||
|
$.ajax({
|
||||||
|
"url": "{{ path('prod_subdefs_metadata', {'databox_id': record.get_sbas_id(), 'record_id': record.get_record_id, 'subdef_name': 'document'}) }}",
|
||||||
|
"type": "GET",
|
||||||
|
beforeSend: function(){
|
||||||
|
$('#metadata-content').empty();
|
||||||
|
$('#metadata-load').removeClass('hidden').addClass('loading');
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
$('#metadata-load').removeClass('loading').addClass('hidden');
|
||||||
|
$('#metadata-content').append(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
49
templates/web/prod/actions/Tools/metadata.html.twig
Normal file
49
templates/web/prod/actions/Tools/metadata.html.twig
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{% set thumbnail = record.get_thumbnail() %}
|
||||||
|
|
||||||
|
<img style='float:left; margin-right:15px'
|
||||||
|
src="{{thumbnail.get_url()}}"
|
||||||
|
width="{{thumbnail.get_width()}}"
|
||||||
|
height="{{thumbnail.get_height()}}" />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1><b>Metadatas</b></h1>
|
||||||
|
<hr>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
{% if metadatas|length %}
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% if app.getAclForUser(app.getAuthenticatedUser()).is_admin() %}
|
||||||
|
{% for metadata in metadatas %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ metadata.getTag().getTagname() }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ metadata.getValue().asString() }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% for metadata in metadatas if 'System' not in metadata.getTag().getTagname() %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ metadata.getTag().getTagname() }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ metadata.getValue().asString() }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td>{{- "No metadata available"|trans -}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
Reference in New Issue
Block a user