EDM/commit

WIP to define a specialised local view for ore:Proxy objects

authorJan Wielemaker
Thu Nov 25 13:33:22 2010 +0100
committerJan Wielemaker
Thu Nov 25 13:33:22 2010 +0100
commit0dbdc29e5d5629297263cde9f35e9f916f319a7a
tree7407a43f6cab6f421fc3e9f5199e05875825e744
parent691047646e8c23bafadd8de6eb66dcba4f46e9a8
Diff style: patch stat
diff --git a/components/edm/components.pl b/components/edm/components.pl
index e7a12d5..1b1f21b 100644
--- a/components/edm/components.pl
+++ b/components/edm/components.pl
@@ -29,14 +29,21 @@
 */
 
 :- module(edm_components,
-	  [ edm_display_link//2		% +URI, +Options
+	  [ edm_display_link//2,	% +URI, +Options
+	    edm_proxy_view//2		% +URI, +Options
 	  ]).
 :- use_module(cliopatria(hooks)).
 :- use_module(library(http/page_info)).
+:- use_module(library(sgml)).
 :- use_module(library(http/html_write)).
+:- use_module(library(http/html_head)).
 :- use_module(library(semweb/rdf_db)).
+:- use_module(library(semweb/rdf_label)).
 :- use_module(library(http/http_path)).
 :- use_module(components(label)).
+:- use_module(library(http/http_dispatch)).
+:- use_module(library(http/http_wrapper)).
+
 
 /** <module> Domain-specific components for EDM models
 
@@ -69,4 +76,83 @@ edm_display_link(R, Options) -->
 	).
 
 
+%%	edm_proxy_view(+URI, +Options)// is det.
+%
+%	Provide a _|local view|_ for an EDM ore:Proxy object. The caller
+%	must ensure that URI is indeed of type ore:Proxy.
+
+edm_proxy_view(URI, _Options) -->
+	{ type_styles(URI, Styles),
+	  http_current_request(Request),
+	  http_reload_with_parameters(Request, [raw(true)], FullHREF)
+	},
+	html_requires(css('edm.css')),
+	html(div(class(Styles),
+		 [ \divs(URI, dcterms:title),
+		   \divs(URI, ore:proxyIn -> ens:hasThumbnail),
+		   \divs(URI, dcterms:creator),
+		   \divs(URI, dcterms:description),
+		   div(class(fullview), a(href(FullHREF), 'Full view'))
+		 ])).
+
+type_styles(URI, Styles) :-
+	findall(Style, type_style(URI, Style), Styles).
+
+type_style(URI, Class) :-
+	rdf_has(URI, rdf:type, Type),
+	uri_css_class(Type, Class).
+
+divs(URI, Path) -->
+	{ has_values(URI, Path, Pairs)
+	},
+	divs(Pairs).
+
+divs([]) --> [].
+divs([V-Classes|T]) -->
+	html(div(class(Classes), \value(V))),
+	divs(T).
+
+
+%%	has_values(+URI, +Path, -Pairs) is det.
+%
+%	Pairs is a list of Value-Classes pairs.
+
+has_values(URI, Path, Pairs) :-
+	findall(Value-Classes, has_value(Path, URI, Classes, Value), Pairs).
+
+has_value(P0->P, URI, Classes, Value) :- !,
+	has_value(P0, URI, Classes0, Value0),
+	has_value(P, Value0, Classes1, Value),
+	append(Classes0, Classes1, Classes).
+has_value(NS:Local, URI, Class, Value) :- !,
+	rdf_global_id(NS:Local, P),
+	has_value(P, URI, Class, Value).
+has_value(P, URI, Classes, Value) :-
+	rdf_has(URI, P, Value, RP),
+	p_classes(RP, P, Classes).
+
+%%	p_classes(+FoundPred, +QueryPred, -CSSClasses) is det.
+%
+%	@tbd	Find intermediate properties
+
+p_classes(RP, RP, [RC]) :- !,
+	uri_css_class(RP, RC).
+p_classes(RP, P, [RC, PC]) :-
+	uri_css_class(P, PC),
+	uri_css_class(RP, RC).
 
+uri_css_class(URI, Class) :-
+	iri_xml_namespace(URI, _, Class).
+
+
+%%	value(+Value)// is det.
+%
+%	Show the actual value
+
+value(Literal) -->
+	{ rdf_is_literal(Literal), !,
+	  literal_text(Literal, Text)
+	},
+	html(Text).
+value(R) -->
+	rdf_link(R).
diff --git a/config-available/EDM.pl b/config-available/EDM.pl
index 202047f..d8594e3 100644
--- a/config-available/EDM.pl
+++ b/config-available/EDM.pl
@@ -1,5 +1,6 @@
 :- module(conf_EDM, []).
 :- use_module(library(semweb/rdf_db)).
+:- use_module(library(semweb/rdfs)).
 :- use_module(cliopatria(hooks)).
 
 /** <module> View Europeana Data Model
@@ -22,3 +23,7 @@ cliopatria:context_graph(R, RDF, Options) :-
 
 cliopatria:node_shape(URI, Shape, Options) :-
 	edm_node_shape(URI, Shape, Options).
+
+cliopatria:list_resource(Proxy) -->
+	{ rdfs_individual_of(Proxy, ore:'Proxy') },
+	edm_proxy_view(Proxy, []).
diff --git a/web/css/edm.css b/web/css/edm.css
new file mode 100644
index 0000000..aa09d37
--- /dev/null
+++ b/web/css/edm.css
@@ -0,0 +1,20 @@
+div.description a
+{ color: #000;
+}
+
+div.Proxy div.title
+{ font-size: 200%;
+  font-weight: bold;
+}
+
+div.Proxy img.thumbnail
+{ border: 0px;
+  max-height: 250px;
+  float: left;
+}
+
+div.Proxy div.fullview
+{ border-top: 1px solid;
+  text-align: right;
+  font-style: italic;
+}