Fix Urls in command line

This commit is contained in:
Dietrich 2021-06-24 16:00:27 +02:00 committed by Franz Dietrich
parent 6c6f66cdf8
commit ffe31504ee
2 changed files with 43 additions and 22 deletions

View File

@ -1,4 +1,6 @@
//! List all the links the own links editable or if an admin is logged in all links editable. //! 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 enum_map::EnumMap;
use fluent::fluent_args; use fluent::fluent_args;
use image::{DynamicImage, ImageOutputFormat, Luma}; use image::{DynamicImage, ImageOutputFormat, Luma};
@ -46,11 +48,11 @@ pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model {
#[derive(Debug)] #[derive(Debug)]
pub struct Model { pub struct Model {
links: Vec<FullLink>, // will contain the links to display links: Vec<Cached<FullLink>>, // will contain the links to display
i18n: I18n, // to translate i18n: I18n, // to translate
formconfig: LinkRequestForm, // when requesting links the form is stored here formconfig: LinkRequestForm, // when requesting links the form is stored here
inputs: EnumMap<LinkOverviewColumns, FilterInput>, // the input fields for the searches inputs: EnumMap<LinkOverviewColumns, FilterInput>, // 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<CmdHandle>, // Rendering qr-codes takes time... it is aborted when this handle is dropped and replaced. handle_render: Option<CmdHandle>, // Rendering qr-codes takes time... it is aborted when this handle is dropped and replaced.
handle_timeout: Option<CmdHandle>, // Rendering qr-codes takes time... it is aborted when this handle is dropped and replaced. handle_timeout: Option<CmdHandle>, // 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<T> {
data: T,
cache: String,
}
impl<T> Deref for Cached<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.data
}
}
/// There can allways be only one dialog. /// There can allways be only one dialog.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Dialog { 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... // Also sort the links locally - can probably removed...
model.links.sort_by(match column { model.links.sort_by(match column {
LinkOverviewColumns::Code => { LinkOverviewColumns::Code => {
|o: &FullLink, t: &FullLink| o.link.code.cmp(&t.link.code) |o: &Cached<FullLink>, t: &Cached<FullLink>| o.link.code.cmp(&t.link.code)
} }
LinkOverviewColumns::Description => { LinkOverviewColumns::Description => {
|o: &FullLink, t: &FullLink| o.link.title.cmp(&t.link.title) |o: &Cached<FullLink>, t: &Cached<FullLink>| o.link.title.cmp(&t.link.title)
} }
LinkOverviewColumns::Target => { LinkOverviewColumns::Target => {
|o: &FullLink, t: &FullLink| o.link.target.cmp(&t.link.target) |o: &Cached<FullLink>, t: &Cached<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)
} }
LinkOverviewColumns::Author => |o: &Cached<FullLink>, t: &Cached<FullLink>| {
o.user.username.cmp(&t.user.username)
},
LinkOverviewColumns::Statistics => |o: &Cached<FullLink>, t: &Cached<FullLink>| {
o.clicks.number.cmp(&t.clicks.number)
},
}); });
} }
QueryMsg::Received(response) => { 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) => { QueryMsg::CodeFilterChanged(s) => {
log!("Filter is: ", &s); log!("Filter is: ", &s);
@ -602,9 +624,9 @@ fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> N
} }
/// display a single table row containing one link /// display a single table row containing one link
fn view_link(l: &FullLink, logged_in_user: &User) -> Node<Msg> { fn view_link(l: &Cached<FullLink>, logged_in_user: &User) -> Node<Msg> {
use shared::apirequests::users::Role; use shared::apirequests::users::Role;
let link = LinkDelta::from(l.clone()); let link = LinkDelta::from(l.data.clone());
tr![ tr![
IF! (logged_in_user.role == Role::Admin IF! (logged_in_user.role == Role::Admin
|| (logged_in_user.role == Role::Regular) && l.user.id == logged_in_user.id => || (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<Msg> {
a![ a![
ev(Ev::Click, |event| event.stop_propagation()), ev(Ev::Click, |event| event.stop_propagation()),
attrs![At::Href => format!["/admin/download/png/{}", &l.link.code], At::Download => true.as_at_value()], 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 if logged_in_user.role == Role::Admin
|| (logged_in_user.role == Role::Regular) && l.user.id == logged_in_user.id || (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![ td![
ev(Ev::Click, |event| { ev(Ev::Click, |event| {
event.stop_propagation(); event.stop_propagation();

View File

@ -14,7 +14,7 @@ use shared::datatypes::Secret;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use std::{fmt::Display, path::PathBuf, str::FromStr}; use std::{fmt::Display, path::PathBuf, str::FromStr};
use thiserror::Error; use thiserror::Error;
use tracing::{error, info, trace}; use tracing::{error, info};
use tracing_actix_web::TracingLogger; use tracing_actix_web::TracingLogger;
/// The Error type that is returned by most function calls if anything failed. /// The Error type that is returned by most function calls if anything failed.
@ -217,14 +217,13 @@ pub async fn webservice(
) -> Result<actix_web::dev::Server, std::io::Error> { ) -> Result<actix_web::dev::Server, std::io::Error> {
let host_port = format!("{}:{}", &server_config.internal_ip, &server_config.port); let host_port = format!("{}:{}", &server_config.internal_ip, &server_config.port);
info!( info!(
"Running on: {}://{}/apps/", "Running on: {}://{}/app/",
&server_config.protocol, host_port &server_config.protocol, host_port
); );
info!( 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 &server_config.protocol, &server_config.public_url
); );
trace!("The tera templates are ready");
let server = HttpServer::new(move || { let server = HttpServer::new(move || {
let generated = generate(); let generated = generate();