mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
show identity details as dropdown item tooltip
This commit is contained in:
parent
763c59ed4f
commit
cb08217ffa
@ -33,6 +33,7 @@ impl Gemini {
|
||||
Value::UseGuestSession,
|
||||
"Guest session",
|
||||
"No identity for this request",
|
||||
None,
|
||||
false,
|
||||
);
|
||||
|
||||
@ -41,6 +42,7 @@ impl Gemini {
|
||||
Value::GenerateNewAuth,
|
||||
"Create new",
|
||||
"Generate long-term certificate",
|
||||
None,
|
||||
false,
|
||||
);
|
||||
|
||||
@ -49,6 +51,7 @@ impl Gemini {
|
||||
Value::ImportPem,
|
||||
"Import identity",
|
||||
"Use existing certificate",
|
||||
None,
|
||||
false,
|
||||
);
|
||||
|
||||
@ -63,13 +66,47 @@ impl Gemini {
|
||||
Err(reason) => todo!("{reason}"),
|
||||
};
|
||||
|
||||
// Get auth details for tooltip
|
||||
let mut auth_scope = Vec::new();
|
||||
|
||||
for auth in profile
|
||||
.identity
|
||||
.gemini
|
||||
.auth
|
||||
.database
|
||||
.records_scope(None)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|this| this.profile_identity_gemini_id == identity.id)
|
||||
{
|
||||
auth_scope.push(auth.scope.clone())
|
||||
}
|
||||
|
||||
// Build tooltip
|
||||
let mut tooltip = format!(
|
||||
"Valid:\n{}\n{}",
|
||||
certificate
|
||||
.not_valid_before()
|
||||
.unwrap()
|
||||
.format_iso8601()
|
||||
.unwrap(),
|
||||
certificate
|
||||
.not_valid_after()
|
||||
.unwrap()
|
||||
.format_iso8601()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
if auth_scope.len() > 0 {
|
||||
tooltip.push_str(&format!("\n\nScope:\n{}", auth_scope.join("\n")));
|
||||
}
|
||||
|
||||
// Append record option
|
||||
widget.form.list.append(
|
||||
Value::ProfileIdentityGeminiId(identity.id),
|
||||
&certificate.subject_name().unwrap().replace("CN=", ""), // trim prefix
|
||||
&format!(
|
||||
"{} - {} | scope: {}",
|
||||
// certificate validity time
|
||||
certificate
|
||||
.not_valid_before()
|
||||
.unwrap()
|
||||
@ -80,26 +117,16 @@ impl Gemini {
|
||||
.unwrap()
|
||||
.format(DATE_FORMAT)
|
||||
.unwrap(),
|
||||
// count active certificate sessions
|
||||
profile
|
||||
.identity
|
||||
.gemini
|
||||
.auth
|
||||
.database
|
||||
.records_scope(None)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|this| this.profile_identity_gemini_id == identity.id)
|
||||
.count(),
|
||||
auth_scope.len(),
|
||||
),
|
||||
// is selected
|
||||
Some(&tooltip),
|
||||
profile
|
||||
.identity
|
||||
.gemini
|
||||
.auth
|
||||
.memory
|
||||
.match_scope(&url)
|
||||
.is_some_and(|auth| auth.profile_identity_gemini_id == identity.id),
|
||||
.is_some_and(|auth| auth.profile_identity_gemini_id == identity.id), // is selected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -63,12 +63,10 @@ impl List {
|
||||
title.set_css_classes(if item.is_active() { &["success"] } else { &[] });
|
||||
|
||||
// Update `subtitle` (expected as the last child)
|
||||
child
|
||||
.last_child()
|
||||
.unwrap()
|
||||
.downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&item.subtitle());
|
||||
let subtitle = child.last_child().unwrap().downcast::<Label>().unwrap();
|
||||
|
||||
subtitle.set_label(&item.subtitle());
|
||||
subtitle.set_tooltip_text(Some(&item.tooltip()));
|
||||
});
|
||||
|
||||
// Init main `DropDown`
|
||||
@ -87,9 +85,18 @@ impl List {
|
||||
// Actions
|
||||
|
||||
/// Append new item
|
||||
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_active: bool) {
|
||||
let item = Item::new(value, title, subtitle, is_active);
|
||||
pub fn append(
|
||||
&self,
|
||||
value: Value,
|
||||
title: &str,
|
||||
subtitle: &str,
|
||||
tooltip: Option<&str>,
|
||||
is_active: bool,
|
||||
) {
|
||||
let item = Item::new(value, title, subtitle, tooltip, is_active);
|
||||
|
||||
self.list_store.append(&item);
|
||||
|
||||
if is_active {
|
||||
self.dropdown
|
||||
.set_selected(self.list_store.find(&item).unwrap()); // @TODO panic or handle?
|
||||
|
@ -18,7 +18,13 @@ impl Item {
|
||||
// Constructors
|
||||
|
||||
/// Create new `GObject`
|
||||
pub fn new(value: Value, title: &str, subtitle: &str, is_active: bool) -> Self {
|
||||
pub fn new(
|
||||
value: Value,
|
||||
title: &str,
|
||||
subtitle: &str,
|
||||
tooltip: Option<&str>,
|
||||
is_active: bool,
|
||||
) -> Self {
|
||||
Object::builder()
|
||||
.property(
|
||||
"value",
|
||||
@ -31,6 +37,13 @@ impl Item {
|
||||
)
|
||||
.property("title", title)
|
||||
.property("subtitle", subtitle)
|
||||
.property(
|
||||
"tooltip",
|
||||
match tooltip {
|
||||
Some(text) => text,
|
||||
None => "", // NULL
|
||||
},
|
||||
)
|
||||
.property("is_active", is_active)
|
||||
.build()
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ pub struct Item {
|
||||
#[property(get, set)]
|
||||
subtitle: RefCell<String>,
|
||||
#[property(get, set)]
|
||||
tooltip: RefCell<String>,
|
||||
#[property(get, set)]
|
||||
is_active: Cell<bool>,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user