Permalink
Browse files

Added LocalFile form element. Changed Shop logo.

  • Loading branch information...
adampiotrowski committed May 9, 2017
1 parent 6036709 commit 576387ae0090aee8ace72565f1874577fc52f694
Showing with 576 additions and 196 deletions.
  1. +89 −0 src/WellCommerce/Bundle/AppBundle/Controller/Admin/MediaController.php
  2. +4 −14 src/WellCommerce/Bundle/AppBundle/Entity/Shop.php
  3. +6 −8 src/WellCommerce/Bundle/AppBundle/Form/Admin/ShopFormBuilder.php
  4. +5 −32 src/WellCommerce/Bundle/AppBundle/Resources/config/doctrine/Shop.orm.yml
  5. +16 −0 src/WellCommerce/Bundle/AppBundle/Resources/config/routing/media/admin.yml
  6. +13 −22 src/WellCommerce/Bundle/AppBundle/Resources/public/css/admin.css
  7. +1 −1 src/WellCommerce/Bundle/AppBundle/Resources/public/css/admin.min.css
  8. +13 −13 src/WellCommerce/Bundle/AppBundle/Resources/public/js/compiled/libs.min.js
  9. +0 −7 src/WellCommerce/Bundle/AppBundle/Resources/public/js/core/form/39.image.js
  10. +375 −77 src/WellCommerce/Bundle/AppBundle/Resources/public/js/core/form/40.local_file.js
  11. +1 −0 src/WellCommerce/Bundle/AppBundle/Resources/translations/wellcommerce.en.yml
  12. +1 −0 src/WellCommerce/Bundle/AppBundle/Resources/translations/wellcommerce.pl.yml
  13. +1 −0 src/WellCommerce/Bundle/AppBundle/Resources/translations/wellcommerce.ru.yml
  14. +9 −0 src/WellCommerce/Bundle/CoreBundle/Resources/translations/wellcommerce.en.yml
  15. +9 −0 src/WellCommerce/Bundle/CoreBundle/Resources/translations/wellcommerce.pl.yml
  16. +9 −0 src/WellCommerce/Bundle/CoreBundle/Resources/translations/wellcommerce.ru.yml
  17. +20 −0 src/WellCommerce/Component/Form/Elements/Upload/File.php
  18. +4 −22 src/WellCommerce/Component/Form/Elements/Upload/LocalFile.php
@@ -12,6 +12,10 @@
namespace WellCommerce\Bundle\AppBundle\Controller\Admin;
use Carbon\Carbon;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use WellCommerce\Bundle\AppBundle\Exception\InvalidMediaException;
@@ -60,6 +64,91 @@ public function addAction(Request $request): Response
return $this->jsonResponse($response);
}
public function indexLocalAction(Request $request): JsonResponse
{
$rootPath = trim($request->get('rootPath'), '/');
$path = trim($request->get('path'), '/');
$extensions = $request->get('types');
$finder = $this->createFinder($path, $extensions);
$files = [];
$inRoot = $rootPath === $path;
if (!$inRoot) {
$currentPath = explode('/', $path);
array_pop($currentPath);
$files[] = [
'dir' => true,
'name' => '..',
'path' => implode('/', $currentPath),
'size' => '',
'mtime' => '',
];
}
foreach ($finder as $file) {
$files[] = [
'dir' => $file->isDir(),
'name' => $file->getFilename(),
'path' => sprintf('%s/%s', $path, $file->getFilename()),
'size' => $file->isDir() ? '' : $file->getSize(),
'mtime' => Carbon::createFromTimestamp($file->getMTime())->format('Y-m-d H:i:s'),
];
}
return $this->jsonResponse([
'files' => $files,
'inRoot' => $inRoot,
'cwd' => $path,
]);
}
private function createFinder(string $path, array $extensions): Finder
{
$directory = $this->getKernel()->getRootDir() . '/../' . $path;
$finder = new Finder();
$finder->in($directory)->ignoreVCS(true)->sortByType()->depth(0)->filter(function (\SplFileInfo $file) use ($extensions) {
if ($this->isValidFile($file, $extensions) || $this->isValidDirectory($file)) {
return true;
}
return false;
});
return $finder;
}
public function uploadLocalAction(Request $request): JsonResponse
{
if ($request->files->has('file')) {
$file = $request->files->get('file');
if ($file instanceof UploadedFile) {
$directory = $request->get('cwd');
$uploadDir = $this->getKernel()->getRootDir() . '/../' . $directory;
$file->move($uploadDir, $file->getClientOriginalName());
return $this->jsonResponse([
'sFilename' => $file->getClientOriginalName(),
]);
}
}
return $this->jsonResponse([
'error' => 'No file to upload',
]);
}
private function isValidFile(\SplFileInfo $file, array $extensions): bool
{
return $file->isFile() && $file->isReadable() && in_array($file->getExtension(), $extensions);
}
private function isValidDirectory(\SplFileInfo $file): bool
{
return $file->isDir() && $file->isReadable();
}
private function getUploader(): MediaUploaderInterface
{
return $this->get('media.uploader');
@@ -31,13 +31,13 @@ class Shop implements EntityInterface
use Timestampable;
use Blameable;
use Translatable;
use AddressTrait;
use ShopExtraTrait;
protected $name = '';
protected $url = '';
protected $defaultCountry = '';
protected $defaultCurrency = '';
protected $logo = '';
protected $enableClient = true;
/**
@@ -65,11 +65,6 @@ class Shop implements EntityInterface
*/
protected $theme;
/**
* @var Media
*/
protected $logo;
public function __construct()
{
$this->mailerConfiguration = new MailerConfiguration();
@@ -176,18 +171,13 @@ public function setEnableClient(bool $enableClient)
$this->enableClient = $enableClient;
}
public function getLogo()
public function getLogo(): string
{
return $this->logo;
return null !== $this->logo ? $this->logo : '';
}
public function setLogo(Media $logo = null)
public function setLogo(string $logo)
{
$this->logo = $logo;
}
public function translate($locale = null, $fallbackToDefault = true): ShopTranslation
{
return $this->doTranslate($locale, $fallbackToDefault);
}
}
@@ -177,9 +177,6 @@ public function buildForm(FormInterface $form)
'tls' => 'tls',
'ssl' => 'ssl',
],
'rules' => [
$this->getRule('required'),
],
]));
$mailerConfiguration->addChild($this->getElement('text_field', [
@@ -241,18 +238,19 @@ public function buildForm(FormInterface $form)
$this->addMetadataFieldset($form, $this->get('shop.repository'));
$mediaData = $form->addChild($this->getElement('nested_fieldset', [
'name' => 'media_data',
'label' => 'common.fieldset.photos',
'name' => 'logo_data',
'label' => 'shop.fieldset.logo',
]));
$mediaData->addChild($this->getElement('image', [
$mediaData->addChild($this->getElement('local_file', [
'name' => 'logo',
'label' => 'form.media_data.image_id',
'label' => 'local_file.label.selected',
'repeat_min' => 0,
'repeat_max' => 1,
'transformer' => $this->getRepositoryTransformer('media_entity', $this->get('media.repository')),
'session_id' => $this->getRequestHelper()->getSessionId(),
'session_name' => $this->getRequestHelper()->getSessionName(),
'file_source' => 'web/themes/',
'file_types' => ['png', 'jpg', 'jpeg'],
]));
$form->addFilter($this->getFilter('no_code'));
@@ -30,6 +30,11 @@ WellCommerce\Bundle\AppBundle\Entity\Shop:
length: 3
nullable: true
column: default_country
logo:
type: string
length: 255
nullable: true
column: logo
defaultCurrency:
type: string
length: 16
@@ -41,31 +46,6 @@ WellCommerce\Bundle\AppBundle\Entity\Shop:
column: enable_client
options:
default: true
line1:
type: string
length: 255
nullable: true
line2:
type: string
length: 255
nullable: true
postalCode:
type: string
length: 255
nullable: true
column: postal_code
state:
type: string
length: 255
nullable: true
city:
type: string
length: 255
nullable: true
country:
type: string
length: 3
nullable: true
manyToOne:
company:
targetEntity: WellCommerce\Bundle\AppBundle\Entity\Company
@@ -88,10 +68,3 @@ WellCommerce\Bundle\AppBundle\Entity\Shop:
client_group_id:
referencedColumnName: id
onDelete: 'SET NULL'
logo:
targetEntity: WellCommerce\Bundle\AppBundle\Entity\Media
fetch: LAZY
joinColumns:
photo_id:
referencedColumnName: id
onDelete: 'SET NULL'
@@ -53,3 +53,19 @@ admin.media.delete_group:
options:
expose: true
require_admin_permission: media.delete
admin.local_file.index:
path: /local/index
defaults:
_controller: 'media.controller.admin:indexLocalAction'
options:
expose: true
require_admin_permission: media.index
admin.local_file.upload:
path: /local/add
defaults:
_controller: 'media.controller.admin:uploadLocalAction'
options:
expose: true
require_admin_permission: media.add
@@ -884,10 +884,6 @@ a.button-green span img, span.button-green span img {
list-style: none;
}
.field-colour .upload-queue, .field-localfile .upload-queue, .column.wide-collapsed .upload-queue {
width: 475px;
}
.upload-queue li {
margin: 0 0 10px;
}
@@ -2027,13 +2023,19 @@ a.button-green span img, span.button-green span img {
white-space: nowrap;
}
.GForm .field-localfile label {
text-align: left;
}
.GForm .field-localfile .filename, .GForm .field-colour .filename {
display: inline;
line-height: 22px;
margin: 0 10px 0 0;
float: left;
font-weight: bold;
max-width: 155px;
display: inline;
line-height: 22px;
margin: 0 10px 0 0;
float: left;
font-weight: bold;
max-width: 400px;
margin-left: 110px;
margin-top: 6px;
}
.GForm .field-localfile .filename .none, .GForm .field-colour .filename .none {
@@ -2043,7 +2045,7 @@ a.button-green span img, span.button-green span img {
}
.GForm .field-localfile .repetition, .GForm .field-colour .repetition {
width: 473px;
margin-left: 0px;
}
.GForm .field-localfile .repetition .add-pictures, .GForm .field-localfile .repetition .browse-pictures, .GForm .field-colour .repetition .add-pictures, .GForm .field-colour .repetition .browse-pictures {
@@ -2057,10 +2059,6 @@ a.button-green span img, span.button-green span img {
margin-top: 10px;
}
.GForm .field-localfile .GF_Datagrid, .GForm .field-colour .GF_Datagrid {
width: 473px;
}
.GForm .field-localfile .GF_Datagrid tbody img, .GForm .field-colour .GF_Datagrid tbody img {
vertical-align: middle;
}
@@ -2070,13 +2068,6 @@ a.button-green span img, span.button-green span img {
margin-right: 170px !important;
}
.GForm .field-layout-box-scheme-preview iframe {
width: 473px;
height: 100px;
margin-left: 195px;
border: none;
}
.GForm .field-border .side {
clear: both;
padding: 5px 0 0;

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -49,7 +49,6 @@ var oDefaults = {
sFileTypesDescription: '',
fDeleteHandler: GCore.NULL,
fLoadFiles: GCore.NULL,
sSwfUploadUrl: '_js_libs/swfupload.swf',
iLimit: 100,
iWidth: 131,
iHeight: 34,
@@ -292,11 +291,9 @@ var GFormImage = GCore.ExtendClass(GFormFile, function () {
gThis._InitFilesDatagrid();
gThis._InitUploader();
if (gThis.m_bRepeatable) {
console.log('OnShow m_bRepeatable' + gThis.m_oOptions.asDefaults);
gThis.Populate(gThis.m_oOptions.asDefaults);
}
else {
console.log('OnShow' + gThis.m_oOptions.sDefault);
gThis.Populate(gThis.m_oOptions.sDefault);
}
gThis.m_bShown = true;
@@ -360,10 +357,6 @@ var GFormImage = GCore.ExtendClass(GFormFile, function () {
gThis.m_jQueue.append(jLi);
};
gThis.OnDelete = function () {
gThis.m_jSwfUpload.swfupload('cancelUpload', sFid);
};
gThis.OnUploadProgress = function (oFile) {
var jLi = gThis.m_jQueue.find('.upload__' + oFile.id);
jLi.find('.' + gThis._GetClass('Progress')).text(oFile.percent + '%');
Oops, something went wrong.

0 comments on commit 576387a

Please sign in to comment.