]> git.plutz.net Git - lobster/commitdiff
always sort categories, caching and ordering for list in course filter
authorPaul Hänsch <paul@plutz.net>
Fri, 5 Feb 2021 12:00:34 +0000 (13:00 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 5 Feb 2021 12:00:34 +0000 (13:00 +0100)
cards/widgets.sh
categories/edit_categories.sh

index 7dfa3ad2e657ba157b979d9d5ac5e57042ecbf02..c0c05946b1c594272d034a33081e351444873df9 100755 (executable)
@@ -19,6 +19,19 @@ list_categories() {
   grep -vxE '^[        ]*$' "${_DATA}/mappings/categories"
 }
 
+list_courses() {
+  local file name cachefile="${_DATA}/cache/courses.ui.cache"
+  if [ $cachefile -nt "${_DATA}/ical" ]; then
+    cat "$cachefile"
+  else
+    for file in "$_DATA/ical"/*.ics; do
+      name="$(pdi_value "$(pdi_load "$file")" SUMMARY |HTML)"
+      printf '%s       %s\n' "$file" "$name"
+    done \
+    | sort -k2 |tee "$cachefile"
+  fi
+}
+
 w_filter_item() {
 n=$3
 cat <<EOF
@@ -41,11 +54,11 @@ cat <<EOF
       [a href="/categories/" $(l10n edit_categories)]
     ]
     [fieldset .courses
-      $(for course in "$_DATA/ical"/*.ics; do
+      $(list_courses | while read course coursename; 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)"
+               "$coursename"
       done)
     ]
   ]
index 232499bd4c8d39fc1c6ab581fa4d998cb32a90f1..7ee6f36edffe91bb9d2c48feff824bccf90ebdb1 100755 (executable)
@@ -23,7 +23,11 @@ remove="$(POST remove)"
 newcat="$(POST newcat)"
 
 if [ "$(POST add)" = "add" ]; then
-  printf %s\\n "$newcat" >>"$catfile"
+  categories="$( {
+    cat "$catfile"
+    printf %s\\n "$newcat"
+  } |sort -u )"
+  printf %s\\n "$categories" >"$catfile"
 elif [ "$remove" ]; then
   sed -E -i '/^'"${remove}"'$/d' "$catfile"
 fi