diff --git a/src/handler.rs b/src/handler.rs index acd50cf..b7a2586 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,5 +1,6 @@ pub mod home; pub mod login; +pub mod projects; use axum::http::StatusCode; use axum::response::Response; diff --git a/src/handler/home.rs b/src/handler/home.rs index 8268cc4..6f121f9 100644 --- a/src/handler/home.rs +++ b/src/handler/home.rs @@ -10,12 +10,14 @@ pub async fn home_page(State(ctx): State, auth_session: AuthSession, + auth_session: AuthSession, +) -> Response { + if let Some(user) = auth_session.user { + let projects: Vec = vec![ + Project { + id: 1, + owner_id: 1, + name: "Blog posts".to_owned(), + description: "Planning and publication schedule for my blog".to_owned(), + key: "BLOG".to_owned(), + }, + Project { + id: 2, + owner_id: 1, + name: "Bugs (Pique)".to_owned(), + description: "The bugs we've found so far in Pique".to_owned(), + key: "BUG".to_owned(), + }, + ]; + + let values = context! { + user => user, + projects => projects, + }; + + ctx.render_resp("projects/list_projects.html", values) + } else { + Redirect::to("/login").into_response() + } +} + +pub async fn create_project( + State(ctx): State, + auth_session: AuthSession, +) -> Response { + if let Some(_user) = auth_session.user { + let values = context! {}; + + ctx.render_resp("projects/create_project.html", values) + } else { + Redirect::to("/login").into_response() + } +} diff --git a/src/models.rs b/src/models.rs index bfd9d34..1a8bd5d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -6,6 +6,7 @@ pub struct Project { pub owner_id: i32, pub name: String, + pub description: String, // The key is the short code, like BUG, which is used to refer to a project // quickly and to display it more compactly. This must be unique across the diff --git a/src/server.rs b/src/server.rs index e966b29..7225332 100644 --- a/src/server.rs +++ b/src/server.rs @@ -10,7 +10,7 @@ use tower_sessions::SessionManagerLayer; use tower_sessions_sqlx_store::{sqlx::SqlitePool, SqliteStore}; use tracing::Level; -use crate::{config::CommandLineOptions, context::Context, handler::{home::home_page, login::logout, login_page, login_submit}, logging::setup_logging, templates::make_template_loader}; +use crate::{config::CommandLineOptions, context::Context, handler::{home::home_page, login::logout, login_page, login_submit, projects::{create_project, projects_page}}, logging::setup_logging, templates::make_template_loader}; pub async fn run() -> Result<()> { dotenvy::dotenv()?; @@ -40,6 +40,8 @@ pub async fn run() -> Result<()> { .route("/login", get(login_page)) .route("/login", post(login_submit)) .route("/logout", get(logout)) + .route("/projects", get(projects_page)) + .route("/projects/new", get(create_project)) .layer(trace_layer) .layer(session_layer) .layer(auth_layer) diff --git a/templates/components/nav/main_item.html b/templates/components/nav/main_item.html new file mode 100644 index 0000000..91c5734 --- /dev/null +++ b/templates/components/nav/main_item.html @@ -0,0 +1,17 @@ +
  • +{% if selected %} + + + {{ text }} + +{% else %} + + + {{ text }} + +{% endif %} +
  • diff --git a/templates/components/sidebar.html b/templates/components/sidebar.html index 8bdd34d..a36728e 100644 --- a/templates/components/sidebar.html +++ b/templates/components/sidebar.html @@ -1,3 +1,4 @@ +
    @@ -10,41 +11,22 @@
    • -
    • - - - - Dashboard - -
    • -
    • - - - Projects - -
    • -
    • - - - Documents - -
    • -
    • - - - Chats - -
    • + {% with path = "/", text = "Dashboard", selected = (current_page == "home"), svg = "M2.25 12.75V12A2.25 2.25 0 014.5 9.75h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z" %} + {% include "components/nav/main_item.html" %} + {% endwith %} + {% with path = "/projects", text = "Projects", selected = (current_page == "projects"), svg = "M2.25 12.75V12A2.25 2.25 0 014.5 9.75h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z" %} + {% include "components/nav/main_item.html" %} + {% endwith %} + + {% with path = "/documents", text = "Documents", selected = (current_page == "documents"), svg = "M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75" %} + {% include "components/nav/main_item.html" %} + {% endwith %} + + {% with path = "/chats", text = "Chats", selected = (current_page == "chats"), svg = "M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 0 1-.825-.242m9.345-8.334a2.126 2.126 0 0 0-.476-.095 48.64 48.64 0 0 0-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0 0 11.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" %} + {% include "components/nav/main_item.html" %} + {% endwith %}
  • @@ -60,13 +42,18 @@ {{ project.name }} + {% else %} +
    + No projects. +
    {% endfor %}
  • - +
  • diff --git a/templates/home.html b/templates/home.html index 30e9ce1..f0b1f4e 100644 --- a/templates/home.html +++ b/templates/home.html @@ -4,6 +4,7 @@
    + {% set current_page = "home" %} {% include "components/sidebar.html" %}
    diff --git a/templates/login.html b/templates/login.html index 89994f2..202d624 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,11 +1,11 @@ - + {% include "head.html" %}
    -

    Sign in to Pique

    +

    Sign in to Pique

    @@ -14,19 +14,19 @@
    - +
    - +
    - +
    diff --git a/templates/projects/create_project.html b/templates/projects/create_project.html new file mode 100644 index 0000000..512e576 --- /dev/null +++ b/templates/projects/create_project.html @@ -0,0 +1,31 @@ + + +{% include "head.html" %} + + +
    + {% set current_page = "projects" %} + {% include "components/sidebar.html" %} + +
    + +
    + +
    +
    + + + + + diff --git a/templates/projects/list_projects.html b/templates/projects/list_projects.html new file mode 100644 index 0000000..58c0576 --- /dev/null +++ b/templates/projects/list_projects.html @@ -0,0 +1,45 @@ + + +{% include "head.html" %} + + +
    + {% set current_page = "projects" %} + {% include "components/sidebar.html" %} + +
    + +
    + + + {% for project in projects %} +
    +
    +

    {{ project.key }} - {{ project.name }}

    +

    {{ project.description }}

    +
    + + +
    +
    +
    + {% endfor %} + +
    +
    + + + + +