accurator/commit

Added api for retrieving attributes user profile.

authorChris Dijkshoorn
Wed Apr 6 16:11:55 2016 +0200
committerChris Dijkshoorn
Wed Apr 6 16:11:55 2016 +0200
commit1c2d58a8c49c6347238954aebca74bbace6afe6c
treea3b1fd30c650b81c844d4c6cda0d31eef367dd3c
parent4ae24d1542b9c022ee04ac20e6c6e136b661db89
Diff style: patch stat
diff --git a/api/accurator.pl b/api/accurator.pl
index 3c0eea0..741cf27 100644
--- a/api/accurator.pl
+++ b/api/accurator.pl
@@ -59,6 +59,7 @@ user:file_search_path(fonts, web(fonts)).
 :- http_handler(cliopatria(get_user), get_user, []).
 :- http_handler(cliopatria(get_user_settings), get_user_settings, []).
 :- http_handler(cliopatria(save_user_info), save_user_info, []).
+:- http_handler(cliopatria(get_user_info), user_info_api, []).
 :- http_handler(cliopatria(recommendation), recommendation_api, []).
 
 :- set_setting_default(thumbnail:thumbnail_size, size(350,300)).
@@ -221,7 +222,7 @@ expertise_topics_api(Request) :-
     get_parameters_expertise(Request, Options0),
 	logged_on(User),
 	Options1 = [user(User) | Options0],
-	get_domain(User, Domain),
+	get_attribute(User, domain, Domain),
 	Options = [domain(Domain) | Options1],
 	get_expertise_topics(Dic, Options),
 	reply_json_dict(Dic).
@@ -262,7 +263,7 @@ get_parameters_expertise(Request, Options) :-
 expertise_values_api(Request) :-
 	member(method(get), Request),
 	logged_on(User),
-	get_domain(User, Domain),
+	get_attribute(User, domain, Domain),
 	get_user_expertise_domain(User, Domain, ExpertiseValues),
 	dict_pairs(ExpertiseDict, elements, ExpertiseValues),
 	reply_json_dict(ExpertiseDict).
@@ -332,6 +333,27 @@ reply_expertise_results(cluster, Clusters) :-
 reply_expertise_results(list, List) :-
 	reply_json_dict(List).
 
+%%	user_info_api(+Request)
+%
+%	Retrieves the value in the user profile for specified attribute
+user_info_api(Request) :-
+    get_parameters_user_info(Request, Options),
+    get_user_info(Options).
+
+%%	get_parameters_user_info(+Request, -Options)
+%
+%	Retrieves an option list of parameters from the url.
+get_parameters_user_info(Request, Options) :-
+	logged_on(LoggedinUser),
+    http_parameters(Request,
+        [attribute(Attribute,
+			[description('Attribute for which values are retrieved'),
+			 optional(false)]),
+		 user(User,
+			[description('User for which values are retrieved'),
+			 default(LoggedinUser)])]),
+    Options = [attribute(Attribute), user(User)].
+
 %%	page_item(+Request)
 %
 %	Replies html page
diff --git a/lib/accurator/accurator_user.pl b/lib/accurator/accurator_user.pl
index ce895bc..021c367 100644
--- a/lib/accurator/accurator_user.pl
+++ b/lib/accurator/accurator_user.pl
@@ -1,11 +1,11 @@
 :- module(accurator_user, [get_annotated/2,
 						   get_annotated_user/2,
-						   get_domain/2,
-						   get_locale/2,
+						   get_attribute/3,
 						   register_user/1,
 						   get_user/1,
 						   get_user_settings/1,
-						   save_user_info/1]).
+						   save_user_info/1,
+						   get_user_info/1]).
 
 /** <module> Domain
 */
@@ -71,17 +71,29 @@ get_user(_Request) :-
 %	Return saved domain and locale of user.
 get_user_settings(_Request) :-
 	logged_on(User),
-	get_domain(User, Domain),
-	get_locale(User, Locale),
+	get_attribute(User, domain, Domain),
+	get_attribute(User, locale, Locale),
 	reply_json_dict(settings{locale:Locale, domain:Domain}).
 
-get_domain(User, Domain) :-
-	user_property(User, domain(Domain)), !.
-get_domain(_User, "").
+%%	get_user_info(-Dic, +Options)
+%
+%	get the value of the user profile for the given attribute
+get_user_info(Options) :-
+	option(attribute(Attribute), Options),
+	option(user(User), Options),
+	get_attribute(User, Attribute, Value),
+	reply_user_info(Attribute, Value).
+
+reply_user_info(_Attribute, "") :-
+	reply_json_dict(settings{}), !.
+
+reply_user_info(Attribute, Value) :-
+	reply_json_dict(settings{}.put(Attribute, Value)).
 
-get_locale(User, Locale) :-
-	user_property(User, locale(Locale)), !.
-get_locale(_User, "").
+get_attribute(User, Attribute, Value) :-
+	Atom =.. [Attribute, Value],
+	user_property(User, Atom), !.
+get_attribute(_User, _Attribute, "").
 
 %%	save_additional_info(+Request)
 %
diff --git a/lib/accurator/recommendation/strategy_expertise.pl b/lib/accurator/recommendation/strategy_expertise.pl
index 993363e..9a3b1b1 100644
--- a/lib/accurator/recommendation/strategy_expertise.pl
+++ b/lib/accurator/recommendation/strategy_expertise.pl
@@ -22,7 +22,7 @@
 strategy_expertise(Result, Options0) :-
 	option(output_format(OutputFormat), Options0),
 	option(user(User), Options0),
-	get_domain(User, Domain),
+	get_attribute(User, domain, Domain),
 	Options1 = [domain(Domain) | Options0],
 	%set initial max agenda
 	Options = [max_agenda(100) | Options1],
diff --git a/web/js/components/utilities.js b/web/js/components/utilities.js
index 38e7a5a..4f3a944 100644
--- a/web/js/components/utilities.js
+++ b/web/js/components/utilities.js
@@ -50,6 +50,11 @@ function save_user_info(info) {
 	});
 }
 
+function get_user_info(attribute) {
+	// get user setting from cliopatria
+	return $.getJSON("get_user_info", {"attribute":attribute});
+}
+
 function getParameterByName(name) {
 	// retrieve information from url parameters (often settings)
 	name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
diff --git a/web/js/item.js b/web/js/item.js
index c762090..4f97623 100644
--- a/web/js/item.js
+++ b/web/js/item.js
@@ -122,6 +122,15 @@ function events(user, locale, labels) {
 		}
 
 		if (annotations.length === 26) {
+			console.log("get info");
+			get_user_info("form_peronal_shown")
+			.then(function(info) {
+				console.log("check whether to show form", info.form_peronal_shown);
+				if (!info.form_peronal_shown) {
+					console.log("should show form");
+				}
+			});
+
 			var formPersonal = new Form(
 				"formPersonal",
 				["country", "language", "education", "gender", "birthDate"],