From 1902cbbff7f9728f303cdb5e3fc37b18eddff4db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 26 Jul 2018 00:17:05 +0200 Subject: [PATCH] allow tag removal in multitagger --- multitag.sh | 19 +++++++++++++++---- widgets.sh | 6 ++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/multitag.sh b/multitag.sh index 4579806..8b60ade 100644 --- a/multitag.sh +++ b/multitag.sh @@ -7,7 +7,8 @@ newtags='' for tn in $(seq 1 $(POST_COUNT tag)); do newtags="${newtags},$(POST tag $tn)" done -newtags="${newtags},$(POST newtag |tr -d '\r')" +newtags="${newtags},$(POST newtag |tr -d '\r' |tr '\n' ,)" +[ "$(POST op)" = del ] && deltags="$newtags" for select in $(seq 1 $(POST_COUNT select)); do file="$_DATA/$ITEM/$(POST select $select |PATH)" @@ -16,9 +17,19 @@ for select in $(seq 1 $(POST_COUNT select)); do read -r length width height tags comment fn <<-EOF $(meta_info "$file") EOF - - tags="$(UNSTRING "${tags#tags=}")" - tags="$(printf '%s\n' "${tags}" "${newtags}" |tr , '\n' |sort -u |tr '\n' , |STRING)" + tags="$(UNSTRING "${tags#tags=}" |tr , '\n')" + + if [ ! "$deltags" ]; then + tags="$(printf '%s\n' "${tags},${newtags}" \ + | tr , '\n' |sort -u |tr '\n' , \ + | STRING)" + else + detag="${deltags},"; while [ "$detag" ]; do + tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%,*}")" + detag="${detag#*,}" + done + tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)" + fi tags="${tags#,}"; tags="${tags%,}" if LOCK "$meta"; then diff --git a/widgets.sh b/widgets.sh index ab09899..916f1d7 100644 --- a/widgets.sh +++ b/widgets.sh @@ -225,7 +225,7 @@ w_advsearch(){ w_tagging(){ local tag category - printf '[a href="#multitag" Add Tags] + printf '[a href="#multitag" Add Tags / Remove Tags] [div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri" printf '[a href="#" Hide][br]' @@ -246,5 +246,7 @@ w_tagging(){ printf ']]' done - printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]' + printf '[fieldset [legend New:][textarea name=newtag\n] + [submit "op" "del" Remove Tags][submit "op" "add" Add Tags] + ]]' } -- 2.39.2