Commit a6acf51b authored by Ghislain Loas's avatar Ghislain Loas
Browse files

holtine #72835 fix image selection after upload

parent 0caae503
Pipeline #3674 passed with stage
in 32 minutes and 36 seconds
- ticket #72835 : Explorateur de fichier : correction de la sélection d'image lorsqu'on vient de la téléverser.
\ No newline at end of file
......@@ -192,7 +192,7 @@ class Admin_FileManagerController extends ZendAfi_Controller_Action {
return $this->_ajaxUploadImage($resized_file, $into);
if (!$form->isValid($this->_request->getPost()))
return;
return;
if(!$form->file->receive())
return;
......@@ -268,7 +268,7 @@ class Admin_FileManagerController extends ZendAfi_Controller_Action {
$item = $this->_findItemFromParams();
$this->view->titre = $this->_('Renommer "%s"', $item->getBasename());
$this->view->form = $form = ZendAfi_Form_Admin_FileManager_Rename::newWith(['into' => $item->getRealpath(),
'name' => $item->getBasename()]);
'name' => $item->getBasename()]);
$form->setAction($this->view->url());
......@@ -372,14 +372,15 @@ class Admin_FileManagerController extends ZendAfi_Controller_Action {
protected function _getUrlWithNewPath($path) {
return $this->view->url(['module' => 'admin',
'controller' => 'file-manager',
'action' => 'index',
'browser' => $this->_getParam('browser'),
'splitted_browser' => $this->_getParam('splitted_browser'),
'focused_browser' => $this->_getParam('focused_browser'),
'display_mode_browser' => $this->_getParam('display_mode_browser'),
'display_mode_splitted_browser' => $this->_getParam('display_mode_splitted_browser'),
$this->_getParam('focused_browser', 'browser') => $path,
], null, true);
'controller' => 'file-manager',
'action' => 'index',
$this->_getParam('focused_browser', 'browser') => $path,
'ajax_resized_image' => null,
'render' => null,
'into' => null,
'file' => null,
'item' => null,
'filename' => null,
]);
}
}
......@@ -411,7 +411,7 @@ class Class_FileManager extends Class_Entity {
public function getUrl() {
return rawurlencode($this->getPath());
return Class_Url::absolute($this->getPath(), null, true);
}
......
......@@ -155,7 +155,12 @@ class Class_Url {
if('' === $url)
return static::baseUrl();
if ((!static::$_do_not_add_base_url) && BASE_URL && (0 !== strpos($url, BASE_URL)))
if (static::_hasProtocol($url))
return $url;
if ((!static::$_do_not_add_base_url)
&& BASE_URL
&& (0 !== strpos($url, BASE_URL)))
$url = BASE_URL . static::_beginWithSlash($url);
return static::_beginWithSlash($url);
......
......@@ -39,8 +39,10 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
['url' => '#',
'icon' => '',
'caption' => function($model) {
if($model->isSelectable($this->_view->settings->getSelectableExtensions()))
return $this->_view->tag('i', '', ['class' => 'fa fa-check']) . $this->_view->tag('span', $this->_('Sélectionner'));
return $this->_view->tag('i', '', ['class' => 'fa fa-check']) . $this->_view->tag('span', $this->_('Sélectionner'));
},
'condition' => function($model) {
return $model->isSelectable($this->_view->settings->getSelectableExtensions());
},
'label' => $this->_('Sélectionner "%s"', $model->getName()),
'anchorOptions' => array_filter(['title' => $this->_('Sélectionner "%s"', $model->getName()),
......@@ -50,9 +52,9 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'into' => $model->getId()],
'icon' => '',
'caption' => function($model) {
if($model->isDir())
return $this->_view->tag('i', '', ['class' => 'fa icon-folder-plus']) . $this->_view->tag('span', $this->_('Créer'));
return $this->_view->tag('i', '', ['class' => 'fa icon-folder-plus']) . $this->_view->tag('span', $this->_('Créer'));
},
'condition' => 'isDir',
'label' => $this->_('Créer un nouveau dossier dans "%s".', $model->getPath()),
'anchorOptions' => array_filter(['title' => $this->_('Ajouter un nouveau dossier dans "%s".', $model->getPath()),
'data-popup' => 'true',
......@@ -62,9 +64,9 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'into' => $model->getId()],
'icon' => '',
'caption' => function($model) {
if($model->isDir())
return $this->_view->tag('i', '', ['class' => 'fa fa-upload']) . $this->_view->tag('span', $this->_('Téléverser'));
return $this->_view->tag('i', '', ['class' => 'fa fa-upload']) . $this->_view->tag('span', $this->_('Téléverser'));
},
'condition' => 'isDir',
'label' => $this->_('Téléverser un nouveau fichier dans le dossier "%s".', $model->getPath()),
'anchorOptions' => array_filter(['title' => $this->_('Téléverser un nouveau fichier dans le dossier "%s".', $model->getPath()),
'data-popup' => 'true',
......@@ -74,9 +76,9 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'item' => $model->getId()],
'icon' => '',
'caption' => function($model) {
if($model->isResizable())
return $this->_view->tag('i', '', ['class' => 'fa fa-compress']) . $this->_view->tag('span', $this->_('Redimensionner'));
return $this->_view->tag('i', '', ['class' => 'fa fa-compress']) . $this->_view->tag('span', $this->_('Redimensionner'));
},
'condition' => 'isResizable',
'label' => $this->_('Redimensionner le fichier "%s".', $model->getPath()),
'anchorOptions' => array_filter(['title' => $this->_('Redimensionner le fichier "%s".', $model->getPath()),
'data-popup' => 'true',
......@@ -104,12 +106,12 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'data-popup' => 'true',
'class' => $model->isWritable() ? null : 'disabled'])],
['url' => $model->getUrl(),
['url' => $this->_view->escape($model->getUrl()),
'icon' => '',
'caption' => function($model) {
if($model->isFile())
return $this->_view->tag('i', '', ['class' => 'fa fa-download']) . $this->_view->tag('span', $this->_('Télécharger'));
return $this->_view->tag('i', '', ['class' => 'fa fa-download']) . $this->_view->tag('span', $this->_('Télécharger'));
},
'condition' => 'isFile',
'label' => $this->_('Télécharger "%s"', $model->getName()),
'anchorOptions' => array_filter(['download' => $model->getName(),
'title' => $this->_('Télécharger "%s"', $model->getName())])],
......
......@@ -25,7 +25,7 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
if(!$settings)
$settings = (new Class_Entity)->setSelectFile(false);
$url = $this->view->absoluteUrl($file->getUrl(), null, true);
$url = $file->getUrl();
$dt = [
$this->_tag('dt', $this->_('Nom :')),
......@@ -54,14 +54,14 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
if($file->isFile())
$dt = array_merge($dt,
[$this->_tag('dt', $this->_('URL publique :')),
$this->_tag('dd', urldecode($url))]);
$this->_tag('dd', $url)]);
$dl = $this->_tag('dl', implode(array_filter($dt)));
$url_reload = $url . '?version='. time(); // force reload image
$open_new_tab = ($file->isFile()
? $this->view->tagAnchor($url_reload,
? $this->view->tagAnchor($this->view->escape($url_reload),
$this->_('Accéder à "%s" dans un nouvel onglet.', $file->getName()),
['target' => '_blank'])
: '');
......
......@@ -724,7 +724,7 @@ class FileManagerControllerImportCssDispatchTest extends FileManagerControllerTe
/** @test */
public function dispatchFormShouldSubmit() {
public function dispatchFormShouldContainsSubmit() {
$this->dispatch('/admin/file-manager/import?into=userfiles', true);
$this->assertXpath('//div//button[contains(@class, "validate")][contains(@onclick, "image-loading-status")]');
}
......@@ -734,7 +734,16 @@ class FileManagerControllerImportCssDispatchTest extends FileManagerControllerTe
public function postDispatchImportShouldRedirectWithSucces() {
$this->postDispatch('/admin/file-manager/import?into=userfiles', ['file' => 'stylesheet.css']);
$this->assertFlashMessengerContentContains('Fichier "userfiles/stylesheet.css" téléversé.');
$this->assertRedirect();
$this->assertRedirectTo('/admin/file-manager/index?browser=userfiles%2Fstylesheet.css');
}
/** @test */
public function postDispatchImportWithExtentionSelectableShouldRedirectWithThem() {
$this->postDispatch('/admin/file-manager/import?into=userfiles&selectable_extensions=css',
['file' => 'stylesheet.css']);
$this->assertFlashMessengerContentContains('Fichier "userfiles/stylesheet.css" téléversé.');
$this->assertRedirectTo('/admin/file-manager/index?browser=userfiles%2Fstylesheet.css&selectable_extensions=css');
}
}
......@@ -951,8 +960,8 @@ class FileManagerControllerResizeImageDispatchTest extends FileManagerController
/** @test */
public function resizeFileShouldBePresent() {
$this->dispatch('/admin/file-manager/index', true);
$this->assertXPath('//div//a[contains(@href, "/admin/file-manager/resize")]');
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fnew_image.jpg', true);
$this->assertXPathContentContains('//div//a[contains(@href, "/admin/file-manager/resize")]', 'Redimensionner');
}
......@@ -1016,7 +1025,7 @@ Class FileManagerControllerDispatchImageTest extends FileManagerControllerTestCa
/** @test */
public function downloadCaliforniaAnchorShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "userfiles%2Fcalifornia.jpg")]', 'Télécharger', $this->_response->getBody());
$this->assertXPathContentContains('//div//a[contains(@href, "userfiles/california.jpg")]', 'Télécharger');
}
......@@ -1536,12 +1545,21 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
/** @test */
public function accessInNewTabShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%20%27direct%22ory%2Fnew%27_ima%22ge.jpg?version=")][@target="_blank"]', 'Accéder à ');
$this->assertContains("/userfiles/my 'direct"ory/new'_ima"ge.jpg?version=",
$this->_response->getBody());
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles/my \'direct")][@target="_blank"]',
'Accéder à ');
}
/** @test */
public function downloadLinkShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%20%27direct%22ory%2Fnew%27_ima%22ge.jpg")]', 'Télécharger');
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles/my \'direct")]', 'Télécharger');
}
/** @test */
public function urlPublicShouldBePrenset() {
$this->assertXPathContentContains('//dd', '/userfiles/my \'direct"ory/new\'_ima"ge.jpg');
}
}
\ No newline at end of file
Markdown is supported
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