]> ruin.nu Git - ndwebbie.git/commitdiff
Converted covop target list
authorMichael Andreen <harv@ruin.nu>
Wed, 25 Jun 2008 21:45:06 +0000 (23:45 +0200)
committerMichael Andreen <harv@ruin.nu>
Wed, 25 Jun 2008 21:45:06 +0000 (23:45 +0200)
NDWeb/Pages/CovOp.pm [deleted file]
database/group_roles.sql
lib/NDWeb.pm
lib/NDWeb/Controller/CovOp.pm [new file with mode: 0644]
lib/NDWeb/Controller/Root.pm
root/lib/inc/targetlist.tt2
root/lib/site/leftbar.tt2
root/src/covop/index.tt2 [new file with mode: 0644]
t/controller_CovOp.t [new file with mode: 0644]
templates/covop.tmpl [deleted file]

diff --git a/NDWeb/Pages/CovOp.pm b/NDWeb/Pages/CovOp.pm
deleted file mode 100644 (file)
index 16a429b..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-package NDWeb::Pages::CovOp;
-use strict;
-use warnings FATAL => 'all';
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{covop} = __PACKAGE__;
-
-sub parse {
-       my ($uri) = @_;
-       if ($uri =~ m{^/.*/(\w+)$}){
-               param('list',$1);
-       }
-}
-
-sub render_body {
-       my $self = shift;
-       my ($BODY) = @_;
-       $self->{TITLE} = 'CovOp Targets';
-       my $DBH = $self->{DBH};
-
-       return $self->noAccess unless $self->isMember;
-
-       my $show = q{AND (NOT planet_status IN ('Friendly','NAP')) AND  (relationship IS NULL OR NOT relationship IN ('Friendly','NAP'))};
-       $show = '' if defined param('show') && param('show') eq 'all';
-       if (defined param('covop') && param('covop') =~ /^(\d+)$/){
-               my $update = $DBH->prepare(q{INSERT INTO covop_attacks (uid,id,tick) VALUES(?,?,tick())});
-               $update->execute($ND::UID,$1) or warn $DBH->errstr;
-       }
-
-       my $list = '';
-       my $where = '';
-       if (defined param('list') && param('list') eq 'distwhores'){
-               $list = 'list=distwhores';
-               $where = qq{AND distorters > 0 $show
-               ORDER BY distorters DESC,COALESCE(seccents::float/structures*100,0)ASC}
-       }else{
-               $where = qq{AND MaxResHack > 130000
-               $show
-               ORDER BY minalert ASC,MaxResHack DESC};
-       }
-       $BODY->param(List => $list);
-
-       my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium
-               , covop_alert(seccents,structures,gov,0) AS minalert 
-               , covop_alert(seccents,structures,gov,50) AS maxalert 
-               , distorters,gov
-               , MaxResHack,co.tick AS lastcovop
-               FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
-                       seccents,NULLIF(ss.total::integer,0) AS structures,distorters
-                       ,max_bank_hack(metal,crystal,eonium,p.value
-                               ,(SELECT value FROM current_planet_stats WHERE id = ?)) AS MaxResHack
-                       , planet_status, relationship,gov
-                       FROM current_planet_stats p
-                               LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
-                               LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
-                       ) AS foo
-                       LEFT OUTER JOIN (SELECT id,max(tick) AS tick FROM covop_attacks GROUP BY id) co USING (id)
-               WHERE (metal IS NOT NULL OR seccents IS NOT NULL)
-               $where
-       }) or warn $DBH->errstr;
-       $query->execute($self->{PLANET}) or warn $DBH->errstr;
-
-       my @targets;
-       while (my $target = $query->fetchrow_hashref){
-               push @targets,$target;
-       }
-       $BODY->param(Targets => \@targets);
-       return $BODY;
-}
-
-1;
index 3ae93d42be22c5e0bb168a1c9dd67e9a90f5c327..16e0c4e499d859499ec3abd8b9a38bae9ba0fe3a 100644 (file)
@@ -21,10 +21,12 @@ INSERT INTO roles VALUES('alliances_resources');
 INSERT INTO roles VALUES('graphs_intel');
 INSERT INTO roles VALUES('members');
 INSERT INTO roles VALUES('members_points_nolimit');
+INSERT INTO roles VALUES('covop');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
 INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
 INSERT INTO group_roles (gid,role) VALUES(2,'members');
+INSERT INTO group_roles (gid,role) VALUES(2,'covop');
 
 INSERT INTO group_roles (gid,role) VALUES(6,'dc_menu');
 
index 238e5f409e057a63575d2fb37a6b16521751fff8..b47a9fa278ceea70e3b12aacb1b38cd37aefc53f 100644 (file)
@@ -72,6 +72,7 @@ __PACKAGE__->deny_access_unless('/alliances/resources',[qw/alliances_resources/]
 __PACKAGE__->deny_access_unless('/graphs/alliancevsintel',[qw/graphs_intel/]);
 __PACKAGE__->deny_access_unless('/graphs/avgalliancevsintel',[qw/graphs_intel/]);
 __PACKAGE__->deny_access_unless('/members',[qw/members/]);
+__PACKAGE__->deny_access_unless('/covop',[qw/covop/]);
 
 =head1 NAME
 
diff --git a/lib/NDWeb/Controller/CovOp.pm b/lib/NDWeb/Controller/CovOp.pm
new file mode 100644 (file)
index 0000000..68ef8a8
--- /dev/null
@@ -0,0 +1,90 @@
+package NDWeb::Controller::CovOp;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+NDWeb::Controller::CovOp - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+       my ( $self, $c ) = @_;
+       $c->stash( where => q{AND MaxResHack > 130000
+               ORDER BY minalert ASC,MaxResHack DESC});
+}
+
+sub distwhores : Local {
+       my ( $self, $c ) = @_;
+       $c->stash( where =>  qq{AND distorters > 0
+               ORDER BY distorters DESC, minalert ASC});
+}
+
+sub marktarget : Local {
+       my ( $self, $c, $target ) = @_;
+       my $dbh = $c->model;
+
+       my $update = $dbh->prepare(q{INSERT INTO covop_attacks (uid,id,tick) VALUES(?,?,tick())});
+       $update->execute($c->user->id,$target);
+
+       $c->res->redirect($c->req->referer);
+}
+
+sub end : Private {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       my $query = $dbh->prepare(q{SELECT id, coords, metal, crystal, eonium
+               , covop_alert(seccents,structures,gov,0) AS minalert
+               , covop_alert(seccents,structures,gov,50) AS maxalert
+               , distorters,gov
+               , MaxResHack,co.tick AS lastcovop
+               FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
+                       seccents,NULLIF(ss.total::integer,0) AS structures,distorters
+                       ,max_bank_hack(metal,crystal,eonium,p.value
+                               ,(SELECT value FROM current_planet_stats WHERE id = ?)) AS MaxResHack
+                       , planet_status, relationship,gov
+                       FROM current_planet_stats p
+                               LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
+                               LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
+                       ) AS foo
+                       LEFT OUTER JOIN (SELECT id,max(tick) AS tick FROM covop_attacks GROUP BY id) co USING (id)
+               WHERE (metal IS NOT NULL OR seccents IS NOT NULL)
+                       AND (NOT planet_status IN ('Friendly','NAP'))
+                       AND  (relationship IS NULL OR NOT relationship IN ('Friendly','NAP'))
+               } . $c->stash->{where});
+       $query->execute($c->user->planet);
+
+       my @targets;
+       while (my $target = $query->fetchrow_hashref){
+               push @targets,$target;
+       }
+       $c->stash(targets => \@targets);
+
+       $c->stash(template => 'covop/index.tt2');
+       $c->forward('/end');
+}
+=head1 AUTHOR
+
+Michael Andreen (harv@ruin.nu)
+
+=head1 LICENSE
+
+GPL 2.0, or later
+
+=cut
+
+1;
index 9048fd0c965b8c578d04273280766661bfc083f3..16f0e8cb8719db5ddd900f35d8613f83ddc806fc 100644 (file)
@@ -86,7 +86,7 @@ ORDER BY r.tick+c.wave,x,y,z});
                push @targets, $target;
        }
 
-       $c->stash(targets => \@targets);
+       $c->stash(claimedtargets => \@targets);
 }
 
 sub auto : Private {
index 4b1890f7c81052a579d69be5d65ea694a126111c..4f8cced40415ab2b905d7c8bc732bbd5f4561b05 100644 (file)
@@ -1,7 +1,7 @@
 [% IF targets%]
 <table>
        <tr><th>Target</th><th>Tick</th></tr>
-       [% FOR target IN targets %]
+       [% FOR target IN claimedtargets %]
        <tr>
                <td><a href="[% target.released_coords and c.uri_for('/check',target.coords)%]">
                        [% target.released_coords and target.coords%][% IF target.launched%]*[% END %]</a></td>
index 450cfdc71e0dedd93d74cb8f461b52a43ec63f65..62a7bf06b354cbd4d2a791742d805c4c1e99b5f8 100644 (file)
@@ -32,7 +32,7 @@
        <li><a href="/members/addintel">Add intel/scans</a></li>
        <li><a href="/members/launchConfirmation">Launch confirmation</a></li>
        <li><a href="/covop">CovOp targets</a></li>
-       <li><a href="/covop?list=distwhores">Distwhores</a></li>
+       <li><a href="/covop/distwhores">Distwhores</a></li>
        <li><a href="/members/defrequest">Request defense</a></li>
 </ul>
        [% ELSE %]
diff --git a/root/src/covop/index.tt2 b/root/src/covop/index.tt2
new file mode 100644 (file)
index 0000000..1c44bee
--- /dev/null
@@ -0,0 +1,22 @@
+[% META title = 'Covert operations' %]
+<table>
+       <tr>
+       <th>Coords</th><th>Metal</th><th>Crystal</th><th>Eonium</th><th>Gov</th><th>Alert</th><th>Dists</th><th>Max (15 agents)</th><th>Last covop (tick)</th>
+       </tr>
+
+[% debug(targets.size) %]
+[% FOR t IN targets %]
+       <tr align="center" class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
+       <td><a href="[% c.uri_for('/stats/planet',t.id) %]">[% t.coords %]</a></td>
+       <td>[% t.metal %]</td>
+       <td>[% t.crystal %]</td>
+       <td>[% t.eonium %]</td>
+       <td>[% t.gov %]</td>
+       <td>[% t.minalert %] - [% t.maxalert %]</td>
+       <td>[% t.distorters %]</td>
+       <td>[% t.maxreshack %]</td>
+       <td>[% t.lastcovop %]</td>
+       <td><a href="[% c.uri_for('marktarget', t.id) %]">Did CovOp this tick</a></td>
+       </tr>
+[% END %]
+</table>
diff --git a/t/controller_CovOp.t b/t/controller_CovOp.t
new file mode 100644 (file)
index 0000000..f608b36
--- /dev/null
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'NDWeb' }
+BEGIN { use_ok 'NDWeb::Controller::CovOp' }
+
+ok( request('/covop')->is_success, 'Request should succeed' );
+
+
diff --git a/templates/covop.tmpl b/templates/covop.tmpl
deleted file mode 100644 (file)
index 2a80247..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<table>
-       <tr>
-       <th>Coords</th><th>Metal</th><th>Crystal</th><th>Eonium</th><th>Gov</th><th>Alert</th><th>Dists</th><th>Max (15 agents)</th><th>Last covop (tick)</th>
-       </tr>
-       <TMPL_LOOP Targets>
-       <tr align="center" class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
-       <td><a href="/check?coords=<TMPL_VAR NAME=Coords>"><TMPL_VAR NAME=Coords></a></td>
-       <td><TMPL_VAR NAME=Metal></td>
-       <td><TMPL_VAR NAME=Crystal></td>
-       <td><TMPL_VAR NAME=Eonium></td>
-       <td><TMPL_VAR NAME=Gov></td>
-       <td><TMPL_VAR NAME=MinAlert> - <TMPL_VAR NAME=MaxAlert></td>
-       <td><TMPL_VAR NAME=Distorters></td>
-       <td><TMPL_VAR NAME=MaxResHack></td>
-       <td><TMPL_VAR NAME=LastCovOp></td>
-       <td><a href="/<TMPL_VAR NAME=PAGE>?<TMPL_VAR NAME=List>&amp;covop=<TMPL_VAR NAME=Id>">Did CovOp this tick</a></td>
-       </tr>
-       </TMPL_LOOP>
-</table>