This commit is contained in:
Alex Wied
2026-06-23 21:55:52 -04:00
parent f5ca8dd9ae
commit 42dea77976
14 changed files with 543 additions and 897 deletions
+37 -21
View File
@@ -1,4 +1,3 @@
use std::collections::HashSet;
use crate::rdf::ontology::{LabeledIri, Ontology};
use crate::rdf::term_helper::{TermHelper, TermHelperMut};
use crate::rdf::vocab::{gl, rda};
@@ -9,7 +8,10 @@ use iced::widget::button::Style;
use iced::widget::grid::Sizing;
use iced::widget::{button, center, column, combo_box, container, grid, mouse_area, opaque, pick_list, row, scrollable, space, stack, table, text, text_input, toggler};
use iced::window::Settings;
use iced::{Background, Color, Element, Length, Subscription, Task, color, window};
use iced::{Background, Color, Element, Length, Subscription, Task, color, window, keyboard};
//use iced::advanced::Widget;
use iced::keyboard::{Event, Key};
use iced::keyboard::key::Named::Control;
use iced::widget::text::Wrapping;
use ldp::middleware::BasicAuthMiddleware;
use ldp::model::{KeyedDataset, QuadKey};
@@ -21,10 +23,12 @@ use oxigraph::io::RdfFormat;
use oxigraph::model::vocab::{rdf, rdfs};
use oxigraph::model::{BaseDirection, Dataset, NamedNode, NamedNodeRef, Quad, Term, TermRef};
use tracing::{debug, error, info};
use crate::widget::iri_input::iri_input;
#[derive(Debug, Clone)]
pub(crate) enum Message {
None,
Foo(QuadKey),
Traverse,
IndexRdfSource(RdfSource<Dataset>),
CommitIndex,
@@ -96,7 +100,7 @@ pub(crate) struct Publisher {
impl Publisher {
pub(crate) fn new() -> (Self, Task<Message>) {
let ontology = Ontology::builder()
.with_default_ontologies()
.with_path("/home/alex/.local/share/org.graphofliberty.desktop/ontology")
.build()
.expect("Failed to build ontology");
@@ -107,7 +111,8 @@ impl Publisher {
if let Some(id) = ontology.catalog_id(&rdf::PROPERTY.into_owned()) { index.remove_all_of_type(id); }
if let Some(id) = ontology.catalog_id(&rdfs::CLASS.into_owned()) { index.remove_all_of_type(id); }
for (iri, info) in ontology.iri_info() {
/*for (iri, info) in ontology.iri_info() {
if let Some(type_) = ontology.catalog_id(&info.type_) {
let mut document = doc!(
Schema::type_field() => type_,
@@ -127,11 +132,11 @@ impl Publisher {
index.add(document).expect("Unable to add annotated IRI to search index");
}
}
index.commit().expect("Unable to commit ontology to index");
index.commit().expect("Unable to commit ontology to index");*/
let mut abbreviated_datatypes = ontology
.datatypes()
.map(|node| ontology.abbreviate(node))
.map(|node| ontology.abbreviate(node.as_ref()))
.collect::<Vec<_>>();
abbreviated_datatypes.sort();
@@ -340,9 +345,11 @@ impl Publisher {
.get(key)
.and_then(|quad| if quad.predicate == rdf::TYPE {
self.ontology.catalog_id(&rdfs::CLASS.into_owned())
} else { None })
} else {
self.ontology.catalog_id(&search_state.type_.iri)
})
},
SearchResultClickAction::URLInput => None,
SearchResultClickAction::URLInput => self.ontology.catalog_id(&search_state.type_.iri),
};
search_state.results = self
@@ -429,7 +436,7 @@ impl Publisher {
Message::SaveGraph(overwrite) => {
let client = self.http_client.clone();
let options = SerializationOptions::from_format(RdfFormat::Turtle)
.with_filter(self.ontology.exclude_read_only());
;//.with_filter(self.ontology.exclude_read_only());
let request = self
.document
.to_update(options)
@@ -497,7 +504,9 @@ impl Publisher {
}
pub(crate) fn subscription(&self) -> Subscription<Message> {
window::close_events().map(Message::WindowClosed)
Subscription::batch([
window::close_events().map(Message::WindowClosed),
])
}
fn view_row<'a>(
@@ -517,11 +526,11 @@ impl Publisher {
container(space()).width(BUTTON_WIDTH)
};
let property_label = self
let property_label = "foo"; /*self
.ontology
.info(triple.predicate.as_ref())
.and_then(|info| info.label.clone())
.unwrap_or(self.ontology.abbreviate(triple.predicate.as_ref()));
.unwrap_or(self.ontology.abbreviate(triple.predicate.as_ref()));*/
let property: Element<Message> = if state.read_only {
text(property_label).into()
@@ -536,12 +545,12 @@ impl Publisher {
let term = TermHelper::new(&triple.object);
let value_label = term.value_as_named_node().and_then(|node| {
let value_label = "bar"; /*term.value_as_named_node().and_then(|node| {
self.ontology
.info(node)
.and_then(|info| info.label.clone())
.map(|label| container(text(label)))
});
});*/
let value = term
.value_as_named_node()
@@ -556,7 +565,8 @@ impl Publisher {
})
.unwrap_or(Horizontal::Left);
let value_input_base = text_input("Value", value.as_str()).align_x(value_alignment);
let value_input_base = text_input("Value", value.as_str())
.align_x(value_alignment);
let value_input = if !state.read_only {
let is_named_node = term.is_named_node();
@@ -576,7 +586,12 @@ impl Publisher {
value_input_base
};
let search_launcher = if term.is_named_node() && !state.read_only {
let foo = iri_input(value_input)
.on_control_click(Message::OpenQueryWindow(SearchResultClickAction::Object(
key,
)));
/*let search_launcher = if term.is_named_node() && !state.read_only {
Some(container(
button(text("\u{1f50e}"))
.on_press(Message::OpenQueryWindow(SearchResultClickAction::Object(
@@ -586,7 +601,7 @@ impl Publisher {
))
} else {
None
};
};*/
let selected_datatype = term.datatype().map(|node| self.ontology.abbreviate(node));
let datatype_selector: Element<Message> = if state.read_only {
@@ -640,8 +655,9 @@ impl Publisher {
button_area,
property,
value_label,
value_input,
search_launcher,
//value_input,
foo,
//search_launcher,
datatype_selector,
language_input,
direction_slider,
@@ -658,11 +674,11 @@ impl Publisher {
entities: impl Iterator<Item = NamedNode>,
) -> Element<'_, Message> {
let buttons = entities.map(|entity| {
let label = self
let label = "baz"; /*self
.ontology
.info(entity.as_ref())
.and_then(|info| info.label.clone())
.unwrap_or(entity.as_str().to_string());
.unwrap_or(entity.as_str().to_string());*/
button(text(label))
.on_press(Message::NewDocument(entity))
.into()