-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a status page, the option for access token requests to use this system, and a script for manual generation.
- Loading branch information
Showing
7 changed files
with
300 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env perl | ||
|
||
# csv-export | ||
# Offline creation of CSV export, first take | ||
|
||
use v5.14; | ||
use warnings; | ||
|
||
BEGIN { | ||
use File::Basename qw(dirname); | ||
use File::Spec; | ||
my $d = dirname(File::Spec->rel2abs($0)); | ||
require "$d/../setenv.pl"; | ||
} | ||
|
||
use open ':std', ':encoding(UTF-8)'; | ||
use Getopt::Long::Descriptive; | ||
use Path::Tiny; | ||
use CronFns; | ||
use FixMyStreet::Cobrand; | ||
use FixMyStreet::DB; | ||
use FixMyStreet::Reporting; | ||
|
||
my $site = CronFns::site(FixMyStreet->config('BASE_URL')); | ||
CronFns::language($site); | ||
|
||
my ($opts, $usage) = describe_options( | ||
'%c %o', | ||
['cobrand=s', 'which cobrand is asking for the data', { required => 1 }], | ||
['type=s', 'whether to export problems or updates', { required => 1 }], | ||
['out=s', 'where to output CSV data'], | ||
|
||
['body=i', 'Body ID to restrict export to'], | ||
['wards=s', 'Ward area IDs to restrict export to'], | ||
['category=s', 'Category to restrict export to'], | ||
['state=s', 'State to restrict export to'], | ||
['start_date=s', 'Start date for export (default 30 days ago)'], | ||
['end_date=s', 'End date for export'], | ||
|
||
['user=i', 'user ID which requested this export'], | ||
['verbose|v', 'more verbose output'], | ||
['help|h', "print usage message and exit" ], | ||
); | ||
$usage->die if $opts->help; | ||
|
||
my $use_stdout = !$opts->out || $opts->out eq '-'; | ||
my ($file, $fh); | ||
if ($use_stdout) { | ||
$fh = *STDOUT; | ||
} else { | ||
$file = path($opts->out . '-part'); | ||
$fh = $file->openw_utf8; | ||
} | ||
|
||
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($opts->cobrand); | ||
FixMyStreet::DB->schema->cobrand($cobrand); | ||
|
||
my $user = FixMyStreet::DB->resultset("User")->find($opts->user) if $opts->user; | ||
my $body = FixMyStreet::DB->resultset("Body")->find($opts->body) if $opts->body; | ||
my $wards = $opts->wards ? [split',', $opts->wards] : []; | ||
|
||
my $reporting = FixMyStreet::Reporting->new( | ||
type => $opts->type, | ||
user => $user, | ||
category => $opts->category, | ||
state => $opts->state, | ||
wards => $wards, | ||
body => $body, | ||
$opts->start_date ? (start_date => $opts->start_date) : (), | ||
end_date => $opts->end_date, | ||
); | ||
$reporting->construct_rs_filter; | ||
$reporting->csv_parameters; | ||
$reporting->generate_csv($fh); | ||
unless ($use_stdout) { | ||
$file->move($opts->out); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
[% USE date %] | ||
[% IF NOT c.get_param('ajax') %] | ||
[% INCLUDE 'header.html' | ||
title = loc('Dashboard') | ||
robots = 'noindex, nofollow' | ||
bodyclass = 'fullwidthpage'; | ||
%] | ||
|
||
[% IF body %] | ||
<hgroup> | ||
[% tprintf(loc('<h2>Reports, Statistics and Actions for</h2> <h1>%s</h1>'), body_name) %] | ||
</hgroup> | ||
[% ELSE %] | ||
<h1>[% loc('Summary statistics') %]</h1> | ||
[% END %] | ||
|
||
<p><a href="[% c.uri_for_action('dashboard/index') %]">[% loc('Back') %]</a></p> | ||
|
||
[% END %] | ||
|
||
<table id="overview" cellpadding=8 cellspacing=0> | ||
<tr> | ||
<th scope="col">[% loc('Created') %]</th> | ||
<th scope="col">[% loc('CSV File') %]</th> | ||
</tr> | ||
[% in_progress = 0 %] | ||
[% FOR file IN rows %] | ||
<tr> | ||
<td>[% date.format(file.ctime, format = '%Y-%m-%d %H:%M') %]</td> | ||
<td> | ||
[% IF file.finished %] | ||
<a href="/dashboard/csv/[% file.name %]">[% file.name %]</a> | ||
<br>[% file.size div 1024 %]KB | ||
[% ELSE %] | ||
[% file.name %] | ||
<br>[% file.size div 1024 %]KB | ||
<i>[% loc('In progress') %]</i> | ||
[% in_progress = 1 %] | ||
[% END %] | ||
</td> | ||
</tr> | ||
[% END %] | ||
</table> | ||
|
||
[% IF NOT c.get_param('ajax') %] | ||
|
||
[% IF in_progress %] | ||
<script nonce="[% csp_nonce %]"> | ||
(function() { | ||
var wait = 1; | ||
setTimeout(function refresh() { | ||
$('#overview').load('[% c.uri_for_action('dashboard/status') %]?ajax=1', function() { | ||
if ($(this).html().indexOf('<i>[% loc('In progress') %]</i>') === -1) { | ||
return; | ||
} | ||
wait += 1; | ||
if (wait > 10) { | ||
wait = 10; | ||
} | ||
setTimeout(refresh, wait * 1000); | ||
}); | ||
}, wait * 1000); | ||
})(); | ||
</script> | ||
[% END %] | ||
|
||
[% INCLUDE 'footer.html' %] | ||
[% END %] |