changeset 21:d964d9a23837

now with clickable author names in detail panel.
author casties
date Fri, 09 Oct 2015 15:01:20 +0200
parents d8bbf6d5920b
children b709419d4235
files ismi-python-neo4jrestclient/ismi-vis.py ismi-python-neo4jrestclient/static/commentaries_authors3.html
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py	Fri Oct 09 12:54:39 2015 +0200
+++ b/ismi-python-neo4jrestclient/ismi-vis.py	Fri Oct 09 15:01:20 2015 +0200
@@ -188,9 +188,9 @@
              " optional match (s)-[:was_created_by]->(sa:PERSON)"
              " optional match (t)<-[:is_commentary_on]-(c:TEXT)" 
              " optional match (c)-[:was_created_by]->(ca:PERSON)"
-             " return t,a.label,s.label,s.ismi_id,sa.label,c.label,c.ismi_id,ca.label")
+             " return t,a.label,a.ismi_id,s.label,s.ismi_id,sa.label,c.label,c.ismi_id,ca.label")
     print("query:%s"%query)
-    results = gdb.query(query, returns=(Node,str,str,str,str,str,str,str), 
+    results = gdb.query(query, returns=(Node,str,str,str,str,str,str,str,str), 
                         params={"text_id": int(text_id)})
     
     print("result:%s"%results)
@@ -198,9 +198,10 @@
     author = None
     scs = {}
     cs = {}
-    for [t,a_label,s_label,s_id,sa_label,c_label,c_id,ca_label] in results:
+    for [t,a_label,a_id,s_label,s_id,sa_label,c_label,c_id,ca_label] in results:
         text = t
         author = a_label
+        author_id = a_id
         if s_id is not None and s_id != "None":
             scs[int(s_id)] = {"title": s_label, "author":sa_label}
             
@@ -209,7 +210,7 @@
         
     print("text:%s scs:%s cs:%s"%(text, scs, cs))
     return Response(dumps({"title": text['label'], "attrs": text.properties, 
-                           "author": author,
+                           "author": {"label": author, "ismi_id": author_id},
                            "commenting": scs, "commentaries": cs}),
                     mimetype="application/json")
 
--- a/ismi-python-neo4jrestclient/static/commentaries_authors3.html	Fri Oct 09 12:54:39 2015 +0200
+++ b/ismi-python-neo4jrestclient/static/commentaries_authors3.html	Fri Oct 09 15:01:20 2015 +0200
@@ -39,14 +39,13 @@
     <div class="col-md-5">
         <div class="panel panel-default">
             <div class="panel-heading">
-                <span>Texts by this author</span>
+                <span id="author">Titles by this author</span>
                 <span class="clickhide">(click to hide)</span>
                 <span class="clickhide" style="display:none;">(click to show)</span>
             </div>
             <table id="results" class="table table-striped table-hover">
                 <thead>
                 <tr>
-                    <th>Author (translit)</th>
                     <th>Title (translit)</th>
                     <th>Title (arabic)</th>
                     <th>ismi_id</th>
@@ -124,7 +123,10 @@
                         if (!data) return;
                         $("#title").text("Title: "+data.title);
                         var $list = $("#info").empty();
-                        $list.append($("<li> author: " + data.author + "</li>"));
+                        $list.append($("<li> Author: " + data.author.label + "</li>")
+                                .click(function() { 
+                                    search(data.author.ismi_id, true); 
+                                    }));
                         for (var key in data.attrs) {
                             var val = data.attrs[key];
                             if (key === "link") {
@@ -135,6 +137,7 @@
                         // re-set selected
                         $("#graph .selected").each(function(){this.classList.remove("selected")});
                         $("#graph .ismi-"+data.attrs.ismi_id).each(function(){this.classList.add("selected")});
+                        // add commentaries
                         var $commentaries = $("#commentaries").empty();
                         for (var key in data.commentaries) {
                             var val = data.commentaries[key];
@@ -150,19 +153,23 @@
                     }, "json");
             return false;
         }
-        function search() {
-            var query=$("#search").find("input[name=search]").val();
+        function search(query, keep_detail_view) {
+            if (query == null) {
+                query=$("#search").find("input[name=search]").val();
+            }
             $.get(backendApiPrefix+"/search?q=" + encodeURIComponent(query),
                     function (data) {
                         var t = $("table#results tbody").empty();
                         if (!data || data.length == 0) return;
                         // clear all marks
                         $("#graph .marked").each(function(){this.classList.remove("marked")});
+                        // fill table of titles
                         data.forEach(function (row) {
                             var text = row.text;
                             var author = row.author;
+                            $("#author").text("Titles by Author: "+author.label+" ["+author.ismi_id+"]");
                             var comm = row.is_commentary || row.has_commentaries;
-                            var $row = $("<tr><td>" + author.label + "</td><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
+                            var $row = $("<tr><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
                                     .click(function() { showText($(this).find("td.text_id").text());});
                             if (comm) {
                                 $row.addClass("marked");
@@ -170,7 +177,10 @@
                             // set mark
                             $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")});
                         });
-                        showText(data[0].text.ismi_id);
+                        if (!keep_detail_view) {
+                            // show first title
+                            showText(data[0].text.ismi_id);
+                        }
                     }, "json");
             return false;
         }
@@ -212,7 +222,7 @@
                     .attr("class","arrowHead");
 
     // load graph
-    d3.json(backendApiPrefix+"/graph?limit=1000", function(error, graph) {
+    d3.json(backendApiPrefix+"/graph?limit=10", function(error, graph) {
 		if (error) return;
 		
         force.nodes(graph.nodes).links(graph.links).start();
@@ -231,7 +241,6 @@
                 .attr("r", 8) // 10
                 .attr("data-ismi_id", function(d) {return d.ismi_id})
                 .on("click", function() {
-                    console.log("click on ", this);
                     var id = this.getAttribute("data-ismi_id");
                     searchApi.showText(id);
                     })