- Timestamp:
- 03/23/10 16:59:41 (11 years ago)
- Location:
- trunk/server/www/app
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/www/app/config/sql/schema.php
r324 r329 1 1 <?php 2 2 /* SVN FILE: $Id$ */ 3 /* App schema generated on: 2010-03- 17 11:03:05 : 1268821265*/3 /* App schema generated on: 2010-03-23 15:03:08 : 1269352928*/ 4 4 class AppSchema extends CakeSchema { 5 5 var $name = 'App'; … … 32 32 'order' => array('type' => 'integer', 'null' => false, 'default' => NULL), 33 33 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) 34 ); 35 var $doctypes_workers = array( 36 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 37 'doctype_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'index'), 38 'worker_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'index'), 39 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'doctype_id' => array('column' => 'doctype_id', 'unique' => 0), 'worker_id' => array('column' => 'worker_id', 'unique' => 0)) 34 40 ); 35 41 var $factories = array( -
trunk/server/www/app/controllers/jobs_controller.php
r325 r329 432 432 foreach ($factory['Worker'] as $worker) { 433 433 $formats = array_merge(array(''), Set::extract('/Format/id', $worker)); 434 $doctypes = array_merge(array(''), Set::extract('/ Application/Doctype/id', $worker));434 $doctypes = array_merge(array(''), Set::extract('/Doctype/id', $worker)); 435 435 foreach ($formats as &$format) { $format = "'" . $format . "'"; } 436 436 foreach ($doctypes as &$doctype) { $doctype = "'" . $doctype . "'"; } -
trunk/server/www/app/controllers/workers_controller.php
r324 r329 25 25 { 26 26 /** @var array The helpers that will be available on the view */ 27 public $helpers = array('Html', 'Form' );27 public $helpers = array('Html', 'Form', 'Javascript'); 28 28 29 29 /** @var array The components this controller uses */ … … 37 37 { 38 38 $this->redirect(array('controller' => 'factories', 'action'=>'index')); 39 } 40 41 /** 42 * Filter unsupported doctypes from $this->data 43 * @param boolean $flash Add a flash error message when doctypes are all invalid 44 * @return true if the doctypes are valid, false if not 45 */ 46 private function _filterDoctypes($flash = true) 47 { 48 $application = $this->Worker->Application->find('first', array( 49 'conditions' => array('Application.id' => $this->data['Worker']['application_id']), 50 'contain' => array('Doctype'), 51 )); 52 $doctypes = Set::extract('/Doctype/id', $application); 53 54 if (!empty($this->data['Doctype']['Doctype'])) { 55 foreach ($this->data['Doctype']['Doctype'] as $index => $doctype_id) { 56 if (!in_array($doctype_id, $doctypes)) { 57 unset($this->data['Doctype']['Doctype'][$index]); 58 } 59 } 60 } 61 62 if (!empty($this->data['Doctype']['Doctype'])) { 63 return true; 64 } 65 66 if ($flash) { 67 $this->Session->setFlash(sprintf( 68 __('You did not select any valid document types for application "%s". Please, try again.', true), 69 $application['Application']['name'] 70 )); 71 } 72 73 return false; 74 } 75 76 /** 77 * Generate a parsable list of doctypes per application 78 */ 79 private function _applicationDoctypes() 80 { 81 $applications = $this->Worker->Application->find('all', array( 82 'contain' => array('Doctype'), 83 )); 84 85 $return = array(); 86 foreach ($applications as $application) { 87 $return[$application['Application']['id']] = Set::extract('/Doctype/id', $application); 88 } 89 90 return $return; 39 91 } 40 92 … … 62 114 63 115 if (!empty($this->data)) { 64 $this->Worker->create(); 65 if ($this->Worker->save($this->data)) { 66 $this->Session->setFlash(__('The Worker has been saved', true)); 67 $this->redirect(array('controller' => 'factories', 'action'=>'view', $factory_id)); 68 } else { 69 $this->Session->setFlash(__('The Worker could not be saved. Please, try again.', true)); 116 if ($this->_filterDoctypes()) { 117 $this->Worker->create(); 118 if ($this->Worker->save($this->data)) { 119 $this->Session->setFlash(__('The Worker has been saved', true)); 120 $this->redirect(array('controller' => 'factories', 'action'=>'view', $factory_id)); 121 } else { 122 $this->Session->setFlash(__('The Worker could not be saved. Please, try again.', true)); 123 } 70 124 } 71 125 } … … 73 127 $this->data['Worker']['factory_id'] = $factory_id; 74 128 $this->data['Factory']['name'] = $this->Worker->Factory->field('name'); 129 130 $doctypes = $this->Worker->Doctype->find('list'); 75 131 $formats = $this->Worker->Format->find('list'); 76 132 $applications = $this->Worker->Application->find('list'); 77 $this->set(compact('formats', 'applications')); 133 $applicationDoctypes = $this->_applicationDoctypes(); 134 135 $this->set(compact('doctypes', 'formats', 'applications', 'applicationDoctypes')); 78 136 79 137 $this->render('edit'); … … 100 158 101 159 if (!empty($this->data)) { 102 if ($this->Worker->save($this->data)) { 103 $this->Session->setFlash(__('The application has been saved', true)); 104 $this->redirect(array('controller' => 'factories', 'action'=>'view', $this->Worker->Factory->id)); 105 } else { 106 $this->Session->setFlash(__('The application could not be saved. Please, try again.', true)); 160 if ($this->_filterDoctypes()) { 161 if ($this->Worker->save($this->data)) { 162 $this->Session->setFlash(__('The application has been saved', true)); 163 $this->redirect(array('controller' => 'factories', 'action'=>'view', $this->Worker->Factory->id)); 164 } else { 165 $this->Session->setFlash(__('The application could not be saved. Please, try again.', true)); 166 } 107 167 } 108 168 } else { … … 110 170 } 111 171 172 $doctypes = $this->Worker->Doctype->find('list'); 112 173 $formats = $this->Worker->Format->find('list'); 113 174 $applications = $this->Worker->Application->find('list'); 114 $this->set(compact('formats','applications')); 175 $applicationDoctypes = $this->_applicationDoctypes(); 176 177 $this->set(compact('doctypes', 'formats', 'applications', 'applicationDoctypes')); 115 178 } 116 179 … … 168 231 169 232 if (!empty($this->data)) { 170 $this->Worker->create(); 171 if ($this->Worker->save($this->data)) { 172 $this->Session->setFlash(__('The Worker has been saved', true)); 173 $this->redirect(array('controller' => 'factories', 'action'=>'view', $factory_id)); 174 } else { 175 $this->Session->setFlash(__('The Worker could not be saved. Please, try again.', true)); 233 if ($this->_filterDoctypes()) { 234 $this->Worker->create(); 235 if ($this->Worker->save($this->data)) { 236 $this->Session->setFlash(__('The Worker has been saved', true)); 237 $this->redirect(array('controller' => 'factories', 'action'=>'view', $factory_id)); 238 } else { 239 $this->Session->setFlash(__('The Worker could not be saved. Please, try again.', true)); 240 } 176 241 } 177 242 } … … 179 244 $this->data['Worker']['factory_id'] = $factory_id; 180 245 $this->data['Factory']['name'] = $this->Worker->Factory->field('name'); 246 $doctypes = $this->Worker->Doctype->find('list'); 181 247 $formats = $this->Worker->Format->find('list'); 182 248 $applications = $this->Worker->Application->find('list'); 183 $this->set(compact('formats', 'applications')); 249 $applicationDoctypes = $this->_applicationDoctypes(); 250 251 $this->set(compact('doctypes', 'formats', 'applications', 'applicationDoctypes')); 184 252 185 253 $this->render('edit'); … … 202 270 203 271 if (!empty($this->data)) { 204 if ($this->Worker->save($this->data)) { 205 $this->Session->setFlash(__('The application has been saved', true)); 206 $this->redirect(array('controller' => 'factories', 'action'=>'view', $this->Worker->Factory->id)); 207 } else { 208 $this->Session->setFlash(__('The application could not be saved. Please, try again.', true)); 272 if ($this->_filterDoctypes()) { 273 if ($this->Worker->save($this->data)) { 274 $this->Session->setFlash(__('The application has been saved', true)); 275 $this->redirect(array('controller' => 'factories', 'action'=>'view', $this->Worker->Factory->id)); 276 } else { 277 $this->Session->setFlash(__('The application could not be saved. Please, try again.', true)); 278 } 209 279 } 210 280 } else { … … 212 282 } 213 283 284 $doctypes = $this->Worker->Doctype->find('list'); 214 285 $formats = $this->Worker->Format->find('list'); 215 286 $applications = $this->Worker->Application->find('list'); 216 $this->set(compact('formats','applications')); 287 $applicationDoctypes = $this->_applicationDoctypes(); 288 289 $this->set(compact('doctypes', 'formats', 'applications', 'applicationDoctypes')); 217 290 $this->render('edit'); 218 291 } -
trunk/server/www/app/models/doctype.php
r69 r329 25 25 { 26 26 /** @var string Every application supports a doctype */ 27 public $hasAndBelongsToMany = 'Application';27 public $hasAndBelongsToMany = array('Application', 'Worker'); 28 28 29 29 /** @var array Multiple Mimetypes can be associated with a single Doctype */ -
trunk/server/www/app/models/factory.php
r291 r329 53 53 'Worker.Application.id', 54 54 'Worker.Application.Doctype', 55 'Worker.Doctype', 55 56 'Worker.Format', 56 57 ), -
trunk/server/www/app/models/worker.php
r324 r329 32 32 /** @var array Every application supports one or more output formats */ 33 33 public $hasAndBelongsToMany = array( 34 'Format' => array('unique' => true) 34 'Doctype' => array('unique' => true), 35 'Format' => array('unique' => true), 35 36 ); 36 37 … … 87 88 LEFT JOIN `platforms` AS `Platform` ON (`Operatingsystem`.`platform_id` = `Platform`.`id`) 88 89 LEFT JOIN `applications` AS `Application` ON (`Worker`.`application_id` = `Application`.`id`) 89 LEFT JOIN ` applications_doctypes` AS `ApplicationsDoctype` ON `Application`.`id` = `ApplicationsDoctype`.`application_id`90 LEFT JOIN `doctypes` AS `Doctype` ON (` ApplicationsDoctype`.`doctype_id` = `Doctype`.`id`)90 LEFT JOIN `doctypes_workers` AS `DoctypesWorker` ON `Worker`.`id` = `DoctypesWorker`.`worker_id` 91 LEFT JOIN `doctypes` AS `Doctype` ON (`DoctypesWorker`.`doctype_id` = `Doctype`.`id`) 91 92 WHERE `Factory`.`last_poll` > '$time' 92 93 $sqlWhere … … 107 108 LEFT JOIN `operatingsystems` AS `Operatingsystem` ON (`Factory`.`operatingsystem_id` = `Operatingsystem`.`id`) 108 109 LEFT JOIN `applications` AS `Application` ON (`Worker`.`application_id` = `Application`.`id`) 109 LEFT JOIN ` applications_doctypes` AS `ApplicationsDoctype` ON `Application`.`id` = `ApplicationsDoctype`.`application_id`110 LEFT JOIN `doctypes_workers` AS `DoctypesWorker` ON `Worker`.`id` = `DoctypesWorker`.`worker_id` 110 111 WHERE `Factory`.`last_poll` > '$time' 111 112 $sqlWhere … … 113 114 AND `Application`.`id` = '" . $app['Application']['id'] . "' 114 115 AND `Operatingsystem`.`platform_id` = '" . $app['Platform']['id'] . "' 115 AND ` ApplicationsDoctype`.`doctype_id` = '" . $app['Doctype']['id'] . "'");116 AND `DoctypesWorker`.`doctype_id` = '" . $app['Doctype']['id'] . "'"); 116 117 117 118 $app['Format'] = array(); … … 124 125 return array(); 125 126 } 126 127 /**128 * Get a list of all worker application names and versions, grouped by ODF doctype and platform129 *130 * @param integer $time Maximum time since the last poll, in minutes131 * @return array A nested array132 */133 public function getActiveGrouped($time = 10)134 {135 $result = array();136 $doctypes = $this->Application->Doctype->find('all');137 $platforms = $this->Factory->Operatingsystem->Platform->find('all');138 139 foreach ($doctypes as $doctype) {140 foreach ($platforms as $platform) {141 $result[$doctype['Doctype']['name']][$platform['Platform']['name']] = array();142 }143 }144 145 $active = $this->getActive();146 return $active;147 }148 127 } 149 128 -
trunk/server/www/app/vendors/shells/upgrade.php
r303 r329 27 27 { 28 28 /** @var array The models to use */ 29 public $uses = array('Request', 'Result', 'User', 'Group' );29 public $uses = array('Request', 'Result', 'User', 'Group', 'Worker'); 30 30 31 31 /** … … 209 209 210 210 /** 211 * Assign the correct doctypes to all workers 212 */ 213 public function workerDoctypes() 214 { 215 $workers = $this->Worker->find('all', array( 216 'contain' => array( 217 'Application', 218 'Application.Doctype', 219 ), 220 )); 221 222 foreach ($workers as $worker) { 223 foreach ($worker['Application']['Doctype'] as $doctype) { 224 $this->Worker->DoctypesWorker->create(); 225 $this->Worker->DoctypesWorker->save(array('DoctypesWorker' => array( 226 'doctype_id' => $doctype['id'], 227 'worker_id' => $worker['Worker']['id'], 228 ))); 229 } 230 } 231 } 232 233 /** 211 234 * Print shell help 212 235 */ … … 224 247 $this->out("\n\tdefaultGroupMembership\n\t\tUpdate the default group membership for all existing users."); 225 248 $this->out("\n\tfilesystemLayout\n\t\tUpdate the layour of requests on the filesystem."); 249 $this->out("\n\tworkerDoctypes\n\t\tAssign the correct doctypes to all workers."); 226 250 $this->out("\n\thelp\n\t\tShow this help"); 227 251 $this->out(''); -
trunk/server/www/app/views/workers/edit.ctp
r324 r329 1 <script type="text/javascript"> 2 $(function() { 3 doctypes_map = <?php echo $javascript->object($applicationDoctypes);?>; 4 5 select_doctypes = function() { 6 app = $("#WorkerApplicationId").val(); 7 doctypes = doctypes_map[app]; 8 9 $('#workerDoctypes input[type=checkbox]').each(function(i) { 10 if (jQuery.inArray(this.value, doctypes) > -1) { 11 $(this).removeAttr('disabled'); 12 $('label[for=' + this.id + ']').toggleClass('disabled', false); 13 } else { 14 $(this).removeAttr('checked').attr('disabled', 'disabled'); 15 $('label[for=' + this.id + ']').toggleClass('disabled', true); 16 } 17 }); 18 } 19 20 $("#WorkerApplicationId").change(function() { 21 select_doctypes(); 22 }); 23 24 select_doctypes(); 25 }) 26 </script> 27 28 <?php 29 $javascript->link('jquery-1.3.2.min.js', false); 30 $javascript->link('jquery.rich-array-min.js', false); 31 ?> 32 1 33 <div class="workers form"> 2 34 <?php echo $form->create('Worker');?> … … 20 52 echo $form->input('development', array('label' => __('This is an unstable development version, beta or release candidate', true))); 21 53 echo $form->input('testsuite', array('label' => __('Participate in rendering the ODF test suites (Note: This can be hundreds of jobs)', true))); 54 echo $form->input('Doctype', array('label' => __('Supported document types', true), 'type' => 'select', 'multiple' => 'checkbox', 'div' => array('id' => 'workerDoctypes'))); 22 55 echo $form->input('Format', array('label' => __('Supported output formats', true), 'type' => 'select', 'multiple' => 'checkbox')); 23 56 ?> -
trunk/server/www/app/webroot/css/cake.override.css
r292 r329 131 131 } 132 132 133 #RequestAddFormlabel.disabled {133 label.disabled { 134 134 color: #999; 135 135 }
Note: See TracChangeset
for help on using the changeset viewer.