]> git.plutz.net Git - serve0/commitdiff
split up functions in tagger
authorpaul <paul@plutz.net>
Wed, 29 Jul 2015 21:28:04 +0000 (21:28 +0000)
committerpaul <paul@plutz.net>
Wed, 29 Jul 2015 21:28:04 +0000 (21:28 +0000)
svn path=/trunk/; revision=66

pages/list.sh
templates/advfilter.html.sh
templates/list.html.sh
templates/tagger.html.sh

index f970a32be1d45f6be8f114771df4fbc444fe027e..9cf7e6faeb6a544ce4e52b1c12cdde81eda79b74 100755 (executable)
 filters="$(echo -E "$_GET[\"f\"]" |sed -r 's;^!*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')"
 debug "FILTERS: $filters"
 
+quicklinks(){
+  output=''
+  tac ${_DATA}/meta/recent |while [ "$(echo "$output" |wc -l)" -lt 10 ] && read line; do
+    line="<a href="$line">$line</a>" 
+    echo "$output" |grep -qF "$line" || output="$output$line\n"
+  done 
+  echo $output
+}
+
+list_categories(){
+  echo none 
+  printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
+}
+
+category_selected(){
+  cat="${1}:"
+  filter="$2"
+  [ "$cat" = "none:" ] && cat=''
+
+  printf %s "$taglist" \
+  | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
+  | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
+  | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
+}
+
 case "$1" in
   title)
     echo "Videos"
index f63d4dc7f328c3a4168594203f1426b18f733bda..dbfd32314d1c9cbd83990271ecb61eb81cd2c010 100755 (executable)
 # You should have received a copy of the GNU Affero General Public License
 # along with Serve0  If not, see <http://www.gnu.org/licenses/>. 
 
-quicklinks(){
-  output=''
-  tac ${_DATA}/meta/recent |while [ "$(echo "$output" |wc -l)" -lt 10 ] && read line; do
-    line="<a href="$line">$line</a>"
-    echo "$output" |grep -qF "$line" || output="$output$line\n"
-  done
-  echo $output
-}
-
-list_categories(){
-  echo none
-  printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
-}
-
-category_selected(){
-  cat="$1"
-  filter="$2"
-
-  printf %s "$taglist" \
-  | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
-  | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
-  | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
-}
-
 category_tabs(){
   for cat in "$@"; do
   cat <<EOF
@@ -46,7 +22,7 @@ category_tabs(){
     <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" = none ] && printf %s general || printf %s "$cat")</label>
     <select class="category tabcontent" class="input tagfilter" name="cfilter${n}_" size="12" multiple>
-      $([ "$cat" = none ] && category_selected "" "$filter" || category_selected "${cat}:" "$filter")
+      $(category_selected "$cat" "$filter")
     </select>
     </div>
 EOF
@@ -54,29 +30,30 @@ EOF
 }
 
 filterbox(){
-  n=$1
-  filter="$(printf '%s^' "$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 -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" ${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">
-      $(category_tabs $(list_categories) )
-    </div>
-  </div>
-EOF
+  for n in "$@"; do
+    filter="$(printf '%s^' "$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 -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" ${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">
+           $(category_tabs $(list_categories) )
+         </div>
+       </div>
+       EOF
+  done
 }
 
 cat <<EOF
@@ -96,7 +73,7 @@ cat <<EOF
     <hr>
 
     <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 filterbox "$n"; done)
+    $(filterbox {0..9})
 
     <p class="filter final">
       <label for="o3" class="order">Order by:</label>
index ca875df4c0342a1c6576b29d740e7a17ecc61cd4..a4e50bb2a274b2fb67158021c411e748844dbef3 100755 (executable)
@@ -45,7 +45,7 @@ cat <<EOF
     <ul id="thumblist">
       $(thumblist)
     </ul>
-    $($_EXEC/templates/tagger.html.sh)
+    $($_EXEC/templates/tagger.html.sh)
   </form>
 
   <div class="panel footer" id="foot">
index 10e657c020d57ccd543bb0b1c4b3315bc6a6fc0e..779f29c95801759f1e584107a264274490535142 100755 (executable)
 # You should have received a copy of the GNU Affero General Public License
 # along with Serve0  If not, see <http://www.gnu.org/licenses/>. 
 
+category_options(){
+  cat="${1}:"
+  [ "$cat" = "none:" ] && cat=''
+
+  printf %s "$taglist" \
+  | sed -rn 's;^('"$cat"')([^:]+)$;<option value="\1\2">\2</option>;p'
+}
+
+category_box(){
+  for cat in "$@"; do
+  cat <<EOF
+  <p class="newtag">
+    <label class="category">${cat}:</label>
+    <input type="hidden" name="category" value="$cat">
+    <select name="ctag" size="12" multiple>
+      $(category_options "$cat")
+    </select>
+  </p>
+EOF
+  done
+}
+
 cat <<EOF
   <div class="panel footer" id="tagger">
     <a class="panel tagger hide" href="#foot">Hide</a>
     <hr>
     <p class="help">Add selectetd tags to selected videos.</p>
-    <p class="newtag">
-      <label class="category">None:</label>
-      <select name="ctag" size="12" multiple id="${n}_none">
-       $(echo "$taglist" |sed -rn 's;^([^:]+)$;<option value="\1">\1</option>;p')
-      </select>
-    </p>
-    $(echo "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u |while read cat; do echo "
-    <p class=\"newtag\">
-      <label class=\"category\">${cat}:</label>
-      <input type=\"hidden\" name=\"category\" value=\"$cat\">
-      <select name=\"ctag\" size=\"12\" multiple id=\"${n}_$cat\">
-       $(echo "$taglist" |sed -rn "s;^${cat}:(.*)$;<option value=\"${cat}:\\1\">\\1</option>;p")
-      </select>
-    </p>"
-    done)
+    $(category_box $(list_categories))
     <p class="newtag additional">
       <label class="additional">Additional Tags (one per line):</label>
       <textarea name="tags" rows="2"></textarea>