Skip to content

Commit

Permalink
worked on Knockout templates some more
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewit committed Apr 18, 2012
1 parent 103c49a commit 6c5d35d
Show file tree
Hide file tree
Showing 27 changed files with 1,062 additions and 154 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/AvroGeneratorExtension.php
Expand Up @@ -24,7 +24,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('avro_generator.add_fields', $config['add_fields']);
$container->setParameter('avro_generator.use_owner', $config['use_owner']);

$supportedStyles = array('avro');
$supportedStyles = array('avro', 'knockout');

if (in_array($config['style'], $supportedStyles)) {
$loader->load(sprintf('templates/%s.yml', $config['style']));
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Expand Up @@ -23,7 +23,7 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('avro_generator');

$supportedStyles = array('avro', false);
$supportedStyles = array('avro', 'knockout', false);

$rootNode
->children()
Expand Down
151 changes: 151 additions & 0 deletions Resources/config/templates/knockout.yml
@@ -0,0 +1,151 @@
parameters:
avro_generator.use_owner: true
avro_generator.files:
controller:
filename: 'Controller/{{ entity }}Controller.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Controller/Controller.php'
parameters:
actions: ['list', 'new', 'edit', 'delete', 'restore', 'getForm', 'import', 'batchDelete', 'batchRestore']
tags: ['controller', 'crud']
manipulator:
service: 'avro_generator.routing.manipulator'
method: 'updateBundleRouting'
filename: 'Resources/config/routing.yml'
setters:
format: 'yml'
list_view:
filename: 'Resources/views/{{ entity }}/list.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/list.html.twig'
tags: ['view', 'crud']

table_view:
filename: 'Resources/views/{{ entity }}/table.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/table.html.twig'
tags: ['view', 'crud']

searchForm_view:
filename: 'Resources/views/{{ entity }}/searchForm.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/searchForm.html.twig'
tags: ['view', 'crud']

form_view:
filename: 'Resources/views/{{ entity }}/form.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/form.html.twig'
tags: ['view', 'crud']

import_view:
filename: 'Resources/views/{{ entity }}/import.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/import.html.twig'
tags: ['view', 'crud', 'import']

features:
filename: 'Features/{{ entity }}.feature'
template: 'AvroGeneratorBundle:Templates/Knockout/Features/feature.feature'
tags: ['test', 'feature']

entity:
filename: 'Entity/{{ entity }}.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Entity/Entity.php'
tags: ['entity', 'crud']

entity_manager:
filename: 'Entity/{{ entity }}Manager.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Entity/EntityManager.php'
tags: ['entity', 'crud']

form_type:
filename: 'Form/Type/{{ entity }}FormType.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Form/Type/FormType.php'
tags: ['form', 'crud']

searchForm_type:
filename: 'Form/Type/{{ entity }}SearchFormType.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Form/Type/SearchFormType.php'
tags: ['form', 'crud']

form_handler:
filename: 'Form/Handler/{{ entity }}FormHandler.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Form/Handler/FormHandler.php'
tags: ['form', 'crud']

service_config:
filename: 'Resources/config/services/{{ entityCC }}.yml'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/config/services/service.yml'
tags: ['service', 'crud']
manipulator:
service: 'avro_generator.config.manipulator'
method: 'addResource'
filename: 'Resources/config/config.yml'
setters:
format: 'yml'

avro_generator.bundle_folders:
controller:
path: 'Controller'
entity:
path: 'Entity'
form:
path: 'Form'
form_type:
path: 'Form/Type'
form_handler:
path: 'Form/Handler'
features:
path: 'Features'
listener:
path: 'Listener'
resources:
path: 'Resources'
views:
path: 'Resources/views'
doc:
path: 'Resources/doc'
meta:
path: 'Resources/meta'
css:
path: 'Resources/public/css'
images:
path: 'Resources/public/images'
js:
path: 'Resources/public/js'
uploads:
path: 'Resources/public/uploads'
translations:
path: 'Resources/translations'
config:
path: 'Resources/config'
services:
path: 'Resources/config/services'

avro_generator.bundle_files:
bundle:
filename: '{{ bundleName }}.php'
template: 'AvroGeneratorBundle:Templates/Knockout/Bundle.php'
configuration:
filename: 'DependencyInjection/Configuration'
template: 'AvroGeneratorBundle:Templates/Knockout/DependencyInjection/Configuration.php'
extension:
filename: 'DependencyInjection/Extension'
template: 'AvroGeneratorBundle:Templates/Knockout/DependencyInjection/{{ bundleVendor }}/{{ bundleCoreName | ucFirst }}Extension.php'
readme:
filename: 'README.md'
template: 'AvroGeneratorBundle:Templates/Knockout/README.md'
layout:
filename: 'Resources/views/layout.html.twig'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/views/layout.html.twig'
routing:
filename: 'Resources/config/routing.yml'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/config/routing.yml'
config:
filename: 'Resources/config/config.yml'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/config/config.yml'
license:
filename: 'Resources/meta/LICENSE'
template: 'AvroGeneratorBundle:Templates/Knockout/Resources/meta/LICENSE'
git_ignore:
filename: '.gitignore'
template: 'AvroGeneratorBundle:Templates/Knockout/gitignore.html.twig'
composer:
filename: 'composer.json'
template: 'AvroGeneratorBundle:Templates/Knockout/composer.json'

2 changes: 1 addition & 1 deletion Templates/Avro/Controller/actions/list.html.twig
Expand Up @@ -6,7 +6,7 @@
*/
public function listAction($filter)
{
$form = $this->container->get('avro_crm.clientSearch.form');
$form = $this->container->get('{{ bundle_alias }}.{{ entity_cc }}Search.form');
$request = $this->container->get('request');
$form->bindRequest($request);

Expand Down
4 changes: 2 additions & 2 deletions Templates/Knockout/Controller/Controller.php
Expand Up @@ -12,13 +12,13 @@
/**
* {{ entity }} controller.
*
* @Route("/{{ entityTitle }}")
* @Route("/{{ entityCC }}")
*
* @author Joris de Wit <joris.w.dewit@gmail.com>
*/
class {{ entity }}Controller extends ContainerAware
{
{% for action in actions %}
{%- include 'Controller/Knockout/actions/'~ action ~'.html.twig' %}
{%- include 'Knockout/Controller/actions/'~ action ~'.php' %}
{% endfor %}
}
5 changes: 3 additions & 2 deletions Templates/Knockout/Controller/actions/delete.php
Expand Up @@ -12,12 +12,13 @@ public function deleteAction($id)
if ($process === true) {
$response = new Response('{
"status": "OK",
"notice": "{{ entity | camelCaseToTitle | lower | ucFirst }} deleted."
"notice": "{{ entityTitle }} deleted.",
"data": $id
}');
} else {
$response = new Response('{
"status": "OK",
"notice": "Unable to delete {{ entity | camelCaseToTitle | lower | ucFirst }}."
"notice": "Unable to delete {{ entityTitle }}."
}');
}
$response->headers->set('Content-Type', 'application/json');
Expand Down
2 changes: 2 additions & 0 deletions Templates/Knockout/Controller/actions/edit.php
Expand Up @@ -7,13 +7,15 @@
public function editAction($id)
{
${{ entityCC }} = $this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->find($id);

$form = $this->container->get('{{ bundleAlias }}.{{ entityCC }}.form');
$formHandler = $this->container->get('{{ bundleAlias }}.{{ entityCC }}.form.handler');

$process = $formHandler->process(${{ entityCC }});
if ($process === true) {
$response = new Response('{
"status": "OK",
"action": "edit",
"notice": "{{ entity | camelCaseToTitle | lower | ucFirst }} updated.",
"data": '.$this->container->get('serializer')->serialize($form->getData(), 'json').'
}');
Expand Down
23 changes: 16 additions & 7 deletions Templates/Knockout/Controller/actions/getForm.php
Expand Up @@ -6,13 +6,22 @@
*/
public function getFormAction($id)
{
$form = $this->container->get('{{ bundleAlias }}.{{ entityCC }}.form');

${{ entityCC }} = $this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->find($id);

{% for field in uniqueManyToOneRelations %}
${{ field.targetEntityName }}s = $this->container->get('{{ field.targetBundleAlias }}.{{ field.targetEntityName | lower }}_manager')->findAllActive();
{% endfor %}
$form = $this->container->get('form.factory')->create(new \{{ bundleNamespace }}\Form\Type\{{ entity }}FormType({% if uniqueManyToOneRelations %}array(
{% for field in uniqueManyToOneRelations %}
'{{ field.targetEntityName }}s' => ${{ field.targetEntityName }}s,
{% endfor %}
)
{% endif %}
));
return array(
'{{ entityCC }}' => ${{ entityCC }},
'{{ entityCC }}Form' => $form->createView()
);
'{{ entityCC }}Form' => $form->createView(),
{% for field in uniqueManyToOneRelations %}
'{{ field.targetEntityName }}s' => ${{ field.targetEntityName }}s,
{% endfor %}
);

}

4 changes: 2 additions & 2 deletions Templates/Knockout/Controller/actions/import.php
Expand Up @@ -6,12 +6,12 @@
*/
public function importAction()
{
$form = $this->container->get('avro_csv.csv.form');
$form = $this->container->get('avro_csv.form');
$formHandler = $this->container->get('avro_csv.form.handler');

$process = $formHandler->process('{{ bundleNamespace }}\Entity\{{ entityCC }}');
if ($process === true) {
$this->container->get('session')->getFlashBag()->set('success', $formHandler->getImportCount()).' {{ entityTitleLC }}s imported.');
$this->container->get('session')->getFlashBag()->set('success', $formHandler->getImportCount().' {{ entityTitleLC }}s imported.');

return new RedirectResponse($this->container->get('router')->generate('{{ bundleAlias }}_{{ entityCC }}_list'));
}
Expand Down
14 changes: 7 additions & 7 deletions Templates/Knockout/Controller/actions/list.php
Expand Up @@ -6,14 +6,14 @@
*/
public function listAction()
{
$form = $this->container->get('{{ bundleAlias }}.{{ entityCC }}Search.form');
$form->bindRequest($this->container->get('request'));
$searchForm = $this->container->get('{{ bundleAlias }}.{{ entityCC }}Search.form');
$searchForm->bindRequest($this->container->get('request'));

if ('POST' == $this->container->get('request')->getMethod()) {
if ($form->isValid()) {
if ($searchForm->isValid()) {
$response = new Response('{
"status" => "OK",
"data" => '.$this->container->get('serializer')->serialize($this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->search($form->getData()), 'json').'
"status": "OK",
"data": '.$this->container->get('serializer')->serialize($this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->search($searchForm->getData()), 'json').'
}');
} else {
$response = new Response('{
Expand All @@ -25,9 +25,9 @@ public function listAction()

} else {
$response = array(
'{{ entityCC }}s' => $this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->search(),
'searchForm' => $searchForm->createView(),
'{{ entityCC }}Form' => $this->container->get('{{ bundleAlias }}.{{ entityCC }}.form')->createView(),
'searchForm' => $form->createView()
'{{ entityCC }}s' => $this->container->get('{{ bundleAlias }}.{{ entityCC }}_manager')->search(),
);
}

Expand Down
1 change: 1 addition & 0 deletions Templates/Knockout/Controller/actions/new.php
Expand Up @@ -13,6 +13,7 @@ public function newAction()
if ($process === true) {
$response = new Response('{
"status": "OK",
"action": "new",
"notice": "{{ entity | camelCaseToTitle | lower | ucFirst }} created.",
"data": '.$this->container->get('serializer')->serialize($form->getData(), 'json').'
}');
Expand Down
5 changes: 3 additions & 2 deletions Templates/Knockout/Controller/actions/restore.php
Expand Up @@ -11,12 +11,13 @@ public function restoreAction($id)
if ($process === true) {
$response = new Response('{
"status": "OK",
"notice": "{{ entity | camelCaseToTitle | lower | ucFirst }} restored."
"notice": "{{ entityTitle }} restored.",
"data": $id
}');
} else {
$response = new Response('{
"status": "OK",
"notice": "Unable to restore {{ entity | camelCaseToTitle | lower | ucFirst }}."
"notice": "Unable to restore {{ entityTitle }}."
}');
}
$response->headers->set('Content-Type', 'application/json');
Expand Down
31 changes: 31 additions & 0 deletions Templates/Knockout/DependencyInjection/Configuration.php
@@ -0,0 +1,31 @@
<?php

namespace {{ bundleNamespace }}\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*/
class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('{{ bundleAlias }}');

$rootNode
->children()
->scalarNode('db_driver')->cannotBeOverwritten()->defaultValue('{{ db_driver }}')->cannotBeEmpty()->end()
->end();

return $treeBuilder;
}
}
22 changes: 22 additions & 0 deletions Templates/Knockout/DependencyInjection/Extension.php
@@ -0,0 +1,22 @@
<?php
namespace {{ bundleNamespace }}\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;

class {{ bundleVendor }}{{ bundleCoreName | ucFirst }}Extension extends Extension
{
public function load(array $configs, ContainerBuilder $container) {

$processor = new Processor();
$configuration = new Configuration();

$config = $processor->processConfiguration($configuration, $configs);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
}
}

10 changes: 0 additions & 10 deletions Templates/Knockout/Entity/Entity.html.twig

This file was deleted.

0 comments on commit 6c5d35d

Please sign in to comment.