From 25df01c6064c070a1ed703ee83670096712a6450 Mon Sep 17 00:00:00 2001 From: Alex Agulyansky Date: Sat, 20 Feb 2016 02:21:26 -0800 Subject: [PATCH] For now simply brought the pages management back to life in a nasty way --- Entity/Area.php | 142 ++++++----- Entity/Layout.php | 14 +- Entity/Page.php | 57 ++--- Entity/Template.php | 201 ++++++++------- Form/PageLayoutType.php | 3 +- Resources/public/js/app.js | 31 +++ Resources/public/js/controllers.js | 300 +++++++++++++++++++++++ Resources/views/Pages/layout.html.twig | 4 +- Resources/views/Pages/showPage.html.twig | 13 + Service/SitemapDataProvider.php | 2 +- composer.json | 14 +- 11 files changed, 574 insertions(+), 207 deletions(-) mode change 100644 => 100755 Entity/Area.php mode change 100644 => 100755 Entity/Template.php create mode 100755 Resources/public/js/app.js create mode 100755 Resources/public/js/controllers.js diff --git a/Entity/Area.php b/Entity/Area.php old mode 100644 new mode 100755 index 7df05dd..bddf73f --- a/Entity/Area.php +++ b/Entity/Area.php @@ -1,95 +1,103 @@ id; - } + /** + * @ORM\ManyToOne(targetEntity="Template", inversedBy="areas") + * @ORM\JoinColumn(name="template_id", referencedColumnName="id", nullable=false) + * @Gedmo\Versioned + */ + private $template; - /** - * Sets the ID - * - * @param int $id - */ - public function setId($id) - { - $this->id = (int) $id; - } + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + /** + * Sets the ID + * + * @param int $id + */ + public function setId($id) + { + $this->id = (int) $id; + } - /** - * Set template - * - * @param Arnm\PagesBundle\Entity\Template $template - */ - public function setTemplate(Template $template) - { - $this->template = $template; - } + /** + * Set template + * + * @param Arnm\PagesBundle\Entity\Template $template + */ + public function setTemplate(Template $template) + { + $this->template = $template; + } - /** - * Get template - * - * @return Arnm\PagesBundle\Entity\Template - */ - public function getTemplate() - { - return $this->template; - } + /** + * Get template + * + * @return Arnm\PagesBundle\Entity\Template + */ + public function getTemplate() + { + return $this->template; + } /** * Set templateId diff --git a/Entity/Layout.php b/Entity/Layout.php index 77754fb..2b8ced3 100755 --- a/Entity/Layout.php +++ b/Entity/Layout.php @@ -1,20 +1,28 @@ widgets; } - - /** - * @return \DateTime - */ - public function getCreated() - { - return $this->created; - } - - /** - * @return \DateTime - */ - public function getUpdated() - { - return $this->updated; - } } \ No newline at end of file diff --git a/Entity/Template.php b/Entity/Template.php old mode 100644 new mode 100755 index 7bcd059..bde9e25 --- a/Entity/Template.php +++ b/Entity/Template.php @@ -1,111 +1,122 @@ id; - } - - /** - * Set name - * - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - public function __construct() - { - $this->pages = new \Doctrine\Common\Collections\ArrayCollection(); - $this->areas = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Add page - * - * @param Page $page - */ - public function addPage(Page $page) - { - $this->pages[] = $page; - } - - /** - * Get pages - * - * @return Doctrine\Common\Collections\Collection - */ - public function getPages() - { - return $this->pages; - } - -/** - * - * @return string - */ - public function __toString() - { - return $this->getName(); - } + use SoftDeleteableEntity; + use TimestampableEntity; + use BlameableEntity; + + /** + * + * @var integer $id + * + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * + * @var string $name + * + * @ORM\Column(name="name", type="string", length=255) + * @Gedmo\Versioned + * + * @Assert\NotBlank() + */ + private $name; + + /** + * @ORM\OneToMany(targetEntity="Page", mappedBy="template") + */ + private $pages; + + /** + * @ORM\OneToMany(targetEntity="Area", mappedBy="template") + */ + private $areas; + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + public function __construct() + { + $this->pages = new \Doctrine\Common\Collections\ArrayCollection(); + $this->areas = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Add page + * + * @param Page $page + */ + public function addPage(Page $page) + { + $this->pages[] = $page; + } + + /** + * Get pages + * + * @return Doctrine\Common\Collections\Collection + */ + public function getPages() + { + return $this->pages; + } + + /** + * + * @return string + */ + public function __toString() + { + return $this->getName(); + } /** * Add areas @@ -120,7 +131,7 @@ public function addArea(\Arnm\PagesBundle\Entity\Area $areas) /** * Get areas * - * @return Doctrine\Common\Collections\Collection + * @return Doctrine\Common\Collections\Collection */ public function getAreas() { diff --git a/Form/PageLayoutType.php b/Form/PageLayoutType.php index fd3fefa..ffda11f 100755 --- a/Form/PageLayoutType.php +++ b/Form/PageLayoutType.php @@ -21,7 +21,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'data-toggle' => 'popover', 'content' => 'page.form.layout.help', 'class' => 'form-control', - 'ng-model' => 'page.layout.id' + 'ng-model' => 'selectedLayout', + 'ng-init' => "selectedLayout=''" ), 'required' => false )); diff --git a/Resources/public/js/app.js b/Resources/public/js/app.js new file mode 100755 index 0000000..c299f42 --- /dev/null +++ b/Resources/public/js/app.js @@ -0,0 +1,31 @@ +'use strict'; + +/* App Module */ + +var pageApp = angular.module('pageApp', [ 'ngRoute', 'pageControllers', 'ui.sortable', 'ui.tinymce', 'ui.bootstrap', 'ui.bootstrap.modal']); + +pageApp.config([ '$routeProvider', function($routeProvider) { + $routeProvider. + when('/overview', { + templateUrl : '/araneum/view/page/manage-page.html', + controller : 'PageOverviewCtrl' + }). + when('/header', { + templateUrl : '/araneum/view/page/manage-page.html', + controller : 'PageHeaderCtrl' + }). + when('/layout', { + templateUrl : '/araneum/view/page/manage-page.html', + controller : 'PageLayoutCtrl' + }). + when('/template', { + templateUrl : '/araneum/view/page/manage-page.html', + controller : 'PageTemplateCtrl' + }). + otherwise({ + redirectTo : '/overview' + }); + + tinyMCE.baseURL = '/bower_components/tinymce'; + tinyMCE.suffix = '.min'; +} ]); \ No newline at end of file diff --git a/Resources/public/js/controllers.js b/Resources/public/js/controllers.js new file mode 100755 index 0000000..5593554 --- /dev/null +++ b/Resources/public/js/controllers.js @@ -0,0 +1,300 @@ +'use strict'; + +/* Controllers */ + +var pageControllers = angular.module('pageControllers', []); + +pageControllers.controller('PageOverviewCtrl', [ '$scope', function($scope) { + $scope.contentTmpl = '/bundles/arnmpages/tmpl/overview.html' +} ]); + +pageControllers.controller('PageStatusCtrl', [ '$scope', '$http', function($scope, $http) { + $http.get($scope.restBaseUrl).success(function(data) { + $scope.page = data; + }); + + $scope.triggerStatus = function(){ + $http.put($scope.restBaseUrl + '/status').success(function(data) { + $scope.page = data; + }); + }; +} ]); + + +pageControllers.controller('PageHeaderCtrl', [ '$scope', '$http', function($scope, $http) { + $scope.contentTmpl = '/araneum/view/page/header.html'; + + $scope.reset = function() { + $http.get($scope.restBaseUrl).success(function(data) { + $scope.page = data; + }); + }; + + $scope.update = function(page) { + //prepare the data for put request + var data = { + title: page.title, + description: page.description, + keywords: page.keywords + } + $http.put($scope.restBaseUrl+'/header', data).success(function(data) { + $scope.page = data; + }); + } + + $scope.reset(); +} ]); + + +pageControllers.controller('PageLayoutCtrl', [ '$scope', '$http', '$log', function($scope, $http, $log) { + $scope.contentTmpl = '/araneum/view/page/layout.html'; +// $scope.selectedLayout = null; + + $scope.reset = function() { + $http.get($scope.restBaseUrl).success(function(data) { + $scope.page = data; + $scope.selectedLayout = $scope.page.layout.id; + }); + }; + + $scope.update = function() { + $log.debug("Selected Layout: ", $scope.selectedLayout); + //prepare the data for put request + var data = { + layout: $scope.selectedLayout + } + $http.put($scope.restBaseUrl+'/layout', data).success(function(data) { + $scope.page = data; + $scope.selectedLayout = $scope.page.layout.id; + }); + }; + + $scope.reset(); +} ]); + +/** + * Template organizer controller + */ +pageControllers.controller('PageTemplateCtrl', [ '$scope', '$rootScope', '$http', '$uibModal', function($scope, $rootScope, $http, $uibModal) { + $scope.contentTmpl = '/araneum/view/page/template.html'; + $scope.templateTmpl = ''; + $scope.widgetsList = []; + $scope.pageWidgets = null; + var originalWidgetsList = []; + +// $scope.selectedTemplate = null; + + $scope.init = function() { + $http.get($scope.restBaseUrl).success(function(data) { + $scope.page = data; + $scope.widgetList + if($scope.page) { + $scope.loadTmpl($scope.page); + }; + }); + $http.get('/araneum/rest/page/widgets').success(function(data) { + originalWidgetsList = data; + $scope.initWidgetList(); + }); + }; + + $scope.initWidgetList = function() { + $scope.widgetsList = originalWidgetsList.slice(); + }; + + $scope.update = function(page) { + //prepare the data for put request + var data = { + template: page.template.id + } + $http.put($scope.restBaseUrl+'/template', data).success(function(data) { + $scope.page = data; + if($scope.page) { + $scope.loadTmpl($scope.page); + }; + }); + }; + + $scope.loadTmpl = function(page) { + $scope.templateTmpl = '/araneum/view/page/templateOrganizer/'+page.id+'.html'+'#'+Math.random(); + $http.get($scope.restBaseUrl+'/widgets'+'#'+Math.random()).success(function(data) { + $scope.pageWidgets = data; + }); + }; + + $scope.removePageWidget = function(widgetId, areaCode, index) { + if(!confirm('Are you sure?')) { + return; + } + + $http.delete($scope.restBaseUrl+'/deleteWidget/'+widgetId) + .success(function(data) { + $scope.pageWidgets[areaCode].splice(index, 1); + }) + .error(function(data, status, headers, config) { + console.err("Failed to remove widget!"); + }); + }; + + $scope.configureWidget = function(widgetId) { + if ($rootScope.configModal == null) { + $rootScope.configModal = $uibModal.open({ + animation: true, + templateUrl: 'widgetConfigModal.html', + controller: 'WidgetConfigCtrl', + size: 'lg', + backdrop: 'static', + resolve: { + widgetId: function () { + return widgetId; + } + } + }); + } + }; + + /** + * Widgets organization code + */ + $scope.sortableOptions = { + connectWith: ".area", + update: function(e, ui) { + var requestData = { + 'title': ui.item.data('widget-title'), + 'bundle': ui.item.data('widget-bundle'), + 'controller': ui.item.data('widget-controller'), + 'area': ui.item.sortable.droptarget.attr('id'), + 'index': ui.item.sortable.dropindex + }; + + var widgetId = ui.item.data('widget-id'); + //if the widget coming from source + //we need to create an additional widget + if(ui.item.sortable.received && $(ui.sender).hasClass('source')) { + console.log("Adding widget"); + console.log("Data: ", requestData); + $http.post($scope.restBaseUrl+'/addWidget', requestData) + .success(function(data) { + $scope.pageWidgets[data.areaCode][data.sequence].id = data.id; + }) + .error(function(data, status, headers, config) { + ui.item.sortable.cancel(); + }); + } else if(angular.isNumber(widgetId) && widgetId > 0 && (ui.item.sortable.received || (!ui.item.sortable.received && !ui.sender && ui.item.sortable.index != ui.item.sortable.dropindex))) { + //this one is probably moving existing widget from one place to another + console.log("Sorting widget"); + $http.put($scope.restBaseUrl+'/sortWidget/'+widgetId, requestData) + .success(function(data) { + console.log("Response from sort:", data); + }) + .error(function(data, status, headers, config) { + ui.item.sortable.cancel(); + }); + } else { +// ui.item.sortable.cancel(); + } + }, + stop: function(e, ui) { + if($(e.target).hasClass('source')) { + console.log("Source widgets restored"); + $scope.initWidgetList(); + } + } + }; + + $scope.init(); +} ]); + +/** + * Controller that is responsible for widget configuration modal + */ +pageControllers.controller('WidgetConfigCtrl', [ '$scope', '$rootScope', '$http', '$uibModalInstance', 'widgetId', function($scope, $rootScope, $http, $uibModalInstance, widgetId) { + $scope.widgetId = widgetId; + + $scope.widgetConfigFormTmpl = ''; + $scope.widgetConfigSubmitTarget = null; + $scope.dataSource = null; + $scope.widgetConfigFormTitle = 'Loading...'; + $scope.wConfigForm = {}; + + $scope.init = function() { + $http.get('/araneum/view/page/templateOrganizer/widget/'+$scope.widgetId+'/form.html').success(function(data) { + $scope.widgetConfigFormTmpl = data.formTmpl; + $scope.widgetConfigSubmitTarget = data.formSubmitTarget; + $scope.dataSource = data.dataSource; + $scope.widgetConfigFormTitle = data.formTitle; + $http.get($scope.dataSource).success(function(data) { + $scope.wConfigForm = data; + }); + }); + }; + + $scope.configSave = function () { + console.log("Form data: ", $scope.wConfigForm); + $http.put($scope.widgetConfigSubmitTarget, $scope.wConfigForm).success(function(data) { + $scope.resetwidgetConfigForm(); + $rootScope.configModal.close(); + $rootScope.configModal.dismiss(); + $rootScope.configModal = null; + }); + }; + + $scope.configCancel = function () { + $scope.resetwidgetConfigForm(); + $rootScope.configModal.close(); + $rootScope.configModal.dismiss(); + $rootScope.configModal = null; + }; + + $scope.resetwidgetConfigForm = function(){ + $scope.wConfigForm = {}; + $scope.widgetConfigFormTmpl = ''; + $scope.widgetConfigSubmitTarget = null; + $scope.dataSource = null; + $scope.widgetConfigFormTitle = 'Loading...'; + }; + + $scope.tinymceOptions = { + theme_url: '/bower_components/tinymce/themes/modern/theme.min.js', + skin_url: '/bower_components/tinymce/skins/lightgray', + document_base_url: "/bower_components/tinymce/", + height : 300, + external_plugins: { + "advlist": "/bower_components/tinymce/plugins/advlist/plugin.min.js", + "autolink": "/bower_components/tinymce/plugins/autolink/plugin.min.js", + "link": "/bower_components/tinymce/plugins/link/plugin.min.js", + "image": "/bower_components/tinymce/plugins/image/plugin.min.js", + "lists": "/bower_components/tinymce/plugins/lists/plugin.min.js", + "charmap": "/bower_components/tinymce/plugins/charmap/plugin.min.js", + "print": "/bower_components/tinymce/plugins/print/plugin.min.js", + "hr": "/bower_components/tinymce/plugins/hr/plugin.min.js", + "anchor": "/bower_components/tinymce/plugins/anchor/plugin.min.js", + "pagebreak": "/bower_components/tinymce/plugins/pagebreak/plugin.min.js", + "spellchecker": "/bower_components/tinymce/plugins/spellchecker/plugin.min.js", + "searchreplace": "/bower_components/tinymce/plugins/searchreplace/plugin.min.js", + "wordcount": "/bower_components/tinymce/plugins/wordcount/plugin.min.js", + "visualblocks": "/bower_components/tinymce/plugins/visualblocks/plugin.min.js", + "visualchars": "/bower_components/tinymce/plugins/visualchars/plugin.min.js", + "code": "/bower_components/tinymce/plugins/code/plugin.min.js", + "fullscreen": "/bower_components/tinymce/plugins/fullscreen/plugin.min.js", + "insertdatetime": "/bower_components/tinymce/plugins/insertdatetime/plugin.min.js", + "media": "/bower_components/tinymce/plugins/media/plugin.min.js", + "nonbreaking": "/bower_components/tinymce/plugins/nonbreaking/plugin.min.js", + "save": "/bower_components/tinymce/plugins/save/plugin.min.js", + "table": "/bower_components/tinymce/plugins/table/plugin.min.js", + "contextmenu": "/bower_components/tinymce/plugins/contextmenu/plugin.min.js", + "directionality": "/bower_components/tinymce/plugins/directionality/plugin.min.js", + "emoticons": "/bower_components/tinymce/plugins/emoticons/plugin.min.js", + "template": "/bower_components/tinymce/plugins/template/plugin.min.js", + "paste": "/bower_components/tinymce/plugins/paste/plugin.min.js", + "textcolor": "/bower_components/tinymce/plugins/textcolor/plugin.min.js", + }, + plugins: [ + "advlist autolink link image lists charmap print print hr anchor pagebreak spellchecker", + "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", + "save table contextmenu directionality emoticons template paste textcolor" + ] + }; + + $scope.init(); +}]); \ No newline at end of file diff --git a/Resources/views/Pages/layout.html.twig b/Resources/views/Pages/layout.html.twig index aac5085..60ea715 100755 --- a/Resources/views/Pages/layout.html.twig +++ b/Resources/views/Pages/layout.html.twig @@ -3,11 +3,11 @@

{{ 'page.elements.layout'|trans }}

{% form_theme form 'ArnmAraneumBundle:Form:araneum.html.twig' %} -
+ {{ form_widget(form) }}
- +
diff --git a/Resources/views/Pages/showPage.html.twig b/Resources/views/Pages/showPage.html.twig index 60cba76..ebb596e 100755 --- a/Resources/views/Pages/showPage.html.twig +++ b/Resources/views/Pages/showPage.html.twig @@ -4,6 +4,19 @@ {{ parent() }} | {{ 'page.form.title.update'|trans }} {% endblock %} +{% block javascripts %} + {{ parent() }} + {% javascripts + '@ArnmPagesBundle/Resources/public/js/app.js' + '@ArnmPagesBundle/Resources/public/js/controllers.js' + '@ArnmAraneumBundle/Resources/public/js/form/app.js' + '@ArnmAraneumBundle/Resources/public/js/form/controllers.js' + '@ArnmAraneumBundle/Resources/public/js/tinymce.js' + %} + + {% endjavascripts %} +{% endblock %} + {% block ngapp %}ng-app="pageApp"{% endblock %} {% block fullcontent %} diff --git a/Service/SitemapDataProvider.php b/Service/SitemapDataProvider.php index d23507a..16c9012 100755 --- a/Service/SitemapDataProvider.php +++ b/Service/SitemapDataProvider.php @@ -58,7 +58,7 @@ public function onSitemapGeneration(SitemapGenerationEvent $event) continue; } - $urlSet->createAndAddUrl($loc, ((is_null($page->getUpdated())) ? new \DateTime('now') : $page->getUpdated()), ChangeFreq::CF_MONTHLY, 0.3); + $urlSet->createAndAddUrl($loc, ((is_null($page->getUpdatedAt())) ? new \DateTime('now') : $page->getUpdatedAt()), ChangeFreq::CF_MONTHLY, 0.3); } } diff --git a/composer.json b/composer.json index 2c9cbf4..0e0de26 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name" : "iibs/arnm-pages", "description" : "Araneum's pages bundle", - "version" : "1.0.4", + "version" : "1.0.5", "require" : { "php" : ">=5.3.9", "symfony/symfony" : "2.7.*", @@ -9,16 +9,16 @@ "stof/doctrine-extensions-bundle" : "dev-master", "iibs/arnm-core" : "1.0.*" }, + "autoload" : { + "psr-0" : { + "Arnm\\PagesBundle" : "" + } + }, "target-dir" : "Arnm/PagesBundle", "authors" : [ { "name" : "Alex Agulyansky", "email" : "alex@iibspro.com", "homepage" : "http://www.iibspro.com", "role" : "Dev Lead" - } ], - "autoload" : { - "psr-0" : { - "Arnm\\PagesBundle" : "" - } - } + } ] } \ No newline at end of file