Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 public function api_jobinfo()
 {
     $job = new Job($this->args('job_id'));
     if (!$job->isHydrated()) {
         throw new Exception("Job does not exist.");
     }
     if (!$job->getQueue()->isMine()) {
         throw new Exception("This job is not in your queue.");
     }
     return $job->getAPIData();
 }
Esempio n. 3
0
 /**
  * @param Job $job
  * @throws Exception
  */
 private function ensureJobExists($job)
 {
     //did we really get someone?
     if (!$job->isHydrated()) {
         throw new Exception("Could not find that job.");
     }
 }
Esempio n. 4
0
 public function update_sort()
 {
     $this->assertLoggedIn();
     if (!$this->args('jobs')) {
         die("Error: You didn't pass any jobs in.");
     }
     $jobs = explode(",", $this->args('jobs'));
     if (count($jobs) < 1) {
         die("Error: You need to pass in at least 2 jobs.");
     }
     //load up our ids.
     $jobIds = preg_filter('/^job_(\\d+)$/', '$1', $jobs);
     $jobs = array();
     // Only grab jobs that exist and are ours
     foreach ($jobIds as $id) {
         /** @var Job $job */
         $job = new Job($id);
         if ($job->isHydrated() && $job->isMine()) {
             $jobs[$id] = $job->get('user_sort');
         }
     }
     // Sort the values, but not the keys
     $values = array_values($jobs);
     sort($values);
     $jobs = array_combine(array_keys($jobs), $values);
     // Now actually update
     foreach ($jobs as $id => $sort) {
         /** @var Job $job */
         $job = new Job($id);
         $job->set('user_sort', $sort);
         $job->save();
     }
     die(print_r($jobs, true));
 }
Esempio n. 5
0
 public function create()
 {
     $this->assertLoggedIn();
     if ($this->args('step2')) {
         $this->setTitle('Step 2 of 2: Create Job');
     } else {
         $this->setTitle('Create new Job');
     }
     try {
         if ($this->args('job_id')) {
             $job = new Job($this->args('job_id'));
             if (!$job->isHydrated()) {
                 throw new Exception("That job does not exist.");
             }
             if ($job->get('user_id') != User::$me->id) {
                 throw new Exception("You do not own this job.");
             }
             $file = $job->getFile();
             $queue_id = $job->get('queue_id');
         } else {
             $file = new S3File($this->args('file_id'));
         }
         if (!$file->isHydrated()) {
             throw new Exception("That file does not exist.");
         }
         if ($file->get('user_id') != User::$me->id) {
             throw new Exception("You do not have access to this file.");
         }
         $this->set('file', $file);
         //load up our form.
         $form = $this->_createJobForm($file, $queue_id);
         if (isset($job)) {
             $form->action = "/job/create/job:{$job->id}";
         } else {
             $form->action = "/job/create/file:{$file->id}";
         }
         //handle our form
         if ($form->checkSubmitAndValidate($this->args())) {
             //pull in our quantity
             $quantity = (int) $form->data('quantity');
             $quantity = max(1, $quantity);
             $quantity = min(1000, $quantity);
             //queue error checking.
             $queue = new Queue($form->data('queue_id'));
             if (!$queue->isHydrated()) {
                 throw new Exception("That queue does not exist.");
             }
             if (!$queue->canAdd()) {
                 throw new Exception("You do not have permission to add to that queue.");
             }
             //okay, we good?
             $queue->addGCodeFile($file, $quantity);
             Activity::log("added {$quantity} new " . Utility::pluralizeWord('job', $quantity));
             $this->forwardToUrl($queue->getUrl());
         }
         $this->set('form', $form);
     } catch (Exception $e) {
         $this->set('megaerror', $e->getMessage());
     }
 }