diff --git a/info.txt b/info.txt
new file mode 100644
index 0000000..4f2d4c3
--- /dev/null
+++ b/info.txt
+Olemme Jaakon alaisia
+
diff --git a/src/main.cpp b/src/main.cpp
index 876f325..5139375 100644
--- a/src/main.cpp
+++ b/src/main.cpp
}
struct Asunto {
- std::string osoite;
- std::string kuvaPolku;
+ const std::string osoite;
+ const std::string kuvaPolku;
};
int main()
crow::FileStore{"./sessions"}}};
// Asunnot lista
std::vector<Asunto> asunnot;
+ // "Tietoa meistä"
+ std::string info;
CROW_ROUTE(app, "/")
- .methods("GET"_method, "POST"_method)([&asunnot](){
+ .methods("GET"_method, "POST"_method)([&asunnot, &info](){
auto page = crow::mustache::load("index.html");
crow::json::wvalue asunnotJson;
for (int i = 0; i < asunnot.size(); ++i) {
asunnotJson[i]["osoite"] = asunnot.at(i).osoite;
asunnotJson[i]["kuva"] = asunnot.at(i).kuvaPolku;
}
- crow::mustache::context ctx({{"asunnot", asunnotJson}});
+ crow::mustache::context ctx({{"asunnot", asunnotJson}, {"tieto", info}});
return page.render(ctx);
});
});
CROW_ROUTE(app, "/admin")
- .methods("GET"_method, "POST"_method)([&app](const crow::request& req, crow::response& res){
+ .methods("GET"_method, "POST"_method)([&app, &info](const crow::request& req, crow::response& res){
auto& session = app.get_context<Session>(req);
if (session.get("name","_NO_") == "_NO_") {
return;
}
// Jatka jos kirjautunut sisään
+ if (req.method == "POST"_method) { // Jos POST request
+ // Muuta "Tietoa meistä"
+ info = req.get_body_params().get("info");
+ // Kirjoita tieto info.txt tiedostoon
+ std::ofstream infoTxt("info.txt", std::ios::out | std::ios::trunc);
+ if (not infoTxt.is_open()) {
+ CROW_LOG_ERROR << "Cannot open info.txt";
+ res.redirect("/");
+ res.code = 500;
+ res.end();
+ return;
+ }
+ // Kirjoita
+ infoTxt << info + "\n";
+ infoTxt.close();
+ // Valmista ollaan
+ res.redirect("/");
+ res.end();
+ return;
+ }
// Renderöi sivu
auto page = crow::mustache::load("admin.html");
- res.body = page.render().body_;
+ crow::mustache::context ctx({{"info", info}});
+ res.body = page.render(ctx).body_;
res.end();
});
}
// Write file to hard drive
std::ofstream file(outfilePath);
- if (file.fail()) {
+ if (not file.is_open()) {
CROW_LOG_ERROR << "Cannot write file";
res.code = 500;
res.redirect("/");
return;
});
-
+ // Lue tietokannasta asunnot
try
{
pqxx::connection cx("dbname = postgres user = postgres password = 1234 \
tx.commit();
for (auto s : r) {
- struct Asunto asunto;
- asunto.osoite = s[0].as<std::string>();
- asunto.kuvaPolku = s[2].as<std::string>();
+ const struct Asunto asunto(
+ s[0].as<std::string>(),
+ s[2].as<std::string>());
//CROW_LOG_INFO << asunto.osoite << ":" << asunto.kuvaPolku << "\n";
asunnot.push_back( asunto );
}
CROW_LOG_ERROR << e.what();
return EXIT_FAILURE;
}
+ // Lue tiedostosta "Tietoa meistä"
+ std::ifstream infoTxt("info.txt", std::ios::in);
+ if (not infoTxt.is_open()) {
+ CROW_LOG_ERROR << "Unable to open info.txt";
+ return EXIT_FAILURE;
+ }
+ std::string line;
+ while (getline(infoTxt, line)) {
+ info += line += "\n";
+ }
+ infoTxt.close();
// :D
//app.loglevel(crow::LogLevel::Debug);
diff --git a/static/images/d8yutup1drfsg7kp5ntk.jpg b/static/images/d8yutup1drfsg7kp5ntk.jpg
new file mode 100644
index 0000000..98fe140
Binary files /dev/null and b/static/images/d8yutup1drfsg7kp5ntk.jpg differ
diff --git a/static/style.css b/static/style.css
index d8049e1..9ccf9e2 100644
--- a/static/style.css
+++ b/static/style.css
max-width: 100%;
max-height: 100%;
}
+.img-full {
+ width: 100%;
+}
diff --git a/templates/index.html b/templates/index.html
index 4cefa94..e1684b4 100644
--- a/templates/index.html
+++ b/templates/index.html
</ul>
</nav>
</header>
- <img class="img-fluid" src="https://wisdurm.fi/static/images/sign.webp">
+ <div class="container-fluid">
+ <img class="img-full" src="https://www.gradia.fi/sites/default/files/styles/image_paragraph_large/public/media/embed/20240610_Jyv%C3%A4skyl%C3%A4n%20asuntola.jpg?itok=wGzrX8_C">
+ </div>
<div class="container">
<h1 class="pt-5 pb-5">Asunnot</h1>
- <div class="row">
+ <div class="row w-100">
{{#asunnot}}
- <div class="col bg h-good p-0 m-1" style="background-image: url('/static/images/{{ kuva }}');">
- <div class="text-bg-dark w-50">
+ <div class="col-md-3 bg h-good p-0 m-0" style="background-image: url('/static/images/{{ kuva }}');">
+ <div class="text-bg-dark w-75">
<p>{{osoite}}</p>
</div>
</div>