Skip to content

Commit

Permalink
Move logic to display status legend to HTML API
Browse files Browse the repository at this point in the history
Avoid code duplication by adding a parameter to html_status_legend() to
specify the desired position for the legend, and performing the checks
within that function instead of doing it in each of the callers.

This follows @vboctor's suggestion in pull request
#607

Issue #19573
  • Loading branch information
dregad committed May 19, 2015
1 parent 276649e commit 91f21ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
12 changes: 2 additions & 10 deletions core/bug_group_action_api.php
Expand Up @@ -88,12 +88,7 @@ function bug_group_action_print_bottom() {
* @return void
*/
function bug_group_action_print_bug_list( array $p_bug_ids_array ) {
$t_legend_position = config_get( 'status_legend_position' );

if( ( $t_legend_position & STATUS_LEGEND_POSITION_TOP ) == STATUS_LEGEND_POSITION_TOP ) {
html_status_legend();
echo '<br />';
}
html_status_legend( STATUS_LEGEND_POSITION_TOP );

echo '<div id="action-group-issues-div">';
echo '<table>';
Expand All @@ -115,10 +110,7 @@ function bug_group_action_print_bug_list( array $p_bug_ids_array ) {
echo '</table>';
echo '</div>';

if( ( $t_legend_position & STATUS_LEGEND_POSITION_BOTTOM ) == STATUS_LEGEND_POSITION_BOTTOM) {
echo '<br />';
html_status_legend();
}
html_status_legend( STATUS_LEGEND_POSITION_BOTTOM );
}

/**
Expand Down
41 changes: 25 additions & 16 deletions core/html_api.php
Expand Up @@ -1344,11 +1344,12 @@ function print_summary_menu( $p_page = '' ) {
}

/**
* Print the color legend for the status colors
* Print the color legend for the status colors at the requested position
* @param int $p_display_position STATUS_LEGEND_POSITION_TOP or STATUS_LEGEND_POSITION_BOTTOM
* @param bool $p_restrict_by_filter If true, only display status visible in current filter
* @return void
*/
function html_status_legend( $p_restrict_by_filter = false ) {
function html_status_legend( $p_display_position, $p_restrict_by_filter = false ) {

if( $p_restrict_by_filter ) {
# Don't show the legend if only one status is selected by the current filter
Expand Down Expand Up @@ -1403,23 +1404,31 @@ function html_status_legend( $p_restrict_by_filter = false ) {
}
}

echo '<br />';
echo '<table class="status-legend width100" cellspacing="1">';
echo '<tr>';
# Display the legend
$t_legend_position = config_get( 'status_legend_position' ) & $p_display_position;

# draw the status bar
$t_status_enum_string = config_get( 'status_enum_string' );
foreach( $t_status_array as $t_status => $t_name ) {
$t_val = isset( $t_status_names[$t_status] ) ? $t_status_names[$t_status] : $t_status_array[$t_status];
$t_status_label = MantisEnum::getLabel( $t_status_enum_string, $t_status );
if( STATUS_LEGEND_POSITION_NONE != $t_legend_position ) {
echo '<br />';
echo '<table class="status-legend width100" cellspacing="1">';
echo '<tr>';

echo '<td class="small-caption ' . $t_status_label . '-color">' . $t_val . '</td>';
}
# draw the status bar
$t_status_enum_string = config_get( 'status_enum_string' );
foreach( $t_status_array as $t_status => $t_name ) {
$t_val = isset( $t_status_names[$t_status] ) ? $t_status_names[$t_status] : $t_status_array[$t_status];
$t_status_label = MantisEnum::getLabel( $t_status_enum_string, $t_status );

echo '</tr>';
echo '</table>';
if( ON == config_get( 'status_percentage_legend' ) ) {
html_status_percentage_legend();
echo '<td class="small-caption ' . $t_status_label . '-color">' . $t_val . '</td>';
}

echo '</tr>';
echo '</table>';
if( ON == config_get( 'status_percentage_legend' ) ) {
html_status_percentage_legend();
}
}
if( STATUS_LEGEND_POSITION_TOP == $t_legend_position ) {
echo '<br />';
}
}

Expand Down
15 changes: 2 additions & 13 deletions my_view_page.php
Expand Up @@ -91,14 +91,7 @@
?>

<div>
<?php
$t_legend_position = config_get( 'status_legend_position' );

if( ( $t_legend_position & STATUS_LEGEND_POSITION_TOP ) == STATUS_LEGEND_POSITION_TOP ) {
html_status_legend();
echo '<br />';
}
?>
<?php html_status_legend( STATUS_LEGEND_POSITION_TOP ); ?>

<div>
<?php include( $g_core_path . 'timeline_inc.php' ); ?>
Expand Down Expand Up @@ -182,10 +175,6 @@
</div>

<?php
if( ( $t_legend_position & STATUS_LEGEND_POSITION_BOTTOM ) == STATUS_LEGEND_POSITION_BOTTOM ) {
html_status_legend();
}
?>
html_status_legend( STATUS_LEGEND_POSITION_BOTTOM );

<?php
html_page_bottom();
11 changes: 2 additions & 9 deletions view_all_inc.php
Expand Up @@ -87,12 +87,8 @@


# -- ====================== BUG LIST ============================ --
html_status_legend( STATUS_LEGEND_POSITION_TOP, true );

$t_legend_position = config_get( 'status_legend_position' );

if( ( $t_legend_position & STATUS_LEGEND_POSITION_TOP ) == STATUS_LEGEND_POSITION_TOP ) {
html_status_legend( true );
}
?>
<br />
<form id="bug_action" method="get" action="bug_actiongroup_page.php">
Expand Down Expand Up @@ -254,10 +250,7 @@ function write_bug_rows( array $p_rows ) {
</form>

<?php

if( ( $t_legend_position & STATUS_LEGEND_POSITION_BOTTOM ) == STATUS_LEGEND_POSITION_BOTTOM ) {
html_status_legend( true );
}
html_status_legend( STATUS_LEGEND_POSITION_BOTTOM, true );

# -- ====================== FILTER FORM ========================= --
if( ( $t_filter_position & FILTER_POSITION_BOTTOM ) == FILTER_POSITION_BOTTOM ) {
Expand Down

0 comments on commit 91f21ca

Please sign in to comment.