/** * @param Bot $bot * @param Job $job * @return array */ private function _getBotData($bot, $job) { $botData = array(); $botData['id'] = $bot->id; $botData['name'] = $bot->getName(); $botData['status'] = $bot->getStatus(); $botData['status_class'] = BotStatus::getStatusHTMLClass($bot); $botData['url'] = $bot->getUrl(); $botData['last_seen'] = BotLastSeen::getHTML($bot); $webcam = $bot->getWebCamImage(); if ($webcam->isHydrated()) { $botData['webcam_url'] = $webcam->getDownloadURL(); } else { $botData['webcam_url'] = "/img/colorbars.gif"; } $buttons = $this->_getStatusButtons($bot); $menu = array(); $status = $bot->getStatus(); if ($status == BotState::Working) { $menu[] = $buttons['pause']; $menu[] = $buttons['dropjob']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Paused) { $menu[] = $buttons['play']; $menu[] = $buttons['dropjob']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Slicing) { $menu[] = $buttons['dropjob']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Waiting) { $menu[] = $buttons['qa']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Idle) { $menu[] = $buttons['offline']; $menu[] = $buttons['edit']; $menu[] = $buttons['error']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Offline) { $menu[] = $buttons['online']; $menu[] = $buttons['edit']; $menu[] = $buttons['error']; $menu[] = $buttons['delete']; $menu[] = $buttons['retire']; } else { if ($status == BotState::Maintenance) { $menu[] = $buttons['online']; $menu[] = $buttons['offline']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Error) { $menu[] = $buttons['online']; $menu[] = $buttons['offline']; $menu[] = $buttons['edit']; $menu[] = $buttons['delete']; } else { if ($status == BotState::Retired) { $menu[] = $buttons['delete']; } } } } } } } } } $botData['menu'] = $menu; if ($job->isHydrated()) { $jobData = array(); $jobData['id'] = $job->id; $jobData['name'] = $job->getName(); $jobData['url'] = $job->getUrl(); $jobData['status'] = $job->get('status'); $jobData['status_class'] = JobStatus::getStatusHTMLClass($job->get('status')); $jobData['elapsed'] = $job->getElapsedText(); $jobData['estimated'] = $job->getEstimatedText(); if ($job->get('status') == 'taken' || $job->get('status') == 'slicing') { $jobData['progress'] = round($job->get('progress'), 2); $jobData['bar_class'] = ""; } $temps = JSON::decode($bot->get('temperature_data')); if ($bot->get('status') == BotState::Working && $temps !== NULL) { if (isset($temps->extruder)) { $botData['temp_extruder'] = $temps->extruder; } if (isset($temps->bed)) { $botData['temp_bed'] = $temps->bed; } } if ($job->get('status') == 'qa') { $jobData['qa_url'] = $job->getUrl() . "/qa"; } $sliceJob = $job->getSliceJob(); if ($job->get('status') == 'slicing' && $sliceJob->get('status') == 'pending') { $jobData['qa_url'] = $sliceJob->getUrl(); $jobData['bar_class'] = "bar-warning"; // Set it to 100% so it actually displays $jobData['progress'] = 100.0; } $botData['job'] = $jobData; } if ($bot->get('status') == 'error') { $botData['error_text'] = $bot->get('error_text'); return $botData; } return $botData; }
public function edit() { $this->assertLoggedIn(); $this->set('area', 'bots'); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } else { throw new Exception("Could not find that bot."); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } $this->setTitle('Edit Bot - ' . $bot->getName()); $wizard = new Wizard('bot', $this->args()); if (!$this->args('setup')) { $wizard->disableWizardMode(); } // Create our forms $infoForm = $this->_createInfoForm($bot); $queuesForm = $this->_createQueueForm($bot); $slicingForm = $this->_createSlicingForm($bot); $driverForm = $this->_createDriverForm($bot); // Add them to the wizard $wizard->add("Information / Details", $infoForm); $wizard->add("Queues", $queuesForm); $wizard->add("Slicing Setup", $slicingForm); $wizard->add("Driver Configuration", $driverForm); //handle our forms if ($infoForm->checkSubmitAndValidate($this->args())) { $bot->set('name', $infoForm->data('name')); $bot->set('manufacturer', $infoForm->data('manufacturer')); $bot->set('model', $infoForm->data('model')); $bot->set('electronics', $infoForm->data('electronics')); $bot->set('firmware', $infoForm->data('firmware')); $bot->set('extruder', $infoForm->data('extruder')); $bot->save(); Activity::log("edited the information for bot " . $bot->getLink() . "."); } else { if ($queuesForm->checkSubmitAndValidate($this->args())) { $sql = "DELETE FROM bot_queues WHERE bot_id = ?"; db()->execute($sql, array($bot->id)); $priority = 1; $used = array(); foreach ($this->args() as $key => $value) { if (substr($key, 0, 6) === "queue-" && $value != 0) { if (in_array($value, $used)) { continue; } else { $used[] = $value; } $sql = "INSERT INTO bot_queues VALUES(?, ?, ?)"; $data = array($value, $bot->id, $priority); $priority++; db()->execute($sql, $data); } } } else { if ($slicingForm->checkSubmitAndValidate($this->args())) { $bot->set('slice_engine_id', $slicingForm->data('slice_engine_id')); $bot->set('slice_config_id', $slicingForm->data('slice_config_id')); $config = $bot->getDriverConfig(); $config->can_slice = (bool) $slicingForm->data('can_slice'); $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the slicing info for bot " . $bot->getLink() . "."); } else { if ($driverForm->checkSubmitAndValidate($this->args())) { $bot->set('oauth_token_id', $driverForm->data('oauth_token_id')); $bot->set('driver_name', $driverForm->data('driver_name')); //create and save our config $config = $bot->getDriverConfig(); $config->driver = $bot->get('driver_name'); if ($bot->get('driver_name') == 'dummy') { if ($this->args('delay')) { $config->delay = $this->args('delay'); } } elseif ($bot->get('driver_name') == 'printcore' || $bot->get('driver_name') == 's3g') { $config->port = $this->args('serial_port'); $config->port_id = $this->args('port_id'); $config->baud = $this->args('baudrate'); } //did we get webcam info? if ($this->args('webcam_device')) { if (!isset($config->webcam)) { $config->webcam = new stdClass(); } $config->webcam->device = $this->args('webcam_device'); if ($this->args('webcam_id')) { $config->webcam->id = $this->args('webcam_id'); } if ($this->args('webcam_name')) { $config->webcam->name = $this->args('webcam_name'); } if ($this->args('webcam_brightness')) { $config->webcam->brightness = (int) $this->args('webcam_brightness'); } if ($this->args('webcam_contrast')) { $config->webcam->contrast = (int) $this->args('webcam_contrast'); } } else { unset($config->webcam); } //save it all to the bot as json. $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the driver configuration for bot " . $bot->getLink() . "."); } } } } if ($wizard->isFinished()) { $this->forwardToURL($bot->getUrl()); } $this->set('bot_id', $bot->id); $this->set('wizard', $wizard); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Edit - Error"); } }
<?php $rank++; ?> <?php $bot = new Bot($row['bot_id']); ?> <tr <?php echo $bot->get('user_id') == User::$me->id ? 'class="success"' : ''; ?> > <td><?php echo $rank; ?> </td> <td><?php echo $bot->getName(); ?> </td> <td><?php echo $bot->getUser()->getName(); ?> </td> <td><?php echo $row['hours']; ?> </td> <?php } ?> </tbody> </table> </div>
public function dropjob() { $this->assertLoggedIn(); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } else { throw new Exception("This shouldn't happen"); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } if (!($bot->get('status') == 'slicing' || $bot->get('status') == 'working' || $bot->get('status') == 'paused')) { throw new Exception("Bot must be slicing, working, or paused to drop a job."); } $job = $bot->getCurrentJob(); if (!$job->isHydrated()) { throw new Exception("Job must be a real job."); } if (!$bot->canDrop($job)) { throw new Exception("Job cannot be dropped."); } $this->setTitle('Drop Job - ' . $bot->getName() . " - " . $job->getName()); //load up our form. $form = $this->_createJobDropForm($bot, $job); $form->action = $bot->getUrl() . "/dropjob"; //handle our form if ($form->checkSubmitAndValidate($this->args())) { $bot->dropJob($job); //do we want to cancel the job? if ($form->data('cancel_job')) { $job->cancelJob(); } //do we want to go offline? if ($form->data('take_offline')) { $bot->setStatus(BotState::Offline); $bot->save(); } //was there a job error? if ($form->data('job_error')) { if ($form->data('failure_reason') == 'Other') { $error_text = $form->data('failure_reason_other'); } else { $error_text = $form->data('failure_reason'); } $job->logError($error_text); } Activity::log("dropped the job " . $job->getLink() . "."); $this->forwardToUrl($bot->getUrl()); } $this->set('form', $form); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Drop Job - Error"); } }
public function edit() { $this->assertLoggedIn(); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } $this->setTitle('Edit Bot - ' . $bot->getName()); //load up our form. $form = $this->_createBotForm($bot); $form->action = $bot->getUrl() . "/edit"; //handle our form if ($form->checkSubmitAndValidate($this->args())) { $bot->set('queue_id', $form->data('queue_id')); $bot->set('name', $form->data('name')); $bot->set('manufacturer', $form->data('manufacturer')); $bot->set('model', $form->data('model')); $bot->set('electronics', $form->data('electronics')); $bot->set('firmware', $form->data('firmware')); $bot->set('extruder', $form->data('extruder')); $bot->save(); Activity::log("edited the bot " . $bot->getLink() . "."); $this->forwardToUrl($bot->getUrl()); } $this->set('form', $form); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Edit - Error"); } }