{"id":282,"date":"2013-07-26T12:40:53","date_gmt":"2013-07-26T12:40:53","guid":{"rendered":"http:\/\/www.w3.org\/community\/rww\/?p=282"},"modified":"2013-07-26T12:40:53","modified_gmt":"2013-07-26T12:40:53","slug":"tabulator-creating-a-new-pane-part-2","status":"publish","type":"post","link":"https:\/\/www.w3.org\/community\/rww\/2013\/07\/26\/tabulator-creating-a-new-pane-part-2\/","title":{"rendered":"Tabulator \u2014 Creating a New Pane \u2014 Part 2"},"content":{"rendered":"<p>Last week, we looked at <a href=\"http:\/\/www.w3.org\/community\/rww\/2013\/07\/19\/tabulator-creating-a-new-pane-part-1\/\">how to create a new tabulator pane<\/a>.\u00a0 The first part was just a template, without any real content.\u00a0 This time we will look at how to add a pane for a specific object type and to query the object&#8217;s fields and display them in the pane.\u00a0 If you havent already completed the first part, go back and follow the instructions to make a new file <strong>microblogPostPane.js<\/strong>.\u00a0 This is the file we&#8217;ll be editing in this part.<\/p>\n<h2><span style=\"color: #0000ff\">Step 1 &#8212; Only Display an Icon for Microblog Posts<\/span><\/h2>\n<p>Previously we would display our microblog icon in all cases.\u00a0 We would rather only show the icon when we are looking at a microblog post.\u00a0 Instead of the if (true) condition we had in the label() function we will now replace it with:<\/p>\n<pre style=\"background: #f1f1f1;color: #000\">    <span style=\"color: #a08000\">var<\/span> SIOCt <span style=\"color: #2060a0\">=<\/span> tabulator.rdf.Namespace(<span style=\"color: #c03030\">'http:\/\/rdfs.org\/sioc\/types#'<\/span>);\r\n    <span style=\"color: #2060a0\">if<\/span> (tabulator.kb.whether(\r\n        subject, tabulator.ns.rdf(<span style=\"color: #c03030\">'type'<\/span>), SIOCt(<span style=\"color: #c03030\">'MicroblogPost'<\/span>))) {\r\n      <span style=\"color: #2060a0\">return<\/span> <span style=\"color: #c03030\">\"MicroblogPost\"<\/span>;          <span style=\"color: #406040\">\/\/The icon text<\/span>\r\n    } <span style=\"color: #2060a0\">else<\/span> {\r\n      <span style=\"color: #2060a0\">return<\/span> null;\r\n    }<\/pre>\n<p>The kb.whether function will test whether we are looking at something of type SIOC MicroblogPost.\u00a0 More on the kb later.<\/p>\n<h2><span style=\"color: #0000ff\">Step 2 &#8212; Initialize the Render Function<br \/>\n<\/span><\/h2>\n<p>The first thing to initialize is the tabulator knowledge base.\u00a0 The following code will go in the render() function.<\/p>\n<pre style=\"background: #f1f1f1;color: #000\">    <span style=\"color: #a08000\">var<\/span> kb   <span style=\"color: #2060a0\">=<\/span> tabulator.kb;<\/pre>\n<p>The knowledge base is an indexed database of all the information you will store.\u00a0 It allows many features such as fast querying and utility functions.\u00a0 As you browse the web of data, the knowledge base is automatically populated.\u00a0\u00a0 The next thing we will do is set up namespaces.<\/p>\n<pre style=\"background: #f1f1f1;color: #000\">    <span style=\"color: #a08000\">var<\/span> SIOC <span style=\"color: #2060a0\">=<\/span> tabulator.rdf.Namespace(<span style=\"color: #c03030\">\"http:\/\/rdfs.org\/sioc\/ns#\"<\/span>);\r\n    <span style=\"color: #a08000\">var<\/span> dc   <span style=\"color: #2060a0\">=<\/span> tabulator.rdf.Namespace(<span style=\"color: #c03030\">\"http:\/\/purl.org\/dc\/elements\/1.1\/\"<\/span>);\r\n    <span style=\"color: #a08000\">var<\/span> FOAF <span style=\"color: #2060a0\">=<\/span> tabulator.rdf.Namespace(<span style=\"color: #c03030\">'http:\/\/xmlns.com\/foaf\/0.1\/'<\/span>);<\/pre>\n<p>Once we have the knowledge base in place, we add the popular namespaces for the FOAF, dublin core and SIOC ontologies.<\/p>\n<h2><span style=\"color: #0000ff\">Step 3 &#8212; Query the Knowledge Base<br \/>\n<\/span><\/h2>\n<p>We will use the kb.any function to get the values of data points for our microblog post.\u00a0 The function queries the knowledge base in a similar way to NoSQL or map reduce style databases.\u00a0 In this case we will get the avatar, name, content and date of the microblog post.<\/p>\n<pre style=\"background: #f1f1f1;color: #000\">    <span style=\"color: #a08000\">var<\/span> content <span style=\"color: #2060a0\">=<\/span> kb.any(subject, SIOC(<span style=\"color: #c03030\">\"content\"<\/span>));\r\n    <span style=\"color: #a08000\">var<\/span> date    <span style=\"color: #2060a0\">=<\/span> kb.any(subject, dc(<span style=\"color: #c03030\">\"date\"<\/span>));\r\n    <span style=\"color: #a08000\">var<\/span> maker <span style=\"color: #2060a0\"> =<\/span> kb.any(subject, FOAF(<span style=\"color: #c03030\">\"maker\"<\/span>));\r\n    <span style=\"color: #a08000\">var<\/span> name <span style=\"color: #2060a0\"> =<\/span> kb.any(maker, FOAF(<span style=\"color: #c03030\">\"name\"<\/span>));\r\n    <span style=\"color: #a08000\">var<\/span> avatar <span style=\"color: #2060a0\"> =<\/span> kb.any(maker, FOAF(<span style=\"color: #c03030\">\"depiction\"<\/span>));<\/pre>\n<p>Now that we have our data we can go ahead and display it.<\/p>\n<h2><span style=\"color: #0000ff\">Step 4 &#8212; Draw the Pane<br \/>\n<\/span><\/h2>\n<p>Now that we have our data, all that&#8217;s left is to draw the microblog post.\u00a0 I&#8217;m using a simple native javascript commands of createElement, createTextNode and appendChild.\u00a0 However tabulator also works with jQuery too.<\/p>\n<pre style=\"background: #f1f1f1;color: #000\">    <span style=\"color: #a08000\">var<\/span> postLi <span style=\"color: #2060a0\">=<\/span> document.createElement(<span style=\"color: #c03030\">\"div\"<\/span>);\r\n    postLi.className <span style=\"color: #2060a0\">=<\/span> <span style=\"color: #c03030\">\"post\"<\/span>;\r\n    main.appendChild(postLi);\r\n\r\n    <span style=\"color: #a08000\">var<\/span> img <span style=\"color: #2060a0\">=<\/span> document.createElement(<span style=\"color: #c03030\">\"img\"<\/span>);\r\n    img.src <span style=\"color: #2060a0\">=<\/span> (<span style=\"color: #c03030\">\"\"<\/span><span style=\"color: #2060a0\">+<\/span>avatar).slice(<span style=\"color: #0080a0\">1<\/span>,<span style=\"color: #2060a0\">-<\/span><span style=\"color: #0080a0\">1<\/span>);\r\n    img.height <span style=\"color: #2060a0\">=<\/span> img.width <span style=\"color: #2060a0\">=<\/span> <span style=\"color: #0080a0\">50<\/span>;\r\n    img.className <span style=\"color: #2060a0\">=<\/span> <span style=\"color: #c03030\">\"postAvatar\"<\/span>;\r\n    postLi.appendChild(img);\r\n\r\n    <span style=\"color: #a08000\">var<\/span> nameHeading <span style=\"color: #2060a0\">=<\/span> document.createElement(<span style=\"color: #c03030\">\"h3\"<\/span>);\r\n    nameHeading.appendChild(document.createTextNode(name));\r\n    postLi.appendChild(nameHeading);\r\n\r\n    <span style=\"color: #a08000\">var<\/span> contentDiv <span style=\"color: #2060a0\">=<\/span> document.createElement(<span style=\"color: #c03030\">\"div\"<\/span>);\r\n    contentDiv.appendChild(document.createTextNode(content));\r\n    postLi.appendChild(contentDiv);\r\n\r\n    <span style=\"color: #a08000\">var<\/span> dateDiv <span style=\"color: #2060a0\">=<\/span> document.createElement(<span style=\"color: #c03030\">\"div\"<\/span>);\r\n    dateDiv.appendChild(document.createTextNode(date));\r\n    postLi.appendChild(dateDiv);<\/pre>\n<p>The basic styles live in an existing file, mbStyle.css, so I have just reused that.<\/p>\n<h2><span style=\"color: #0000ff\">Step 5 &#8212; Test the Microblog Post<\/span><\/h2>\n<p><a href=\"http:\/\/www.w3.org\/community\/rww\/files\/2013\/07\/microblogpostpane.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-286\" src=\"http:\/\/www.w3.org\/community\/rww\/files\/2013\/07\/microblogpostpane-300x98.png\" alt=\"\" width=\"300\" height=\"98\" srcset=\"https:\/\/www.w3.org\/community\/rww\/files\/2013\/07\/microblogpostpane-300x98.png 300w, https:\/\/www.w3.org\/community\/rww\/files\/2013\/07\/microblogpostpane.png 459w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If all has gone well your file should look like the following <a href=\"https:\/\/gist.github.com\/melvincarvalho\/6088200\" target=\"_blank\" rel=\"nofollow\">gist<\/a>.\u00a0 When clicking on a microblog post such as this <a href=\"http:\/\/foaf.cc\/demo\/microblogpost.ttl#post101\" target=\"_blank\" rel=\"nofollow\">test post<\/a>, you should see something like the image above.<\/p>\n<h2><span style=\"color: #0000ff\">Summary<\/span><\/h2>\n<p>We&#8217;ve seen how to add a simple pane to The Tabulator, how to set up and query the knowledge base, and how to display a new pane in the tabulator.\u00a0 In future blogs we will show how to use Tabuator&#8217;s read and write functions to both render, and update, the web of data!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week, we looked at how to create a new tabulator pane.\u00a0 The first part was just a template, without any real content.\u00a0 This time we will look at how to add a pane for a specific object type and &hellip; <a href=\"https:\/\/www.w3.org\/community\/rww\/2013\/07\/26\/tabulator-creating-a-new-pane-part-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"yes","footnotes":""},"categories":[19],"tags":[16,15,13,21,20],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-rww-2","tag-linkeddata","tag-rww","tag-readwriteweb","tag-tabulator","tag-w3c"],"_links":{"self":[{"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/comments?post=282"}],"version-history":[{"count":7,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":290,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/posts\/282\/revisions\/290"}],"wp:attachment":[{"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/media?parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/categories?post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3.org\/community\/rww\/wp-json\/wp\/v2\/tags?post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}