Skip to content

Commit

Permalink
Timeline fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dregad committed Jan 22, 2015
2 parents d698fd7 + 8139fa8 commit e77fcd4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 25 deletions.
72 changes: 64 additions & 8 deletions core/classes/IssueStatusChangeTimelineEvent.class.php
Expand Up @@ -31,6 +31,16 @@ class IssueStatusChangeTimelineEvent extends TimelineEvent {
private $issue_id;
private $old_status;
private $new_status;
private $type;

/**
* Status change types to be displayed in Timeline
* IGNORED = not displayed
*/
const IGNORED = 0;
const RESOLVED = 1;
const CLOSED = 2;
const REOPENED = 3;

/**
* @param integer $p_timestamp Timestamp representing the time the event occurred.
Expand All @@ -45,24 +55,70 @@ public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_old_statu
$this->issue_id = $p_issue_id;
$this->old_status = $p_old_status;
$this->new_status = $p_new_status;
$this->type = $this->change_type();
}

/**
* Returns html string to display
* @return string
* Return the type of status change
* @return int One of the status change constants defined above
*/
public function html() {
private function change_type() {
$t_resolved = config_get( 'bug_resolved_status_threshold' );
$t_closed = config_get( 'bug_closed_status_threshold' );

if( $this->old_status < $t_closed && $this->new_status >= $t_closed ) {
$t_string = sprintf( lang_get( 'timeline_issue_closed' ), user_get_name( $this->user_id ), string_get_bug_view_link( $this->issue_id ) );
return IssueStatusChangeTimelineEvent::CLOSED;
} else if( $this->old_status < $t_resolved && $this->new_status >= $t_resolved ) {
$t_string = sprintf( lang_get( 'timeline_issue_resolved' ), user_get_name( $this->user_id ), string_get_bug_view_link( $this->issue_id ) );
return IssueStatusChangeTimelineEvent::RESOLVED;
} else if( $this->old_status >= $t_resolved && $this->new_status < $t_resolved ) {
$t_string = sprintf( lang_get( 'timeline_issue_reopened' ), user_get_name( $this->user_id ), string_get_bug_view_link( $this->issue_id ) );
return IssueStatusChangeTimelineEvent::REOPENED;
} else {
return '';
return IssueStatusChangeTimelineEvent::IGNORED;
}
}

/**
* Whether to skip this timeline event.
* This normally implements access checks for the event.
* @return boolean
*/
public function skip() {
return $this->type == IssueStatusChangeTimelineEvent::IGNORED;
}

/**
* Returns html string to display
* @return string
*/
public function html() {
switch( $this->type ) {
case IssueStatusChangeTimelineEvent::RESOLVED:
$t_string = sprintf(
lang_get( 'timeline_issue_resolved' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::CLOSED:
$t_string = sprintf(
lang_get( 'timeline_issue_closed' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::REOPENED:
$t_string = sprintf(
lang_get( 'timeline_issue_reopened' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::IGNORED:
return '';
default:
# Unknown status change type
trigger_error( ERROR_GENERIC, ERROR );
return '';
}

$t_html = $this->html_start();
Expand All @@ -71,4 +127,4 @@ public function html() {

return $t_html;
}
}
}
9 changes: 9 additions & 0 deletions core/classes/TimelineEvent.class.php
Expand Up @@ -69,6 +69,15 @@ public function compare( TimelineEvent $p_other ) {
return 0;
}

/**
* Whether to skip this timeline event.
* This normally implements access checks for the event.
* @return boolean
*/
public function skip() {
return false;
}

/**
* Returns html string to display
* @return string
Expand Down
24 changes: 19 additions & 5 deletions core/timeline_api.php
Expand Up @@ -68,6 +68,7 @@ function timeline_get_affected_issues( $p_start_time, $p_end_time ) {

/**
* Get an array of timeline events
* Events for which the skip() method returns true will be excluded
* @param integer $p_start_time Timestamp representing start time of the period.
* @param integer $p_end_time Timestamp representing end time of the period.
* @return array
Expand Down Expand Up @@ -127,7 +128,8 @@ function timeline_events( $p_start_time, $p_end_time ) {
break;
}

if( $t_event != null ) {
# Do not include skipped events
if( $t_event != null && !$t_event->skip() ) {
$t_timeline_events[] = $t_event;
}
}
Expand Down Expand Up @@ -163,12 +165,24 @@ function timeline_sort_events( array $p_events ) {

/**
* Print for display an array of events
* @param array $p_events Array of events to display.
* @return void
* @param array $p_events Array of events to display
* @param int $p_max_num Maximum number of events to display, 0 = all
* @return int Number of displayed events
*/
function timeline_print_events( array $p_events ) {
foreach ( $p_events as $t_event ) {
function timeline_print_events( array $p_events, $p_max_num = 0 ) {
if( empty( $p_events ) ) {
echo '<p>' . lang_get( 'timeline_no_activity' ) . '</p>';
return 0;
}

$i = 0;
foreach( $p_events as $t_event ) {
# Stop displaying events if we're reached the maximum
if( $p_max_num && $i++ >= $p_max_num ) {
break;
}
echo $t_event->html();
}
return min( $p_max_num, $i);
}

21 changes: 9 additions & 12 deletions core/timeline_inc.php
Expand Up @@ -17,11 +17,13 @@
require_once( 'core.php' );
require_api( 'timeline_api.php' );

define( 'MAX_EVENTS', 50 );

$f_days = gpc_get_int( 'days', 0 );
$f_all = gpc_get_int( 'all', 0 );

$t_end_time = time() - ( $f_days * 24 * 60 * 60 );
$t_start_time = $t_end_time - ( 7 * 24 * 60 * 60 );
$t_end_time = time() - ( $f_days * SECONDS_PER_DAY );
$t_start_time = $t_end_time - ( 7 * SECONDS_PER_DAY );
$t_events = timeline_events( $t_start_time, $t_end_time );

echo '<div class="timeline">';
Expand All @@ -44,17 +46,12 @@
echo '<div class="date-range">' . date( $t_short_date_format, $t_start_time ) . ' .. ' . date( $t_short_date_format, $t_end_time ) . $t_prev_link . $t_next_link . '</div>';
$t_events = timeline_sort_events( $t_events );

if ( $f_all == 0 ) {
$t_events = array_slice( $t_events, 0, 50 );
}

if( count( $t_events ) > 0 ) {
timeline_print_events( $t_events );
} else {
echo '<p>' . lang_get( 'timeline_no_activity' ) . '</p>';
}
$t_num_events = timeline_print_events( $t_events, ( $f_all ? 0 : MAX_EVENTS ) );

if( $f_all == 0 ) {
# Don't display "More Events" link if there are no more entries to show
# Note: as of 2015-01-19, this does not cover the case of entries excluded
# by filtering (e.g. Status Change not in RESOLVED, CLOSED, REOPENED)
if( !$f_all && $t_num_events < count( $t_events )) {
echo '<p>' . $t_prev_link = ' [ <a href="my_view_page.php?days=' . $f_days . '&amp;all=1">' . lang_get( 'timeline_more' ) . '</a> ]</p>';
}

Expand Down

0 comments on commit e77fcd4

Please sign in to comment.