From 79a7bb3560f305a48ecd2b2f2b9957c206fa6792 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 5 Feb 2021 00:07:28 +0100 Subject: [PATCH] allow filter by course attendance --- cards/filter_card.sh | 10 ++++++++-- cards/list.sh | 32 ++++++++++++++++++++++++++++++-- cards/widgets.sh | 12 ++++++++++-- style.css | 8 ++++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/cards/filter_card.sh b/cards/filter_card.sh index e7d1114..9953a22 100755 --- a/cards/filter_card.sh +++ b/cards/filter_card.sh @@ -21,12 +21,18 @@ filter="$( seq 0 100 |while read n; do filter_type="$(POST "filter_type${n}")" filter_text="$(POST "filter_text${n}")" - [ ! "$filter_type" -a ! "$filter_text" ] && break - if [ "$filter_type" = CATEGORIES ]; then + if [ ! "$filter_type" -a ! "$filter_text" ]; then + break + elif [ "$filter_type" = CATEGORIES ]; then printf '^CATEGORIES:' seq 0 $(POST_COUNT filter_cat$n) |while read m; do printf '|%s' "$(POST filter_cat$n $m)" done + elif [ "$filter_type" = course ]; then + printf '^course:' + seq 0 $(POST_COUNT filter_course$n) |while read m; do + printf '|%s' "$(POST filter_course$n $m)" + done else printf '^%s:%s' "$filter_type" "$filter_text" fi diff --git a/cards/list.sh b/cards/list.sh index 77c96b0..cd0d21f 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -121,11 +121,36 @@ print_cards(){ done } +filter_attendance(){ + fatt="$1" + attfile="$_DATA/mappings/attendance" + + if [ ! "$fatt" ]; then + # debug 'list all' + printf '%s\n' "$_DATA/vcard"/*.vcf + elif [ "${fatt#* }" = "${fatt}" ]; then + # debug "list $fatt" + grep -xiE "(${fatt}) .+vcf" "$attfile" \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + else + # debug "filter ${fatt%% *}" + filter_attendance "${fatt#* }" \ + | while read vcf; do + grep -xiE "(${fatt%% *}) ${vcf##*/}" "$attfile" + done \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + fi +} + filter_cards(){ local filter f fex='x;p;' filter="$(printf %s "${filter}" \ - | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\\\&;g; + | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\&;g; '"$upcase" )^" @@ -134,6 +159,8 @@ filter_cards(){ case $f in '') break ;; + COURSE:*) fatt="${fatt}${fatt:+ }${f#*:}" + ;; ANY:*) fex="/\n.*(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" ;; NAME:*) fex="/\n(N|FN|NICKNAME)(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" @@ -145,7 +172,8 @@ filter_cards(){ esac done - for cardfile in "${_DATA}"/vcard/*.vcf; do + # for cardfile in "${_DATA}"/vcard/*.vcf; do + filter_attendance "$fatt" |while read cardfile; do printf '%s\n' "$cardfile" cat "$cardfile" done \ diff --git a/cards/widgets.sh b/cards/widgets.sh index 5395a82..376199e 100755 --- a/cards/widgets.sh +++ b/cards/widgets.sh @@ -25,12 +25,12 @@ cat <