1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
package FixMyStreet::Cobrand::Zurich;
use base 'FixMyStreet::Cobrand::Default';
use POSIX qw(strcoll);
use strict;
use warnings;
sub enter_postcode_text {
my ( $self ) = @_;
return _('Enter a Zürich street name');
}
sub example_places {
return [ 'Langstrasse', 'Basteiplatz' ];
}
# If lat/lon are in the URI, we must have zoom as well, otherwise OpenLayers defaults to 0.
sub uri {
my ( $self, $uri ) = @_;
$uri->query_param( zoom => 7 )
if $uri->query_param('lat') && !$uri->query_param('zoom');
return $uri;
}
sub remove_redundant_areas {
my $self = shift;
my $all_areas = shift;
# Remove all except Zurich
foreach (keys %$all_areas) {
delete $all_areas->{$_} unless $_ eq 274456;
}
}
sub show_unconfirmed_reports {
1;
}
# Specific administrative displays
sub admin_type {
my $self = shift;
my $c = $self->{c};
my $user = $c->user;
my $body = $user->from_body;
$c->stash->{body} = $body;
my $parent = $body->parent;
my $children = $body->bodies->count;
my $type;
if (!$parent) {
$type = 'super';
} elsif ($parent && $children) {
$type = 'dm';
} elsif ($parent) {
$type = 'sdm';
}
$c->stash->{admin_type} = $type;
return $type;
}
sub admin {
my $self = shift;
my $c = $self->{c};
my $type = $c->stash->{admin_type};
if ($type eq 'dm') {
$c->stash->{template} = 'admin/index-dm.html';
my $body = $c->stash->{body};
my @children = map { $_->id } $body->bodies->all;
my @all = (@children, $body->id);
# XXX No multiples or missing bodies
$c->stash->{unconfirmed} = $c->cobrand->problems->search({
state => 'unconfirmed',
bodies_str => $c->stash->{body}->id,
});
$c->stash->{approval} = $c->cobrand->problems->search({
'me.state' => 'in progress',
bodies_str => \@children,
'comments.state' => 'unconfirmed'
}, { join => 'comments', distinct => 1 } );
$c->stash->{other} = $c->cobrand->problems->search({
state => { '!=', 'unconfirmed' },
bodies_str => \@all,
});
} elsif ($type eq 'sdm') {
$c->stash->{template} = 'admin/index-sdm.html';
my $body = $c->stash->{body};
# XXX No multiples or missing bodies
my $p = $c->cobrand->problems->search({
'me.state' => 'in progress',
bodies_str => $body->id,
} );
$c->stash->{reports_new} = $p->search({
'comments.state' => undef
}, { join => 'comments', distinct => 1 } );
$c->stash->{reports_unpublished} = $p->search({
'comments.state' => 'unconfirmed'
}, { join => 'comments', distinct => 1 } );
$c->stash->{reports_published} = $p->search({
'comments.state' => 'confirmed'
}, { join => 'comments', distinct => 1 } );
}
}
sub admin_report_edit {
my $self = shift;
my $c = $self->{c};
my $type = $c->stash->{admin_type};
my $problem = $c->stash->{problem};
my $body = $c->stash->{body};
if ($type ne 'super') {
my %allowed_bodies = map { $_->id => 1 } ( $body->bodies->all, $body );
$c->detach( '/page_error_404_not_found' )
unless $allowed_bodies{$problem->bodies_str};
}
if ($type eq 'super') {
my @bodies = $c->model('DB::Body')->all();
@bodies = sort { strcoll($a->name, $b->name) } @bodies;
$c->stash->{bodies} = \@bodies;
} elsif ($type eq 'dm') {
# Can assign to other DMs, and their own subdivisions
my @bodies = $c->model('DB::Body')->search( [ { parent => $body->parent->id }, { parent => $body->id } ] );
@bodies = sort { strcoll($a->name, $b->name) } @bodies;
$c->stash->{bodies} = \@bodies;
} elsif ($type eq 'sdm') {
# Has cut-down edit template for adding update and sending back up only
$c->stash->{template} = 'admin/report_edit-sdm.html';
if ($c->req->param('send_back')) {
$c->forward('check_token');
$problem->bodies_str( $body->parent->id );
$problem->update;
# log here
$c->res->redirect( '/admin/summary' );
return 1;
} elsif ($c->req->param('submit')) {
$c->forward('check_token');
# Add new update from status_update
return 1;
}
}
return 0;
}
1;
|