]> git.plutz.net Git - confetti/commitdiff
allow filter by course attendance
authorPaul Hänsch <paul@plutz.net>
Thu, 4 Feb 2021 23:07:28 +0000 (00:07 +0100)
committerPaul Hänsch <paul@plutz.net>
Thu, 4 Feb 2021 23:07:28 +0000 (00:07 +0100)
cards/filter_card.sh
cards/list.sh
cards/widgets.sh
style.css

index e7d1114a2deb3077c0bfe10584ed3dea044d4962..9953a225553f760a733463704ab8f77af68f8b02 100755 (executable)
@@ -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
index 77c96b00019291f28066e0bf9d6123850ef9b13e..cd0d21f1e320aa958839b8fdbe75dec051286da9 100755 (executable)
@@ -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 \
index 5395a8299a326f424e4b2909700f36c9911d3011..376199efe24397931c22c921de5b2f271d32678c 100755 (executable)
@@ -25,12 +25,12 @@ cat <<EOF
   [fieldset .item
     [legend $(l10n filter_item):]
 
-    $(for field in any name street zip TEL BDAY CATEGORIES; do
+    $(for field in any name street zip TEL BDAY CATEGORIES course; do
       printf '[input id="%s%i" type="radio" name="filter_type%i" value="%s" %s][label for="%s%i" %s ]' \
               "$field" "$n" "$n" "$field" "$([ "$1" = "$field" ] && printf checked )" \
               "$field" "$n" "$(l10n filter_$field)"
     done)
-    [input type="text" name="filter_text$n" value="$([ "$1" = CATEGORIES ] || HTML "$2")" placeholder="$(l10n filter_placeholder)"]
+    [input type="text" name="filter_text$n" value="$([ "$1" = CATEGORIES -o "$1" = course ] || HTML "$2")" placeholder="$(l10n filter_placeholder)"]
     [fieldset .categories
       $(list_categories | while read cat; do
           printf '[label [checkbox "filter_cat%i" "|%s" %s] %s ]' \
@@ -40,6 +40,14 @@ cat <<EOF
       done)
       [a href="/categories/" $(l10n edit_categories)]
     ]
+    [fieldset .courses
+      $(for course in "$_DATA/ical"/*.ics; do
+        printf '[label [checkbox "filter_course%i" "|%s" %s] %s ]' \
+               "$n" "$(HTML "${course##*/}")" \
+               "$(printf %s "${course##*/}" |grep -qxEe "$2" && printf checked )" \
+               "$(pdi_value "$(pdi_load "$course")" SUMMARY |HTML)"
+      done)
+    ]
   ]
 EOF
 }
index e02a695bb0cab9dfdea2c36cc2e00b31dc830320..fcc608dd0a908d798ca091bbfe6062256e121d59 100644 (file)
--- a/style.css
+++ b/style.css
@@ -146,6 +146,7 @@ form.filter fieldset.item input[type=radio]:checked + label {
   z-index: 1;
 }
 form.filter fieldset.item input[type=text],
+form.filter fieldset.item fieldset.courses,
 form.filter fieldset.item fieldset.categories {
   position: relative;
   display: block;
@@ -155,9 +156,12 @@ form.filter fieldset.item fieldset.categories {
   border: 1pt solid;
   box-shadow: .125em .125em .25em #888;
 }
+form.filter fieldset.item fieldset.courses,
 form.filter fieldset.item fieldset.categories { display: none; }
-form.filter fieldset.item input[value=CATEGORIES]:checked + label + input[type=text] { display: none; }
-form.filter fieldset.item input[value=CATEGORIES]:checked + label + input[type=text] + fieldset.categories { display: block; }
+form.filter fieldset.item input[value=course]:checked ~ input[type=text],
+form.filter fieldset.item input[value=CATEGORIES]:checked ~ input[type=text] { display: none; }
+form.filter fieldset.item input[value=course]:checked ~ fieldset.courses,
+form.filter fieldset.item input[value=CATEGORIES]:checked ~ fieldset.categories { display: block; }
 
 form.filter fieldset.order legend {
   float: left; margin-right: 1em;