Skip to content

Commit

Permalink
Fix dynamic CSS script for status color
Browse files Browse the repository at this point in the history
Avoids problem with spaces in custom status enum.
- CSS class is now named based on enum value
- code cleanup and optimization
  • Loading branch information
dregad committed Oct 24, 2015
2 parents 5e12bf9 + 4a71f24 commit 73e5f8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 17 additions & 6 deletions core/html_api.php
Expand Up @@ -1430,10 +1430,13 @@ function html_status_legend( $p_display_position, $p_restrict_by_filter = false
# 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 );
$t_val = isset( $t_status_names[$t_status] )
? $t_status_names[$t_status]
: $t_status_array[$t_status];

echo '<td class="small-caption ' . $t_status_label . '-color">' . $t_val . '</td>';
echo '<td class="small-caption status-legend-width '
. html_get_status_css_class( $t_status ) . '">'
. $t_val . '</td>';
}

echo '</tr>';
Expand Down Expand Up @@ -1471,8 +1474,11 @@ function html_status_percentage_legend() {
$t_percent = ( isset( $t_status_percents[$t_status] ) ? $t_status_percents[$t_status] : 0 );

if( $t_percent > 0 ) {
$t_status_label = MantisEnum::getLabel( $t_status_enum_string, $t_status );
echo '<td class="small-caption-center ' . $t_status_label . '-color ' . $t_status_label . '-percentage">' . $t_percent . '%</td>';
$t_class = html_get_status_css_class( $t_status );
echo '<td class="small-caption-center '
. $t_class . ' '
. str_replace( 'color', 'percentage', $t_class ) . '">'
. $t_percent . '%</td>';
}
}

Expand Down Expand Up @@ -1906,5 +1912,10 @@ function html_buttons_view_bug_page( $p_bug_id ) {
* Build CSS including project or even user-specific colors ?
*/
function html_get_status_css_class( $p_status, $p_user = null, $p_project = null ) {
return string_attribute( MantisEnum::getLabel( config_get( 'status_enum_string', null, $p_user, $p_project ), $p_status ) . '-color' );
$t_status_enum = config_get( 'status_enum_string', null, $p_user, $p_project );
if( MantisEnum::hasValue( $t_status_enum, $p_status ) ) {
return 'status-' . $p_status . '-color';
} else {
return '';
}
}
20 changes: 15 additions & 5 deletions css/status_config.php
Expand Up @@ -71,15 +71,25 @@
$t_status_string = config_get( 'status_enum_string' );
$t_statuses = MantisEnum::getAssocArrayIndexedByValues( $t_status_string );
$t_colors = config_get( 'status_colors' );
$t_color_count = count( $t_colors );
$t_color_width = ( $t_color_count > 0 ? ( round( 100/$t_color_count ) ) : 0 );
$t_status_percents = auth_is_user_authenticated() ? get_percentage_by_status() : array();

foreach( $t_statuses AS $t_id=>$t_label ) {
foreach( $t_statuses as $t_id => $t_label ) {
$t_css_class = html_get_status_css_class( $t_id );

# Status color class
if( array_key_exists( $t_label, $t_colors ) ) {
echo ".$t_label-color { background-color: {$t_colors[$t_label]}; width: $t_color_width%; }\n";
echo '.' . $t_css_class
. " { background-color: {$t_colors[$t_label]}; }\n";
}

# Status percentage width class
if( array_key_exists( $t_id, $t_status_percents ) ) {
echo ".$t_label-percentage { width: {$t_status_percents[$t_id]}%; }\n";
echo '.' . str_replace( 'color', 'percentage', $t_css_class )
. " { width: {$t_status_percents[$t_id]}%; }\n";
}
}

# Status legend width class
$t_color_count = count( $t_colors );
$t_color_width = ( $t_color_count > 0 ? ( round( 100/$t_color_count ) ) : 0 );
echo ".status-legend-width { width: $t_color_width%; }\n";

0 comments on commit 73e5f8c

Please sign in to comment.