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 {
# Normal route to controller
$r->get('/')->to('RV#index');
$r->get('/:election')->to('RV#index');
$r->get('/api/members/')->to('RV#members');
$r->post('/api/calculate/')->to('evaluation#process');
}
......
package RVVote::Controller::Evaluation;
use Mojo::Base 'Mojolicious::Controller';
use MIME::Base64 qw(encode_base64url);
use YAML;
sub process {
......@@ -9,6 +10,8 @@ sub process {
my $r;
$c->stash->{permalink} = encode_base64url( $c->req->body );
BALLOT:
foreach my $ballot ( @{ $c->req->json } ) {
......
package RVVote::Controller::RV;
use Mojo::Base 'Mojolicious::Controller';
use RVVote::GraphAPI;
use MIME::Base64 qw(decode_base64url);
use JSON;
sub index {
my $c = shift;
......@@ -9,9 +11,26 @@ sub index {
sub members {
my $c = shift;
my $gapi = RVVote::GraphAPI->new($c->config->{graph_api}{url});
my @members = $gapi->get_group_members($c->config->{graph_api}{rv_gid});
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});
@members = $gapi->get_group_members($c->config->{graph_api}{rv_gid});
}
$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}} ) {
%= include 'layouts/log', log => $log
% }
......@@ -27,3 +12,4 @@
</div>
% }
<p><a href="/<%= $c->stash->{permalink} %>">permalink</a></p>
......@@ -5,7 +5,7 @@
<div class="row">
<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>
<tr>
<th data-field="fullname">Člen RV</th>
......@@ -24,34 +24,42 @@
<script>
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) {
$('input.votes').on('keyup', function () {
var bills = [];
var a = $('form').serializeArray();
$.each(a, function() {
var id = this.name.split('_');
bills.push({
"id": id[1],
"value": this.value,
"voter": $('input[name='+this.name+']').attr('data-fullname'),
});
function evaluate() {
var bills = [];
var a = $('form').serializeArray();
$.each(a, function() {
var id = this.name.split('_');
bills.push({
"id": id[1],
"value": this.value,
"voter": $('input[name='+this.name+']').attr('data-fullname'),
});
});
$.ajax({
url: '/api/calculate/',
data: JSON.stringify(bills),
contentType: 'application/json',
type: "POST",
}).done(function( html ) {
$( "#Result" ).html( html );
})
}
$.ajax({
url: '/api/calculate/',
data: JSON.stringify(bills),
contentType: 'application/json',
type: "POST",
}).done(function( 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