From ffe31504ee7f88932bb6f76f89b48234d3fa74e1 Mon Sep 17 00:00:00 2001 From: Dietrich Date: Thu, 24 Jun 2021 16:00:27 +0200 Subject: [PATCH] Fix Urls in command line --- app/src/pages/list_links.rs | 58 +++++++++++++++++++++++++------------ pslink/src/lib.rs | 7 ++--- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/app/src/pages/list_links.rs b/app/src/pages/list_links.rs index abd1ca7..43add76 100644 --- a/app/src/pages/list_links.rs +++ b/app/src/pages/list_links.rs @@ -1,4 +1,6 @@ //! List all the links the own links editable or if an admin is logged in all links editable. +use std::ops::Deref; + use enum_map::EnumMap; use fluent::fluent_args; use image::{DynamicImage, ImageOutputFormat, Luma}; @@ -46,11 +48,11 @@ pub fn init(mut url: Url, orders: &mut impl Orders, i18n: I18n) -> Model { #[derive(Debug)] pub struct Model { - links: Vec, // will contain the links to display - i18n: I18n, // to translate - formconfig: LinkRequestForm, // when requesting links the form is stored here + links: Vec>, // will contain the links to display + i18n: I18n, // to translate + formconfig: LinkRequestForm, // when requesting links the form is stored here inputs: EnumMap, // the input fields for the searches - dialog: Dialog, // User interaction - there can only ever be one dialog open. + dialog: Dialog, // User interaction - there can only ever be one dialog open. handle_render: Option, // Rendering qr-codes takes time... it is aborted when this handle is dropped and replaced. handle_timeout: Option, // Rendering qr-codes takes time... it is aborted when this handle is dropped and replaced. } @@ -61,6 +63,20 @@ impl Model { } } +#[derive(Debug)] +pub struct Cached { + data: T, + cache: String, +} + +impl Deref for Cached { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.data + } +} + /// There can allways be only one dialog. #[derive(Debug, Clone)] enum Dialog { @@ -206,24 +222,30 @@ pub fn process_query_messages(msg: QueryMsg, model: &mut Model, orders: &mut imp // Also sort the links locally - can probably removed... model.links.sort_by(match column { LinkOverviewColumns::Code => { - |o: &FullLink, t: &FullLink| o.link.code.cmp(&t.link.code) + |o: &Cached, t: &Cached| o.link.code.cmp(&t.link.code) } LinkOverviewColumns::Description => { - |o: &FullLink, t: &FullLink| o.link.title.cmp(&t.link.title) + |o: &Cached, t: &Cached| o.link.title.cmp(&t.link.title) } LinkOverviewColumns::Target => { - |o: &FullLink, t: &FullLink| o.link.target.cmp(&t.link.target) - } - LinkOverviewColumns::Author => { - |o: &FullLink, t: &FullLink| o.user.username.cmp(&t.user.username) - } - LinkOverviewColumns::Statistics => { - |o: &FullLink, t: &FullLink| o.clicks.number.cmp(&t.clicks.number) + |o: &Cached, t: &Cached| o.link.target.cmp(&t.link.target) } + LinkOverviewColumns::Author => |o: &Cached, t: &Cached| { + o.user.username.cmp(&t.user.username) + }, + LinkOverviewColumns::Statistics => |o: &Cached, t: &Cached| { + o.clicks.number.cmp(&t.clicks.number) + }, }); } QueryMsg::Received(response) => { - model.links = response; + model.links = response + .into_iter() + .map(|l| { + let cache = generate_qr_from_code(&l.link.code); + Cached { data: l, cache } + }) + .collect(); } QueryMsg::CodeFilterChanged(s) => { log!("Filter is: ", &s); @@ -602,9 +624,9 @@ fn view_link_table_filter_input String>(model: &Model, t: F) -> N } /// display a single table row containing one link -fn view_link(l: &FullLink, logged_in_user: &User) -> Node { +fn view_link(l: &Cached, logged_in_user: &User) -> Node { use shared::apirequests::users::Role; - let link = LinkDelta::from(l.clone()); + let link = LinkDelta::from(l.data.clone()); tr![ IF! (logged_in_user.role == Role::Admin || (logged_in_user.role == Role::Regular) && l.user.id == logged_in_user.id => @@ -620,14 +642,14 @@ fn view_link(l: &FullLink, logged_in_user: &User) -> Node { a![ ev(Ev::Click, |event| event.stop_propagation()), attrs![At::Href => format!["/admin/download/png/{}", &l.link.code], At::Download => true.as_at_value()], - raw!(&generate_qr_from_code(&l.link.code)) + raw!(&l.cache) ] ] }, if logged_in_user.role == Role::Admin || (logged_in_user.role == Role::Regular) && l.user.id == logged_in_user.id { - let link = LinkDelta::from(l.clone()); + let link = LinkDelta::from(l.data.clone()); td![ ev(Ev::Click, |event| { event.stop_propagation(); diff --git a/pslink/src/lib.rs b/pslink/src/lib.rs index 725cbdc..49ad8a3 100644 --- a/pslink/src/lib.rs +++ b/pslink/src/lib.rs @@ -14,7 +14,7 @@ use shared::datatypes::Secret; use sqlx::{Pool, Sqlite}; use std::{fmt::Display, path::PathBuf, str::FromStr}; use thiserror::Error; -use tracing::{error, info, trace}; +use tracing::{error, info}; use tracing_actix_web::TracingLogger; /// The Error type that is returned by most function calls if anything failed. @@ -217,14 +217,13 @@ pub async fn webservice( ) -> Result { let host_port = format!("{}:{}", &server_config.internal_ip, &server_config.port); info!( - "Running on: {}://{}/apps/", + "Running on: {}://{}/app/", &server_config.protocol, host_port ); info!( - "If the public url is set up correctly it should be accessible via: {}://{}/admin/login/", + "If the public url is set up correctly it should be accessible via: {}://{}/app/", &server_config.protocol, &server_config.public_url ); - trace!("The tera templates are ready"); let server = HttpServer::new(move || { let generated = generate();