Skip to content

Commit

Permalink
settings view style change
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang2821 committed Aug 22, 2024
1 parent 1f83081 commit f90d5f1
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 61 deletions.
78 changes: 42 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ members = [
]

[workspace.dependencies]
rust_decimal = "1.36.0"
toml = "0.8.11"
clap = { version = "4.5.2", features = ["derive"] }
tempfile = "3.8.1"
Expand Down
1 change: 1 addition & 0 deletions lapdev-dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ web-sys = "0.3.65"
urlencoding = "2.1.3"
leptos = { version = "0.6.5", features = ["csr"] }
leptos_router = { version = "0.6.5", features = ["csr"] }
rust_decimal.workspace = true
chrono.workspace = true
uuid.workspace = true
serde.workspace = true
Expand Down
42 changes: 21 additions & 21 deletions lapdev-dashboard/src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ where
match result {
Ok(_) => {
update_counter.update(|c| *c += 1);
success.set(Some("save successfully"));
success.set(Some("Saved successfully"));
}
Err(e) => {
error.set(Some(e.error.clone()));
Expand All @@ -341,26 +341,6 @@ where
view!{ <h5 class="text-lg font-semibold dark:text-white">{title}</h5> }.into_view()
}
}
{ move || if let Some(error) = error.get() {
view! {
<div class="my-2 p-4 rounded-lg bg-red-50 dark:bg-gray-800 ">
<span class="text-sm font-medium text-red-800 dark:text-red-400">{ error }</span>
</div>
}.into_view()
} else {
view! {}.into_view()
}
}
{ move || if let Some(success) = success.get() {
view! {
<div class="my-2 p-4 rounded-lg bg-green-50 dark:bg-gray-800 ">
<span class="text-sm font-medium text-green-800 dark:text-green-400">{ success }</span>
</div>
}.into_view()
} else {
view! {}.into_view()
}
}
{ body }
<div class="mt-4 flex flex-row items-center">
<button
Expand All @@ -385,6 +365,26 @@ where
view!{}.into_view()
}
}
{ move || if let Some(error) = error.get() {
view! {
<div class="ml-4 py-2 px-4 rounded-lg bg-red-50 dark:bg-gray-800 ">
<span class="text-sm font-medium text-red-800 dark:text-red-400">{ error }</span>
</div>
}.into_view()
} else {
view! {}.into_view()
}
}
{ move || if let Some(success) = success.get() {
view! {
<div class="ml-4 py-2 px-4 rounded-lg bg-green-50 dark:bg-gray-800 ">
<span class="text-sm font-medium text-green-800 dark:text-green-400">{ success }</span>
</div>
}.into_view()
} else {
view! {}.into_view()
}
}
</div>
}
}
10 changes: 9 additions & 1 deletion lapdev-dashboard/src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ fn QuotaItemView(
.await
});

let current_usage = match kind {
QuotaKind::Workspace => value.existing.to_string(),
QuotaKind::RunningWorkspace => value.existing.to_string(),
QuotaKind::Project => value.existing.to_string(),
QuotaKind::DailyCost => format!("{} Hours", value.existing),
QuotaKind::MonthlyCost => format!("{} Hours", value.existing),
};

view! {
<div
class="flex items-center w-full px-4 py-2"
Expand All @@ -198,7 +206,7 @@ fn QuotaItemView(
</div>
<div class="w-1/2 flex flex-row">
<div class="w-1/3 flex flex-col">
<p>{value.existing}</p>
<p>{current_usage}</p>
</div>
<div class="w-2/3 flex flex-row items-center justify-between">
<div class="flex flex-row items-center">
Expand Down
15 changes: 12 additions & 3 deletions lapdev-dashboard/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use leptos::{
IntoView, Signal, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate, SignalWith,
SignalWithUntracked,
};
use rust_decimal::{prelude::FromPrimitive, Decimal};

use crate::{
datepicker::Datepicker,
Expand Down Expand Up @@ -185,7 +186,7 @@ pub fn UsageView() -> impl IntoView {
{" of "}
<span class="font-semibold text-gray-900 dark:text-white">{move || usage.with(|u| u.total_items)}</span>
</span>
<p><span class="text-gray-500 mr-1">{"Total Cost:"}</span>{move || usage.with(|u| u.total_cost)}</p>
<p><span class="text-gray-500 mr-1">{"Total Cost:"}</span>{move || usage.with(|u| format_cost(u.total_cost))}</p>
<div class="flex flex-row items-center">
<p class="mr-2">{"rows per page"}</p>

Expand Down Expand Up @@ -278,8 +279,8 @@ fn RecordItemView(i: usize, record: UsageRecord) -> impl IntoView {
<p><span class="text-gray-500 mr-1">{"Machine Type:"}</span>{record.machine_type}</p>
</div>
<div class="w-1/4 flex flex-col">
<p>{duration}</p>
<p><span class="text-gray-500 mr-1">{"Cost:"}</span>{record.cost}</p>
<p><span class="text-gray-500 mr-1">{"Duration:"}</span>{duration}</p>
<p><span class="text-gray-500 mr-1">{"Cost:"}</span>{ format_cost(record.cost) }</p>
</div>
<div class="w-1/4 flex flex-col">
<span class="mb-2 truncate pr-2 text-gray-900 dark:text-white flex flex-row items-center">
Expand All @@ -295,3 +296,11 @@ fn RecordItemView(i: usize, record: UsageRecord) -> impl IntoView {
</div>
}
}

pub fn format_cost(cost: usize) -> String {
let cost = cost as f64 / 60.0 / 60.0;
let cost = Decimal::from_f64(cost)
.map(|d| d.trunc_with_scale(2).to_string())
.unwrap_or_else(|| cost.to_string());
format!("{cost} Hours")
}
4 changes: 4 additions & 0 deletions lapdev-enterprise/src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,15 @@ impl Quota {
self.usage
.get_daily_cost(organization, None, Utc::now().into(), None)
.await?
/ 60
/ 60
}
QuotaKind::MonthlyCost => {
self.usage
.get_monthly_cost(organization, None, Utc::now().into(), None)
.await?
/ 60
/ 60
}
};
Ok(existing)
Expand Down

0 comments on commit f90d5f1

Please sign in to comment.