From e6aeb5dceeefbf3b449687e26cc6e9070288d4bb Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 8 Oct 2009 19:10:43 -0700 Subject: [PATCH] Make the EMS handle displaying a schedule when the user has not entered in locations. Fixes bug #10874 --- docs/changelog/7.x.x.txt | 1 + .../Asset/Wobject/EventManagementSystem.pm | 34 ++++----- t/Asset/Wobject/EventManagementSystem.t | 69 +++++++++++++++++-- 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index abacaeaa3..eb7e5f45a 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,7 @@ - fixed #11104: Wrong name for request tracker post form template - fixed #11077: Untested result in WebGUI::Storage->getFiles - fixed #11080: Asset Manage Crumb Trail flyout menu + - fixed #10874: EMS Schedule displaying incorrectly 7.8.1 - mark $session->datetime->time as deprecated and remove its use from core code diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index ae04b1d45..f1f4d3ad0 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -288,23 +288,12 @@ sub getLocations { my %hash; my %hashDate; + my %h; my $tickets = $self->getTickets; - for my $ticket ( @$tickets ) { - my $name = $ticket->get('location'); - my $date = $ticket->get('startDate'); - $hash{$name} = 1 if defined $name; - # cut off the time from the startDate. - $date =~ s/\s*\d+:\d+(:\d+)?// if defined $date; - $hashDate{$date} = 1 if defined $date; - } - my @locations = sort keys %hash; - push @$dateRef, sort keys %hashDate ; -# @locations = $self->session->db->read(q{ -# select distinct(EMSTicket.location) -# from EMSTicket join asset using (assetId) -# where asset.parentId = ? -# order by EMSTicket.location -# },[$self->getId])->array; +# this is a really compact 'uniq' operation + my @locations = map { $h{$_}++ == 0 ? $_ : () } ( map { $_->get('location') } ( @$tickets ) ); +# the dates have the time data removed with a pattern substitution + push @$dateRef, map { s/\s*\d+:\d+(:\d+)?//; $h{$_}++ == 0 ? $_ : () } ( map { $_->get('startDate') } ( @$tickets ) ); return @locations; } @@ -1198,7 +1187,7 @@ sub www_getScheduleDataJSON { and ( assetData.status = 'approved' or assetData.tagId = ? ) ) - order by EMSTicket.startDate + order by EMSTicket.startDate, eventNumber asc },[ $self->getId, $currentDate, $session->scratch->get("versionTag") ]); @@ -1206,8 +1195,10 @@ sub www_getScheduleDataJSON { tie %hash, 'Tie::IxHash'; while( my $row = $tickets->hashRef ) { $row->{type} = 'ticket'; - $hash{$row->{startDate}}{$row->{location}} = $row; + $row->{location} = ' ' if $row->{location} eq ''; + push @{$hash{$row->{startDate}}{$row->{location}}}, $row; } + grep { $_ = ' ' if defined $_ && $_ eq '' } @ticketLocations; my %results = (); $results{records} = []; ##Initialize to an empty array my $ctr = 0; @@ -1215,20 +1206,25 @@ sub www_getScheduleDataJSON { # fill out the columns in the table while( $ctr < $locationsPerPage ) { $locationMap{ 'col' . ++$ctr } = '' }; push @{$results{records}}, { colDate => '' , map { $_ , { type => 'label', title => $locationMap{$_} || '' } } ( keys %locationMap ) }; + my $redo = 0; for my $startDate ( keys %hash ) { + $redo = 0; my $row = { colDate => $startDate }; my $empty = 1; for my $col ( keys %locationMap ) { my $location = $locationMap{$col}; if( exists $hash{$startDate}{$location} ) { - $row->{$col} = $hash{$startDate}{$location}; + $row->{$col} = pop @{$hash{$startDate}{$location}}; $empty = 0; + $redo = 1 if scalar(@{$hash{$startDate}{$location}}) > 0; + delete $hash{$startDate}{$location} if scalar(@{$hash{$startDate}{$location}}) == 0; } else { $row->{$col} = { type => 'empty' }; } } next if $empty; push @{$results{records}}, $row; + redo if $redo; } my $rowCount = scalar(@{$results{records}}); diff --git a/t/Asset/Wobject/EventManagementSystem.t b/t/Asset/Wobject/EventManagementSystem.t index 9385fee85..9796a6d91 100644 --- a/t/Asset/Wobject/EventManagementSystem.t +++ b/t/Asset/Wobject/EventManagementSystem.t @@ -49,7 +49,7 @@ $versionTag->set({name=>"EventManagementSystem Test"}); #---------------------------------------------------------------------------- # Tests -plan tests => 34 ; # Increment this number for each test you create +plan tests => 35 ; # Increment this number for each test you create #---------------------------------------------------------------------------- @@ -185,7 +185,7 @@ cmp_deeply($records, [], 'www_getScheduleDataJSON: visitor may not see the sched $session->user({userId => $attender->getId}); $json = $ems->www_getScheduleDataJSON(); $records = eval { JSON::from_json($json)->{records} }; -cmp_deeply($records, [ignore(), ignore()], '... attender can see the schedule JSON'); +cmp_deeply($records, [ignore(), ignore(), ignore()], '... attender can see the schedule JSON'); foreach my $ticket (@tickets) { $ticket->purge; @@ -297,12 +297,26 @@ my @tickets= ( startDate => '2009-01-01 14:00:00', location => 'f', }), + $ems->addChild({ + className => "WebGUI::Asset::Sku::EMSTicket", + title => 'lecture 13 blank location 2 pm', + eventNumber => 13, + startDate => '2009-01-01 14:00:00', + location => '', + }), + $ems->addChild({ + className => "WebGUI::Asset::Sku::EMSTicket", + title => 'lecture 14 blank location 2 pm', + eventNumber => 14, + startDate => '2009-01-01 14:00:00', + location => '', + }), ); -is( scalar(@tickets), 12, 'created tickets for ems'); +is( scalar(@tickets), 14, 'created tickets for ems'); my $tickets = $ems->getTickets; -is(scalar(@{ $tickets }), 12, 'Fourteen tickets exist'); +is(scalar(@{ $tickets }), 14, 'Fourteen tickets exist'); my $locations = [ $ems->getLocations ]; -cmp_deeply($locations, [ 'a','b','c','d','e','f' ], 'get locations returns all expected locations'); +cmp_deeply($locations, [ 'a','b','c','d','e','f','' ], 'get locations returns all expected locations'); # print 'locations=[', join( ',', @$locations ),"]\n"; $data = $ems->www_getScheduleDataJSON(); @@ -312,7 +326,7 @@ sub ticketInfo { my $tk = shift; return { title => $tk->get('title'), assetId => $tk->get('assetId'), description => $tk->get('description'), - location => $tk->get('location'), + location => $tk->get('location') || ' ', startDate => $tk->get('startDate'), }; } cmp_deeply( JSON::from_json($data), { @@ -373,6 +387,47 @@ cmp_deeply( JSON::from_json($data), { pageSize => 10, rowsPerPage => 6, }, - 'twelve tickets: schedule data looks good' + 'Fourteen tickets: schedule data looks good' +); +$session->request->setup_body({ locationPage => 2 } ); +$data = $ems->www_getScheduleDataJSON(); +cmp_deeply( JSON::from_json($data), { + records => [ + { colDate => '', + col1 => { type => 'label', title => 'f' }, + col2 => { type => 'label', title => ' ' }, + col3 => { type => 'label', title => '' }, + col4 => { type => 'label', title => '' }, + col5 => { type => 'label', title => '' }, + }, + { colDate => $tickets[11]->get('startDate'), + col1 => ticketInfo( $tickets[11] ), + col2 => ticketInfo( $tickets[13] ), + col3 => { type => 'empty' }, + col4 => { type => 'empty' }, + col5 => { type => 'empty' }, + }, + { colDate => $tickets[13]->get('startDate'), + col1 => { type => 'empty' }, + col2 => ticketInfo( $tickets[12] ), + col3 => { type => 'empty' }, + col4 => { type => 'empty' }, + col5 => { type => 'empty' }, + }, + ], + totalRecords => 3, + recordsReturned => 3, + startIndex => 0, + sort => undef, + dir => 'asc', + totalLocationPages => 2, + currentLocationPage => 2, + totalDatePages => 1, + currentDatePage => 1, + dateRecords => [ '2009-01-01' ], + pageSize => 10, + rowsPerPage => 3, + }, + 'Location page #2 looks good' );