Skip to content
This repository has been archived by the owner on Jun 25, 2018. It is now read-only.

Commit

Permalink
clean + tinyMce image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
romainnorberg committed Apr 11, 2017
1 parent fe35efd commit f696151
Show file tree
Hide file tree
Showing 47 changed files with 756 additions and 478 deletions.
20 changes: 11 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ module.exports = function(grunt) {
files: {
'web/built/app/css/fos_user.css': 'web/bundles/app/scss/fos_user.sass'
}
},
admin: {
options: {
style: 'compressed',
loadPath: 'web/vendor/bootstrap-sass/assets/stylesheets'
},
files: {
'web/built/app/css/admin.css': 'web/bundles/app/scss/admin.sass'
}
}
},
coffee: {
Expand Down Expand Up @@ -108,13 +117,6 @@ module.exports = function(grunt) {
files: [
{expand: true, flatten: true, src: ['web/vendor/bootstrap-sass/assets/fonts/bootstrap/*'], dest: 'web/built/app/fonts/bootstrap/', filter: 'isFile'}
]
},
plupload: {
files: [
{src: ['vendor/moxiecode/plupload/js/plupload.full.min.js'], dest: 'web/bundles/app/js/plupload.full.min.js'},
{src: ['vendor/moxiecode/plupload/js/Moxie.swf'], dest: 'web/bundles/app/js/Moxie.swf'},
{src: ['vendor/moxiecode/plupload/js/Moxie.xap'], dest: 'web/bundles/app/js/Moxie.xap'}
]
}
}
});
Expand All @@ -129,7 +131,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-modernizr");

grunt.registerTask('default', ['buildCss', 'buildJs', 'assets:install']);
grunt.registerTask('buildCss', ['sass:dist', 'concat:css', 'sass:fos_user']);
grunt.registerTask('buildCss', ['sass:dist', 'concat:css', 'sass:fos_user', 'sass:admin']);
grunt.registerTask('buildJs', ['modernizr:dist', 'coffee:compile', 'concat:js', 'uglify']);
grunt.registerTask('assets:install', ['symlink', 'copy:fonts', 'copy:plupload']);
grunt.registerTask('assets:install', ['symlink', 'copy:fonts']);
};
2 changes: 2 additions & 0 deletions app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ framework:
resource: "%kernel.root_dir%/config/routing_dev.yml"
strict_requirements: true
profiler: { only_exceptions: false }
session:
save_path: /var/tmp/

web_profiler:
toolbar: true
Expand Down
24 changes: 24 additions & 0 deletions app/config/services/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ services:
calls:
- [ setTemplate, [edit, AppBundle::admin/edit.html.twig]]

admin.page:
class: AppBundle\Admin\PageAdmin
arguments: [~, AppBundle\Entity\Page, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Page }
calls:
- [ setTemplate, [edit, AppBundle::admin/edit.html.twig]]

admin.page_category:
class: AppBundle\Admin\PageCategoryAdmin
arguments: [~, AppBundle\Entity\PageCategory, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Page catégorie }
calls:
- [ setTemplate, [edit, AppBundle::admin/edit.html.twig]]

admin.post:
class: AppBundle\Admin\PostAdmin
arguments: [~, AppBundle\Entity\Post, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Post }
calls:
- [ setTemplate, [edit, AppBundle::admin/edit.html.twig]]

admin.tinymce:
class: AppBundle\Admin\TinymceAdmin
arguments: [~, ~, ~]
43 changes: 43 additions & 0 deletions src/AppBundle/Admin/PageAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin,
Sonata\AdminBundle\Datagrid\ListMapper,
Sonata\AdminBundle\Datagrid\DatagridMapper,
Sonata\AdminBundle\Form\FormMapper;

class PageAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name', 'text');
$formMapper->add('title', 'text');
$formMapper->add('slug', 'text');
$formMapper->add('description', 'text', [
'required' => false,
]);
$formMapper->add('keywords', 'text', [
'required' => false,
]);
$formMapper->add('content', 'textarea', [
'attr' => [
'class' => 'tinymce',
'data-theme' => 'admin',
],
'required' => false,
]);
$formMapper->add('page_category');
$formMapper->add('active');
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('title');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('title');
}
}
29 changes: 29 additions & 0 deletions src/AppBundle/Admin/PageCategoryAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin,
Sonata\AdminBundle\Datagrid\ListMapper,
Sonata\AdminBundle\Datagrid\DatagridMapper,
Sonata\AdminBundle\Form\FormMapper;

class PageCategoryAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name', 'text');
$formMapper->add('description', 'text', [
'required' => false,
]);
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('name');
}
}
42 changes: 42 additions & 0 deletions src/AppBundle/Admin/PostAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin,
Sonata\AdminBundle\Datagrid\ListMapper,
Sonata\AdminBundle\Datagrid\DatagridMapper,
Sonata\AdminBundle\Form\FormMapper;

class PostAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('title', 'text');
$formMapper->add('slug', 'text');
$formMapper->add('description', 'text', [
'required' => false,
]);
$formMapper->add('keywords', 'text', [
'required' => false,
]);
$formMapper->add('content', 'textarea', [
'attr' => [
'class' => 'tinymce',
'data-theme' => 'admin',
],
'required' => false,
]);
$formMapper->add('labels', 'text');
$formMapper->add('active');
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('title');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('title');
}
}
2 changes: 1 addition & 1 deletion src/AppBundle/Admin/ProjectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function configureFormFields(FormMapper $formMapper)
'required' => false,
]);
$formMapper->add('content', 'textarea', [
'attr' => [
'attr' => [
'class' => 'tinymce',
'data-theme' => 'admin',
],
Expand Down
60 changes: 30 additions & 30 deletions src/AppBundle/Admin/ProjectTypeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin,
Sonata\AdminBundle\Datagrid\ListMapper,
Sonata\AdminBundle\Datagrid\DatagridMapper,
Sonata\AdminBundle\Form\FormMapper,
Vich\UploaderBundle\Form\Type\VichImageType;
Sonata\AdminBundle\Datagrid\ListMapper,
Sonata\AdminBundle\Datagrid\DatagridMapper,
Sonata\AdminBundle\Form\FormMapper,
Vich\UploaderBundle\Form\Type\VichImageType;

class ProjectTypeAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('title', 'text');
$formMapper->add('page_title', 'text');
$formMapper->add('slug', 'text');
$formMapper->add('description', 'text');
$formMapper->add('content', 'textarea', [
'attr' => [
'class' => 'tinymce',
'data-theme' => 'admin',
]
]);
$formMapper->add('imageFile', VichImageType::class, [
'required' => false,
'allow_delete' => true,
'download_link' => true,
]);
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('title', 'text');
$formMapper->add('page_title', 'text');
$formMapper->add('slug', 'text');
$formMapper->add('description', 'text');
$formMapper->add('content', 'textarea', [
'attr' => [
'class' => 'tinymce',
'data-theme' => 'admin',
],
]);
$formMapper->add('imageFile', VichImageType::class, [
'required' => false,
'allow_delete' => true,
'download_link' => true,
]);
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('title');
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('title');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('title');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('title');
}
}
9 changes: 5 additions & 4 deletions src/AppBundle/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Form\Type\AdminFileUploadType;
use Cocur\Slugify\Slugify;
Expand All @@ -16,6 +17,7 @@ class AdminController extends AppBundleBaseController
*/
public function uploadAction(Request $request)
{
// TODO: refactor
$admin_file_form = $this->createForm(AdminFileUploadType::class);

$admin_file_form->handleRequest($request);
Expand All @@ -37,10 +39,9 @@ public function uploadAction(Request $request)
$thumbnail = $image->thumbnail(new \Imagine\Image\Box(800, 800));
$thumbnail->save($file_path);

// upload to bucket

return $this->redirectToRoute('admin_upload');

return new JsonResponse([
'filepath' => '/uploads/medias/' . $fileName,
]);
}

return $this->render(
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;

class ErrorController extends Controller
{
Expand Down
12 changes: 6 additions & 6 deletions src/AppBundle/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public function testAction(Request $request)
{

$projectType = $this->getDoctrine()
->getRepository('AppBundle:ProjectType')
->find('23e64e10-1767-11e6-a73b-080027716959');
->getRepository('AppBundle:ProjectType')
->find('23e64e10-1767-11e6-a73b-080027716959');

if (!$projectType) {
throw $this->createNotFoundException(
'No product found for id '.$productId
);
throw $this->createNotFoundException(
'No product found for id ' . $productId
);
}

$image = $projectType->getImageName();

return $this->render(
'AppBundle::test.html.twig',
[
'image' => $image
'image' => $image,
]
);
}
Expand Down
Loading

0 comments on commit f696151

Please sign in to comment.