1
0
mirror of https://git.cant.at/Madeorsk/PollVerlaine synced 2024-12-03 18:17:54 +01:00

End of Home page, begin of Poll page and Configuration

* Finished Home page behavior;
* Started Poll (just the title for now);
* Changed POST /polls return code to 206 (CREATED);
+ Add a configuration file (only app_url inside of it for now).
This commit is contained in:
Madeorsk 2018-08-12 19:29:13 +02:00
parent cbb85097e3
commit 5ac9b5d0e4
7 changed files with 67 additions and 14 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ composer.lock
## App ## ## App ##
db/ db/
config/app.php

5
config/app.default.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$VERLAINE = [
"app_url" => "",
];

View File

@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . "/vendor/autoload.php"; require __DIR__ . "/vendor/autoload.php";
require __DIR__ . "/models/Poll.php"; require __DIR__ . "/models/Poll.php";
require __DIR__ . "/config/app.php";
function format_poll($poll) function format_poll($poll)
{ {
@ -19,7 +20,7 @@ Flight::route("POST /polls", function () {
$request_json = $request->data; $request_json = $request->data;
$poll = Poll::create_poll($request_json); $poll = Poll::create_poll($request_json);
if ($poll) if ($poll)
Flight::json(format_poll($poll)); Flight::json(format_poll($poll), 206);
else else
Flight::halt(403, "<h1>403 Forbidden</h1><h3>Invalid data.</h3>"); Flight::halt(403, "<h1>403 Forbidden</h1><h3>Invalid data.</h3>");
} }
@ -43,7 +44,8 @@ Flight::route("GET /polls/@id:[a-fA-F0-9]+", function ($id) {
}); });
Flight::route("/", function () { Flight::route("/", function () {
Flight::render("home", [], "body_content"); global $VERLAINE;
Flight::render("home", ["app_url" => $VERLAINE["app_url"]], "body_content");
Flight::render("layout"); Flight::render("layout");
}); });

View File

@ -32,8 +32,21 @@ main
margin: 0 5%; margin: 0 5%;
} }
main form input, main p
main form button {
font-size: 1.5em;
text-align: center;
}
main p strong
{
font-family: "PT Serif", serif;
font-size: 1.2em;
font-weight: normal;
}
main input,
main button,
main a.button
{ {
transition: background 0.1s ease-in; transition: background 0.1s ease-in;
display: block; display: block;
@ -43,34 +56,47 @@ main form button
box-sizing: border-box; box-sizing: border-box;
background: #141414; background: #141414;
color: #ECECEC;
border: none; border: none;
outline: none; outline: none;
font-size: 1.3em; font-size: 1.3em;
text-align: center; text-align: center;
text-decoration: none;
} }
main form input[type="submit"], main input[type="submit"],
main form button main button,
main a.button
{ cursor: pointer; } { cursor: pointer; }
main form input[type="submit"] main input[type="submit"]
{ margin-top: 1em; } { margin-top: 1em; }
main form input:focus, main input:focus,
main form input[type="submit"]:hover, main input[type="submit"]:hover,
main form button:hover main button:hover,
main a.button:hover
{ background: #1D1D1D; } { background: #1D1D1D; }
main form input[name="title"], main input[name="title"],
main form input[name="title"]:focus main input[name="title"]:focus
{ {
background: transparent; background: transparent;
font-family: "PT Serif", serif; font-family: "PT Serif", serif;
font-size: 1.5em; font-size: 1.5em;
} }
@keyframes scalex
{
0%
{ transform: scaleX(0); }
100%
{ transform: scaleX(1); }
}
main #choices .choice main #choices .choice
{ {
animation: scalex 0.2s linear;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
margin: auto; margin: auto;
@ -86,6 +112,16 @@ main #choices .choice .delete
width: 4em; width: 4em;
} }
/*
* IFNEZIUN
*/
h1.poll
{
margin: 1.5em 5%;
font-family: "PT Serif", serif;
font-size: 2.5rem;
}
footer footer
{ {
display: block; display: block;

View File

@ -44,7 +44,11 @@ document.addEventListener("DOMContentLoaded", () => {
}).then((res) => { }).then((res) => {
return res.json(); return res.json();
}).then((json) => { }).then((json) => {
console.log(json); form.setAttribute("hidden", true);
let result_el = document.getElementById("result");
result_el.innerHTML = result_el.innerHTML.replace(/:poll_title/g, json.title);
result_el.innerHTML = result_el.innerHTML.replace(/:poll_url/g, `/polls/${json.id}`);
result_el.removeAttribute("hidden");
}); });
}); });
}); });

View File

@ -11,6 +11,11 @@
<button type="button" id="add-choice">New choice</button> <button type="button" id="add-choice">New choice</button>
<input type="submit" value="Create poll" /> <input type="submit" value="Create poll" />
</form> </form>
<div id="result" hidden>
<p>Your poll <strong>:poll_title</strong> is ready!</p>
<input type="text" name="pollurl" value="<?= $app_url ?>:poll_url" />
<a class="button" href=":poll_url">See the poll!</a>
</div>
</main> </main>
<template id="choice"> <template id="choice">

View File

@ -1,4 +1,4 @@
<h1>mdr todo</h1> <h1 class="poll"><?= $poll->title ?></h1>
<main> <main>
<pre> <pre>
<?= var_dump($poll) ?> <?= var_dump($poll) ?>