function ajax_reference_sparkline($params) { require_once 'HudsonJob.class.php'; require_once 'HudsonBuild.class.php'; require_once 'hudson_Widget_JobLastBuilds.class.php'; $ref = $params['reference']; switch ($ref->getNature()) { case 'hudson_build': $val = $params['val']; $group_id = $params['group_id']; $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance()); if (strpos($val, "/") !== false) { $arr = explode("/", $val); $job_name = $arr[0]; $build_id = $arr[1]; $dar = $job_dao->searchByJobName($job_name, $group_id); } else { $build_id = $val; $dar = $job_dao->searchByGroupID($group_id); if ($dar->rowCount() != 1) { $dar = null; } } if ($dar && $dar->valid()) { $row = $dar->current(); try { $build = new HudsonBuild($row['job_url'] . '/' . $build_id . '/'); $params['sparkline'] = $build->getStatusIcon(); } catch (Exception $e) { } } break; case 'hudson_job': $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance()); $job_name = $params['val']; $group_id = $params['group_id']; $dar = $job_dao->searchByJobName($job_name, $group_id); if ($dar->valid()) { $row = $dar->current(); try { $job = new HudsonJob($row['job_url']); $params['sparkline'] = $job->getStatusIcon(); } catch (Exception $e) { } } break; } }
function _display_jobs_table($group_id, $services) { $request =& HTTPRequest::instance(); $group_id = $request->get('group_id'); $user = UserManager::instance()->getCurrentUser(); $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance()); $dar = $job_dao->searchByGroupID($group_id); if ($dar && $dar->valid()) { $project_manager = ProjectManager::instance(); $project = $project_manager->getProject($group_id); echo '<table id="jobs_table" class="table table-bordered table-striped">'; echo ' <thead><tr>'; echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_job') . '</th>'; echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_lastsuccess') . '</th>'; echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_lastfailure') . '</th>'; echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_rss') . '</th>'; if ($project->usesSVN()) { echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_svn_trigger') . '</th>'; } if ($project->usesCVS()) { echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_cvs_trigger') . '</th>'; } if (!empty($services)) { foreach ($services as $service) { echo ' <th>' . $service['title'] . '</th>'; } } if ($user->isMember($request->get('group_id'), 'A')) { echo ' <th>' . $GLOBALS['Language']->getText('plugin_hudson', 'header_table_actions') . '</th>'; } echo ' </tr></thead>'; echo '<tbody>'; $cpt = 1; while ($dar->valid()) { $row = $dar->current(); $job_id = $row['job_id']; echo ' <tr>'; try { $job = new HudsonJob($row['job_url']); // function toggle_iframe is in script plugins/hudson/www/hudson_tab.js echo '<td>'; echo '<img src="' . $job->getStatusIcon() . '" alt="' . $job->getStatus() . '" title="' . $job->getStatus() . '" /> '; echo '<a href="' . $job->getUrl() . '" onclick="toggle_iframe(this); return false;" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'show_job', array($row['name'])) . '">' . $row['name'] . '</a>'; echo '</td>'; if ($job->getLastSuccessfulBuildNumber() != '') { echo ' <td><a href="' . $job->getLastSuccessfulBuildUrl() . '" onclick="toggle_iframe(this); return false;" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'show_build', array($job->getLastSuccessfulBuildNumber(), $row['name'])) . '">' . $GLOBALS['Language']->getText('plugin_hudson', 'build') . ' #' . $job->getLastSuccessfulBuildNumber() . '</a></td>'; } else { echo ' <td> </td>'; } if ($job->getLastFailedBuildNumber() != '') { echo ' <td><a href="' . $job->getLastFailedBuildUrl() . '" onclick="toggle_iframe(this); return false;" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'show_build', array($job->getLastFailedBuildNumber(), $row['name'])) . '">' . $GLOBALS['Language']->getText('plugin_hudson', 'build') . ' #' . $job->getLastFailedBuildNumber() . '</a></td>'; } else { echo ' <td> </td>'; } echo ' <td align="center"><a href="' . $job->getUrl() . '/rssAll" onclick="toggle_iframe(this); return false;"><img src="' . $this->getControler()->getIconsPath() . 'rss_feed.png" alt="' . $GLOBALS['Language']->getText('plugin_hudson', 'rss_feed', array($row['name'])) . '" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'rss_feed', array($row['name'])) . '"></a></td>'; if ($project->usesSVN()) { if ($row['use_svn_trigger'] == 1) { echo ' <td align="center"><img src="' . $this->getControler()->getIconsPath() . 'server_lightning.png" alt="' . $GLOBALS['Language']->getText('plugin_hudson', 'alt_svn_trigger') . '" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'alt_svn_trigger') . '"></td>'; } else { echo ' <td> </td>'; } } if ($project->usesCVS()) { if ($row['use_cvs_trigger'] == 1) { echo ' <td align="center"><img src="' . $this->getControler()->getIconsPath() . 'server_lightning.png" alt="' . $GLOBALS['Language']->getText('plugin_hudson', 'alt_cvs_trigger') . '" title="' . $GLOBALS['Language']->getText('plugin_hudson', 'alt_cvs_trigger') . '"></td>'; } else { echo ' <td> </td>'; } } if (!empty($services)) { foreach ($services as $service) { if (isset($service['used'][$job_id]) && $service['used'][$job_id] == true) { echo ' <td align="center"><img src="' . $this->getControler()->getIconsPath() . 'server_lightning.png" alt="' . $service['title'] . '" title="' . $service['title'] . '"></td>'; } else { echo ' <td> </td>'; } } } } catch (Exception $e) { echo ' <td><img src="' . $this->getControler()->getIconsPath() . 'link_error.png" alt="' . $e->getMessage() . '" title="' . $e->getMessage() . '" /></td>'; $nb_columns = 4; if ($project->usesSVN()) { $nb_columns++; } if ($project->usesCVS()) { $nb_columns++; } foreach ($services as $service) { $nb_columns++; } echo ' <td colspan="' . $nb_columns . '"><span class="error">' . $e->getMessage() . '</span></td>'; } if ($user->isMember($request->get('group_id'), 'A')) { echo ' <td>'; // edit job echo ' <span class="job_action">'; echo ' <a href="?action=edit_job&group_id=' . $group_id . '&job_id=' . $job_id . '">' . $GLOBALS['HTML']->getimage('ic/edit.png', array('alt' => $GLOBALS['Language']->getText('plugin_hudson', 'edit_job'), 'title' => $GLOBALS['Language']->getText('plugin_hudson', 'edit_job'))) . '</a>'; echo ' </span>'; // delete job echo ' <span class="job_action">'; echo ' <a href="?action=delete_job&group_id=' . $group_id . '&job_id=' . $job_id . '" onclick="return confirm('; echo "'" . $GLOBALS['Language']->getText('plugin_hudson', 'delete_job_confirmation', array($row['name'], $project->getUnixName())) . "'"; echo ');">' . $GLOBALS['HTML']->getimage('ic/cross.png', array('alt' => $GLOBALS['Language']->getText('plugin_hudson', 'delete_job'), 'title' => $GLOBALS['Language']->getText('plugin_hudson', 'delete_job'))) . '</a>'; echo ' </span>'; echo ' </td>'; } echo ' </tr>'; $dar->next(); $cpt++; } echo '</table>'; } else { echo '<p>' . $GLOBALS['Language']->getText('plugin_hudson', 'no_jobs_linked') . '</p>'; } }