Skip to content
Snippets Groups Projects
Commit 83c236e9 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Podpora permalinku

parent 53b058b4
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ sub startup { ...@@ -13,6 +13,7 @@ sub startup {
# Normal route to controller # Normal route to controller
$r->get('/')->to('RV#index'); $r->get('/')->to('RV#index');
$r->get('/:election')->to('RV#index');
$r->get('/api/members/')->to('RV#members'); $r->get('/api/members/')->to('RV#members');
$r->post('/api/calculate/')->to('evaluation#process'); $r->post('/api/calculate/')->to('evaluation#process');
} }
......
package RVVote::Controller::Evaluation; package RVVote::Controller::Evaluation;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller';
use MIME::Base64 qw(encode_base64url);
use YAML; use YAML;
sub process { sub process {
...@@ -9,6 +10,8 @@ sub process { ...@@ -9,6 +10,8 @@ sub process {
my $r; my $r;
$c->stash->{permalink} = encode_base64url( $c->req->body );
BALLOT: BALLOT:
foreach my $ballot ( @{ $c->req->json } ) { foreach my $ballot ( @{ $c->req->json } ) {
......
package RVVote::Controller::RV; package RVVote::Controller::RV;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller';
use RVVote::GraphAPI; use RVVote::GraphAPI;
use MIME::Base64 qw(decode_base64url);
use JSON;
sub index { sub index {
my $c = shift; my $c = shift;
...@@ -10,8 +12,25 @@ sub index { ...@@ -10,8 +12,25 @@ sub index {
sub members { sub members {
my $c = shift; my $c = shift;
my @members = ();
if ($c->param('election')) {
eval {
my $election = decode_json(decode_base64url($c->param('election')));
@members = map {
{
fullname => $_->{voter},
value => $_->{value},
user_id => $_->{id},
}
} @{ $election }
};
}
if ( ! scalar @members ) {
my $gapi = RVVote::GraphAPI->new($c->config->{graph_api}{url}); my $gapi = RVVote::GraphAPI->new($c->config->{graph_api}{url});
my @members = $gapi->get_group_members($c->config->{graph_api}{rv_gid}); @members = $gapi->get_group_members($c->config->{graph_api}{rv_gid});
}
$c->render( json => \@members ); $c->render( json => \@members );
} }
......
<!--
% if (scalar @{ $c->stash->{ballots}} ) {
<div class="card bg-light">
<div class="card-header">Platné listky: <%= scalar @{$c->stash->{ballots}} %></div>
<div class="card-body">
<div class="card-text">
% foreach my $ballot ( @{ $c->stash->{ballots}} ) {
%= include 'layouts/ballot', ballot => $ballot
% }
</div>
</div>
</div>
% }
-->
% foreach my $log ( @{ $c->stash->{log}} ) { % foreach my $log ( @{ $c->stash->{log}} ) {
%= include 'layouts/log', log => $log %= include 'layouts/log', log => $log
% } % }
...@@ -27,3 +12,4 @@ ...@@ -27,3 +12,4 @@
</div> </div>
% } % }
<p><a href="/<%= $c->stash->{permalink} %>">permalink</a></p>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<div class="row"> <div class="row">
<div class="col-5"> <div class="col-5">
<table id="Members" data-toggle="table" data-url="/api/members/" data-classes="table table-borderless table-sm" data-show-header="false"> <table id="Members" data-toggle="table" data-url="/api/members/<%= $c->stash->{election} ? '?election='.$c->stash->{election}:'' %>" data-classes="table table-borderless table-sm" data-show-header="false">
<thead> <thead>
<tr> <tr>
<th data-field="fullname">Člen RV</th> <th data-field="fullname">Člen RV</th>
...@@ -24,12 +24,10 @@ ...@@ -24,12 +24,10 @@
<script> <script>
function votes_detail(value, record) { function votes_detail(value, record) {
return '<input class="votes" name="votes_'+value+'" type="text" size="16" data-fullname="'+record.fullname+'">'; return '<input class="votes" name="votes_'+value+'" type="text" size="16" data-fullname="'+record.fullname+'" value="'+ (record.value || '' )+'">';
} }
$('#Members').on('post-body.bs.table', function (data) { function evaluate() {
$('input.votes').on('keyup', function () {
var bills = []; var bills = [];
var a = $('form').serializeArray(); var a = $('form').serializeArray();
$.each(a, function() { $.each(a, function() {
...@@ -49,9 +47,19 @@ $('#Members').on('post-body.bs.table', function (data) { ...@@ -49,9 +47,19 @@ $('#Members').on('post-body.bs.table', function (data) {
}).done(function( html ) { }).done(function( html ) {
$( "#Result" ).html( html ); $( "#Result" ).html( html );
}) })
}
$('#Members').on('post-body.bs.table', function (data) {
$('input.votes').on('keyup', function () {
evaluate();
}); });
% if ($c->stash->{election}) {
evaluate();
% }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment