]> git.plutz.net Git - serve0/commitdiff
make filters reusable
authorpaul <paul@plutz.net>
Fri, 3 Jul 2015 13:48:23 +0000 (13:48 +0000)
committerpaul <paul@plutz.net>
Fri, 3 Jul 2015 13:48:23 +0000 (13:48 +0000)
svn path=/trunk/; revision=59

pages/filter.sh
templates/filter.html.sh

index 629a08f7791eb97cc1f0c5b3833e42bac8eee351..c19589be1c8626a9cd0d9fcddcbcead4a1acebc8 100755 (executable)
@@ -19,6 +19,9 @@
 
 . $_EXEC/pages/common.sh
 
+filters="$(echo -E "$_GET[\"f\"]" |sed -r 's;^!r*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')"
+debug "FILTERS: $filters"
+
 case "$1" in
   title)
     echo "Videos"
index 0ba32bbabcb148bd0eb6c4b97f0be4d9ab13aff2..368591e54f29d578aeb70f1aef4b2cf3401ebc61 100755 (executable)
@@ -34,23 +34,46 @@ cat <<EOF
     <p class="help">Up to <strong>10</strong> filter boxes will appear as you start selecting tags. You can select <strong>multiple</strong> tags in each box by holding down the <strong>Ctrl</strong>-key. Click the "<strong>Filter!</strong>" button when you are ready.</p>
 
   $(for n in {0..9}; do
+    filter="$(echo -E "$filters" |cut -d^ -f$(($n+1)))"
+    fneg="${filter%%[a-zA-Z]*}"
+    filter="${filter#!}"
+    fcat="${filter%%:*}"
+    [ "$fcat" = "$filter" ] && fcat=none
+
+    debug "fneg: $fneg fcat: $fcat     filter: $filter"
+    
     cat <<-EOF
-       <input class="tabhandle" type="checkbox" id="filter$n" $([ $n = 0 ] && echo checked) >
+       <input class="tabhandle" type="checkbox" id="filter$n" $([ $n = 0 -o -n "$filter" ] && echo checked) >
        <label class="tabhandle filter" for="filter$n">+ and</label>
        <div class="tabcontent filter">
-         <input type="radio" name="type$n" value="pos" id="pos$n" checked><label for="pos$n" class="conjunction">Any</label>
-         <input type="radio" name="type$n" value="neg" id="neg$n">        <label for="neg$n" class="conjunction">None</label>
+         <input type="radio" name="type$n" value="pos" id="pos$n" ${fneg:-checked} ><label for="pos$n" class="conjunction">Any</label>
+         <input type="radio" name="type$n" value="neg" id="neg$n" ${fneg:+checked} ><label for="neg$n" class="conjunction">None</label>
          <span class="help">of the items selected here:</span>
 
          <label class="category">Category:</label>
           <div class="category tabcontainer">
-         $( {echo none; echo "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u} \
+           <div class="tab">
+           <input class="tabhandle" type="radio" name="category$n" id="cat${n}_none" value="none" $([ "none" = "$fcat" ] && echo checked)>
+           <label class="category tabhandle" for="cat${n}_none">general</label>
+           <select class="category tabcontent" class="input tagfilter" name="cfilter${n}_" size="12" multiple>
+             $(echo "$taglist" |grep -v : |while read item; do
+                 echo -E "$item" |egrep -q "^($filter)$" && \
+                    echo "<option selected >$item</option>" \
+                 || echo "<option>$item</option>"
+              done)
+           </select>
+           </div>
+         $( echo "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u \
              |while read cat; do echo "
            <div class="tab">
-           <input class="tabhandle" type="radio" name="category$n" id="cat${n}_$cat" value="$cat" $([ $cat = none ] && echo checked)>
+           <input class="tabhandle" type="radio" name="category$n" id="cat${n}_$cat" value="$cat" $([ "$cat" = "$fcat" ] && echo checked)>
            <label class=\"category tabhandle\" for="cat${n}_$cat">$cat</label>
            <select class=\"category tabcontent\" class=\"input tagfilter\" name="cfilter${n}_" size="12" multiple>
-             $(echo "$taglist" |sed -r 's;^[^:]+$;none:&;' |sed -rn 's;^'"$cat"':(.*)$;<option>\1</option>;p')
+             $(echo "$taglist" |sed -rn "s;^$cat:;;p" | while read item; do
+                echo -E "${cat}:${item}" |egrep -q "^($filter)$" && \
+                    echo "<option selected >$item</option>" \
+                 || echo "<option>$item</option>"
+              done)
            </select>
            </div>
          "
@@ -63,9 +86,9 @@ cat <<EOF
     <p class="filter final">
       <label for="o3" class="order">Order by:</label>
       <select class="edit order" size="1" name="o" id="o3">
-        <option>Name</option>
-        <option>Date</option>
-        <option>Length</option>
+        <option $([ "$_GET[\"o\"]" = Name ] && echo selected) >Name</option>
+        <option $([ "$_GET[\"o\"]" = Date ] && echo selected) >Date</option>
+        <option $([ "$_GET[\"o\"]" = Length ] && echo selected) >Length</option>
       </select>
       <input type="submit" value="Filter!">
     </p>