add prev/next pictures for easier slide show mode
authorArun Persaud <arun@nubati.net>
Wed, 1 Feb 2012 06:54:34 +0000 (22:54 -0800)
committerArun Persaud <apersaud@lbl.gov>
Wed, 1 Feb 2012 06:54:34 +0000 (22:54 -0800)
for some reason all new elements show up in the enter-selection of d3. Should really be just the new pics...

getjson.php
index.php
style.css

index 07294ba5fb6a9b5864b240cedc4af74af30ff2ee..d5dab8b20bb637b5a5afbd7c8487de377688093d 100644 (file)
@@ -23,6 +23,48 @@ if (isset($_REQUEST["S"]))
 
     $result = $DB->query("SELECT name FROM tags");
   }
+ else if (isset($_REQUEST["NP"]))
+  {
+    /* get +- 5 pics from ordered list to show next to a large image */
+
+    /* first create a temp table with all images and then use rowid to get +-5 images */
+
+    if (isset($_REQUEST["T"]))
+      {
+       /* single tag or part of tag */
+       $tags = $_REQUEST["T"];
+       $tags = explode(",",$tags);
+       $nrtags = count($tags);
+
+       foreach ($tags as $key => $value)
+         $tags[$key]=sqlite_escape_string(trim($value));
+       $tags = "'".implode("','",$tags)."'";
+
+       $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, p.id as id  FROM photo_tags pt, photos p, tags t".
+                  " WHERE pt.tag_id = t.id".
+                  " AND (t.name COLLATE NOCASE IN ($tags))".
+                  " AND p.id = pt.photo_id ".
+                  " GROUP BY p.id HAVING COUNT( p.id )=$nrtags");
+
+      }
+    else
+      {
+       $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, p.id as id FROM  photos p");
+      };
+
+    if (isset($_REQUEST["ID"]))
+      {
+       $ID=intval($_REQUEST["ID"]);
+       $result = $DB->query("SELECT * FROM NEXTPREV".
+                            " WHERE rowid > (select rowid from NEXTPREV where id=$ID) -5".
+                            "   AND rowid < (select rowid from NEXTPREV where id=$ID) +5");
+      }
+    else
+      {
+       $result = $DB->query("SELECT 1 where 1=2");
+      }
+
+  }
  else if (isset($_REQUEST["ID"]))
   {
     $id  = intval($_REQUEST["ID"]);
index 45bf53fcda08b1f576c1edbddfa0eea99b2ba037..ab6243572a831cb9f34cc45e75732d3f499538e7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -58,7 +58,9 @@ else
   <button class="next" type="button" onclick="cloud()">tag cloud</button>
 </div>
 
-<div class="pics"> </div>
+<div class="nextprev"> <ul></ul></div>
+
+<div class="pics"><ul></ul> </div>
 
 <footer>
   This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
@@ -68,7 +70,7 @@ else
 
 <script type="text/javascript" >
 
-var pics = d3.select(".pics").append("ul");
+var pics = d3.select(".pics").select("ul");
 
 var page=<?php echo $page ?>;
 var N=<?php echo $N ?>;
@@ -132,9 +134,39 @@ function load_content(a) {
                s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-small/');
                return s;
              });
+
+         /* update thumbnails */
+         if(T!="")
+           url2 = "<?php echo $webbase?>/getjson.php?NP=1&T="+T+"&ID="+ID;
+         else
+           url2 = "<?php echo $webbase?>/getjson.php?NP=1&ID="+ID;
+
+         d3.json(url2, function(json2) {
+             var thumbs= d3.select(".nextprev").select("ul").selectAll("li").data(json2);
+             thumbs.enter().append("li")
+               .append("a")
+               .attr("href",function(d) {
+                   s = '<?php echo $webbase; ?>';
+                   if(T!="")
+                     s = s + '/tag/' + T;
+                   s = s + '/pic/' + d.id;
+                   return s;
+                 })
+               .append("img")
+               .attr("src",function(d) {
+                   s= d.base_uri+'/'+d.filename;
+                   s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
+                   return s;
+                 });
+
+             thumbs.exit().remove();
+
+
+           });
        }
       else
        {
+         d3.select(".nextprev").select("ul").selectAll("li").remove();
          pics.selectAll("li").data(picdata)
            .enter().append("li")
            .append("a")
index b81bbbbbfa910b22e07d36c00ce1bcc2eec1b0d6..75bea143862d0cdc567de9554415ac51aad6ae41 100644 (file)
--- a/style.css
+++ b/style.css
@@ -52,4 +52,11 @@ footer {
 }
 
 
-.debug { position: absolute; top:0; left:0}
\ No newline at end of file
+.debug { position: absolute; top:0; left:0}
+
+.nextprev ul li {
+    display:inline;
+}
+.nextprev ul li img {
+    padding-right: 5px;
+}
\ No newline at end of file