aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm145
-rw-r--r--templates/web/default/admin/header.html2
-rw-r--r--templates/web/default/admin/search_reports.html81
3 files changed, 162 insertions, 66 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 99a7a962b..11194fbcf 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -351,6 +351,86 @@ sub council_edit : Path('council_edit') : Args(2) {
return 1;
}
+sub search_reports : Path('search_reports') {
+ my ( $self, $c ) = @_;
+
+ $c->forward('set_allowed_pages');
+
+
+ if (my $search = $c->req->param('search')) {
+ $c->stash->{searched} = 1;
+
+ my $search_n = 0;
+ $search_n = int($search) if $search =~ /^\d+$/;
+
+ my $like_search = "%$search%";
+
+ # when DBIC creates the join it does 'JOIN users user' in the
+ # SQL which makes PostgreSQL unhappy as user is a reserved
+ # word, hence we need to quote this SQL. However, the quoting
+ # makes PostgreSQL unhappy elsewhere so we only want to do
+ # it for this query and then switch it off afterwards.
+ $c->model('DB')->schema->storage->sql_maker->quote_char( '"' );
+
+ my $problems = $c->model('DB::Problem')->search(
+ {
+ -or => [
+ 'me.id' => $search_n,
+ 'user.email' => { ilike => $like_search },
+ 'me.name' => { ilike => $like_search },
+ title => { ilike => $like_search },
+ detail => { ilike => $like_search },
+ council => { like => $like_search },
+ cobrand_data => { like => $like_search },
+ # site restriction
+ ]
+ },
+ {
+ prefetch => 'user',
+ order_by => [\"(state='hidden')",'created']
+ }
+ );
+
+ $c->stash->{problems} = [ $problems->all ];
+
+ # Switch quoting back off. See above for explanation of this.
+ $c->model('DB')->schema->storage->sql_maker->quote_char( '' );
+
+ $c->stash->{edit_council_contacts} = 1
+ if ( grep {$_ eq 'councilcontacts'} keys %{$c->stash->{allowed_pages}});
+ }
+
+# print $q->h2(_('Updates'));
+# my $updates = Problems::update_search($search);
+# admin_show_updates($q, $updates);
+# }
+
+}
+
+sub set_allowed_pages : Private {
+ my ( $self, $c ) = @_;
+
+ my $allowed_pages = $c->cobrand->admin_pages;
+
+ if( !$allowed_pages ) {
+ $allowed_pages = {
+ 'summary' => [_('Summary'), 0],
+ 'councilslist' => [_('Council contacts'), 1],
+ 'reports' => [_('Search Reports'), 2],
+ 'timeline' => [_('Timeline'), 3],
+ 'questionnaire' => [_('Survey Results'), 4],
+ 'councilcontacts' => [undef, undef],
+ 'counciledit' => [undef, undef],
+ 'report_edit' => [undef, undef],
+ 'update_edit' => [undef, undef],
+ }
+ }
+
+ $c->stash->{allowed_pages} = $allowed_pages;
+
+ return 1;
+}
+
# use Encode;
#
# use Page;
@@ -448,71 +528,6 @@ sub check_token : Private {
#
#
# sub admin_reports {
-# my $q = shift;
-# my $title = _('Search Reports');
-# my $cobrand = Page::get_cobrand($q);
-# my $pages = allowed_pages($q);
-# print html_head($q, $title);
-# print $q->h1($title);
-# print $q->start_form(-method => 'GET', -action => './');
-# print $q->label({-for => 'search'}, _('Search:')), ' ', $q->textfield(-id => 'search', -name => "search", -size => 30);
-# print $q->hidden('page');
-# print $q->end_form;
-#
-# if (my $search = $q->param('search')) {
-# my $results = Problems::problem_search($search);
-# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0});
-# print $q->Tr({}, $q->th({}, [_('ID'), _('Title'), _('Name'), _('Email'), _('Council'), _('Category'), _('Anonymous'), _('Cobrand'), _('Created'), _('State'), _('When sent'), _('*') ]));
-# my $cobrand_data;
-# foreach (@$results) {
-# my $url = $_->{id};
-# if ($_->{state} eq 'confirmed' || $_->{state} eq 'fixed') {
-# # if this is a cobranded admin interface, but we're looking at a generic problem, figure out enough information
-# # to create a URL to the cobranded version of the problem
-# if ($_->{cobrand}) {
-# $cobrand_data = $_->{cobrand_data};
-# } else {
-# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, $_);
-# }
-# $url = $q->a({ -href => Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $_->{id} }, $url);
-# }
-# my $council = $_->{council} || ' ';
-# my $category = $_->{category} || ' ';
-# (my $confirmed = $_->{confirmed} || '-') =~ s/ (.*?)\..*/ $1/;
-# (my $created = $_->{created}) =~ s/\..*//;
-# (my $lastupdate = $_->{lastupdate}) =~ s/ (.*?)\..*/ $1/;
-# (my $whensent = $_->{whensent} || ' ') =~ s/\..*//;
-# my $state = $_->{state};
-# $state .= '<small>';
-# $state .= "<br>" . _('Confirmed:') . "&nbsp;$confirmed" if $_->{state} eq 'confirmed' || $_->{state} eq 'fixed';
-# $state .= '<br>' . _('Fixed:') . ' ' . $lastupdate if $_->{state} eq 'fixed';
-# $state .= "<br>" . _('Last&nbsp;update:') . "&nbsp;$lastupdate" if $_->{state} eq 'confirmed';
-# $state .= '</small>';
-# my $anonymous = $_->{anonymous} ? _('Yes') : _('No');
-# my $cobrand = $_->{cobrand};
-# $cobrand .= "<br>" . $_->{cobrand_data};
-# my $counciltext = '';
-# if (grep {$_ eq 'councilcontacts'} keys %{$pages}) {
-# $counciltext = $q->a({ -href => NewURL($q, page=>'councilcontacts', area_id=>$council)}, $council);
-# } else {
-# $counciltext = $council;
-# }
-# my $attr = {};
-# $attr->{-class} = 'hidden' if $_->{state} eq 'hidden';
-# print $q->Tr($attr, $q->td([ $url, ent($_->{title}), ent($_->{name}), ent($_->{email}),
-# $counciltext,
-# $category, $anonymous, $cobrand, $created, $state, $whensent,
-# $q->a({ -href => NewURL($q, page=>'report_edit', id=>$_->{id}) }, _('Edit'))
-# ]));
-# }
-# print $q->end_table;
-#
-# print $q->h2(_('Updates'));
-# my $updates = Problems::update_search($search);
-# admin_show_updates($q, $updates);
-# }
-#
-# print html_tail($q);
# }
#
# sub admin_edit_report {
diff --git a/templates/web/default/admin/header.html b/templates/web/default/admin/header.html
index 66ffaf770..355bd5b6e 100644
--- a/templates/web/default/admin/header.html
+++ b/templates/web/default/admin/header.html
@@ -12,7 +12,7 @@ dd { margin-left: 8em; }
<strong>[% loc('FixMyStreet admin:') %]</strong>
<a href="[% c.uri_for( '' ) %]">[% loc('Summary') %]</a>
<a href="[% c.uri_for( 'council_list' ) %]">[% loc('Council contacts') %]</a>
- <a href="">[% loc('Search Reports') %]</a>
+ <a href="[% c.uri_for( 'search_reports' ) %]">[% loc('Search Reports') %]</a>
<a href="">[% loc('Timeline') %]</a>
<a href="[% c.uri_for( 'questionnaire') %]">[% loc('Survey Results') %]</a>
diff --git a/templates/web/default/admin/search_reports.html b/templates/web/default/admin/search_reports.html
new file mode 100644
index 000000000..56e9e41d8
--- /dev/null
+++ b/templates/web/default/admin/search_reports.html
@@ -0,0 +1,81 @@
+[% INCLUDE 'admin/header.html' title=loc('Search Reports') %]
+
+[% BLOCK value_or_nbsp -%]
+ [%- IF value %][% value | html %][% ELSE %]&nbsp;[% END %]
+[%- END %]
+
+[% BLOCK format_time -%]
+ [%- IF time %][% time.ymd %]&nbsp;[% time.hms %][% ELSE %]&nbsp;[% END %]
+[%- END %]
+
+<form method="get" action="[% c.uri_for('search_reports') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8">
+ <label for="search">Search:</label> <input type="text" name="search" size="30" id="search">
+</form>
+
+
+[% IF searched %]
+<table cellspacing="0" cellpadding="2" border="1">
+ <tr>
+ <th>ID</th>
+ <th>Title</th>
+ <th>Name</th>
+ <th>Email</th>
+ <th>Council</th>
+ <th>Category</th>
+ <th>Anonymous</th>
+ <th>Cobrand</th>
+ <th>Created</th>
+ <th>State</th>
+ <th>When sent</th>
+ <th>*</th>
+ </tr>
+[%- FOREACH problem IN problems %]
+ <tr[% ' class="hidden"' IF problem.state == 'hidden' %]>
+ <td>[%- IF problem.state == 'confirmed' || problem.state == 'fixed' -%]
+ [%- cobrand_data = problem.cobrand_data %]
+ [%- cobrand_data = c.data_for_generic_problem IF !problem.cobrand %]
+ <a href="[% c.uri_for_email( '/report', problem.id, cobrand_data ) %]">[% problem.id %]</a>
+ [%- ELSE %]
+ [%- problem.id %]
+ [%- END -%]</td>
+ <td>[% PROCESS value_or_nbsp value=problem.title %]</td>
+ <td>[% PROCESS value_or_nbsp value=problem.name %]</td>
+ <td>[% PROCESS value_or_nbsp value=problem.user.email %]</td>
+ <td>[%- IF edit_council_contacts -%]
+ <a href="[% c.uri_for('council_contacts', problem.council ) %]">[% PROCESS value_or_nbsp value=problem.council %]</a>
+ [%- ELSE -%]
+ [%- PROCESS value_or_nbsp value=problem.council -%]
+ [%- END -%]</td>
+ <td>[% PROCESS value_or_nbsp value=problem.category %]</td>
+ <td>[% IF problem.anonymous %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td>
+ <td>[% problem.cobrand %]<br>[% problem.cobrand_data | html %]</td>
+ <td>[% PROCESS format_time time=problem.created %]</td>
+ <td>[% problem.state %]<small>
+ [%- IF problem.state == 'fixed' || problem.state == 'confirmed' %]<br>[% loc('Confirmed:' ) %]&nbsp;[% PROCESS format_time time=problem.confirmed %][% END -%]
+ [%- IF problem.state == 'fixed' %]<br>[% loc('Fixed:') %] [% PROCESS format_time time=problem.lastupdate %][% END -%]
+ [%- IF problem.state == 'confirmed' %]<br>[% loc('Last&nbsp;update:') %] [% PROCESS format_time time=problem.lastupdate %][% END -%]</small>
+ </td>
+ <td>[% PROCESS format_time time=problem.whensent %]</td>
+ <td><a href="[% c.uri_for( 'report_edit', problem.id ) %]">Edit</a></td>
+ </tr>
+[%- END -%]
+</table>
+
+<h2>Updates</h2>
+
+<table cellspacing="0" cellpadding="2" border="1">
+ <tr>
+ <th>ID</th>
+ <th>State</th>
+ <th>Name</th>
+ <th>Email</th>
+ <th>Created</th>
+ <th>Cobrand</th>
+ <th>Text</th>
+ <th>*</th>
+ </tr>
+<tr>
+</table>
+[% END %]
+
+[% INCLUDE 'admin/footer.html' %]