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
[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)
]
]
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