annotation_dashboard/commit

basic dashboard working

authorJacco van Ossenbruggen
Wed May 14 16:27:16 2014 +0200
committerJacco van Ossenbruggen
Wed May 14 16:27:16 2014 +0200
commitc9dda12ff8e7a10ccaeeb1467fa4fef895a5d257
tree65905be2e81e8437a56361f78f0e4ac3380e1cc2
parentf110e719e2890dd6b379475c47331b007b54ba39
Diff style: patch stat
diff --git a/applications/dashboard.pl b/applications/dashboard.pl
index b93ad62..cac5783 100644
--- a/applications/dashboard.pl
+++ b/applications/dashboard.pl
@@ -78,7 +78,7 @@ is_tag(A) :-
 task_page(Task, _Options) :-
 	rdf_display_label(Task, Label),
 	find_annotations_by_task(Task, Annotations),
-	include(is_tag, Annotations, Tags),
+	partition(is_tag, Annotations, Tags, Judgements),
 	maplist(rdf_get_annotation_target, Tags, Targets),
 	sort(Targets, Objects),
 	rdf_has(Task, ann_ui:taskUI, UI),
@@ -99,6 +99,7 @@ task_page(Task, _Options) :-
 				   ['Task objects']),
 				\show_objects(Objects,
 					      [annotations(Annotations),
+					       judgements(Judgements),
 					       ui(UI)
 					      ])
 			      ])
@@ -240,7 +241,7 @@ show_object(O, Options) -->
 		      ]),
 		  div([class('col-xs-6 table-responsive')],
 		      [ table([class('table table-striped')], [
-				  \show_annotations(Annotations, [])
+				  \show_annotations(Annotations, Options)
 			      ])
 		      ])
 		 ])
@@ -445,42 +446,57 @@ show_user_props([Prop|Tail]) -->
 	show_user_props(Tail).
 
 
+current_judgment(Type, A, Jlist, J, checked) :-
+	member(J, Jlist),
+	rdf_has(J, oa:hasTarget, A),
+	rdf_has(J, dc:title, literal(Type)),
+	!.
+
+current_judgment(_Type, A, Jlist, J, unchecked) :-
+	member(J, Jlist),
+	rdf_has(J, oa:hasTarget, A),!.
 
+current_judgment(_,_,_, null, unchecked).
 
 
 button_image(agree,    '../../icons/thumbUp.png').
 button_image(disagree, '../../icons/thumbDown.png').
 
-button_class(Type, _Annotation, Class) :-
+button_class(Type, Checked, Class) :-
 	atomic_list_concat(
 	    ['inline judgeButton ',
 	     Type,
 	     'Button ',
-	     'unchecked'
+	     Checked
 	    ],
 	    Class).
 
-button_title(_,_, title).
-
-judge_button(Type, Annotation, Field) -->
-	{ button_image(Type, ImageSrc),
-	  button_class(Type, Annotation, ButtonClass)
+judge_button(Type, Annotation, Field, Judgements) -->
+	{  current_judgment(Type, Annotation, Judgements, J, Checked),
+	   button_image(Type, ImageSrc),
+	   button_class(Type, Checked, ButtonClass)
 	},
-	html([span([class(ButtonClass), title(Annotation)],
-		   [img([src(ImageSrc), title(Field)])
+	html([span([class(ButtonClass), field(Field), judgement(J), annotation(Annotation)],
+		   [img([src(ImageSrc)])
 		   ])
 	     ]).
+is_judgement_of(A, J) :-
+	rdf_has(J, oa:hasTarget, A).
 
-show_annotation_summery(A, _Options) -->
+show_annotation_summery(A, Options) -->
 	{ rdf_has(A, oa:annotatedBy, User),
 	  (   rdf_has(A, ann_ui:annotationField, Field)
 	  ->  true
 	  ;   Field = undefined
-	  )
+	  ),
+	  option(judgements(J), Options, []),
+	  include(is_judgement_of(A), J, Js)
 	},
 	html([
-	    td([style('width: 3ex;')], \judge_button(agree, A, Field)),
-	    td(\judge_button(disagree, A, Field)),
+	    td([style('')],
+	       [ \judge_button(agree, A, Field, Js),
+		 \judge_button(disagree, A, Field, Js)
+	       ]),
 	    td(\rdf_link(Field, [resource_format(label)])),
 	    td(\rdf_link(A,     [resource_format(label)])),
 	    td(\rdf_link(User,  [resource_format(label)]))
diff --git a/web/js/dashboard.js b/web/js/dashboard.js
index 580fcbf..9f6e80d 100644
--- a/web/js/dashboard.js
+++ b/web/js/dashboard.js
@@ -1,22 +1,31 @@
 YUI().use('event', 'json', 'io', function(Y) {
     Y.on('domready', function() {
-	Y.all('.agreeButton.unchecked').on('click', submitJudgement, 'agree', 'add');
+	Y.all(   '.agreeButton.unchecked').on('click', submitJudgement, null, 'agree', 'disagree', 'add');
+	Y.all('.disagreeButton.unchecked').on('click', submitJudgement, null, 'disagree', 'agree', 'add');
     });
     MOTIVATION = {
 	tagging:    'http://www.w3.org/ns/oa#tagging',
 	commenting: 'http://www.w3.org/ns/oa#commenting',
 	moderating: 'http://www.w3.org/ns/oa#moderating',
     };
-    function submitJudgement(ev, type, mode) {
+    function submitJudgement(ev, type, toggleto, mode) {
+	var button = ev.currentTarget;
+	button.detach('click');
 	
-	var annotationId = ev.currentTarget.getAttribute('title');
-	var fieldId = ev.currentTarget.one('img').getAttribute('title');
+	var annotationId = button.getAttribute('annotation');
+	var fieldId      = button.getAttribute('field');
+	var previous     = button.getAttribute('judgement');
 	var body = {'@value': type };
 	var bodyString = Y.JSON.stringify(body);
 	var targetObject = [{'@id':annotationId}]
 	var targetString = Y.JSON.stringify(targetObject);
-	Y.log(type);
-	Y.log(mode);
+	button.removeAttribute('judgement');
+	if (previous && previous != 'null') Y.io('../../api/annotation/remove', {
+	    method: 'DELETE',
+	    data: { annotation: previous, comment: 'overruled by new judgement ' + type },
+	    on:{ success: function(e,o) {
+	    } }
+	});
 	Y.io('../../api/annotation/add', {
 	    method: 'POST',
 	    data: {
@@ -28,10 +37,18 @@ YUI().use('event', 'json', 'io', function(Y) {
 		motivatedBy: MOTIVATION.moderating
 	    },
 	    on:{ success: function(e,o) {
-		Y.log(e);
-		Y.log(o);
-	    }
-	       }
+		var r = Y.JSON.parse(o.responseText);
+		var buttons = button.get('parentNode').all('.judgeButton');
+		var peer = null;
+		if (buttons.item(0) == button) peer = buttons.item(1);
+		if (buttons.item(1) == button) peer = buttons.item(0);
+		buttons.setAttribute('judgement', r['@id']);
+		button.removeClass('unchecked');
+		button.addClass('checked');
+		peer.addClass('unchecked');
+		peer.removeClass('checked');
+		peer.on('click', submitJudgement, null, toggleto, type, 'add');
+	    } }
 	})
     }
 });