From 009e9158a9241258da11b1b5c582f8176b0b7e0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 3 Jan 2021 20:34:36 +0100 Subject: [PATCH 1/1] some course editing ui --- courses/edit_course.sh | 18 +++++++++++--- courses/l10n.sh | 6 ++++- courses/list.sh | 51 ++++++++++++++++++++++++++++++++------- courses/widgets.sh | 54 +++++++++++++++++++++++------------------- 4 files changed, 92 insertions(+), 37 deletions(-) diff --git a/courses/edit_course.sh b/courses/edit_course.sh index 1841e05..5235344 100755 --- a/courses/edit_course.sh +++ b/courses/edit_course.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014, 2019, 2020 Paul Hänsch # # This file is part of Confetti. # @@ -17,6 +17,18 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -course="${_GET[course]}" +locktimeout=900 +. "$_EXEC"/session_lock.sh -echo -n "Location: ?p=courses&edit=$course\n\n" +course="$(GET course |PATH)" +coursefile="$_DATA/courses/${course##*/}" + +if tempfile="$(SLOCK "$coursefile" "$locktimeout")"; then + REDIRECT "/courses/?e=${course}" +elif [ -f "$tempfile" ]; then + SET_COOKIE session message="SESSLOCK" + REDIRECT "/courses/#${course}" +else + SET_COOKIE session message="EDITLOCK" + REDIRECT "/courses/#${course}" +fi diff --git a/courses/l10n.sh b/courses/l10n.sh index 711916e..4e52bd2 100755 --- a/courses/l10n.sh +++ b/courses/l10n.sh @@ -17,7 +17,7 @@ l10n(){ local word - [ $# -eq 0 ] && read -r word || word="$1" + [ $# -eq 0 ] && read -r word || word="$*" case $word in SUMMARY) printf "Bezeichnung";; @@ -61,5 +61,9 @@ l10n(){ t_times) printf "mal";; t_until) printf "Bis";; t_oclock) printf "Uhr";; + + "Mon Tue Wed Thu Fri Sat Sun") printf "Mo Di Mi Do Fr Sa So";; + + *) printf %s "$word";; esac } diff --git a/courses/list.sh b/courses/list.sh index abf3bf9..4a23af7 100755 --- a/courses/list.sh +++ b/courses/list.sh @@ -2,7 +2,7 @@ . "${_EXEC}"/pdiread.sh -edit_card(){ +edit_course(){ local coursefile="$_DATA/courses/$1" local tempfile course @@ -15,6 +15,28 @@ edit_card(){ cat <<-EOF [form .course #${coursefile##*/} action="/cards/update_course.sh" method="POST" [input type="hidden" name="tid" value="$(transid ${tempfile})"] + [div .section .basic . $( + edit_item "$course" SUMMARY COMMENT + )] + [div .section .dtstart . $( + edit_item "$course" DTSTART + )] + [div .section .recur . $( + edit_item "$course" RRULE + )] + [div .section .select_attendance . $( + edit_item "$course" attendance + )] + [div .control + [select .item name=newfield + [option disabled="disabled" selected . $(l10n edit_addfieldtext)] + $(for f in $SUP_FIELDS; do printf '[option value="%s" . %s]\n' "$f" "$(l10n "$f")"; done) + ] + [button .item type="submit" name="action" value="addfield" . $(l10n edit_addfield)] + [button .item type="submit" name="action" value="update" . $(l10n edit_update)] + [button .item type="submit" name="action" value="delete" . $(l10n edit_delete)] + [button .item type="submit" name="action" value="cancel" . $(l10n edit_cancel)] + ]' ] EOF fi @@ -25,27 +47,38 @@ print_course(){ local course="$(pdi_load "$coursefile")" cat <<-EOF [div .course #${coursefile##*/} - [div .section .basic ­$( + [div .section .basic . $( cal_item "$course" SUMMARY DTSTART RRULE )] - [div .section .COMMENT ­$(cal_item "$course" COMMENT)] - [div .section .attendance [h3 $(l10n course_attendance) ] [ul ­ - $(grep -F " ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do - printf '[li [a .item .attendance href="/courses#%s" ­%s]]' \ + [div .section .COMMENT . $(cal_item "$course" COMMENT)] + [div .section .attendance [h3 $(l10n course_attendance) ] [ul . + $(grep -F "${coursefile##*/} " "$_DATA/mappings/attendance" |while read discard each; do + printf '[li [a .item .attendance href="/cards/#%s" . %s]]\n' \ "$each" \ - "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY |unescape |HTML)" - done)] + "$(pdi_value "$(pdi_load "$_DATA/vcard/$each")" FN |unescape |HTML)" + done |sort -k7)] ] [div .control [a .item href="/courses/edit_course.sh?course=${coursefile##*/}" $(l10n edit)] [a .item href="/courses/export_pdf.sh?course=${coursefile##*/}" target="blank" $(l10n courselist)] [a .item href="/courses/export_ical.sh?course=${coursefile##*/}" $(l10n ics_export)] - [a .item href="mailto:zack@vuesch.org?bcc=$(course_mail "${coursefile##*/}")" $(l10n course_mail)] + [a .item href="mailto:zack@vuesch.org?bcc=$(course_mail "${coursefile##*/}" |HTML)" $(l10n course_mail)] ] ] EOF } +course_mail() { + course="$1" + grep -F "${course} " "$_DATA/mappings/attendance" |while read junk card; do + cat "${_DATA}/vcard/${card}" + done \ + | pdi_load - \ + | sed -rn 's;^EMAIL(\;[^:]*)*:(.+)\r?$;\2,;p' \ + | tr -d \\n \ + | unescape +} + print_courses(){ local calfile cachefile date size name ldate=0 lsize lname diff --git a/courses/widgets.sh b/courses/widgets.sh index 41fc686..9e4fdd0 100755 --- a/courses/widgets.sh +++ b/courses/widgets.sh @@ -113,43 +113,49 @@ edit_item(){ for item in $@; do cnt="$(pdi_count "$course" "$item")" - [ $cnt -lt 1 ] && cnt=1 + [ "$cnt" -lt 1 ] && cnt=1 case $item in DTSTART) - dtstart="$(pdi_value "$course" DTSTART |cal_date)" - ystart="${dtstart%%-*}"; ystart="${ystart##* }" - mstart="${dtstart#*-}"; mstart="${mstart%%-*}" - dstart="${dtstart##*-}"; dstart="${dstart%% *}" - hhstart="${dtstart##* }"; hhstart="${hhstart%%:*}" - mmstart="${dtstart##*:}"; + local dtstart="$(pdi_value "$course" DTSTART |cal_date)" + local ystart="${dtstart%%-*}"; ystart="${ystart##* }" + local mstart="${dtstart#*-}"; mstart="${mstart%%-*}" + local dstart="${dtstart##*-}"; dstart="${dstart%% *}" + local hhstart="${dtstart##* }"; hhstart="${hhstart%%:*}" + local mmstart="${dtstart##*:}"; + local m mn cdow d printf '[div .section .DTSTART][h3 %s]' "$(l10n DTSTART)" - printf '[select .DTSYEAR name="DTSYEAR" onchange="this.form.submit();"' + printf '[select .DTSYEAR name="DTSYEAR" onchange="this.form.submit();"\n' seq $((ystart - 50)) $((ystart + 50)) |while read y; do - printf '[option value="%i" %s %i]' $y "$([ $y -eq $ystart ] && printf selected)" $y + printf '[option value="%i" %s %i]\n' $y "$([ $y -eq $ystart ] && printf selected)" $y done printf ']' - printf '[select .DTSMONTH name="DTSMONTH" onchange="this.form.submit();"' - seq 1 12 |while read m; do - printf '[option value="%i" %s %s]' $m "$([ $m -eq $mstart ] && printf selected)" "$(date -d "2000-${m}-01" +%B)" + printf '[select .DTSMONTH name="DTSMONTH" onchange="this.form.submit();"\n' + m=1; for mn in $(l10n January February March April May June July August September October November December); do + printf '[option value="%i" %s . %s]\n' $m "$(selected $m $mstart)" "$mn" + m=$((m+1)) done - printf '][submit "DTS" "update" .DTS %s]' "$(l10n edit_dtscal)" - printf 'mon tue wed thu fri sat sun' |xargs -n1 date -d '{}' +"[span .DTSCALHEAD %a]" - seq 2 "$(date -d ${ystart}-${mstart}-1 +%u)" |xargs -n1 printf '[span .DTSCAL]' - cnt=$(date -d ${dts_year}-${dts_month}-1 +%s) - dn=1; while [ "$(date ${ystart}-${mstart}-${dn} +%m)" -eq "$mstart" ]; do - printf '[input .DTSCAL type="radio" name="DTSDAY" #DTSCAL_%i value="%i" %s][label .DTSCAL for="DTSCAL_%i" %i]' \ - $dn $n "$([ $dn -eq "$dstart" ] && printf checked)" $dn $dn - dn=$((dn + 1)) + printf '][submit "DTS" "update" .DTS %s]\n' "$(l10n edit_dtscal)" + printf '[table .dtscalt [tr' + printf '[th . %s]' $(l10n Mon Tue Wed Thu Fri Sat Sun) + printf ']\n[tr ' + cdow="$(date -d ${ystart}-${mstart}-1 +%u)" + seq 2 $cdow |xargs -n1 printf '[td .padding .%s]' + d=1; while [ "$d" -lt 29 ] || [ "$(date -d ${ystart}-${mstart}-${d} +%m)" -eq "$mstart" ]; do + [ $cdow -eq 1 -a $d -ne 1 ] && printf ']\n[tr ' + printf '[td [input .DTSCAL type="radio" name="DTSDAY" #DTSCAL_%i value="%i" %s][label .DTSCAL for="DTSCAL_%i" %i]]' \ + $d $d "$(checked $d $dstart)" $d $d + d=$((d + 1)); cdow=$(((cdow + 1) % 7)) done 2>/dev/null + printf ']]\n' printf '[span .DTSTIME %s:][select .DTSTIME name="DTSHOUR"' "$(l10n time)" - seq 0 23 |while read h; do - printf '[option value="%i" %s %i]' $h "$([ $h -eq $hhstart ] && printf checked)" $h + seq 00 23 |while read h; do + printf '[option value="%i" %s %02i]' $h "$(selected "$h" "$hhstart")" $h done printf ']:[select .DTSTIME name="DTSMINUTE"' - seq 0 5 55 |while read m; do - printf '[option value="%i" %s %i]' $m "$([ $m -eq $mmstart ] && printf checked)" $m + seq 00 5 55 |while read m; do + printf '[option value="%i" %s %02i]' $m "$(selected "$m" "$mmstart")" $m done printf ']' ;; -- 2.39.2