Permalink
Browse files

Basic Application, Element and User/Role management

  • Loading branch information...
1 parent 5714e4b commit d54a441a5f4bd4c310cc2fefaa164a11c6e7ab3c @cwygoda cwygoda committed Jun 1, 2012
Showing with 830 additions and 512 deletions.
  1. +66 −0 src/Mapbender/CoreBundle/Command/InitRolesCommand.php
  2. +25 −3 src/Mapbender/CoreBundle/Component/Element.php
  3. +18 −5 src/Mapbender/CoreBundle/DependencyInjection/Configuration.php
  4. +3 −0 src/Mapbender/CoreBundle/DependencyInjection/MapbenderCoreExtension.php
  5. +0 −4 src/Mapbender/CoreBundle/Element/AboutDialog.php
  6. +1 −1 src/Mapbender/CoreBundle/Element/Button.php
  7. +1 −1 src/Mapbender/CoreBundle/Element/FeatureInfo.php
  8. +1 −1 src/Mapbender/CoreBundle/Element/Map.php
  9. +1 −1 src/Mapbender/CoreBundle/Element/Ruler.php
  10. +1 −1 src/Mapbender/CoreBundle/Element/Toc.php
  11. +1 −1 src/Mapbender/CoreBundle/Element/ZoomBar.php
  12. +40 −0 src/Mapbender/CoreBundle/Entity/Application.php
  13. +61 −0 src/Mapbender/CoreBundle/Entity/Repository/RoleRepository.php
  14. +76 −2 src/Mapbender/CoreBundle/Entity/Role.php
  15. +24 −0 src/Mapbender/CoreBundle/Extension/ElementExtension.php
  16. +0 −29 src/Mapbender/CoreBundle/Form/BaseElementType.php
  17. +6 −0 src/Mapbender/CoreBundle/Resources/config/services.xml
  18. +11 −111 src/Mapbender/CoreBundle/Resources/public/backend.css
  19. +0 −48 src/Mapbender/CoreBundle/Resources/public/reset.css
  20. +1 −3 src/Mapbender/CoreBundle/Resources/views/Welcome/list.html.twig
  21. +23 −22 src/Mapbender/CoreBundle/Resources/views/backend.html.twig
  22. +11 −6 src/Mapbender/ManagerBundle/Controller/ApplicationController.php
  23. +216 −78 src/Mapbender/ManagerBundle/Controller/ElementController.php
  24. +6 −8 src/Mapbender/ManagerBundle/Controller/RoleController.php
  25. +4 −2 src/Mapbender/ManagerBundle/Controller/UserController.php
  26. +56 −0 src/Mapbender/ManagerBundle/Form/DataTransformer/YAMLDataTransformer.php
  27. +1 −3 src/Mapbender/ManagerBundle/Form/Type/ApplicationType.php
  28. +5 −0 src/Mapbender/ManagerBundle/Form/Type/RoleType.php
  29. +8 −0 src/Mapbender/ManagerBundle/Form/Type/UserType.php
  30. +26 −0 src/Mapbender/ManagerBundle/Form/Type/YAMLConfigurationType.php
  31. +2 −14 src/Mapbender/ManagerBundle/Resources/public/css/style.css
  32. +20 −0 src/Mapbender/ManagerBundle/Resources/public/js/form-yaml.js
  33. +19 −96 src/Mapbender/ManagerBundle/Resources/public/js/form.js
  34. +1 −1 src/Mapbender/ManagerBundle/Resources/views/Application/edit.html.twig
  35. +10 −9 src/Mapbender/ManagerBundle/Resources/views/Application/form-elements.html.twig
  36. +1 −1 src/Mapbender/ManagerBundle/Resources/views/Application/new.html.twig
  37. +25 −0 src/Mapbender/ManagerBundle/Resources/views/Element/delete.html.twig
  38. +23 −7 src/Mapbender/ManagerBundle/Resources/views/Element/edit.html.twig
  39. +0 −37 src/Mapbender/ManagerBundle/Resources/views/Element/new.html.twig
  40. +14 −0 src/Mapbender/ManagerBundle/Resources/views/Element/select.html.twig
  41. +5 −0 src/Mapbender/ManagerBundle/Resources/views/Element/yaml-form.html.twig
  42. +5 −1 src/Mapbender/ManagerBundle/Resources/views/Role/edit.html.twig
  43. +4 −0 src/Mapbender/ManagerBundle/Resources/views/Role/form-users.html.twig
  44. +0 −11 src/Mapbender/ManagerBundle/Resources/views/Role/form.html.twig
  45. +5 −1 src/Mapbender/ManagerBundle/Resources/views/Role/new.html.twig
  46. +1 −1 src/Mapbender/ManagerBundle/Resources/views/User/edit.html.twig
  47. +1 −1 src/Mapbender/ManagerBundle/Resources/views/User/new.html.twig
  48. +1 −2 src/Mapbender/WmcBundle/Element/WmcStorage.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Mapbender\CoreBundle\Command;
+
+use Mapbender\CoreBundle\Entity\Role;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Output\Output;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Sensio\Bundle\GeneratorBundle\Command\Helper\DialogHelper;
+
+/**
+ * Initialize role tree in database
+ *
+ * @author Christian Wygoda
+ */
+class InitRolesCommand extends ContainerAwareCommand {
+ protected function configure() {
+ $this
+ ->setDescription('Initialize the roles tree in the database')
+ ->setHelp(<<<EOT
+The <info>mapbender:initroles</info> command initializes the role tree in the
+database by inserting the AUTHENTICATED_USER role which is a parent role for
+all other roles which are created later on.
+EOT
+ )
+ ->setName('mapbender:initroles');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ //TODO: Drop all roles, but ask first!
+
+ $em = $this->getContainer()->get('doctrine')->getEntityManager();
+
+ $rootRole = $em->getRepository('MapbenderCoreBundle:Role')
+ ->findOneByOverride('IS_AUTHENTICATED_FULLY');
+
+ if($rootRole !== null) {
+ $output->writeln(array(
+ '',
+ 'The IS_AUTHENTICATED_FULLY role is already in the database.',
+ 'Nothing to do. Good bye.',
+ ''));
+
+ return;
+ }
+
+ $rootRole = new Role();
+ $rootRole
+ ->setTitle('Authenticated User')
+ ->setDescription('')
+ ->setOverride('IS_AUTHENTICATED_FULLY')
+ ->setMpttLeft(1)
+ ->setMpttRight(1);
+
+ $em->persist($rootRole);
+ $em->flush();
+
+ $output->writeln(array(
+ '',
+ 'The role system is now initialized.',
+ ''));
+ }
+}
+
@@ -104,7 +104,9 @@ static public function getClassTags() {
*
* @return array
*/
- abstract public function getDefaultConfiguration();
+ static public function getDefaultConfiguration() {
+ return array();
+ }
/*************************************************************************
* *
@@ -265,8 +267,28 @@ public function httpAction($action) {
*
* @return Symfony\Component\FormTypeInterface
*/
- public function getType() {
- throw new \RuntimeException('NIY getType');
+ public static function getType() {
+ return null;
+ }
+
+ /**
+ * Get the form template to use.
+ *
+ * @return string
+ */
+ public static function getFormTemplate() {
+ return null;
+ }
+
+ /**
+ * Get the form assets.
+ *
+ * @return array
+ */
+ public static function getFormAssets() {
+ return array(
+ 'js' => array(),
+ 'css' => array());
}
}
@@ -17,16 +17,29 @@ public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mapbender_core');
+ $defaultScreenshotPath = 'app_screenshots';
+
$rootNode
->children()
+ ->scalarNode('screenshot_path')
+ ->defaultValue($defaultScreenshotPath)
+ ->end()
->arrayNode('proxy')
- ->canBeUnset()
+ ->canBeUnset()
->addDefaultsIfNotSet()
->children()
- ->scalarNode('host')->defaultNull()->end()
- ->scalarNode('port')->defaultNull()->end()
- ->scalarNode('user')->defaultNull()->end()
- ->scalarNode('password')->defaultNull()->end()
+ ->scalarNode('host')
+ ->defaultNull()
+ ->end()
+ ->scalarNode('port')
+ ->defaultNull()
+ ->end()
+ ->scalarNode('user')
+ ->defaultNull()
+ ->end()
+ ->scalarNode('password')
+ ->defaultNull()
+ ->end()
->arrayNode('noproxy')
->prototype('scalar')
->end()
@@ -12,7 +12,10 @@ public function load(array $configs, ContainerBuilder $container) {
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
+ $screenshot_path = $container->getParameter('kernel.root_dir')
+ . '/../web/' . $config['screenshot_path'];
$container->setParameter('mapbender.proxy', $config['proxy']);
+ $container->setParameter('mapbender.screenshot_path', $screenshot_path);
$loader = new XmlFileLoader($container,
new FileLocator(__DIR__ . '/../Resources/config'));
@@ -18,10 +18,6 @@ static public function getClassTags() {
return array('Help', 'Info', 'About');
}
- public function getDefaultConfiguration() {
- return array();
- }
-
public function getWidgetName() {
return 'mapbender.mbAboutDialog';
}
@@ -22,7 +22,7 @@ static public function getClassTags() {
return array('Button');
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'target' => null,
'click' => null,
@@ -22,7 +22,7 @@ static public function getClassTags() {
return array('Button', 'FeatureInfo');
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'layers' => null,
'target' => null);
@@ -22,7 +22,7 @@ static public function getClassTags() {
return array('Map', 'MapQuery', 'OpenLayers');
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'layerset' => null,
'dpi' => 72,
@@ -29,7 +29,7 @@ public function getAssets($type) {
}
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'type' => 'line');
}
@@ -22,7 +22,7 @@ static public function getClassTags() {
return array('TOC', 'Table of Contents');
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'target' => null,
'autoOpen' => true);
@@ -40,7 +40,7 @@ public function getAssets($type) {
}
}
- public function getDefaultConfiguration() {
+ public static function getDefaultConfiguration() {
return array(
'stepSize' => 50,
'stepByPixel' => false,
@@ -4,6 +4,7 @@
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
+use Symfony\Component\Validator\Constraints as Assert;
/**
* Applicaton entity
@@ -12,12 +13,16 @@
*
* @ORM\Entity
* @ORM\Table(name="mb_application")
+ * @ORM\HasLifecycleCallbacks
*/
class Application {
const SOURCE_YAML = 1;
const SOURCE_DB = 2;
+ private $preparedElements;
+ private $screenshotPath;
+
/**
* @var integer $source
*/
@@ -83,6 +88,11 @@ class Application {
*/
protected $screenshot;
+ /**
+ * @Assert\File(maxSize="102400")
+ */
+ public $screenshotFile;
+
public function __construct() {
$this->elements = new ArrayCollection();
$this->layersets = new ArrayCollection();
@@ -304,5 +314,35 @@ public function setPublished($published) {
public function isPublished() {
return $this->published;
}
+
+ public function getElementsByRegion($region = null) {
+ if($this->preparedElements === null) {
+ $this->preparedElements = array();
+
+ foreach($this->getElements() as $element) {
+ $region = $element->getRegion();
+ if(!array_key_exists($region, $this->preparedElements)) {
+ $this->preparedElements[$region] = array();
+ }
+ $this->preparedElements[$region][] = $element;
+ }
+
+ foreach($this->preparedElements as $region => $elements) {
+ usort($elements, function($a, $b) {
+ return $a->getWeight() - $b->getWeight();
+ });
+ }
+ }
+
+ if($this->preparedElements !== null) {
+ if(array_key_exists($region, $this->preparedElements)) {
+ return $this->preparedElements[$region];
+ } else {
+ return null;
+ }
+ } else {
+ return $this->preparedElements;
+ }
+ }
}
@@ -0,0 +1,61 @@
+<?php
+
+namespace Mapbender\CoreBundle\Entity\Repository;
+
+use Doctrine\ORM\EntityRepository;
+use Mapbender\CoreBundle\Entity\Role;
+use Mapbender\CoreBundle\Entity\User;
+
+/**
+ * Custom role repository
+ *
+ * This repository handles all the magic like extra roles which are
+ * automatically gained and updating the MPTT for the role hierarchy
+ *
+ * @author Christian Wygoda
+ */
+class RoleRepository extends EntityRepository {
+ /**
+ * Find all available roles
+ *
+ * @return array
+ */
+ public function findAllOrdered() {
+ return $this->getEntityManager()
+ ->createQuery('SELECT r FROM MapbenderCoreBundle:Role r ORDER BY r.title')
+ ->getResult();
+ }
+
+ /**
+ * Find all parent roles for given role
+ *
+ * @param Role $role Role to find parent for
+ * @return array
+ */
+ public function findParentRoles(Role $role) {
+ throw new \RuntimeException('NIY');
+ }
+
+ /**
+ * Find all child roles for given role
+ *
+ * @param Role $role Role to find children for
+ * @return array
+ */
+ public function findChildRoles(Role $role) {
+ throw new \RuntimeException('NIY');
+ }
+
+ public function insertRole(Role $role, Role $parent = null, $position = null) {
+ throw new \RuntimeException('NIY');
+ }
+
+ public function updateRole(Role $role, Role $parent = null, $position = null) {
+ throw new \RuntimeException('NIY');
+ }
+
+ public function deleteRole(Role $role) {
+ throw new \RuntimeException('NIY');
+ }
+}
+
Oops, something went wrong.

0 comments on commit d54a441

Please sign in to comment.