Added footer, added radio buttons for single option polls, fixed voting bug
This commit is contained in:
parent
50750c6808
commit
44d0940e23
@ -1,4 +1,7 @@
|
||||
{
|
||||
"name": "hutattedonmyarm/dragonpolls",
|
||||
"version": "0.1.0",
|
||||
"description": "A polling client for pnut.io",
|
||||
"require": {
|
||||
"hutattedonmyarm/apnuti": "@dev"
|
||||
},
|
||||
|
13
globals.php
13
globals.php
@ -51,7 +51,18 @@ function get_page_header(
|
||||
. $greeting
|
||||
. '<div class="spacer"></div>'
|
||||
. $logout_link
|
||||
. '</header>';
|
||||
. '</header><main>';
|
||||
}
|
||||
|
||||
function get_page_footer()
|
||||
{
|
||||
$version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version'];
|
||||
return '</main><footer>'
|
||||
. '<a href="https://phlaym.net/git/phlaym/Pfadlock/releases/tag/'.$version.'">Version ' . $version . '</a>'
|
||||
. '<a href="https://phlaym.net/git/phlaym/Dragonpolls" title="Source"><div class="linkcontents">'
|
||||
. file_get_contents(__DIR__.'/icons/home.svg')
|
||||
. '<span class="linklabel">Source Code</span></div></a>'
|
||||
. '</footer></body></html>';
|
||||
}
|
||||
|
||||
function redirect($to)
|
||||
|
@ -3,3 +3,4 @@
|
||||
require_once __DIR__ .'/bootstrap.php';
|
||||
|
||||
echo get_page_header();
|
||||
echo get_page_footer();
|
||||
|
@ -3,7 +3,10 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
for (const el of document.querySelectorAll('.option input[type=checkbox]')) {
|
||||
el.onclick = updateVotesRemaining;
|
||||
}
|
||||
document.querySelector('.success-banner').onclick = hideBanner;
|
||||
const banner = document.querySelector('.success-banner');
|
||||
if (banner) {
|
||||
banner.onclick = hideBanner;
|
||||
}
|
||||
});
|
||||
|
||||
function displayLocalTimestamps() {
|
||||
|
@ -29,6 +29,12 @@ body {
|
||||
background: var(--main-bg-color);
|
||||
color: var(--main-fg-color);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
button {
|
||||
@ -87,7 +93,7 @@ header {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
header a {
|
||||
header a, footer a {
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
@ -175,3 +181,13 @@ datewrapper time {
|
||||
.success-banner span {
|
||||
font-size: x-large;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px;
|
||||
background: var(--secondary-bg-color);
|
||||
box-shadow: var(--default-shadow);
|
||||
font-size: smaller;
|
||||
}
|
@ -13,11 +13,11 @@ use APnutI\Entities\User;
|
||||
try {
|
||||
echo get_page_header('Poll', true, ['poll']);
|
||||
} catch (\Exception $e) {
|
||||
die('Something went wrong :( "'.$e->getMessage().'"');
|
||||
die('Something went wrong :( "' . $e->getMessage() . '"' . get_page_footer());
|
||||
}
|
||||
|
||||
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
|
||||
die('Invalid poll ID');
|
||||
die('Invalid poll ID'.get_page_footer());
|
||||
}
|
||||
$poll_id = (int)$_GET['id'];
|
||||
$poll = null;
|
||||
@ -26,9 +26,9 @@ try {
|
||||
$poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null;
|
||||
$poll = $api->getPoll($poll_id, $poll_token);
|
||||
} catch (NotFoundException $nfe) {
|
||||
die('Poll not found');
|
||||
die('Poll not found'.get_page_footer());
|
||||
} catch (NotSupportedPollException $nspe) {
|
||||
die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage());
|
||||
die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage() . get_page_footer());
|
||||
} catch (PollAccessRestrictedException $are) {
|
||||
$message = array_key_exists('polltoken', $_GET)
|
||||
? 'Sorry, your poll token is invalid! Please enter a valid token: '
|
||||
@ -38,9 +38,10 @@ try {
|
||||
$message
|
||||
. '<form><input type="text" name="polltoken">'
|
||||
. '<input type="hidden" name="id" value="'.$poll_id.'"><button type="submit">Access poll</button></form>'
|
||||
. get_page_footer()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
die('Something went wrong :( "'.$e->getMessage().'"');
|
||||
die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer());
|
||||
}
|
||||
jslog($poll);
|
||||
|
||||
@ -63,7 +64,7 @@ $disabled_button = ($poll->canVote() && count($user_votes) > 0) ? '' : 'disabled
|
||||
|
||||
if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
|
||||
<div class="banner-wrapper">
|
||||
<div class="success-banner"><span>✔</span> Your vote has been saved, thank you!</div>
|
||||
<div class="success-banner"><span>✓</span> Your vote has been saved, thank you!</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="poll">
|
||||
@ -104,10 +105,15 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
|
||||
'include_html' => false,
|
||||
'include_counts' => false,
|
||||
];
|
||||
$input_type = $poll->max_options === 1 ? 'radio' : 'checkbox';
|
||||
$input_name = $poll->max_options === 1 ? 'options' : 'options[]';
|
||||
foreach ($poll->options as $option) {
|
||||
$checked = $option->is_your_response ? 'checked' : ''; ?>
|
||||
<div class="option" style="grid-row: <?= $row ?>;">
|
||||
<input type="checkbox" <?= $checked.' '.$disabled ?> value="<?= $option->position ?>" name="options[]"/>
|
||||
<input
|
||||
type="<?= $input_type ?>" <?= $checked.' '.$disabled ?>
|
||||
value="<?= $option->position ?>"
|
||||
name="<?= $input_name ?>"/>
|
||||
<span class="option-text"><?= $option->text . ' (' . $option->respondents . ')'?></span>
|
||||
</div>
|
||||
<div class="option-responses" style="grid-row: <?= $row++ ?>;grid-column: 2;">
|
||||
@ -133,4 +139,4 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= get_page_footer(); ?>
|
||||
|
@ -2,16 +2,21 @@
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
$voted_options = [];
|
||||
if (is_array($_POST['options'])) {
|
||||
foreach ($_POST['options'] as $option) {
|
||||
$voted_options[] = (int)$option;
|
||||
}
|
||||
} else {
|
||||
$voted_options[] = (int)$_POST['options'];
|
||||
}
|
||||
try {
|
||||
$res = $api->voteInPoll((int)$_POST['pollid'], $voted_options, $_POST['polltoken']);
|
||||
} catch (\Exception $e) {
|
||||
get_page_header('Voting error');
|
||||
$str = 'Sorry, something went wrong while voting!'
|
||||
. 'Please yell at <a href="https://pnut.io/@hutattedonmyarm">@hutattedonmyarm></a><br>'
|
||||
. '<a href="view_poll.php?id="'.$_POST['pollid'].'>Go back to the poll</a>';
|
||||
$str = 'Sorry, something went wrong while voting! "'
|
||||
. $e->getMessage()
|
||||
. '"<br>Please yell at <a href="https://pnut.io/@hutattedonmyarm">@hutattedonmyarm</a><br>'
|
||||
. '<a href="view_poll.php?id='.$_POST['pollid'].'"s>Go back to the poll</a>';
|
||||
die($str);
|
||||
}
|
||||
redirect('view_poll.php?id='.$_POST['pollid'].'&success=1');
|
||||
|
Loading…
Reference in New Issue
Block a user