reactive_graph_table_model/types/
relations.rs1use tabled::Table;
2use tabled::Tabled;
3use tabled::settings::Modify;
4use tabled::settings::Style;
5use tabled::settings::Width;
6use tabled::settings::object::Segment;
7
8use crate::container::TableInlineFormat;
9use crate::container::TableInlineFormatSetter;
10use crate::container::TableOptions;
11use crate::types::component::ComponentTypeId;
12use crate::types::component::ComponentTypeIds;
13use crate::types::component::display_component_type_ids_html_inline;
14use crate::types::component::display_component_type_ids_inline_str;
15use crate::types::extension::Extension;
16use crate::types::extension::Extensions;
17use crate::types::extension::display_extensions_html_inline;
18use crate::types::extension::display_extensions_inline_str;
19use crate::types::properties::PropertyType;
20use crate::types::properties::PropertyTypes;
21use crate::types::properties::display_property_types_html_inline;
22use crate::types::properties::display_property_types_inline_str;
23use reactive_graph_graph::NamespacedTypeGetter;
24
25#[derive(Clone, Debug, Tabled)]
26pub struct RelationType {
27 pub outbound_type_namespace: String,
29
30 pub outbound_type_name: String,
32
33 pub namespace: String,
35
36 pub name: String,
38
39 pub inbound_type_namespace: String,
41
42 pub inbound_type_name: String,
44
45 pub description: String,
48
49 #[tabled(display("display_component_type_ids", self))]
51 pub components: Vec<ComponentTypeId>,
52
53 #[tabled(display("display_property_types", self))]
55 pub properties: Vec<PropertyType>,
56
57 #[tabled(display("display_extensions", self))]
59 pub extensions: Vec<Extension>,
60
61 #[tabled(skip)]
62 inline_format: TableInlineFormat,
63}
64
65fn display_component_type_ids(components: &[ComponentTypeId], relation_type: &RelationType) -> String {
66 match relation_type.inline_format {
67 TableInlineFormat::Table => display_component_type_ids_inline_str(components),
68 TableInlineFormat::Html => display_component_type_ids_html_inline(components),
69 }
70}
71
72fn display_property_types(properties: &[PropertyType], relation_type: &RelationType) -> String {
73 match relation_type.inline_format {
74 TableInlineFormat::Table => display_property_types_inline_str(properties),
75 TableInlineFormat::Html => display_property_types_html_inline(properties),
76 }
77}
78
79fn display_extensions(extensions: &[Extension], relation_type: &RelationType) -> String {
80 match relation_type.inline_format {
81 TableInlineFormat::Table => display_extensions_inline_str(extensions),
82 TableInlineFormat::Html => display_extensions_html_inline(extensions),
83 }
84}
85
86impl TableInlineFormatSetter for RelationType {
87 fn set_table_inline_format(&mut self, table_inline_format: TableInlineFormat) {
88 self.inline_format = table_inline_format;
89 }
90}
91
92impl From<reactive_graph_graph::RelationType> for RelationType {
93 fn from(relation_type: reactive_graph_graph::RelationType) -> Self {
94 RelationType {
95 outbound_type_namespace: relation_type.outbound_type.namespace(),
96 outbound_type_name: relation_type.outbound_type.type_name(),
97 namespace: relation_type.namespace(),
98 name: relation_type.type_name(),
99 inbound_type_namespace: relation_type.inbound_type.namespace(),
100 inbound_type_name: relation_type.inbound_type.type_name(),
101 description: relation_type.description,
102 components: ComponentTypeIds::from(relation_type.components).0,
103 properties: PropertyTypes::from(relation_type.properties).0,
104 extensions: Extensions::from(relation_type.extensions).0,
105 inline_format: Default::default(),
106 }
107 }
108}
109
110pub struct RelationTypesTableOptions;
111
112impl TableOptions for RelationTypesTableOptions {
113 fn options(table: &mut Table) -> &mut Table {
114 table.with(Style::extended()).with(
115 Modify::new(Segment::new(0.., 0..3))
116 .with(Width::increase(22))
117 .with(Width::increase(22))
118 .with(Width::wrap(40).keep_words(true)),
119 )
120 }
121}