]> ruin.nu Git - ndwebbie.git/commitdiff
Added a controller and template for exporting data in plain text
authorMichael Andreen <harv@ruin.nu>
Sun, 24 Aug 2008 13:36:28 +0000 (15:36 +0200)
committerMichael Andreen <harv@ruin.nu>
Sun, 24 Aug 2008 13:36:28 +0000 (15:36 +0200)
database/group_roles.sql
lib/NDWeb.pm
lib/NDWeb/Controller/TextExport.pm [new file with mode: 0644]
root/lib/site/wrapper.tt2
root/src/alliances/edit.tt2
root/src/textexport/index.tt2 [new file with mode: 0644]
t/controller_TextExport.t [new file with mode: 0644]

index add205fc90bac0c79a3593764d4b47b9490aaaa8..b18c28563f694d2f223dcef942235dc24866637e 100644 (file)
@@ -37,6 +37,7 @@ INSERT INTO roles VALUES('intel');
 INSERT INTO roles VALUES('intel_members');
 INSERT INTO roles VALUES('intel_member');
 INSERT INTO roles VALUES('intel_naps');
+INSERT INTO roles VALUES('textexport_alliance');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
 INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
@@ -82,6 +83,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'intel');
 INSERT INTO group_roles (gid,role) VALUES(1,'intel_members');
 INSERT INTO group_roles (gid,role) VALUES(1,'intel_member');
 INSERT INTO group_roles (gid,role) VALUES(1,'intel_naps');
+INSERT INTO group_roles (gid,role) VALUES(1,'textexport_alliance');
 
 INSERT INTO group_roles (gid,role) VALUES(3,'dc_menu');
 INSERT INTO group_roles (gid,role) VALUES(3,'bc_menu');
@@ -101,3 +103,4 @@ INSERT INTO group_roles (gid,role) VALUES(3,'intel');
 INSERT INTO group_roles (gid,role) VALUES(3,'intel_members');
 INSERT INTO group_roles (gid,role) VALUES(3,'intel_member');
 INSERT INTO group_roles (gid,role) VALUES(3,'intel_naps');
+INSERT INTO group_roles (gid,role) VALUES(3,'textexport_alliance');
index bce6c3879afe43c1c15a72bc9851673c9ace8ef1..d7aec9695d2374bb9310aa1f3c1d38aaff1bb333 100644 (file)
@@ -99,6 +99,7 @@ __PACKAGE__->allow_access_if('/jsrpc/end',1);
 __PACKAGE__->deny_access_unless('/forum/allUnread',[qw//]);
 __PACKAGE__->deny_access_unless('/forum/privmsg',[qw//]);
 __PACKAGE__->deny_access_unless('/settings',[qw//]);
+__PACKAGE__->deny_access_unless('/textexport/alliance',[qw/textexport_alliance/]);
 
 =head1 NAME
 
diff --git a/lib/NDWeb/Controller/TextExport.pm b/lib/NDWeb/Controller/TextExport.pm
new file mode 100644 (file)
index 0000000..37772ee
--- /dev/null
@@ -0,0 +1,58 @@
+package NDWeb::Controller::TextExport;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+NDWeb::Controller::TextExport - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub auto : Private {
+       my ( $self, $c ) = @_;
+       $c->stash(template => 'textexport/index.tt2');
+}
+
+sub alliance : Local {
+       my ( $self, $c, $ally ) = @_;
+       my $dbh = $c->model;
+
+       my $query = $dbh->prepare(q{SELECT coords(x,y,z), size, score, value, COALESCE(nick,'') AS nick
+               FROM current_planet_stats
+               WHERE alliance_id = $1
+               ORDER BY x,y,z});
+       $query->execute($ally);
+
+       $c->stash(titles => $query->{NAME});
+       $c->stash(values => $query->fetchall_arrayref);
+}
+
+sub end : ActionClass('RenderView') {
+       my ( $self, $c ) = @_;
+       $c->res->content_type('text/plain') if $c->stash->{template} =~ m{^textexport/};
+}
+
+=head1 AUTHOR
+
+Michael Andreen (harv@ruin.nu)
+
+=head1 LICENSE
+
+GPL 2.0, or later.
+
+=cut
+
+1;
index 6da016bffd2c9e070dc84d20bcfbdf71a814ac3d..b6431c5ed9853a60413e6119b1107bce8c6d496d 100644 (file)
@@ -7,6 +7,9 @@ ELSIF template.name.match('graphs/');
 ELSIF template.name.match('jsrpc/');
        debug("Passing page through xml: $template.name");
        content WRAPPER site/xml.tt2;
+ELSIF template.name.match('textexport/');
+       debug("Passing page through graph: $template.name");
+       content;
 ELSE;
        debug("Applying HTML page layout wrappers to $template.name\n");
        content WRAPPER site/html.tt2 + site/layout.tt2;
index 3c766d1ddead456d0d3d2292498d746b9de8719f..878fcfc9139862ff4b754b0d57ccceb0f455dc86 100644 (file)
@@ -25,6 +25,7 @@
 </fieldset>
 </div>
 </fieldset>
+<p>Export information <a href="[% c.uri_for('/textexport/alliance',a.id) %]">as text</a>.</p>
 <div class="leftinfo">
 <img class="graph" src="[% c.uri_for('/graphs/alliancevsintel',a.id,STICK) %]" alt="Alliance size and score vs members" height="300" width="500">
 <img class="graph" src="[% c.uri_for('/graphs/avgalliancevsintel',a.id,STICK) %]" alt="Avg alliance size and score vs members" height="300" width="500">
diff --git a/root/src/textexport/index.tt2 b/root/src/textexport/index.tt2
new file mode 100644 (file)
index 0000000..e91fa9e
--- /dev/null
@@ -0,0 +1,4 @@
+[% titles.join("\t") %]
+[% FOR v IN values %]
+       [%- v.join("\t") %]
+[% END %]
diff --git a/t/controller_TextExport.t b/t/controller_TextExport.t
new file mode 100644 (file)
index 0000000..ee764f8
--- /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::TextExport' }
+
+ok( request('/textexport')->is_success, 'Request should succeed' );
+
+