Initial Commit

This commit is contained in:
2025-02-01 16:28:24 +01:00
commit d16391fab0
19 changed files with 2201 additions and 0 deletions

3
.env Normal file
View File

@@ -0,0 +1,3 @@
DATABASE_URL=/home/fpasqua/RustroverProjects/htmxtailwindtest/sqlite.db
HTTP_HOST=0.0.0.0
HTTP_PORT=3000

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

1352
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

20
Cargo.toml Normal file
View File

@@ -0,0 +1,20 @@
[package]
name = "htmxtailwindtest"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1", features = ["full"] }
axum = "0.7.9"
serde = { version = "1.0.217", features = ["derive"] }
tower = "0.5.2"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
tower-http = { version = "0.6.2", features = ["cors", "trace", "fs"] }
diesel = { version = "2.2.7", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] }
dotenvy = "0.15"
anyhow = "1.0.95"
deadpool-diesel = { version = "0.6.1", features = ["sqlite", "tracing"]}
clap = { version = "4.5.21", features = ["derive", "env"] }
askama = { version = "0.12.1", features = ["with-axum"] }
askama_axum = "0.4"

BIN
assets/galaxy.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 MiB

265
assets/logo.svg Normal file
View File

@@ -0,0 +1,265 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="256"
height="256"
viewBox="0 0 256 256"
version="1.1"
id="svg3"
sodipodi:docname="logo.svg"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs3">
<inkscape:path-effect
effect="powermask"
id="path-effect15"
is_visible="true"
lpeversion="1"
uri="#mask-powermask-path-effect15"
invert="false"
hide_mask="false"
background="true"
background_color="#ffffffff" />
<inkscape:path-effect
effect="powermask"
id="path-effect14"
is_visible="true"
lpeversion="1"
uri="#mask-powermask-path-effect14"
invert="false"
hide_mask="false"
background="true"
background_color="#ffffffff" />
<inkscape:path-effect
effect="powerclip"
message=""
id="path-effect13"
is_visible="true"
lpeversion="1"
inverse="true"
flatten="false"
hide_clip="false" />
<inkscape:path-effect
effect="powerclip"
message=""
id="path-effect12"
is_visible="true"
lpeversion="1"
inverse="true"
flatten="false"
hide_clip="false" />
<inkscape:path-effect
effect="powerclip"
message=""
id="path-effect11"
is_visible="true"
lpeversion="1"
inverse="true"
flatten="false"
hide_clip="false" />
<inkscape:path-effect
effect="powermask"
id="path-effect9"
is_visible="true"
lpeversion="1"
uri="#mask-powermask-path-effect9"
invert="false"
hide_mask="false"
background="true"
background_color="#ffffffff" />
<inkscape:path-effect
effect="powermask"
id="path-effect8"
is_visible="true"
lpeversion="1"
uri="#mask-powermask-path-effect8"
invert="false"
hide_mask="false"
background="true"
background_color="#ffffffff" />
<inkscape:path-effect
effect="powermask"
id="path-effect7"
is_visible="true"
lpeversion="1"
uri="#mask-powermask-path-effect7"
invert="false"
hide_mask="false"
background="true"
background_color="#ffffffff" />
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath9">
<rect
style="display:none;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="rect9"
width="100.455"
height="15.318766"
x="126.82163"
y="135.80667"
d="m 126.82163,135.80667 h 100.455 v 15.31877 h -100.455 z" />
<path
id="lpe_path-effect11"
style="display:inline;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
class="powerclip"
d="m 168.34962,137.49724 h 61.89469 v 53.94291 h -61.89469 z m -41.52799,-1.69057 v 15.31877 h 100.455 v -15.31877 z" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath10">
<rect
style="display:none;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="rect10"
width="100.455"
height="15.318766"
x="126.82163"
y="135.80667"
d="m 126.82163,135.80667 h 100.455 v 15.31877 h -100.455 z" />
<path
id="lpe_path-effect12"
style="display:inline;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
class="powerclip"
d="m 121.74987,137.4969 h 61.72408 v 53.96962 h -61.72408 z m 5.07176,-1.69023 v 15.31877 h 100.455 v -15.31877 z" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath11">
<rect
style="display:none;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="rect11"
width="100.455"
height="15.318766"
x="126.82163"
y="135.80667"
d="m 126.82163,135.80667 h 100.455 v 15.31877 h -100.455 z" />
<path
id="lpe_path-effect13"
style="display:inline;opacity:1;mix-blend-mode:normal;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:8.78723;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
class="powerclip"
d="m 123,139 h 106 v 74 H 123 Z m 3.82163,-3.19333 v 15.31877 h 100.455 v -15.31877 z" />
</clipPath>
</defs>
<sodipodi:namedview
id="namedview3"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:zoom="4"
inkscape:cx="129.5"
inkscape:cy="123.125"
inkscape:window-width="1896"
inkscape:window-height="1026"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg3" />
<!-- Background rectangle with rounded corners -->
<rect
width="256"
height="256"
rx="48"
ry="48"
fill="#FF6600"
id="rect1"
style="fill:#ff6600;fill-opacity:1" />
<!-- RSS symbol -->
<!-- Small circle -->
<!-- First arc -->
<path
d="m 72,112 c 38,0 72,34 72,72"
fill="none"
stroke="#ffffff"
stroke-width="24"
stroke-linecap="round"
id="path1" />
<path
d="m 72,36 c 78,0 148,70 148,148"
fill="none"
stroke="#ffffff"
stroke-width="24"
stroke-linecap="round"
id="path2" />
<!-- Second arc -->
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="mail"
style="display:inline;mix-blend-mode:normal">
<path
x="128"
y="144"
width="96"
height="64"
fill="#FFFFFF"
rx="8"
ry="8"
id="rect2"
style="fill:#e6e6e6"
mask="none"
sodipodi:type="rect"
clip-path="url(#clipPath11)"
inkscape:path-effect="#path-effect13"
d="m 136,144 h 80 c 4.432,0 8,3.568 8,8 v 48 c 0,4.432 -3.568,8 -8,8 h -80 c -4.432,0 -8,-3.568 -8,-8 v -48 c 0,-4.432 3.568,-8 8,-8 z" />
<line
x1="128.02968"
y1="144.03561"
x2="177.19414"
y2="184.92781"
stroke="#ff6600"
stroke-width="4.00277"
id="line2"
mask="none"
clip-path="url(#clipPath10)"
inkscape:path-effect="#path-effect12"
d="m 128.02968,144.03561 49.16446,40.8922" />
<line
x1="223.96869"
y1="144.03763"
x2="174.62524"
y2="184.89977"
stroke="#ff6600"
stroke-width="4"
id="line3"
mask="none"
clip-path="url(#clipPath9)"
inkscape:path-effect="#path-effect11"
d="m 223.96869,144.03763 -49.34345,40.86214" />
<polygon
points="224,144 128,144 176,104 "
fill="#ffffff"
id="polygon2"
transform="matrix(0.99906475,0,0,0.99788438,0.1631611,7.4375162)"
style="fill:#e6e6e6;fill-opacity:1" />
<path
style="fill:#fbf46f;fill-opacity:1;stroke:#ff6600;stroke-width:2;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
d="M 139.125,152.375 212.75,152.25 176,183.5 Z"
id="path5" />
<path
style="fill:none;fill-opacity:1;stroke:#ff6600;stroke-width:2;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
d="m 137.62066,152.20474 h 75.8372"
id="path4" />
</g>
<!-- Email envelope -->
<!-- Envelope body -->
<!-- Envelope flap -->
<!-- Envelope details -->
<path
style="fill:none;stroke:#fbf46f;stroke-width:12;stroke-dasharray:none;stroke-opacity:1"
d="m 71.880322,186.18182 c 0,0 -2.986403,-88.537022 29.599538,-106.664846 25.66147,-14.275685 36.95282,17.638952 47.53683,29.110466 15.64037,16.95188 26.85443,-3.75287 26.55983,35.1332 L 175.5,153 v 0 l 0.0625,6.75 v 0"
id="path3"
sodipodi:nodetypes="cssccccc"
mask="none" />
<circle
cx="72"
cy="184"
r="24"
fill="#FFFFFF"
id="circle1" />
</svg>

After

Width:  |  Height:  |  Size: 8.7 KiB

17
assets/oval.svg Normal file
View File

@@ -0,0 +1,17 @@
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#fff">
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)" stroke-width="2">
<circle stroke-opacity=".5" cx="18" cy="18" r="18"/>
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"/>
</path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 694 B

9
diesel.toml Normal file
View File

@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
[migrations_directory]
dir = "/home/fpasqua/RustroverProjects/htmxtailwindtest/migrations"

0
migrations/.keep Normal file
View File

View File

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS rss_feeds;

View File

@@ -0,0 +1,7 @@
-- Your SQL goes here
CREATE TABLE rss_feeds (
id INTEGER NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
feed_url TEXT NOT NULL,
last_pub_date TEXT DEFAULT NULL -- ISO 8601 format e.g. "2023-10-05T14:48:00+02:00"
);

305
src/main.rs Normal file
View File

@@ -0,0 +1,305 @@
use diesel::prelude::*;
use anyhow::{anyhow, Result, Context};
use askama_axum::Template;
use axum::{extract::{Path, State}, http::{Method, header, StatusCode, Request, Uri}, response::{IntoResponse, Response, Html}, routing::{get, post}, Json, Router, Form, http};
use axum::http::HeaderValue;
use deadpool_diesel::sqlite::{Runtime, Manager, Pool};
use clap::Parser;
use tower::{ServiceBuilder};
use tower_http::{
cors::{Any, CorsLayer},
trace::{TraceLayer, DefaultOnResponse},
services::ServeDir,
LatencyUnit
};
use serde::Deserialize;
use tracing::{
info, error, debug, info_span, enabled,
instrument, Level, Span
};
pub mod models;
pub mod schema;
use self::models::*;
#[derive(Parser,Clone)]
struct Config {
#[arg(long,env)]
database_url: String,
#[arg(long,env)]
http_host: String,
#[arg(long,env)]
http_port: u16,
}
#[derive(Clone)]
struct AppContext {
config: Config,
pool: Pool,
}
async fn establish_connection(database_url: &str) -> Pool {
let manager = Manager::new(database_url, Runtime::Tokio1);
let pool = Pool::builder(manager)
.max_size(8)
.build()
.unwrap();
let _ = pool.get().await.expect("DB connection failed"); // Test if DB connection was fine
pool
}
#[tokio::main]
async fn main() -> Result<()> {
// Load Env File
dotenvy::dotenv().ok();
// Init Tracing
tracing_subscriber::fmt::init();
// Parse Env/CLI
let config = Config::parse();
// Establish Connection Pool
let pool: Pool = establish_connection(&config.database_url).await;
// Prepare Web Server Context
let context = AppContext {
config: config.clone(),
pool: pool.clone(),
};
// Prepare Middlewares
let cors = CorsLayer::very_permissive();
let tracelayer = TraceLayer::new_for_http()
.make_span_with(|request: &Request<_>| {
// Log the matched route's path (with placeholders not filled in).
let path = request.uri().to_string();
info_span!(
"request",
method = ?request.method(),
path
)
})
.on_request(|_request: &Request<_>, _span: &Span| {
debug!("Request received");
})
.on_response(
DefaultOnResponse::new()
.level(Level::DEBUG)
.latency_unit(LatencyUnit::Millis)
);
let middlewares = ServiceBuilder::new()
.layer(tracelayer).layer(cors);
// Launch Web Server
let app = Router::new()
.nest_service("/assets", ServeDir::new("assets"))
.route("/", get(index))
.route("/feed/", get(get_list_feed).post(post_feed))
.route("/feed/:id", get(get_feed).delete(delete_feed).put(put_feed))
.route("/feed/:id/edit/form", get(get_feed_form))
.route("/feed/:id/edit/inline", get(get_feed_inline))
.layer(middlewares)
.with_state(context.clone());
// Run our app with hyper
let listener = tokio::net::TcpListener::bind((config.http_host.as_str(), config.http_port))
.await.context(format!("Failed to bind Web Service on {}:{}", config.http_host, config.http_port))?;
info!("Listening on {}:{}", config.http_host, config.http_port);
axum::serve(listener, app).await.context("Failed to serve Web Service")?;
Ok(())
}
#[derive(Template)]
#[template(path="feed.html")]
struct FeedTemplate {
feed: RssFeed
}
async fn get_feed(
State(ctx): State<AppContext>,
Path(feed_id): Path<i32>
) -> FeedTemplate {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(move |conn| {
rss_feeds
.find(feed_id)
.select(RssFeed::as_select())
.first(conn)
.optional()
.expect("Error loading feeds")
}).await.unwrap();
if let Some(feed) = result {
FeedTemplate{ feed }
} else {
FeedTemplate{
feed: RssFeed{
id: -1,
name: "ERROR".to_string(),
feed_url: "ERROR".to_string(),
last_pub_date: Some("ERROR".to_string())
}
}
}
}
#[derive(Template)]
#[template(path="feed_form.html")]
struct FeedFormTemplate {
feed: RssFeed
}
async fn get_feed_form(
State(ctx): State<AppContext>,
Path(feed_id): Path<i32>
) -> impl IntoResponse {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(move |conn| {
rss_feeds
.find(feed_id)
.select(RssFeed::as_select())
.first(conn)
.optional()
.expect("Error loading feeds")
}).await.unwrap();
if let Some(feed) = result {
FeedFormTemplate{ feed }
} else {
FeedFormTemplate{
feed: RssFeed{
id: -1,
name: "ERROR".to_string(),
feed_url: "ERROR".to_string(),
last_pub_date: Some("ERROR".to_string())
}
}
}
}
#[derive(Template)]
#[template(path="feed_inline.html")]
struct FeedInlineTemplate {
feed: RssFeed
}
async fn get_feed_inline(
State(ctx): State<AppContext>,
Path(feed_id): Path<i32>
) -> impl IntoResponse {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(move |conn| {
rss_feeds
.find(feed_id)
.select(RssFeed::as_select())
.first(conn)
.optional()
.expect("Error loading feeds")
}).await.unwrap();
if let Some(feed) = result {
FeedInlineTemplate{ feed }
} else {
FeedInlineTemplate{
feed: RssFeed{
id: -1,
name: "ERROR".to_string(),
feed_url: "ERROR".to_string(),
last_pub_date: Some("ERROR".to_string())
}
}
}
}
#[derive(Deserialize, AsChangeset)]
#[diesel(table_name = crate::schema::rss_feeds)]
struct PostForm{
name: String,
feed_url: String,
}
async fn post_feed(
State(ctx): State<AppContext>,
Form(post): Form<PostForm>,
) -> impl IntoResponse {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(move |conn| {
let new_feed = NewRssFeed{name: post.name.as_str(), feed_url: post.feed_url.as_str() };
diesel::insert_into(rss_feeds)
.values(&new_feed)
.returning(RssFeed::as_select())
.get_result(conn)
.expect("Error saving new feed")
}).await.unwrap();
FeedTemplate{ feed: result }
}
async fn put_feed(
State(ctx): State<AppContext>,
Path(feed_id): Path<i32>,
Form(post): Form<PostForm>
) -> impl IntoResponse {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(move |conn| {
diesel::update(rss_feeds.find(feed_id))
.set(post)
.returning(RssFeed::as_select())
.get_result(conn)
.expect("Error updating feed")
}).await.unwrap();
FeedTemplate{ feed: result }
}
#[derive(Template)]
#[template(source="\
{% for feed in feeds %}
{% include \"feed.html\" %}
{% endfor %}", ext="html")]
struct FeedsTemplate {
feeds: Vec<RssFeed>
}
async fn get_list_feed(
State(ctx): State<AppContext>,
) -> FeedsTemplate {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let result = conn.interact(|conn| {
rss_feeds
.select(RssFeed::as_select())
.load(conn)
.expect("Error loading feeds")
}).await.unwrap();
FeedsTemplate{ feeds: result }
}
async fn delete_feed(
State(ctx): State<AppContext>,
Path(feed_id): Path<i32>,
) -> impl IntoResponse {
let conn = ctx.pool.get().await.unwrap();
use self::schema::rss_feeds::dsl::*;
let num_deleted = conn.interact(move |conn| {
diesel::delete(rss_feeds.find(feed_id))
.execute(conn)
.expect("Error deleting posts")
}).await.unwrap();
if num_deleted == 0 {
(StatusCode::NOT_FOUND, "Not found")
} else {
// HTMX swaps only on 200, so we cannot use NO_CONTENT
// In fact, MSDN says that NO_CONTENT means "do nothing", but this is debated.
(StatusCode::OK, "")
}
}
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {
feeds: FeedsTemplate
}
async fn index(
State(ctx): State<AppContext>,
) -> IndexTemplate {
let feeds = get_list_feed(State(ctx)).await;
IndexTemplate { feeds }
}

19
src/models.rs Normal file
View File

@@ -0,0 +1,19 @@
use diesel::prelude::*;
#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::schema::rss_feeds)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct RssFeed {
pub id: i32,
pub name: String,
pub feed_url: String,
pub last_pub_date: Option<String>,
}
#[derive(Insertable)]
#[diesel(table_name = crate::schema::rss_feeds)]
pub struct NewRssFeed<'a> {
pub name: &'a str,
pub feed_url: &'a str,
}

10
src/schema.rs Normal file
View File

@@ -0,0 +1,10 @@
// @generated automatically by Diesel CLI.
diesel::table! {
rss_feeds (id) {
id -> Integer,
name -> Text,
feed_url -> Text,
last_pub_date -> Nullable<Text>,
}
}

20
templates/base.html Normal file
View File

@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
<title>{% block title %}{{ title }}{% endblock %}</title>
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.8/dist/cdn.min.js"></script>
<style>
[x-cloak] {
display: none !important;
}
</style>
{% block head %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>

24
templates/feed.html Normal file
View File

@@ -0,0 +1,24 @@
<tr id="feed_{{feed.id}}">
<td>{{feed.name}}</td>
<td>{{feed.feed_url}}</td>
<td>{{feed.last_pub_date.clone().unwrap_or("None".to_string())}}</td>
<td>
<button hx-get="/feed/{{feed.id}}/edit/inline"
hx-target="#feed_{{feed.id}}"
hx-swap="outerHTML">
Edit Inline
</button>
<button hx-get="/feed/{{feed.id}}/edit/form"
hx-target="body"
hx-swap="beforeend">
Edit Dialog
</button>
<button class="danger"
hx-confirm="Are you sure?"
hx-delete="/feed/{{feed.id}}"
hx-target="#feed_{{feed.id}}"
hx-swap="outerHTML">
Delete
</button>
</td>
</tr>

29
templates/feed_form.html Normal file
View File

@@ -0,0 +1,29 @@
<div id="modal" x-data>
<div class="overlay" style="z-index: 30"></div>
<dialog open style="z-index: 31">
<header>
<h2>Modify RSS Feed subscription</h2>
</header>
<form id="modify_form" hx-put="/feed/{{feed.id}}" hx-target="#feed_{{feed.id}}" hx-swap="outerHTML"
hx-indicator="#mod_indicator"
@htmx:after-on-load="document.getElementById('modal').remove()">
<label>
Name
<input type="text" name="name" value="{{feed.name}}">
</label>
<label>
Feed URL
<input type="url" name="feed_url" value="{{feed.feed_url}}">
</label>
</form>
<footer>
<button form="modify_form" type="reset" @click="document.getElementById('modal').remove()">Close
</button>
<button form="modify_form" type="submit">
Submit
<img id="mod_indicator" class="htmx-indicator" src="/assets/oval.svg"
style="height: 1rem; margin-left: 2px" alt="...">
</button>
</footer>
</dialog>
</div>

View File

@@ -0,0 +1,29 @@
<tr id="feed_{{feed.id}}">
<td>
<label style="width: 100%">
<input type="text" name="name" form="update_feed_{{feed.id}}" value="{{feed.name}}">
</label>
</td>
<td>
<label style="width: 100%">
<input type="url" name="feed_url" form="update_feed_{{feed.id}}" value="{{feed.feed_url}}">
</label>
</td>
<td>{{feed.last_pub_date.clone().unwrap_or("None".to_string())}}</td>
<td>
<form id="update_feed_{{feed.id}}" hx-put="/feed/{{feed.id}}" hx-target="#feed_{{feed.id}}" hx-swap="outerHTML"
hx-indicator="update_feed_{{feed.id}}_indicator" style="padding: 0; background: unset">
<button type="reset"
hx-get="/feed/{{feed.id}}"
hx-target="#feed_{{feed.id}}"
hx-swap="outerHTML">
Cancel
</button>
<button type="submit">
Confirm
<img id="update_feed_{{feed.id}}_indicator" class="htmx-indicator" src="/assets/oval.svg"
style="height: 1rem; margin-left: 2px" alt="...">
</button>
</form>
</td>
</tr>

89
templates/index.html Normal file
View File

@@ -0,0 +1,89 @@
{% extends "base.html" %}
{% block title %}Hello!{% endblock %}
{% block head %}
<style>
.navbar {
overflow: hidden;
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #161b22;
}
.overlay {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: #161b22;
opacity: 0.75;
}
th {
white-space: nowrap;
}
td {
white-space: nowrap;
}
</style>
{% endblock %}
{% block content %}
<nav class="navbar" style="z-index: 20">
<div>
<a href="/" style="display: flex">
<img src="/assets/logo.svg" style="margin:8px; height: 32px" alt="RSS Notifier Logo"/>
<h2 style="margin-bottom: auto; margin-top: auto">RSS Notifier</h2>
</a>
</div>
</nav>
<div style="height: 48px; margin-bottom: 8px"></div>
<div x-data="{'isModalOpen': false}">
<div style="display:flex; justify-content:flex-end">
<button @click="isModalOpen = true">Create</button>
</div>
<div class="overlay" style="z-index: 30" x-show="isModalOpen" x-cloak></div>
<dialog open style="z-index: 31" x-show="isModalOpen" x-cloak x-transition>
<header>
<h2>Create new RSS Feed subscription</h2>
</header>
<form id="create_form" hx-post="/feed/" hx-target="#feed_tbody" hx-swap="beforeend" hx-indicator="#indicator"
@htmx:after-on-load="document.getElementById('create_form').reset();isModalOpen = false">
<label>
Name
<input type="text" name="name">
</label>
<label>
Feed URL
<input type="url" name="feed_url">
</label>
</form>
<footer>
<button form="create_form" type="reset" @click="isModalOpen = false">Close</button>
<button form="create_form" type="submit">
Submit
<img id="indicator" class="htmx-indicator" src="/assets/oval.svg" style="height: 1rem; margin-left: 2px"
alt="...">
</button>
</footer>
</dialog>
<table style="text-align:center">
<thead>
<tr>
<th>Feed Name</th>
<th>Feed URL</th>
<th>Last Mail Sent</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="feed_tbody">
{{ feeds|safe }}
</tbody>
</table>
</div>
{% endblock %}