From cb80423fdd15de76da37ccc886298e8365403ebf Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Fri, 12 Sep 2014 18:05:24 -0400 Subject: [PATCH] Work on adding image upload to add-show form --- .gitignore | 6 ++ .../controllers/ScheduleController.php | 19 ++--- .../application/forms/AddShowStyle.php | 44 +++++++++++- .../forms/helpers/ValidationTypes.php | 37 ++++++++++ airtime_mvc/application/models/RabbitMq.php | 70 ++++++++++--------- .../application/services/ShowFormService.php | 8 +-- .../public/js/airtime/schedule/add-show.js | 4 +- install_full/ubuntu/airtime-full-install | 21 +++--- 8 files changed, 151 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index bc3c72ed9..3c612020a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ .* *.pyc +*~$ +*log.* +**/airtime_analyzer.egg-info/* +**/build/* +**/dist/* +*~ diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index d41cd37a6..46bbe710d 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -481,7 +481,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->addNewShow = true; $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); - } else { + } else { if (!$validateStartDate) { $this->view->when->getElement('add_show_start_date')->setOptions(array('disabled' => true)); } @@ -554,7 +554,7 @@ class ScheduleController extends Zend_Controller_Action { $service_showForm = new Application_Service_ShowFormService(null); //$service_show = new Application_Service_ShowService(); - + $js = $this->_getParam('data'); $data = array(); @@ -579,21 +579,24 @@ class ScheduleController extends Zend_Controller_Action $log_vars["params"] = array(); $log_vars["params"]["form_data"] = $data; Logging::info($log_vars); - + + $request = $this->getRequest(); + Logging::info($request); + $forms = $this->createShowFormAction(); - + $this->view->addNewShow = true; if ($service_showForm->validateShowForms($forms, $data)) { - $service_show->addUpdateShow($data); - + $service_show->addUpdateShow($data); + //send new show forms to the user $this->createShowFormAction(true); $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); - + Logging::debug("Show creation succeeded"); } else { - $this->view->form = $this->view->render('schedule/add-show-form.phtml'); + $this->view->form = $this->view->render('schedule/add-show-form.phtml'); Logging::debug("Show creation failed"); } } diff --git a/airtime_mvc/application/forms/AddShowStyle.php b/airtime_mvc/application/forms/AddShowStyle.php index e8feeae89..addcf75eb 100644 --- a/airtime_mvc/application/forms/AddShowStyle.php +++ b/airtime_mvc/application/forms/AddShowStyle.php @@ -1,5 +1,7 @@ addElement('text', 'add_show_color', array( 'label' => _('Text Colour:'), 'class' => 'input_text', @@ -41,6 +43,46 @@ class Application_Form_AddShowStyle extends Zend_Form_SubForm $c->setValidators(array( 'Hex', $stringLengthValidator )); + + // Add show image input + $fileCountValidator = Application_Form_Helper_ValidationTypes::overrideFileCountValidator(1); + $fileSizeValidator = Application_Form_Helper_ValidationTypes::overrideFileSizeValidator(array('max' => '5120000')); + $fileExtensionValidator = Application_Form_Helper_ValidationTypes::overrideFileExtensionValidator('jpg,png,gif'); + + $upload = new Zend_Form_Element_File('upload'); + + $upload->setLabel(_('Show Image:')) + ->setRequired(false) + ->setDecorators(array('File', array('ViewScript', array( + 'viewScript' => 'form/add-show-style.phtml', + 'class' => 'big', + 'placement' => false + )))) + ->addValidator('Count', false, 1) + ->addValidator('Extension', false, 'jpg,jpeg,png,gif') + ->addFilter('ImageSize'); + $this->addElement($upload); + +// $this->addElement('file', 'add_show_image', array( +// 'disableLoadDefaultDecorators' => true, +// 'decorators' => array('File', array('ViewScript', array( +// 'viewScript' => 'form/add-show-style.phtml', +// 'class' => 'big', +// 'placement' => false +// ))), +// 'label' => _('Show Image:'), +// 'class' => 'input_file', +// 'required' => false, +// 'validators' => array( +// $fileCountValidator, +// $fileSizeValidator, +// $fileExtensionValidator), +// 'destination' => '../public/images/upload', +// 'method' => 'post' +// )); + + // Change form enctype to accommodate file upload + $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART); } public function disable() diff --git a/airtime_mvc/application/forms/helpers/ValidationTypes.php b/airtime_mvc/application/forms/helpers/ValidationTypes.php index 9f50e25b5..0ea46964a 100644 --- a/airtime_mvc/application/forms/helpers/ValidationTypes.php +++ b/airtime_mvc/application/forms/helpers/ValidationTypes.php @@ -92,5 +92,42 @@ Class Application_Form_Helper_ValidationTypes { return $validator; } + + public static function overrideFileCountValidator($p_fileCount) + { + $validator = new Zend_Validate_File_Count($p_fileCount); + + $validator->setMessage( + _("Please limit the upload to one file"), + Zend_Validate_File_Count::TOO_MANY + ); + + return $validator; + } + + public static function overrideFileSizeValidator($p_fileSize) + { + $validator = new Zend_Validate_File_Size($p_fileSize); + + $validator->setMessage( + _("The uploaded file is too large. Please limit your upload to '%max%'"), + Zend_Validate_File_Size::TOO_BIG + ); + + return $validator; + } + + public static function overrideFileExtensionValidator($p_fileExtensions) + { + $validator = new Zend_Validate_File_Extension($p_fileExtensions); + $validator->setExtension($p_fileExtensions); + + $validator->setMessage( + _("'%value%' is not a valid file format"), + Zend_Validate_File_Extension::FALSE_EXTENSION + ); + + return $validator; + } } \ No newline at end of file diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 208d9d4ab..c3e7edccf 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -129,45 +129,49 @@ class Application_Model_RabbitMq } - public static function SendMessageToHaproxyConfigDaemon($md){ - $config = parse_ini_file("/etc/airtime-saas/rabbitmq.ini", true); - $conn = new AMQPConnection($config["rabbitmq"]["host"], - $config["rabbitmq"]["port"], - $config["rabbitmq"]["user"], - $config["rabbitmq"]["password"], - $config["rabbitmq"]["vhost"]); + + /** + * Disabled to prevent warnings about /etc/airtime-saas/rabbitmq.ini + */ +// public static function SendMessageToHaproxyConfigDaemon($md){ +// $config = parse_ini_file("/etc/airtime-saas/rabbitmq.ini", true); +// $conn = new AMQPConnection($config["rabbitmq"]["host"], +// $config["rabbitmq"]["port"], +// $config["rabbitmq"]["user"], +// $config["rabbitmq"]["password"], +// $config["rabbitmq"]["vhost"]); - $exchange = $config["rabbitmq"]["queue"]; - $queue = $config["rabbitmq"]["queue"]; +// $exchange = $config["rabbitmq"]["queue"]; +// $queue = $config["rabbitmq"]["queue"]; - $ch = $conn->channel(); +// $ch = $conn->channel(); - /* - name: $queue - passive: false - durable: true // the queue will survive server restarts - exclusive: false // the queue can be accessed in other channels - auto_delete: false //the queue won't be deleted once the channel is closed. - */ - $ch->queue_declare($queue, false, true, false, false); +// /* +// name: $queue +// passive: false +// durable: true // the queue will survive server restarts +// exclusive: false // the queue can be accessed in other channels +// auto_delete: false //the queue won't be deleted once the channel is closed. +// */ +// $ch->queue_declare($queue, false, true, false, false); - /* - name: $exchange - type: direct - passive: false - durable: true // the exchange will survive server restarts - auto_delete: false //the exchange won't be deleted once the channel is closed. - */ +// /* +// name: $exchange +// type: direct +// passive: false +// durable: true // the exchange will survive server restarts +// auto_delete: false //the exchange won't be deleted once the channel is closed. +// */ - $ch->exchange_declare($exchange, 'direct', false, true, false); - $ch->queue_bind($queue, $exchange); +// $ch->exchange_declare($exchange, 'direct', false, true, false); +// $ch->queue_bind($queue, $exchange); - $data = json_encode($md).PHP_EOL; - $msg = new AMQPMessage($data, array('content_type' => 'application/json')); +// $data = json_encode($md).PHP_EOL; +// $msg = new AMQPMessage($data, array('content_type' => 'application/json')); - $ch->basic_publish($msg, $exchange); - $ch->close(); - $conn->close(); - } +// $ch->basic_publish($msg, $exchange); +// $ch->close(); +// $conn->close(); +// } } diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 882d22c44..2bdbf8445 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -478,12 +478,8 @@ class Application_Service_ShowFormService } } - if ($what && $live && $record && $who && $style && $when && - $repeats && $absRebroadcast && $rebroadcast) { - return true; - } else { - return false; - } + return ($what && $live && $record && $who && $style && $when && + $repeats && $absRebroadcast && $rebroadcast); } public function calculateDuration($start, $end, $timezone) diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 5e0ad5b37..3dbd74b8a 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -8,6 +8,8 @@ function openAddShowForm() { if($("#add-show-form").length == 1) { if( ($("#add-show-form").css('display')=='none')) { $("#add-show-form").show(); + $("#add-show-form").prop("enctype", "multipart/form-data"); + /* var windowWidth = $(window).width(); // margin on showform are 16 px on each side @@ -579,7 +581,7 @@ function setAddShowEvents(form) { } }) - form.find("#schedule-show-style input").ColorPicker({ + form.find("#schedule-show-style input .input_text").ColorPicker({ onChange: function (hsb, hex, rgb, el) { $(el).val(hex); }, diff --git a/install_full/ubuntu/airtime-full-install b/install_full/ubuntu/airtime-full-install index 7fae5aedd..c2b414bb7 100755 --- a/install_full/ubuntu/airtime-full-install +++ b/install_full/ubuntu/airtime-full-install @@ -29,6 +29,8 @@ echo "----------------------------------------------------" dist=`lsb_release -is` code=`lsb_release -cs` +apache2 -v | grep "2\.4" > /dev/null +apacheversion=$? #enable squeeze backports to get lame packages if [ "$dist" = "Debian" -a "$code" = "squeeze" ]; then @@ -130,16 +132,17 @@ else echo "----------------------------------------------------" echo "2.1 Apache Config File" echo "----------------------------------------------------" - if [ ! -f /etc/apache2/sites-available/airtime ]; then + if [ "$apacheversion" != "1" ]; then + airtimeconfigfile="airtime.conf" + else + airtimeconfigfile="airtime" + fi + + if [ ! -f /etc/apache2/sites-available/$airtimeconfigfile ]; then echo "Creating Apache config for Airtime..." - if [ "$dist" = "Ubuntu" -a "$code" = "saucy" ]; then - cp $SCRIPTPATH/../apache/airtime-vhost /etc/apache2/sites-available/airtime.conf - a2dissite 000-default - else - cp $SCRIPTPATH/../apache/airtime-vhost /etc/apache2/sites-available/airtime - a2dissite default - fi + cp $SCRIPTPATH/../apache/airtime-vhost /etc/apache2/sites-available/$airtimeconfigfile + a2dissite 000-default a2ensite airtime else echo "Apache config for Airtime already exists..." @@ -205,4 +208,4 @@ echo "----------------------------------------------------" cd $SCRIPTPATH/../../install_minimal # Restart apache to clear php cache service apache2 restart -./airtime-install \ No newline at end of file +./airtime-install