35
36:- module(cp_menu,
37 [ cp_menu//0
38 ]). 39:- use_module(library(http/html_write)). 40:- use_module(library(http/html_head)). 41:- use_module(library(http/http_dispatch)). 42:- use_module(library(pairs)). 43:- use_module(library(apply)). 44:- use_module(library(uri)). 45:- use_module(library(ctypes)). 46:- use_module(user(user_db)). 47:- use_module(cliopatria(hooks)).
70cp_menu -->
71 { findall(Key-Item, current_menu_item(Key, Item), Pairs0),
72 sort(Pairs0, Pairs),
73 group_pairs_by_key(Pairs, ByKey),
74 sort_menu_popups(ByKey, Menu)
75 },
76 html_requires(css('menu.css')),
77 html(ul(id(nav),
78 \menu(Menu))).
79
([]) --> !.
81menu([_-[Item]|T]) -->
82 !,
83 menu_item(Item),
84 menu(T).
85menu([Key-Items|T]) -->
86 { menu_label(Key, Key, Label) },
87 html(li([ a([Label]),
88 ul(\menu_items(Items))
89 ])),
90 menu(T).
91
([]) --> [].
93menu_items([H|T]) --> menu_item(H), menu_items(T).
94
(item(_Rank, Spec, Label, Options)) -->
96 { atom(Spec) },
97 !,
98 { ( \+ sub_atom(Spec, 0, _, _, 'http://'),
99 catch(http_location_by_id(Spec, Location), E,
100 ( print_message(informational, E),
101 fail))
102 -> true
103 ; Location = Spec
104 )
105 },
106 html(li(a([href(Location)|Options], Label))).
117current_menu_item(Key, item(Rank, Location, Label, Options)) :-
118 menu_item(Spec, DefLabel),
119 rank(Spec, Rank, Where, Options),
120 ( Where = Key/Location
121 -> menu_label(Location, DefLabel, Label)
122 ; Where = Location,
123 Key = Location,
124 menu_label(Location, DefLabel, Label)
125 ).
126
127rank(Rank=Spec, Rank, Where, Options) :-
128 !,
129 item_options(Spec, Where, Options).
130rank(Spec, 0, Where, Options) :-
131 item_options(Spec, Where, Options).
132
133item_options(Spec+Option, Where, [Option|T]) :-
134 !,
135 item_options(Spec, Where, T).
136item_options(Where, Where, []).
149menu_item(Item, Label) :-
150 cliopatria:menu_item(Item, Label).
151
152menu_item(100=repository/load_file_form, 'Load local file').
153menu_item(200=repository/load_url_form, 'Load from HTTP').
154menu_item(300=repository/load_library_rdf_form, 'Load from library').
155menu_item(400=repository/remove_statements_form, 'Remove triples').
156menu_item(500=repository/clear_repository_form, 'Clear repository').
157
158menu_item(100=query/yasgui_editor, 'YASGUI SPARQL Editor').
159menu_item(200=query/query_form, 'Simple Form').
160
161menu_item(100=places/home, 'Home').
162menu_item(200=places/list_graphs, 'Graphs').
163menu_item(200=places/list_prefixes, 'Prefixes').
164
165menu_item(100=admin/list_users, 'Users').
166menu_item(200=admin/settings, 'Settings').
167menu_item(300=admin/statistics, 'Statistics').
168
169menu_item(100=user/login_form+class(login), 'Login') :-
170 \+ someone_logged_on.
171menu_item(100=current_user/user_logout, 'Logout') :-
172 someone_logged_on.
173menu_item(200=current_user/change_password_form, 'Change password') :-
174 local_user_logged_on.
175menu_item(300=current_user/my_openid_page, 'My OpenID page') :-
176 open_id_user(_).
177
(List, Sorted) :-
179 map_list_to_pairs(popup_order, List, Keyed),
180 keysort(Keyed, KeySorted),
181 pairs_values(KeySorted, Sorted).
182
(Key-Members, Order-(Key-Members)) :-
184 ( menu_popup_order(Key, Order)
185 -> true
186 ; Order = 550 187 ).
194menu_popup_order(Popup, Order) :-
195 cliopatria:menu_popup_order(Popup, Order),
196 !.
197menu_popup_order(places, 100).
198menu_popup_order(admin, 200).
199menu_popup_order(repository, 300).
200menu_popup_order(query, 400).
201menu_popup_order(application, 500).
202menu_popup_order(help, 600).
203menu_popup_order(user, 700).
204menu_popup_order(current_user, 800).
208menu_label(Item, _Default, Label) :-
209 cliopatria:menu_label(Item, Label),
210 !.
211menu_label(current_user, _Default, Label) :-
212 logged_on(User, X),
213 X \== User,
214 !,
215 ( user_property(User, realname(RealName))
216 -> true
217 ; RealName = 'My account'
218 ),
219 ( user_property(User, url(URL))
220 -> Label = a(href(URL), i(RealName))
221 ; Label = i(RealName)
222 ).
223menu_label(_, Default, Label) :-
224 id_to_label(Default, Label).
231id_to_label(Atom, Capital) :-
232 atom_codes(Atom, Codes0),
233 maplist(underscore_to_space, Codes0, Codes),
234 ( maplist(is_upper, Codes)
235 -> Capital = Atom
236 ; Codes = [First|Rest]
237 -> code_type(First, to_lower(Up)),
238 UpCodes = [Up|Rest],
239 atom_codes(Capital, UpCodes)
240 ; Capital = Atom
241 ).
242
243underscore_to_space(0'_, 32) :- !.
244underscore_to_space(X, X).
251local_user_logged_on :-
252 logged_on(User, X),
253 X \== User,
254 \+ ( uri_components(User, Components),
255 uri_data(scheme, Components, Scheme),
256 nonvar(Scheme)
257 ).
263someone_logged_on :-
264 logged_on(User, X),
265 X \== User.
266
267 270
271:- http_handler(root(my_openid_page), my_openid_page, []). 272
273my_openid_page(Request) :-
274 open_id_user(User),
275 http_redirect(see_other, User, Request).
276
277open_id_user(User) :-
278 logged_on(User, X),
279 X \== User,
280 uri_components(User, Components),
281 uri_data(scheme, Components, Scheme),
282 nonvar(Scheme)
ClioPatria menu-bar
This module provides the ClioPatria application menu-bar. The application menu is attached by
cliopatria(skin)
to all HTML pages that match the stylecliopatria(_)
(see reply_html_page/3).