Commit e623e915 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Gère la taille des chunks par un paramètre global.

Showing with 45 additions and 10 deletions
+45 -10
......@@ -20,9 +20,28 @@ class Configuration implements ConfigurationInterface
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('irstea_file_upload');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
$rootNode
->children()
->integerNode('max_chunk_size')
->beforeNormalization()
->ifString()
->then(function($v) {
$int = intval($v);
if(strpos($v, "K")) {
return 1000*$int;
}
if(strpos($v, "M")) {
return 1000000*$int;
}
return $int;
})
->end()
->defaultValue(0)
->treatNullLike(0)
->treatFalseLike(0)
->min(0)
->end()
->end();
return $treeBuilder;
}
......
......@@ -20,6 +20,8 @@ class IrsteaFileUploadExtension extends Extension implements PrependExtensionInt
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$container->setParameter('irstea_file_upload.max_chunk_size', $config['max_chunk_size']);
}
/**
......
......@@ -23,13 +23,11 @@ class FileUploadType extends AbstractType
use \Irstea\ThemeBundle\Form\AbstractJQueryWidgetTrait;
/**
*
* @var Router
*/
private $router;
/**
*
* @var FileManagerInterface
*/
private $fileManager;
......@@ -37,18 +35,24 @@ class FileUploadType extends AbstractType
/**
* @var CsrfProviderInterface
*/
protected $csrfProvider;
private $csrfProvider;
/**
* @var int
*/
private $maxChunkSize;
/**
*
* @param Router $router
* @param FileManagerInterface $fileManager
*/
public function __construct(Router $router, FileManagerInterface $fileManager, CsrfProviderInterface $csrfProvider)
public function __construct(Router $router, FileManagerInterface $fileManager, CsrfProviderInterface $csrfProvider, $maxChunkSize)
{
$this->router = $router;
$this->fileManager = $fileManager;
$this->csrfProvider = $csrfProvider;
$this->maxChunkSize = $maxChunkSize;
}
public function buildForm(FormBuilderInterface $builder, array $options)
......@@ -64,6 +68,16 @@ class FileUploadType extends AbstractType
$view->vars['widget_attr']['data-create-url'] = $this->router->generate('file_upload_create');
$view->vars['csrfToken'] = $this->csrfProvider->generateCsrfToken(UploadController::CSRF_INTENTION);
$view->vars['multiple'] = $options['multiple'];
if($options['max_chunk_size'] > 0) {
$view->vars['widget_attr']['data-max-chunk-size'] = $options['max_chunk_size'];
}
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->setWidgetDefaultOptions($resolver);
$resolver->setDefaults(['max_chunk_size' => $this->maxChunkSize ?: 0]);
$resolver->setAllowedTypes(['max_chunk_size' => 'int']);
}
protected function getWidgetDefaults()
......@@ -77,7 +91,6 @@ class FileUploadType extends AbstractType
'bitrate_interval' => 512,
'progress_interval' => 100,
'recalculate_progress' => true,
'max_chunk_size' => 1000000,
'sequential_uploads' => false,
];
}
......
......@@ -7,6 +7,8 @@ parameters:
irstea_file_upload.filesystem.name: irstea_file_upload
irstea_file_upload.max_chunk_size: 0
services:
# Le gestionnaire de fichiers
......@@ -37,6 +39,7 @@ services:
- @router
- @irstea_file_upload.file_manager
- @form.csrf_provider
- %irstea_file_upload.max_chunk_size%
tags:
- { name: form.type, alias: file_upload }
......
......@@ -23,7 +23,6 @@
if(options.acceptFileTypes) {
options.acceptFileTypes = new RegExp('^' + options.acceptFileTypes + '$');
console.debug(options.acceptFileTypes);
}
var formatSize = function(size) {
......@@ -64,7 +63,6 @@
uploadTemplateId: null,
downloadTemplateId: null,
filesContainer: $this.find('.fileinput-entries'),
maxChunkSize: options.maxChunkSize || 1000000,
uploadTemplate: function(data) {
var rows = $();
$.each(data.files, function (index, file) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment