3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2014,2016,2019, 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 $request =& HTTPRequest::instance();
43 $this->group_id = $request->get('group_id');
45 if ($this->_use_global_status === true) {
46 $this->_all_status = array(
52 $this->computeGlobalStatus();
54 if (forge_check_perm('hudson', $this->group_id, 'read')) {
55 $this->content['title'] = '';
56 if ($this->_use_global_status === true) {
57 $this->content['title'] = '<img src="'.$this->_global_status_icon.'" title="'.$this->_global_status.'" alt="'.$this->_global_status.'" /> ';
59 $this->content['title'] .= _("Hudson Jobs");
63 function computeGlobalStatus() {
64 $jobs = $this->getJobsByGroup($this->group_id);
66 foreach ($jobs as $job) {
67 $this->_all_status[(string)$job->getColorNoAnime()] = $this->_all_status[(string)$job->getColorNoAnime()] + 1;
69 if ($this->_all_status['grey'] > 0 || $this->_all_status['red'] > 0) {
70 $this->_global_status = _("One or more failure or pending job");
71 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_red.png";
72 } elseif ($this->_all_status['yellow'] > 0) {
73 $this->_global_status = _("One or more unstable job");
74 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_yellow.png";
76 $this->_global_status = _("Success");
77 $this->_global_status_icon = '/'.$this->plugin->getIconsPath() . "status_blue.png";
80 $this->_use_global_status == false;
85 return $this->content['title'];
88 function getDescription() {
89 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).");
92 function getContent() {
94 $jobs = $this->getJobsByGroup($this->group_id);
96 if (sizeof($jobs) > 0) {
97 $html .= $HTML->listTableTop();
98 foreach ($jobs as $job_id => $job) {
101 $cells[][] = html_abs_image($job->getStatusIcon(), '15', '15', array('title' => $job->getStatus()));
102 $cells[] = array(util_make_link('/plugins/hudson/?action=view_job&group_id='.$this->group_id.'&job_id='.$job_id, $job->getName()), 'style' => 'width: 99%');
103 $html .= $HTML->multiTableRow(array(), $cells);
104 } catch (Exception $e) {
105 // Do not display wrong jobs
108 $html .= $HTML->listTableBottom();
110 $html .= $HTML->information(_('No job available.'));
112 $html .= html_e('div', array('class' => 'underline-link'), util_make_link('/plugins/hudson/?group_id='.$this->group_id, _('Browse Hudson/Jenkins plugin')));
116 function isAvailable() {
117 return isset($this->content['title']);