3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2014,2016,2019,2021, Franck Villaume - TrivialDev
6 * This file is a part of Fusionforge.
8 * Fusionforge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Fusionforge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'HudsonOverviewWidget.class.php';
23 require_once 'common/include/HTTPRequest.class.php';
24 require_once 'PluginHudsonJobDao.class.php';
25 require_once 'HudsonJob.class.php';
27 class hudson_Widget_ProjectJobsOverview extends HudsonOverviewWidget {
31 var $_not_monitored_jobs;
32 var $_use_global_status = true;
35 var $_global_status_icon;
38 function __construct($plugin) {
39 parent::__construct('plugin_hudson_project_jobsoverview');
40 $this->plugin = $plugin;
42 $this->group_id = getIntFromRequest('group_id');
44 if ($this->_use_global_status === true) {
45 $this->_all_status = array(
51 $this->computeGlobalStatus();
53 if (forge_check_perm('hudson', $this->group_id, 'read')) {
54 $this->content['title'] = '';
55 if ($this->_use_global_status === true) {
56 $this->content['title'] = '<img src="'.$this->_global_status_icon.'" title="'.$this->_global_status.'" alt="'.$this->_global_status.'" /> ';
58 $this->content['title'] .= _("Hudson Jobs");
62 function computeGlobalStatus() {
63 $jobs = $this->getJobsByGroup($this->group_id);
65 foreach ($jobs as $job) {
66 $this->_all_status[(string)$job->getColorNoAnime()] = $this->_all_status[(string)$job->getColorNoAnime()] + 1;
68 if ($this->_all_status['grey'] > 0 || $this->_all_status['red'] > 0) {
69 $this->_global_status = _("One or more failure or pending job");
70 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_red.png";
71 } elseif ($this->_all_status['yellow'] > 0) {
72 $this->_global_status = _("One or more unstable job");
73 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_yellow.png";
75 $this->_global_status = _("Success");
76 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_blue.png";
79 $this->_use_global_status == false;
84 return $this->content['title'];
87 function getDescription() {
88 return _("Shows an overview of all the jobs associated with this project. You can always choose the ones you want to display in the widget (preferences link).");
91 function getContent() {
93 $jobs = $this->getJobsByGroup($this->group_id);
95 if (sizeof($jobs) > 0) {
96 $html .= $HTML->listTableTop();
97 foreach ($jobs as $job_id => $job) {
100 $cells[][] = html_abs_image($job->getStatusIcon(), '15', '15', array('title' => $job->getStatus()));
101 $cells[] = array(util_make_link('/plugins/hudson/?action=view_job&group_id='.$this->group_id.'&job_id='.$job_id, $job->getName()), 'style' => 'width: 99%');
102 $html .= $HTML->multiTableRow(array(), $cells);
103 } catch (Exception $e) {
104 // Do not display wrong jobs
107 $html .= $HTML->listTableBottom();
109 $html .= $HTML->information(_('No job available.'));
111 $html .= html_e('div', array('class' => 'underline-link'), util_make_link('/plugins/hudson/?group_id='.$this->group_id, _('Browse Hudson/Jenkins plugin')));
115 function isAvailable() {
116 return isset($this->content['title']);