Skip to content

Commit

Permalink
Build a progress bar for exporting data from a Thing. Fixes bug #11925.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Oct 25, 2010
1 parent 0f64843 commit 7cae1fd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -12,6 +12,7 @@
- fixed #11922: Help tempalte is squatting on a good URL
- fixed #11923: Collaboration System Mail Cron Errors
- fixed #11925: Some problems in Thingy export (metaData values in CSV export)
- fixed #11925: Some problems in Thingy export (export times out on Things with many rows)

7.9.16
- fixed #11789: Date form reports 1 day earlier on Edit for the time zone corresponding to Europe/Berlin.
Expand Down
25 changes: 18 additions & 7 deletions lib/WebGUI/Asset/Wobject/Thingy.pm
Expand Up @@ -21,6 +21,7 @@ use WebGUI::DateTime;
use base 'WebGUI::Asset::Wobject';
use Data::Dumper;
use PerlIO::eol qw/NATIVE/;
use WebGUI::ProgressBar;


#-------------------------------------------------------------------
Expand Down Expand Up @@ -2686,6 +2687,11 @@ sub www_export {
my $thingProperties = $self->getThing($thingId);
return $session->privilege->insufficient() unless $self->hasPrivileges($thingProperties->{groupIdExport});

my $i18n = WebGUI::International->new($session, 'Asset_Thingy');
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($i18n->get('export label').' '.$thingProperties->{label}, $session->url->extras('assets/thingy.gif'));
$pb->update($i18n->get('Creating column headers'));
my $tempStorage = WebGUI::Storage->createTemp($session);
$fields = $session->db->read('select * from Thingy_fields where assetId =? and thingId = ? order by sequenceNumber',
[$self->get("assetId"),$thingId]);
while (my $field = $fields->hashRef) {
Expand All @@ -2707,9 +2713,13 @@ sub www_export {

### Loop through the returned structure and put it through Text::CSV
# Column heads
$out = WebGUI::Text::joinCSV(@fieldLabels);
my $csv_filename = 'export_'.$thingProperties->{label}.'.csv';
$tempStorage->addFileFromScalar($csv_filename, WebGUI::Text::joinCSV(@fieldLabels));
open my $CSV, '>', $tempStorage->getPath($csv_filename);

# Data lines
$pb->update($i18n->get('Writing data'));
my $rowCounter = 0;
while (my $data = $sth->hashRef) {
my @fieldValues;
foreach my $field (@fields){
Expand All @@ -2723,14 +2733,15 @@ sub www_export {
push(@fieldValues,$data->{$metaDataField});
}
}
$out .= "\n".WebGUI::Text::joinCSV( @fieldValues );
print $CSV "\n".WebGUI::Text::joinCSV( @fieldValues );
#if (! ++$rowCounter % 25) {
$pb->update($i18n->get('Writing data'));
#}
}

$fileName = "export_".$thingProperties->{label}.".csv";
$self->session->http->setFilename($fileName,"application/octet-stream");
$self->session->http->sendHeader;
return $out;
close $CSV;

$pb->update(sprintf q|<a href="%s">%s</a>|, $self->getUrl, sprintf($i18n->get('Return to %s'), $thingProperties->{label}));
return $pb->finish($tempStorage->getUrl($csv_filename));
}

#-------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions lib/WebGUI/i18n/English/Asset_Thingy.pm
Expand Up @@ -1121,6 +1121,24 @@ search has been done.|,
lastUpdated => 1231180362,
},

'Creating column headers' => {
message => q|Creating column headers.|,
lastUpdated => 1231180362,
context => q|Status message in the Export Thingy progress bar.|,
},

'Writing data' => {
message => q|Writing data.|,
lastUpdated => 1231180362,
context => q|Status message in the Export Thingy progress bar.|,
},

'Return to %s' => {
message => q|Return to %s.|,
lastUpdated => 1231180362,
context => q|Status message in the Export Thingy progress bar. %s is the name of the Thing that is being exported.|,
},

};

1;

0 comments on commit 7cae1fd

Please sign in to comment.