Add page for displaying documents
This commit is contained in:
parent
9e98f86fe3
commit
54fa4949c8
5 changed files with 72 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod documents;
|
||||||
pub mod home;
|
pub mod home;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod projects;
|
pub mod projects;
|
||||||
|
|
26
src/handler/documents.rs
Normal file
26
src/handler/documents.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use axum::{response::Redirect, Form};
|
||||||
|
use axum_login::AuthSession;
|
||||||
|
|
||||||
|
use crate::{models::ModelPermission, prelude::*};
|
||||||
|
|
||||||
|
pub async fn documents_page(
|
||||||
|
State(ctx): State<Context>,
|
||||||
|
auth_session: AuthSession<Context>,
|
||||||
|
) -> Response {
|
||||||
|
if let Some(user) = auth_session.user {
|
||||||
|
render_documents_page(ctx, user).await
|
||||||
|
} else {
|
||||||
|
Redirect::to("/login").into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn render_documents_page(ctx: Context, user: crate::entity::user::Model) -> Response {
|
||||||
|
let documents = ModelPermission::user_documents(&ctx.kv_handles, user.id).unwrap_or_default();
|
||||||
|
|
||||||
|
let values = context! {
|
||||||
|
user => user,
|
||||||
|
documents => documents,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.render_resp("documents/list_documents.html", values)
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ use tower_sessions::SessionManagerLayer;
|
||||||
use tower_sessions_sqlx_store::{sqlx::SqlitePool, SqliteStore};
|
use tower_sessions_sqlx_store::{sqlx::SqlitePool, SqliteStore};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::{config::CommandLineOptions, context::Context, handler::{home::home_page, login::logout, login_page, login_submit, projects::{create_project_page, create_project_submit, projects_page}}, kv::KvHandle, logging::setup_logging, templates::make_template_loader};
|
use crate::{config::CommandLineOptions, context::Context, handler::{documents::documents_page, home::home_page, login::logout, login_page, login_submit, projects::{create_project_page, create_project_submit, projects_page}}, kv::KvHandle, logging::setup_logging, templates::make_template_loader};
|
||||||
|
|
||||||
pub async fn run() -> Result<()> {
|
pub async fn run() -> Result<()> {
|
||||||
dotenvy::dotenv()?;
|
dotenvy::dotenv()?;
|
||||||
|
@ -46,6 +46,7 @@ pub async fn run() -> Result<()> {
|
||||||
.route("/projects", get(projects_page))
|
.route("/projects", get(projects_page))
|
||||||
.route("/projects/new", get(create_project_page))
|
.route("/projects/new", get(create_project_page))
|
||||||
.route("/projects/new", post(create_project_submit))
|
.route("/projects/new", post(create_project_submit))
|
||||||
|
.route("/documents", get(documents_page))
|
||||||
.layer(trace_layer)
|
.layer(trace_layer)
|
||||||
.layer(session_layer)
|
.layer(session_layer)
|
||||||
.layer(auth_layer)
|
.layer(auth_layer)
|
||||||
|
|
0
templates/documents/create_document.html
Normal file
0
templates/documents/create_document.html
Normal file
43
templates/documents/list_documents.html
Normal file
43
templates/documents/list_documents.html
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" class="h-full bg-white">
|
||||||
|
{% include "head.html" %}
|
||||||
|
<body class="h-full">
|
||||||
|
|
||||||
|
<div class="h-full">
|
||||||
|
{% set current_page = "documents" %}
|
||||||
|
{% include "components/sidebar.html" %}
|
||||||
|
|
||||||
|
<main class="pl-72 bg-gray-50 h-full">
|
||||||
|
<div class="navbar bg-accent text-accent-content">
|
||||||
|
<div class="navbar-start">
|
||||||
|
<a class="btn" href="/documents/new">New Document</a>
|
||||||
|
</div>
|
||||||
|
<div class="navbar-end">
|
||||||
|
<div class="btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 0 1-.659 1.591l-5.432 5.432a2.25 2.25 0 0 0-.659 1.591v2.927a2.25 2.25 0 0 1-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 0 0-.659-1.591L3.659 7.409A2.25 2.25 0 0 1 3 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0 1 12 3Z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="px-8 py-8 flex flex-col gap-y-4">
|
||||||
|
|
||||||
|
|
||||||
|
{% for document in documents %}
|
||||||
|
<div class="card w-96 bg-base-100 shadow-md border-2 border-solid">
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">{{ document.name }}</h2>
|
||||||
|
<div class="card-actions justify-end">
|
||||||
|
<button class="btn btn-primary">Open</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/static/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue