Skip to content

Commit

Permalink
Merge pull request #197 from Icinga/use-ipl-fileelement
Browse files Browse the repository at this point in the history
Use ipl file element
  • Loading branch information
yhabteab authored Aug 10, 2023
2 parents 971c7e9 + 3103b62 commit b1dd215
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3,502 deletions.
7 changes: 0 additions & 7 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@

namespace Icinga\Module\Reporting {

use Icinga\Application\Version;

/** @var \Icinga\Application\Modules\Module $this */

$this->provideCssFile('system-report.css');

if (version_compare(Version::VERSION, '2.9.0', '<')) {
$this->provideJsFile('vendor/flatpickr.min.js');
$this->provideCssFile('vendor/flatpickr.min.css');
}

$this->menuSection(N_('Reporting'))->add(N_('Reports'), array(
'url' => 'reporting/reports',
));
Expand Down
52 changes: 26 additions & 26 deletions library/Reporting/Web/Forms/TemplateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Icinga\Module\Reporting\Web\Forms;

use Exception;
use GuzzleHttp\Psr7\UploadedFile;
use Icinga\Authentication\Auth;
use Icinga\Module\Reporting\Database;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\Html;
use ipl\Web\Compat\CompatForm;
use reportingipl\Html\FormElement\FileElement;

class TemplateForm extends CompatForm
{
Expand Down Expand Up @@ -65,18 +65,19 @@ protected function assemble()

$this->add(Html::tag('h2', $this->translate('Cover Page Settings')));

$this->addElement(new FileElement('cover_page_background_image', [
'label' => $this->translate('Background Image'),
'accept' => 'image/png, image/jpeg'
]));
$this->addElement('file', 'cover_page_background_image', [
'label' => $this->translate('Background Image'),
'accept' => ['image/png', 'image/jpeg', 'image/jpg'],
'destination' => sys_get_temp_dir()
]);

if (
$this->template !== null
&& isset($this->template->settings['cover_page_background_image'])
) {
$this->add(Html::tag(
'p',
['style' => ['margin-left: 14em;']],
['class' => 'override-uploaded-file-hint'],
$this->translate('Upload a new background image to override the existing one')
));

Expand All @@ -85,18 +86,19 @@ protected function assemble()
]);
}

$this->addElement(new FileElement('cover_page_logo', [
'label' => $this->translate('Logo'),
'accept' => 'image/png, image/jpeg'
]));
$this->addElement('file', 'cover_page_logo', [
'label' => $this->translate('Logo'),
'accept' => ['image/png', 'image/jpeg', 'image/jpg'],
'destination' => sys_get_temp_dir()
]);

if (
$this->template !== null
&& isset($this->template->settings['cover_page_logo'])
) {
$this->add(Html::tag(
'p',
['style' => ['margin-left: 14em;']],
['class' => 'override-uploaded-file-hint'],
$this->translate('Upload a new logo to override the existing one')
));

Expand Down Expand Up @@ -158,17 +160,14 @@ public function onSuccess()
$settings = $this->getValues();

try {
/** @var $uploadedFile \GuzzleHttp\Psr7\UploadedFile */
foreach ($this->getRequest()->getUploadedFiles() as $name => $uploadedFile) {
if ($uploadedFile->getError() === UPLOAD_ERR_NO_FILE) {
continue;
foreach ($settings as $name => $setting) {
if ($setting instanceof UploadedFile) {
$settings[$name] = [
'mime_type' => $setting->getClientMediaType(),
'size' => $setting->getSize(),
'content' => base64_encode((string) $setting->getStream())
];
}

$settings[$name] = [
'mime_type' => $uploadedFile->getClientMediaType(),
'size' => $uploadedFile->getSize(),
'content' => base64_encode((string) $uploadedFile->getStream())
];
}

$db = $this->getDb();
Expand Down Expand Up @@ -250,10 +249,11 @@ protected function addColumnSettings($name, $label)

switch ($this->getValue($type, 'none')) {
case 'image':
$this->addElement(new FileElement($value, [
'label' => 'Image',
'accept' => 'image/png, image/jpeg'
]));
$this->addElement('file', $value, [
'label' => 'Image',
'accept' => ['image/png', 'image/jpeg', 'image/jpg'],
'destination' => sys_get_temp_dir()
]);

if (
$this->template !== null
Expand All @@ -262,7 +262,7 @@ protected function addColumnSettings($name, $label)
) {
$this->add(Html::tag(
'p',
['style' => ['margin-left: 14em;']],
['class' => 'override-uploaded-file-hint'],
'Upload a new image to override the existing one'
));
}
Expand Down
15 changes: 0 additions & 15 deletions library/vendor/ipl/Html/src/FormElement/FileElement.php

This file was deleted.

4 changes: 4 additions & 0 deletions public/css/module.less
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
border-top: 1px solid @gray-lighter;
}

.icinga-controls .override-uploaded-file-hint {
margin-left: 14em;
}

/* Form fallback styles, remove once <=2.9.5 support is dropped */

.icinga-controls {
Expand Down
Loading

0 comments on commit b1dd215

Please sign in to comment.