From ccc8de4ebdd18fb52cdb8ce2013573d079186fba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 20 Dec 2021 16:45:53 +0100 Subject: [PATCH] allow manual grouping --- db_meta.sh | 48 ++++++++++++++++++++++++++---------------------- list.sh | 14 +++++++++++--- multitag.sh | 11 ++++++++++- style.css | 3 +++ widgets.sh | 1 + 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/db_meta.sh b/db_meta.sh index f1eec4d..9f427fc 100755 --- a/db_meta.sh +++ b/db_meta.sh @@ -6,15 +6,15 @@ include_dbmeta="$0" . "$_EXEC/cgilite/storage.sh" # == FILE FORMAT == -# LENGTH WIDTH HEIGHT TAGS COMMENT NAME +# LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP # == GLOBALS == UNSET_META='unset \ - META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME + META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME META_GROUP ' LOCAL_META='local \ - META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME + META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME META_GROUP ' eval "$UNSET_META" @@ -28,12 +28,14 @@ read_meta() { # Global exports META_LENGTH='' META_WIDTH='' META_HEIGHT='' META_TAGS='' - META_COMMENT='' META_NAME='' + META_COMMENT='' META_NAME='' META_GROUP='' if [ $# -eq 0 ]; then - read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME + read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \ + META_NAME META_GROUP elif [ "$name" -a -f "$meta_db" -a -r "$meta_db" ]; then - read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT META_NAME <<-EOF + read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \ + META_NAME META_GROUP <<-EOF $(grep -F " ${name}${CR}" "$meta_db") EOF fi @@ -41,6 +43,7 @@ read_meta() { META_NAME="$(UNSTRING "${META_NAME%${CR}}")" META_COMMENT="$(UNSTRING "${META_COMMENT#comment=}")" META_TAGS="$(UNSTRING "${META_TAGS#tags=}")" + META_GROUP="${META_GROUP#\\}" else eval "$UNSET_META" return 1 @@ -48,8 +51,8 @@ read_meta() { } update_meta(){ - local name="${1:=${META_NAME}}" tags comment length width height - local LENGTH WIDTH HEIGH TAGS COMMENT NAME + local name="${1:=${META_NAME}}" tags comment length width height group + local LENGTH WIDTH HEIGH TAGS COMMENT NAME GROUP local arg cnt meta_db="$_DATA/.index/meta" [ "${name%%/*}" != "$name" ] \ @@ -62,23 +65,24 @@ update_meta(){ lenght=*) lenght="${arg#*=}";; width=*) width="${arg#*=}";; height=*) height="${arg#*=}";; + group=*) group="${arg#*=}";; esac; done if LOCK "$meta_db"; then - read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME <<-EOF + read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP <<-EOF $(grep -F " ${name}${CR}" "$meta_db") EOF if [ ! "$NAME" ]; then RELEASE "$meta_db" return 1 fi - printf '%i %i %i tags=%s comment=%s %s\r\n' \ + printf '%i %i %i tags=%s comment=%s %s\r %s\n' \ "${length:-${length-${LENGTH}}${length+0}}" \ "${width:-${width-${WIDTH}}${width+0}}" \ "${height:-${height-${HEIGHT}}${height+0}}" \ "$(STRING "${tags-$(UNSTRING "${TAGS#tags=}")}")" \ "$(STRING "${comment-$(UNSTRING "${COMMENT#comment=}")}")" \ - "${NAME%${CR}}" \ + "${NAME%${CR}}" "${group:-${GROUP:-\\}}" \ >"${meta_db}.$$" grep -vF " ${name}${CR}" "$meta_db" >>"${meta_db}.$$" @@ -92,20 +96,20 @@ update_meta(){ new_meta(){ local name="$1" meta_db="$_DATA/.index/meta" - local LENGTH WIDTH HEIGHT TAGS COMMENT NAME + local LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP [ "${name%%/*}" != "$name" ] \ && meta_db="$_DATA/${name%%/*}/.index/meta" name="$(STRING "${name##*/}")" if LOCK "$meta_db"; then - while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME; do + while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do if [ "$name" = "${NAME%${CR}}" ]; then RELEASE "$vid_db" return 1 fi done <"$meta_db" - printf '0 0 0 tags=\\ comment=\\ %s\r\n' \ + printf '0 0 0 tags=\\ comment=\\ %s\r \\\n' \ "${name}" >>"$meta_db" RELEASE "$meta_db" else @@ -115,18 +119,18 @@ new_meta(){ delete_meta() { local name="$1" meta_db="$_DATA/.index/meta" - local LENGTH WIDTH HEIGHT TAGS COMMENT NAME + local LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP [ "${name%%/*}" != "$name" ] \ && meta_db="$_DATA/${name%%/*}/.index/meta" name="$(STRING "${name##*/}")" if LOCK "$meta_db"; then - while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME; do + while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do [ "$name" = "${NAME%${CR}}" ] \ - || printf '%i %i %i tags=%s comment=%s %s\r\n' \ + || printf '%i %i %i tags=%s comment=%s %s\r %s\n' \ "$length" "$width" "$height" "${TAGS#tags=}" \ - "${COMMENT#comment=}" "${NAME%${CR}}" + "${COMMENT#comment=}" "${NAME%${CR}}" "${GROUP:-\\}" done <"$meta_db" >"${meta_db}.$$" mv -- "${meta_db}.$$" "$meta_db" @@ -138,7 +142,7 @@ delete_meta() { list_meta(){ local meta pfx - local LENGTH WIDTH HEIGHT TAGS COMMENT NAME + local LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP if [ "$#" -eq 0 ]; then find "$_DATA" -path '*/.index/meta' @@ -151,10 +155,10 @@ list_meta(){ pfx="$(STRING "${pfx#/}")" [ "$pfx" = '\' ] && pfx='' || pfx="${pfx}/" - while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME; do - printf '%i %i %i tags=%s comment=%s %s%s\r\n' \ + while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do + printf '%i %i %i tags=%s comment=%s %s%s\r %s\n' \ $LENGTH $WIDTH $HEIGHT "${TAGS#tags=}" \ - "${COMMENT#comment=}" "${pfx}" "${NAME%${CR}}" + "${COMMENT#comment=}" "${pfx}" "${NAME%${CR}}" "${GROUP:-\\}" done <"$meta" done } diff --git a/list.sh b/list.sh index 2384da8..65d929a 100755 --- a/list.sh +++ b/list.sh @@ -93,8 +93,12 @@ list_order(){ sort -k6 elif [ $ORDER = Group ]; then sed -E ' + /^[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*\r$/bX; + /^[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*\r\t\\$/bX; + s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t)([^\r]*)\r\t(.*)$;\1\r\3 \2\r\t;; + t; :X - s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2\n;; + s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2;; t; s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)([0-9]+)(.*)$;\1\r\3 \2;; tX;' \ @@ -113,12 +117,16 @@ list_order(){ ln="$name" done \ | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;;;' \ - | sed -E ':X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX' + | sed -E ' + s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t)\r([0-9A-Za-z:=]{16}) ([^ ]+)$;\1\3\r\t\2;; t; + :X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX + ' elif [ $ORDER = Length ]; then sort -sn -k1 elif [ $ORDER = Date ]; then while read -r fm; do - fn="$(list_fullname "${fm##* }")" + fn="${fm%${CR} *}" + fn="$(list_fullname "${fn##* }")" printf '%i %s\n' \ "$(stat -c %Y "$fn")" "${fm}" done \ diff --git a/multitag.sh b/multitag.sh index bbbf946..674983a 100755 --- a/multitag.sh +++ b/multitag.sh @@ -1,6 +1,7 @@ #!/bin/sh . "$_EXEC/db_meta.sh" +. "$_EXEC/cgilite/session.sh" nocookie newtags='' for tn in $(seq 1 $(POST_COUNT tag)); do @@ -8,6 +9,10 @@ for tn in $(seq 1 $(POST_COUNT tag)); do done newtags="$(POST newtagn |tr -d '\r' |tr , '\n')${BR}${newtags}" +if [ "$(POST makegroup)" = true ]; then + group="$(timeid)" +fi + while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done @@ -36,5 +41,9 @@ for select in $(seq 1 $(POST_COUNT select)); do fi tags="${tags#,}"; tags="${tags%,}" - update_meta "$META_NAME" tags="${tags}" + if [ "$group" ]; then + update_meta "$META_NAME" tags="${tags}" group="${group}" + else + update_meta "$META_NAME" tags="${tags}" + fi done diff --git a/style.css b/style.css index dd67361..391a6da 100644 --- a/style.css +++ b/style.css @@ -255,6 +255,9 @@ body { display: block; white-space: pre; } +#multitag fieldset [name=newtagn] + label { + display: block; +} /* ====== VIEW PAGE ====== */ diff --git a/widgets.sh b/widgets.sh index 287db5f..4d42c41 100755 --- a/widgets.sh +++ b/widgets.sh @@ -247,6 +247,7 @@ w_tagging(){ cat <<-EOF [fieldset [legend New:][textarea name=newtag\n] + [label [checkbox "makegroup" "true"] Join selected into group] [submit "op" "del" Remove Tags][submit "op" "add" Add Tags] ]] EOF -- 2.39.2