:- module(yaz_tags, [ http_yaz_tags/1 ]). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_parameters)). :- use_module(library(http/html_write)). :- use_module(library(http/http_host)). :- use_module(library(http/http_path)). :- use_module(library(http/html_head)). :- use_module(library(semweb/rdf_db)). :- use_module(user(user_db)). :- use_module(library(yaz_util)). :- use_module(library(video_annotation)). :- use_module(components(yaz_page)). :- use_module(components(paginator)). :- http_handler(yaz(tags), http_yaz_tags, []). %% http_tags(+Request) % % Emit all tags a user has added. http_yaz_tags(Request) :- http_parameters(Request, [ user(User, [optional(true), description('Current user id')]), offset(Offset, [default(0), integer, description('Offset of the result list')]), limit(Limit, [default(100), integer, description('Limit on the number of results')]) ]), findall(Value-Annotation, user_tag(User, Annotation, Value), Pairs0), keysort(Pairs0, Pairs), group_pairs_by_key(Pairs, Groups), length(Groups, NumberOfResults), pairs_sort_by_value_count(Groups, CountTags), list_offset(CountTags, Offset, OffsetResults), list_limit(OffsetResults, Limit, LimitResults, _), delete_nonground([user(User)], Options), html_tags_page(LimitResults, NumberOfResults, Offset, Limit, Options). user_tag(User, Annotation, Value) :- nonvar(User), !, rdf(Annotation, pprime:creator, User), annotation_value(Annotation, Value). user_tag(_User, Annotation, Value) :- annotation_value(Annotation, Value). %% html_tags_page(+Results, +NumberOfResults, +Offset, +Limit, %% +User) % % Emit html page with a list of tags. html_tags_page(Results, NumberOfResults, Offset, Limit, Options) :- reply_html_page(yaz, [ title(['YAZ - ', tags]) ], [\html_requires(css('tags.css')), div(class('topic tag-results'), [ div(class(header), h2([ 'You added ', \tag_count(NumberOfResults)])), div(class(body), ul(class('tag-list'), \html_tag_list(Results, Options))), div(class(footer), div(class(paginator), \html_paginator(NumberOfResults, Offset, Limit))) ]) ]). tag_count(1) --> html('1 tag '). tag_count(N) --> html([N, ' tags ']). %% html_tag_list(+Tags:tag-tag_entries, +Options) % % Emit an html list with tags. html_tag_list([], _) --> !. html_tag_list([Count-Tag|T], Options) --> { tag_term_label(Tag, _Term, Label), http_link_to_id(isearch_page, [q(Label)|Options], Link) }, html(li([a(href(Link), Label), ' (', Count, ')'])), html_tag_list(T, Options).