Compare commits
No commits in common. "417875300f18e6761db29b8acadeccedd8eb0a0a" and "3ba76fdb390c7679f7625ad3b528b8a2770335ae" have entirely different histories.
417875300f
...
3ba76fdb39
|
|
@ -1,5 +0,0 @@
|
||||||
-- Add down migration script here
|
|
||||||
drop table gift_exchange;
|
|
||||||
drop table gift_exchange_participants;
|
|
||||||
|
|
||||||
delete from role_permissions where item = '/giftexchange';
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
CREATE TABLE
|
|
||||||
`gift_exchange` (
|
|
||||||
`id` integer not null primary key autoincrement,
|
|
||||||
`created_at` INTEGER not null default CURRENT_TIMESTAMP,
|
|
||||||
`created_by` integer not null default 0,
|
|
||||||
`updated_at` INTEGER not null default CURRENT_TIMESTAMP,
|
|
||||||
`updated_by` integer not null default 0,
|
|
||||||
`name` varchar(255) not null,
|
|
||||||
`exchange_date` INTEGER not null,
|
|
||||||
`status` INTEGER not null default 0,
|
|
||||||
unique (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE
|
|
||||||
`gift_exchange_participants` (
|
|
||||||
`id` integer not null primary key autoincrement,
|
|
||||||
`created_at` INTEGER not null default CURRENT_TIMESTAMP,
|
|
||||||
`created_by` integer not null default 0,
|
|
||||||
`updated_at` INTEGER not null default CURRENT_TIMESTAMP,
|
|
||||||
`updated_by` integer not null default 0,
|
|
||||||
`exchange_id` INTEGER not null,
|
|
||||||
`participant_id` INTEGER not null,
|
|
||||||
`gifter_id` INTEGER not null,
|
|
||||||
unique (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
insert into `role_permissions` (`created_at`, `created_by`, `id`, `item`, `role_id`, `updated_at`, `updated_by`) values ('0', '0', '10', '/giftexchange', '2', '0', '0')
|
|
||||||
|
|
@ -2,7 +2,6 @@ use std::net::SocketAddr;
|
||||||
use axum::{
|
use axum::{
|
||||||
middleware, routing::{get, get_service}, Extension, Router
|
middleware, routing::{get, get_service}, Extension, Router
|
||||||
};
|
};
|
||||||
use secret_gift_exchange::{giftexchange, giftexchange_save, giftexchanges};
|
|
||||||
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
||||||
use sqlx::migrate::Migrator;
|
use sqlx::migrate::Migrator;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
@ -14,7 +13,6 @@ mod routes;
|
||||||
mod user;
|
mod user;
|
||||||
mod wishlist;
|
mod wishlist;
|
||||||
mod email;
|
mod email;
|
||||||
mod secret_gift_exchange;
|
|
||||||
|
|
||||||
use error_handling::AppError;
|
use error_handling::AppError;
|
||||||
use middlewares::inject_user_data;
|
use middlewares::inject_user_data;
|
||||||
|
|
@ -53,18 +51,12 @@ async fn main() {
|
||||||
// build our application with some routes
|
// build our application with some routes
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/dashboard", get(dashboard))
|
.route("/dashboard", get(dashboard))
|
||||||
|
.route("/cottagecalendar", get(cottagecalendar))
|
||||||
// User
|
|
||||||
.route("/profile", get(profile))
|
.route("/profile", get(profile))
|
||||||
.route("/useradmin", get(useradmin))
|
.route("/useradmin", get(useradmin))
|
||||||
.route("/users/:user_id", get(user_profile))
|
.route("/users/:user_id", get(user_profile))
|
||||||
.route("/roles/:user_id/:role_id/add", get(add_user_role))
|
.route("/roles/:user_id/:role_id/add", get(add_user_role))
|
||||||
.route("/roles/:user_id/:user_role_id/delete", get(delete_user_role))
|
.route("/roles/:user_id/:user_role_id/delete", get(delete_user_role))
|
||||||
|
|
||||||
// Calendar
|
|
||||||
.route("/cottagecalendar", get(cottagecalendar))
|
|
||||||
|
|
||||||
// Wishlist
|
|
||||||
.route("/wishlists", get(wishlists))
|
.route("/wishlists", get(wishlists))
|
||||||
.route("/userwishlist/:user_id", get(user_wishlist))
|
.route("/userwishlist/:user_id", get(user_wishlist))
|
||||||
.route("/userwishlist/add/:user_id", get(user_wishlist_add).post(user_wishlist_add_item))
|
.route("/userwishlist/add/:user_id", get(user_wishlist_add).post(user_wishlist_add_item))
|
||||||
|
|
@ -73,11 +65,6 @@ async fn main() {
|
||||||
.route("/userwishlist/received/:user_id", get(user_wishlist_received_item))
|
.route("/userwishlist/received/:user_id", get(user_wishlist_received_item))
|
||||||
.route("/userwishlist/delete/:item_id", get(user_wishlist_delete_item))
|
.route("/userwishlist/delete/:item_id", get(user_wishlist_delete_item))
|
||||||
.route("/userwishlist/returned/:item_id", get(user_wishlist_returned_item))
|
.route("/userwishlist/returned/:item_id", get(user_wishlist_returned_item))
|
||||||
|
|
||||||
// Secret Gift Exchange - Not ready for public use yet
|
|
||||||
//.route("/giftexchanges", get(giftexchanges))
|
|
||||||
//.route("/giftexchange/:giftexchange_id", get(giftexchange).post(giftexchange_save))
|
|
||||||
|
|
||||||
.nest_service("/assets", ServeDir::new("templates/assets")
|
.nest_service("/assets", ServeDir::new("templates/assets")
|
||||||
.fallback(get_service(ServeDir::new("templates/assets"))))
|
.fallback(get_service(ServeDir::new("templates/assets"))))
|
||||||
.route("/", get(index))
|
.route("/", get(index))
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ pub async fn index(
|
||||||
if logged_in {
|
if logged_in {
|
||||||
// Extract the user data.
|
// Extract the user data.
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
let user = user_data.as_ref().unwrap().clone();
|
||||||
|
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
||||||
|
|
||||||
if is_authorized("/dashboard", user_data, db_pool).await {
|
if is_authorized("/dashboard", user_data, db_pool).await {
|
||||||
Redirect::to("/dashboard").into_response()
|
Redirect::to("/dashboard").into_response()
|
||||||
|
|
|
||||||
|
|
@ -1,272 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use askama::Template;
|
|
||||||
use askama_axum::{IntoResponse, Response};
|
|
||||||
use axum::{
|
|
||||||
body::{self, Body},
|
|
||||||
extract::{FromRequest, Path, Request, State},
|
|
||||||
response::Redirect,
|
|
||||||
Extension, Form, Json, RequestExt,
|
|
||||||
};
|
|
||||||
use axum_extra::response::Html;
|
|
||||||
use chrono::Utc;
|
|
||||||
use http::{header::CONTENT_TYPE, StatusCode};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sqlx::{FromRow, SqlitePool};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
middlewares::is_authorized,
|
|
||||||
user::{get_user_roles_display, UserData},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Select participants from user list
|
|
||||||
/// create group id for exchange
|
|
||||||
/// allow user to only see their recipient but whole list of participants
|
|
||||||
/// link to recipient wish list
|
|
||||||
/// button to create selections
|
|
||||||
///
|
|
||||||
/// Database schema
|
|
||||||
/// Table - gift_exchange
|
|
||||||
/// Columns - id -> number
|
|
||||||
/// - created_by -> number
|
|
||||||
/// - created_at -> number
|
|
||||||
/// - updated_by -> number
|
|
||||||
/// - updated_at -> number
|
|
||||||
/// - name -> text
|
|
||||||
/// - exchange_date -> number
|
|
||||||
///
|
|
||||||
/// Table - gift_exchange_participants
|
|
||||||
/// Columns - id -> number
|
|
||||||
/// - created_by -> number
|
|
||||||
/// - created_at -> number
|
|
||||||
/// - updated_by -> number
|
|
||||||
/// - updated_at -> number
|
|
||||||
/// - exchange_id -> number (reference gift_exchange table)
|
|
||||||
/// - participant_id -> number (reference user table)
|
|
||||||
/// - gifter_id -> number (reference user table)
|
|
||||||
///
|
|
||||||
/// Pages - sge_list
|
|
||||||
/// - list of gift exchanges user is part of
|
|
||||||
/// - sge_exchange
|
|
||||||
/// - exchange details
|
|
||||||
/// - list of participants
|
|
||||||
/// - sge_edit
|
|
||||||
/// - create new exchange
|
|
||||||
/// - edit existing exchange
|
|
||||||
/// - sge_participant_edit
|
|
||||||
/// - add or remove participant to exchange
|
|
||||||
///
|
|
||||||
/// API - select gifters
|
|
||||||
|
|
||||||
struct HtmlTemplate<T>(T);
|
|
||||||
|
|
||||||
impl<T> IntoResponse for HtmlTemplate<T>
|
|
||||||
where
|
|
||||||
T: Template,
|
|
||||||
{
|
|
||||||
fn into_response(self) -> Response {
|
|
||||||
match self.0.render() {
|
|
||||||
Ok(html) => Html(html).into_response(),
|
|
||||||
Err(err) => (
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("Failed to render template. Error: {}", err),
|
|
||||||
)
|
|
||||||
.into_response(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug, Serialize, Deserialize, FromRow)]
|
|
||||||
struct GiftExchange {
|
|
||||||
id: i64,
|
|
||||||
created_at: i64,
|
|
||||||
created_by: i64,
|
|
||||||
updated_at: i64,
|
|
||||||
updated_by: i64,
|
|
||||||
name: String,
|
|
||||||
exchange_date: i64,
|
|
||||||
status: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "giftexchanges.html")]
|
|
||||||
struct GiftExchangesTemplate {
|
|
||||||
logged_in: bool,
|
|
||||||
user: UserData,
|
|
||||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
|
||||||
giftexchanges: Vec<GiftExchange>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn giftexchanges(
|
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
// Is the user logged in?
|
|
||||||
let logged_in = user_data.is_some();
|
|
||||||
|
|
||||||
if logged_in {
|
|
||||||
// Extract the user data.
|
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
|
||||||
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
|
||||||
|
|
||||||
let giftexchanges = sqlx::query_as::<_, GiftExchange>("SELECT * FROM gift_exchange")
|
|
||||||
.fetch_all(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
|
||||||
// Get user roles
|
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
|
||||||
|
|
||||||
let template = GiftExchangesTemplate {
|
|
||||||
logged_in,
|
|
||||||
user,
|
|
||||||
user_roles,
|
|
||||||
giftexchanges,
|
|
||||||
};
|
|
||||||
HtmlTemplate(template).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug, Serialize, Deserialize, FromRow)]
|
|
||||||
struct GiftExchangeParticipant {
|
|
||||||
id: i64,
|
|
||||||
created_at: i64,
|
|
||||||
created_by: i64,
|
|
||||||
updated_at: i64,
|
|
||||||
updated_by: i64,
|
|
||||||
exchange_id: i64,
|
|
||||||
participant_id: i64,
|
|
||||||
gifter_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "giftexchange.html")]
|
|
||||||
struct GiftExchangeTemplate {
|
|
||||||
logged_in: bool,
|
|
||||||
user: UserData,
|
|
||||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
|
||||||
giftexchange: GiftExchange,
|
|
||||||
participants: Vec<UserData>,
|
|
||||||
non_participants: Vec<UserData>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn giftexchange(
|
|
||||||
Path(exchange_id): Path<i64>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
// Is the user logged in?
|
|
||||||
let logged_in = user_data.is_some();
|
|
||||||
|
|
||||||
if logged_in {
|
|
||||||
// Extract the user data.
|
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
|
||||||
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
|
||||||
|
|
||||||
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
|
||||||
// Get user roles
|
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
|
||||||
|
|
||||||
// Get gift exchange
|
|
||||||
let giftexchange = match sqlx::query_as!(
|
|
||||||
GiftExchange,
|
|
||||||
"SELECT * FROM gift_exchange WHERE id = ?",
|
|
||||||
exchange_id
|
|
||||||
)
|
|
||||||
.fetch_one(&db_pool)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(giftexchange) => giftexchange,
|
|
||||||
Err(_) => GiftExchange::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get participants
|
|
||||||
let participants = sqlx::query_as::<_, UserData>(
|
|
||||||
"select * from users where users.id in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
|
||||||
)
|
|
||||||
.bind(exchange_id)
|
|
||||||
.fetch_all(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Get non participants
|
|
||||||
let non_participants = sqlx::query_as::<_, UserData>(
|
|
||||||
"select * from users where users.id not in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
|
||||||
)
|
|
||||||
.bind(exchange_id)
|
|
||||||
.fetch_all(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let template = GiftExchangeTemplate {
|
|
||||||
logged_in,
|
|
||||||
user,
|
|
||||||
user_roles,
|
|
||||||
giftexchange,
|
|
||||||
participants,
|
|
||||||
non_participants,
|
|
||||||
};
|
|
||||||
HtmlTemplate(template).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct ExchangeForm {
|
|
||||||
name: String,
|
|
||||||
exchange_date: String,
|
|
||||||
non_participants: Vec<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn giftexchange_save(
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
request: Request<Body>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let content_type_header = request.headers().get(CONTENT_TYPE);
|
|
||||||
let content_type = content_type_header.and_then(|value| value.to_str().ok());
|
|
||||||
|
|
||||||
/* if let Some(content_type) = content_type {
|
|
||||||
if content_type.starts_with("application/json") {
|
|
||||||
let payload = request
|
|
||||||
.extract()
|
|
||||||
.await
|
|
||||||
.map_err(IntoResponse::into_response);
|
|
||||||
}
|
|
||||||
|
|
||||||
if content_type.starts_with("application/x-www-form-urlencoded") {
|
|
||||||
let payload = request
|
|
||||||
.extract()
|
|
||||||
.await
|
|
||||||
.map_err(IntoResponse::into_response);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
let (req_parts, map_request_body) = request.into_parts();
|
|
||||||
let bytes = match body::to_bytes(map_request_body, usize::MAX).await {
|
|
||||||
Ok(bytes) => bytes,
|
|
||||||
Err(err) => {
|
|
||||||
return Err((
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
format!("failed to read request body: {}", err),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Saving gift exchange: {:?}", req_parts);
|
|
||||||
println!("Saving gift exchange: {:?} ", bytes);
|
|
||||||
Ok(Redirect::to("/").into_response())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct Payload {
|
|
||||||
foo: String,
|
|
||||||
}
|
|
||||||
|
|
@ -111,9 +111,9 @@ pub async fn user_wishlist(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
||||||
// Get user roles
|
// Get user roles
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
|
|
||||||
// Get user wishlist
|
// Get user wishlist
|
||||||
let person_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await;
|
let person_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await;
|
||||||
|
|
@ -249,6 +249,8 @@ pub async fn user_wishlist_edit_item(
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
let user = user_data.as_ref().unwrap().clone();
|
||||||
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
||||||
|
|
||||||
|
// Extract the user data.
|
||||||
|
|
||||||
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
||||||
// Get user roles
|
// Get user roles
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
<li><a href="/dashboard">Web links</a></li>
|
<li><a href="/dashboard">Web links</a></li>
|
||||||
<li><a href="/cottagecalendar">Cottage Calendar</a></li>
|
<li><a href="/cottagecalendar">Cottage Calendar</a></li>
|
||||||
<li><a href="/wishlists">Wish lists</a></li>
|
<li><a href="/wishlists">Wish lists</a></li>
|
||||||
<li><a href="/giftexchanges">Gift Exchanges</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
{% for user_role in user_roles %}
|
{% for user_role in user_roles %}
|
||||||
{% if user_role.role_name == "admin" %}
|
{% if user_role.role_name == "admin" %}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,10 @@
|
||||||
<link rel="icon" type="image/x-icon" href="/assets/favicon.png">
|
<link rel="icon" type="image/x-icon" href="/assets/favicon.png">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="author" content="Chris Jean-Marie">
|
<meta name="author" content="">
|
||||||
|
|
||||||
<!-- Bootstrap CSS -->
|
<!-- Bootstrap CSS -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
|
|
||||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css'>
|
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css'>
|
||||||
|
|
||||||
|
|
@ -25,12 +24,9 @@
|
||||||
</style>
|
</style>
|
||||||
{% block links %}{% endblock links %}
|
{% block links %}{% endblock links %}
|
||||||
</head>
|
</head>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.5/dist/bootstrap-table.min.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid" height="100%">
|
<div class="container-fluid">
|
||||||
|
|
||||||
<!-- HEADER -->
|
<!-- HEADER -->
|
||||||
<div class="row fixed-top sticky-top">
|
<div class="row fixed-top sticky-top">
|
||||||
|
|
@ -80,16 +76,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bootstrap JS Bundle with Popper -->
|
<!-- Bootstrap JS Bundle with Popper -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||||
|
|
||||||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
|
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
{% block scripts %}{% endblock scripts %}
|
{% block scripts %}{% endblock scripts %}
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.5/dist/bootstrap-table.min.js"></script>
|
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
|
||||||
{% block script %}{% endblock script %}
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -1,158 +0,0 @@
|
||||||
{% extends "authorized.html" %}
|
|
||||||
{% block title %}Gift Exchange{% endblock %}
|
|
||||||
{% block center %}
|
|
||||||
<form action="/giftexchange/{{ giftexchange.id }}" method="post">
|
|
||||||
<div class="row">
|
|
||||||
<div class="btn-toolbar" role="toolbar">
|
|
||||||
<a role="button" class="btn btn-primary" href="/giftexchange/{{ giftexchange.id }}">Save</a>
|
|
||||||
<button id="update" type="submit" class="btn btn-danger">Update</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="name">Exchange Name:</label>
|
|
||||||
<input id="name" class="form-control" name="name" type="text" value="{{ giftexchange.name }}" required>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="exchange_date">Exchange Date:</label>
|
|
||||||
<input id="exchange_date" name="exchange_date" type="date" value="{{ giftexchange.exchange_date }}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row align-items-center text-center">
|
|
||||||
<div class="col">
|
|
||||||
<table id="non_participants" data-toggle="table" data-click-to-select="true"
|
|
||||||
data-height="400">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-field="state" data-checkbox="true"></th>
|
|
||||||
<th data-sortable="true" data-field="name" scope="col">Available</th>
|
|
||||||
<th data-hidden="true" data-field="id" scope="col">ID</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="np_tbody">
|
|
||||||
{% for participant in non_participants %}
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>{{ participant.name }}</td>
|
|
||||||
<td>{{ participant.id }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<div class="btn-group-vertical text-center" role="group">
|
|
||||||
<button id="add" type="button" class="btn btn-primary">Add</button>
|
|
||||||
<button id="remove" type="button" class="btn btn-primary">Remove</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<table id="participants" data-toggle="table" data-click-to-select="true" data-height="400">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-field="state" data-checkbox="true"></th>
|
|
||||||
<th data-sortable="true" data-field="name" scope="col">Participating</th>
|
|
||||||
<th data-hidden="true" data-field="id" scope="col">ID</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="p_tbody">
|
|
||||||
{% for participant in participants %}
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>{{ participant.name }}</td>
|
|
||||||
<td>{{ participant.id }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{% endblock center %}
|
|
||||||
|
|
||||||
{% block script %}
|
|
||||||
<script>
|
|
||||||
$(document).ready(() => {
|
|
||||||
var npRows = [];
|
|
||||||
var pRows = [];
|
|
||||||
|
|
||||||
$('#non_participants').bootstrapTable('hideColumn', 'id');
|
|
||||||
$('#participants').bootstrapTable('hideColumn', 'id');
|
|
||||||
|
|
||||||
$('#non_participants').on('check.bs.table', function (e, row) {
|
|
||||||
npRows.push({ name: row.name, id: row.id });
|
|
||||||
console.log(npRows);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#non_participants').on('uncheck.bs.table', function (e, row) {
|
|
||||||
$.each(npRows, function (index, value) {
|
|
||||||
if (value.id === row.id) {
|
|
||||||
npRows.splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(npRows);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#participants').on('check.bs.table', function (e, row) {
|
|
||||||
pRows.push({ name: row.name, id: row.id });
|
|
||||||
console.log(pRows);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#participants').on('uncheck.bs.table', function (e, row) {
|
|
||||||
$.each(pRows, function (index, value) {
|
|
||||||
if (value.id === row.id) {
|
|
||||||
pRows.splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(pRows);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#add").click(function () {
|
|
||||||
$.each(npRows, function (index, value) {
|
|
||||||
$('#non_participants').bootstrapTable('remove', {
|
|
||||||
field: 'id',
|
|
||||||
values: [value.id]
|
|
||||||
});
|
|
||||||
$('#participants').bootstrapTable('insertRow', {
|
|
||||||
index: 0,
|
|
||||||
row: {
|
|
||||||
name: value.name,
|
|
||||||
id: value.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
npRows = [];
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#remove").click(function () {
|
|
||||||
$.each(pRows, function (index, value) {
|
|
||||||
$('#participants').bootstrapTable('remove', {
|
|
||||||
field: 'id',
|
|
||||||
values: [value.id]
|
|
||||||
});
|
|
||||||
$('#non_participants').bootstrapTable('insertRow', {
|
|
||||||
index: 0,
|
|
||||||
row: {
|
|
||||||
name: value.name,
|
|
||||||
id: value.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
pRows = [];
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#update").click(function () {
|
|
||||||
$.each(pRows, function (index, value) {
|
|
||||||
$('#participants').bootstrapTable('insertRow', {
|
|
||||||
index: 0,
|
|
||||||
row: {
|
|
||||||
name: value.name,
|
|
||||||
id: value.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
pRows = [];
|
|
||||||
});
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
{% endblock script %}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
{% extends "authorized.html" %}
|
|
||||||
{% block title %}Gift Exchanges{% endblock %}
|
|
||||||
{% block center %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="btn-toolbar" role="toolbar">
|
|
||||||
<a role="button" class="btn btn-primary" href="/giftexchange/0">Add</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<table data-toggle="table" class="table table-striped table-bordered">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-sortable="true" data-field="name" scope="col">Name</th>
|
|
||||||
<th data-sortable="true" data-field="exchange_date" scope="col">Date</th>
|
|
||||||
<th data-field="status" scope="col">Status</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for giftexchange in giftexchanges %}
|
|
||||||
<tr>
|
|
||||||
<td><a href="/giftexchange/{{ giftexchange.id }}">{{ giftexchange.name }}</a></td>
|
|
||||||
<td>{{ giftexchange.exchange_date }}</td>
|
|
||||||
<td>{{ giftexchange.status }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endblock center %}
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
{% block title %}User Administration{% endblock %}
|
{% block title %}User Administration{% endblock %}
|
||||||
{% block center %}
|
{% block center %}
|
||||||
<h1>Users</h1>
|
<h1>Users</h1>
|
||||||
<table data-toggle="table" data-height="400" class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-sortable="true" data-field="name" scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th data-sortable="true" data-field="email" scope="col">email</th>
|
<th scope="col">email</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@
|
||||||
<a href="/userwishlist/add/{{ user.id }}">Add</a>
|
<a href="/userwishlist/add/{{ user.id }}">Add</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="table-responsive overflow-auto">
|
<div class="table-responsive overflow-auto">
|
||||||
<table data-toggle="table" class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-sortable="true" data-field="item" scope="col">Item</th>
|
<th scope="col">Item</th>
|
||||||
<th scope="col">Link</th>
|
<th scope="col">Link</th>
|
||||||
<th data-sortable="true" data-field="state" scope="col">State</th>
|
<th scope="col">State</th>
|
||||||
<th scope="col">Action</th>
|
<th scope="col">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
{% block title %}Wish Lists{% endblock %}
|
{% block title %}Wish Lists{% endblock %}
|
||||||
{% block center %}
|
{% block center %}
|
||||||
<h1>Wishlists</h1>
|
<h1>Wishlists</h1>
|
||||||
<table data-toggle="table" class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-sortable="true" data-field="name" scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th data-sortable="true" data-field="email" scope="col">email</th>
|
<th scope="col">email</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue