Add html items for updating quest status.
Still need add a handler to edit quest status (remove, change publicity).
This commit is contained in:
parent
67a69ca0d0
commit
d90011b619
6 changed files with 61 additions and 12 deletions
|
@ -7,7 +7,7 @@ use sqlx::{
|
||||||
|
|
||||||
const MAX_CONNS: u32 = 200;
|
const MAX_CONNS: u32 = 200;
|
||||||
const MIN_CONNS: u32 = 5;
|
const MIN_CONNS: u32 = 5;
|
||||||
const TIMEOUT: u64 = 20;
|
const TIMEOUT: u64 = 2000; // in milliseconds
|
||||||
|
|
||||||
pub fn get_db_pool() -> SqlitePool {
|
pub fn get_db_pool() -> SqlitePool {
|
||||||
let conf = crate::conf::Config::get();
|
let conf = crate::conf::Config::get();
|
||||||
|
@ -44,6 +44,7 @@ pub fn get_db_pool() -> SqlitePool {
|
||||||
// be sure to have run `make julid` so that the libjulid extension is built
|
// be sure to have run `make julid` so that the libjulid extension is built
|
||||||
.extension(conf.julid_plugin)
|
.extension(conf.julid_plugin)
|
||||||
.busy_timeout(Duration::from_secs(TIMEOUT))
|
.busy_timeout(Duration::from_secs(TIMEOUT))
|
||||||
|
.pragma("temp_store", "memory")
|
||||||
.create_if_missing(true)
|
.create_if_missing(true)
|
||||||
.optimize_on_close(true, None)
|
.optimize_on_close(true, None)
|
||||||
.pragma("mmap_size", "3000000000");
|
.pragma("mmap_size", "3000000000");
|
||||||
|
|
|
@ -8,7 +8,7 @@ use julid::Julid;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::{query, query_as, query_scalar, SqlitePool};
|
use sqlx::{query, query_as, query_scalar, SqlitePool};
|
||||||
|
|
||||||
use super::templates::{AddNewWatchPage, AddWatchButton, GetWatchPage};
|
use super::templates::{AddNewWatchPage, GetWatchPage, WatchStatusMenus};
|
||||||
use crate::{
|
use crate::{
|
||||||
misc_util::empty_string_as_none, AuthSession, MyWatchesPage, ShowKind, Watch, WatchQuest,
|
misc_util::empty_string_as_none, AuthSession, MyWatchesPage, ShowKind, Watch, WatchQuest,
|
||||||
};
|
};
|
||||||
|
@ -237,11 +237,7 @@ pub async fn get_watch_status(
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
tracing::error!("Got error from checking watch status: {e:?}");
|
tracing::error!("Got error from checking watch status: {e:?}");
|
||||||
})?;
|
})?;
|
||||||
match quest {
|
Ok(WatchStatusMenus { watch, quest }.into_response())
|
||||||
Some(quest) if quest.watched => Ok(format!("{CHECKMARK} watched").into_response()),
|
|
||||||
Some(quest) => Ok(checkmark(quest.public).into_response()),
|
|
||||||
None => Ok(AddWatchButton { watch }.into_response()),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Ok("<a href='/login'>Login to add</a>".into_response())
|
Ok("<a href='/login'>Login to add</a>".into_response())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use askama::Template;
|
||||||
use julid::Julid;
|
use julid::Julid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{OptionalOptionalUser, User, Watch};
|
use crate::{OptionalOptionalUser, User, Watch, WatchQuest};
|
||||||
|
|
||||||
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
||||||
#[template(path = "my_watches_page.html")]
|
#[template(path = "my_watches_page.html")]
|
||||||
|
@ -26,6 +26,7 @@ pub struct AddNewWatchPage {
|
||||||
|
|
||||||
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
#[template(path = "elements/add_watch_button.html")]
|
#[template(path = "elements/add_watch_button.html")]
|
||||||
pub struct AddWatchButton {
|
pub struct WatchStatusMenus {
|
||||||
pub watch: Julid,
|
pub watch: Julid,
|
||||||
|
pub quest: Option<WatchQuest>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,59 @@
|
||||||
|
{% match quest %}
|
||||||
|
{% when Some with (q) %}
|
||||||
|
|
||||||
|
{% let public %}
|
||||||
|
{% let np %}
|
||||||
|
{% if q.public -%}
|
||||||
|
{% let public = "public" %}
|
||||||
|
{% let np = "private" %}
|
||||||
|
{% else %}
|
||||||
|
{% let public = "private" %}
|
||||||
|
{% let np = "public" %}
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
{% let status %}
|
||||||
|
{% if q.watched -%}
|
||||||
|
{% let status = "want to watch" %}
|
||||||
|
{% else %}
|
||||||
|
{% let status = "watched" %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Added</td>
|
||||||
|
<td>{{- public -}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<form id="edit-quest-{{self.watch}}">
|
||||||
|
<button hx-post="/edit/quest" hx-target="#add-watch-{{self.watch}}" hx-trigger="click"
|
||||||
|
hx-swap="outerHTML">remove</button>
|
||||||
|
<input type="hidden" name="watch" value="{{self.watch}}">
|
||||||
|
<input type="hidden" name="act" value="remove">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form id="edit-visibility-{{self.watch}}">
|
||||||
|
<button hx-post="/edit/quest" hx-target="#add-watch-{{self.watch}}" hx-trigger="click"
|
||||||
|
hx-swap="outerHTML">mark as {{ np }}</button>
|
||||||
|
<input type="hidden" name="watch" value="{{self.watch}}">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% when None %}
|
||||||
|
|
||||||
<form id="add-watch-{{self.watch}}">
|
<form id="add-watch-{{self.watch}}">
|
||||||
<button hx-post="/add/watch" hx-target="#add-watch-{{watch}}" hx-trigger="click" hx-swap="outerHTML">add</button>
|
<button hx-post="/add/watch" hx-target="#add-watch-{{self.watch}}" hx-trigger="click"
|
||||||
|
hx-swap="outerHTML">add</button>
|
||||||
<select name="public" id="add-public-watch">
|
<select name="public" id="add-public-watch">
|
||||||
<option value="true">public</option>
|
<option value="true">public</option>
|
||||||
<option value="false">private</option>
|
<option value="false">private</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="hidden" name="watch" value="{{self.watch}}">
|
<input type="hidden" name="watch" value="{{self.watch}}">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% endmatch %}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Year</th>
|
<th>Year</th>
|
||||||
<th>Watching?</th>
|
<th>Status</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Year</th>
|
<th>Year</th>
|
||||||
<th>Watching?</th>
|
<th>Status</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
Loading…
Reference in a new issue