]> git.plutz.net Git - serve0/blobdiff - widgets.sh
Bugfix: keep tag order
[serve0] / widgets.sh
old mode 100644 (file)
new mode 100755 (executable)
index fc6818e..4e93629
@@ -4,6 +4,7 @@
 include_widgets="$0"
 
 . "$_EXEC/cgilite/storage.sh"
+. "$_EXEC/db_meta.sh"
 
 w_refuri="$(URL "$PATH_INFO")?$(HTML "$QUERY_STRING")"
 
@@ -14,23 +15,14 @@ c_tags="$_DATA/.index/tags.cache"; c_tagcategories="$_DATA/.index/tagcategories.
 if [ ! -s "$c_tags" -o ! -s "$c_tagcategories" ] \
    || [ "$(find "$_DATA/" -path '*/.index/meta' -newer "$c_tags")" ]
   then
-  w_tags="$( local cn=1
-    find "$_DATA/" -path '*/.index/meta' -print0 \
-    | xargs -r0 sed -r '
-      s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;;
-      s;,;\n;g;'"$UNSTRING" \
-    | { sort; printf '\n'; } \
-    | while read -r tag; do
-      [ "$tag" = "$otag" ] \
-      && cn=$((cn + 1)) \
-      || {
-        printf "%i     %s\n" "$cn" "$otag"
-        cn=1
-      }
-      otag="$tag"
-    done \
-    |sort -rn |cut -f2- |HTML \
-    |sed "s-
-\n-g; s;\n\n;\n;g;"
+  w_tags="$(
+    list_meta |sed -E '
+      s;^.*\ttags=([^\t]*)\t.*$;\1;;
+      s;,;\n;g;
+    ' \
+    | sort |uniq -c |sort -rn |sed -E 's;^ *[0-9]+ ;;;' \
+    | UNSTRING | HTML \
+    | sed -E 's;&#x0A\;;\n;g; s;\n+;\n;g;'
   )"
   w_tagcategories="$(printf %s "$w_tags" | sed -rn '/:/s;^-?([^:]+):.*$;\1;p' |sort -u )"
   printf %s "$w_tags" >"$c_tags"
@@ -98,7 +90,7 @@ w_bookmarks(){
             [a .link target=blank href="/?o=Date&s=%s&f=%s" by Date]
             [a .link target=blank href="/?o=Length&s=%s&f=%s" by Length]
             [a .link target=blank href="/?o=Group&s=%s&f=%s" by Group]
-            [br]' \
+            ' \
             "$(HTML "$name" |sed 's;&#44\;;&[wbr];g;')" \
             "$search" "$filter" \
             "$search" "$filter" \
@@ -119,6 +111,7 @@ w_search(){
       [option value=Group %s Group]
     ]
     [input name=s placeholder=Search value="%s"]
+    [a #t_avsearch href="#advsearch" Advanced]
   ]
   ' \
   "$w_coname" "$w_codate" "$w_colength" "$w_cogroup" \
@@ -167,8 +160,8 @@ w_advsearch(){
   filter="$(HTML "${FILTER}^")"
 
   printf '[form #advsearch action=./?a=advsearch method=POST
-            [a href="#" Hide]
-            [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br]
+            [a href="#" X]
+            [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.
             Refine the search further by setting additional search tags using the [strong "+and"] button.]'
 
   for n in 1 2 3 4 5 6 7 8 9 10; do
@@ -187,7 +180,7 @@ w_advsearch(){
             $n "${t:+checked}" $n $n
 
     f="|${f#\~}|"
-    printf '*\n%s\n' "$w_tagcategories" \
+    printf '*\n%s\n$\n' "$w_tagcategories" \
     | while read -r category; do
       lbid="cat_${n}_${category}"
 
@@ -196,9 +189,12 @@ w_advsearch(){
       [ "$category" != '*' -a ! "${f%%|${category}:*}" ] && t=checked
       [ "$category" != '*' -a ! "${f%%|-${category}:*}" ] && t=checked
 
+      # printf '[radio "cat_%i" "%s" .cat %s id="%s"][label for="%s" %s]
+      #         [select name=tag_%s size=10 multiple' \
+      #         $n "$category" "$t" "$lbid" "$lbid" "$category" $n
       printf '[radio "cat_%i" "%s" .cat %s id="%s"][label for="%s" %s]
-              [select name=tag_%s size=10 multiple' \
-              $n "$category" "$t" "$lbid" "$lbid" "$category" $n
+              [div .catselect\n' \
+              $n "$category" "$t" "$lbid" "$lbid" "$category"
 
       printf '%s\n' "$w_tags" \
       | { [ "$category" = '*' ] && grep -avF ':' || grep -awF "${category}"; } \
@@ -210,8 +206,11 @@ w_advsearch(){
         [ "$tag" ] || continue
         t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked
         d="${tag#-}"; d="${d#*:}"
-        printf '[option %s value="%s"\n%s]' "$t" "$tag" "$d"
+        # printf '[option %s value="%s"\n%s]' "$t" "$tag" "$d"
+       printf '[label [checkbox "tag_%s" "%s" %s] %s]' "$n" "$tag" "$t" "$d"
       done
+      d="${f##*\$:}" d="${d%%\|*}"
+      [ "$category" = \$ ] && printf '[input name="tag_%i" value="%s"]' "$n" "$(HTML "$d")"
       printf '\n]'
     done
     printf ']'
@@ -232,7 +231,7 @@ w_advsearch(){
 w_delete(){
   printf '[a href="#multitag" Add Tags / Remove Tags]
           [div #multitag [input type="hidden" name="ref" value="%s"]
-          [a href="#" Hide][br]
+          [a href="#" X]
           [fieldset [legend New:]
           [submit "op" "filedelete" Delete Files]
           ]]' "$w_refuri"
@@ -242,12 +241,13 @@ w_tagging(){
   local tag category d
   printf '[a href="#multitag" Add Tags / Remove Tags]
           [div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri"
-  printf '[a href="#" Hide][br]'
+  printf '[a href="#" X]'
 
   printf 'Tags\n%s\n' "$w_tagcategories" \
   | while read -r category; do
     [ "$category" ] || continue
-    printf '[fieldset [legend %s:][select name=tag size=4 multiple\n' "$category"
+    # printf '[fieldset [legend %s:][select name=tag size=4 multiple\n' "$category"
+    printf '[fieldset [legend %s:][div .tagselect\n' "$category"
     printf %s "$w_tags" \
     | { [ "$category" = 'Tags' ] && grep -avF ':' || grep -awF "${category}"; } \
     | { for n in 1 2 3 4 5 6 7 8 9 0; do
@@ -257,7 +257,8 @@ w_tagging(){
     } | while read -r tag; do
       [ "$tag" ] || continue
       d="${tag#-}"; d="${d#*:}"
-      printf '[option value="%s"\n%s]' "$tag" "$d"
+      # printf '[option value="%s"\n%s]' "$tag" "$d"
+      printf '[label [checkbox "tag" "%s"] %s]\n' "$tag" "$d"
     done
     printf ']]'
   done