From 5238c404a50861cf1dbbe610d2c4977c048d3b12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 27 Jul 2021 02:50:49 +0200 Subject: [PATCH] vote count, reply editing --- poll.sh | 94 +++++++++++++++++++++++++++++++++++++++++------------ webpoll.css | 9 ++++- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/poll.sh b/poll.sh index 74fa3e1..d7c0def 100644 --- a/poll.sh +++ b/poll.sh @@ -57,7 +57,8 @@ table_poll() { local dates="$(DBM "$file" get dates)" local todall="$(DBM "$file" get todall)" local timelist="$(timelist)" - local time date span name + local edit="$(GET edit)" + local time date span name yes no maybe yc nc mc [ "$timelist" ] || return 1 @@ -86,10 +87,12 @@ table_poll() { printf '][tbody\n' + # Vote displays { DBM "$file" get participants; printf \\n; } |while read -r name; do + [ "$name" = "$edit" ] && continue + maybe="$(DBM "$file" get "reply_maybe_${name}")" yes="$(DBM "$file" get "reply_yes_${name}")" no="$(DBM "$file" get "reply_no_${name}")" - maybe="$(DBM "$file" get "reply_maybe_${name}")" printf '[tr [th .name . %s]' "$(HTML "$name")" for time in $timelist; do @@ -98,26 +101,62 @@ table_poll() { printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue printf '[td .missing . ?]' done - printf '[td]]' + printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")" done - # Submit line - printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]' - for time in $timelist; do - time="$(tkey "$time")" - printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes] - [radio "%s" "no" #no_%s][label for="no_%s" No] - [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe] - ]' "${time}" "${time}" "${time}" \ - "${time}" "${time}" "${time}" \ - "${time}" "${time}" "${time}" - done - printf '[td [submit "new" "new" Submit]]]\n' + if [ "$edit" ]; then + maybe="$(DBM "$file" get "reply_maybe_${edit}")" + yes="$(DBM "$file" get "reply_yes_${edit}")" + no="$(DBM "$file" get "reply_no_${edit}")" + + printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")" + for time in $timelist; do + ktime="$(tkey "$time")" + printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes] + [radio "%s" "no" #no_%s %s][label for="no_%s" No] + [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe] + ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \ + "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \ + "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}" + done + printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")" + else + + # Vote counts + printf '[tr .votecount [td]' + for time in $timelist; do + yc=0 nc=0 mc=0 + { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do + [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break; + yes="$(DBM "$file" get "reply_yes_${name}")" + no="$(DBM "$file" get "reply_no_${name}")" + maybe="$(DBM "$file" get "reply_maybe_${name}")" + + printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue + printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue + done + done + printf '[td]]\n' + + # Submit line + printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]' + for time in $timelist; do + time="$(tkey "$time")" + printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes] + [radio "%s" "no" #no_%s][label for="no_%s" No] + [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe] + ]' "${time}" "${time}" "${time}" \ + "${time}" "${time}" "${time}" \ + "${time}" "${time}" "${time}" + done + printf '[td [submit "new" "new" Submit]]]\n' + fi printf ']]' } if [ "$REQUEST_METHOD" = POST ]; then + local update="$(POST update)" delete="$(POST delete)" local name="$(POST name |grep -m 1 -xE '.*[^ ].*')" local splittimes="$(DBM "$file" get splittimes || printf no)" local dates="$(DBM "$file" get dates)" @@ -125,14 +164,20 @@ if [ "$REQUEST_METHOD" = POST ]; then local timelist="$(timelist)" local time yes no maybe reply - if [ "$(POST new)" = new ]; then + if [ "$(POST new)" = new -o "$update" ]; then + [ "$update" ] && name="$update" + if [ ! "$name" ]; then REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME" - elif DBM "$file" get participants |grep -qxF "$name"; then + elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS" + elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then + REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST" + fi + if [ ! "$update" ]; then + DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \ + || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS" fi - DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \ - || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS" for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in yes) yes="${yes}${yes:+ }${time}";; @@ -142,8 +187,17 @@ if [ "$REQUEST_METHOD" = POST ]; then DBM "$file" set "reply_yes_${name}" "$yes" DBM "$file" set "reply_no_${name}" "$no" DBM "$file" set "reply_maybe_${name}" "$maybe" - REDIRECT "${_BASE}${PATH_INFO}" + + elif [ "$delete" ]; then + if ! DBM "$file" get participants |grep -qxF "$delete"; then + REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST" + fi + DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")" + DBM "$file" delete "reply_yes_${delete}" + DBM "$file" delete "reply_no_${delete}" + DBM "$file" delete "reply_maybe_${delete}" fi + REDIRECT "${_BASE}${PATH_INFO}" else pagename="$(pagename "$id")" diff --git a/webpoll.css b/webpoll.css index cfc363b..b89bc45 100644 --- a/webpoll.css +++ b/webpoll.css @@ -37,7 +37,6 @@ body.poll table { background-color: rgba(255,255,255,.5); border-collapse: collapse; margin: auto; - -border: .5pt solid; box-shadow: #000 .25em .25em .5em; border-radius: 2pt; } @@ -53,6 +52,7 @@ body.poll table tbody tr td { text-align: center; border: .5pt solid; padding: 0 .25em; + background-clip: padding-box; } body.poll table tbody tr td:first-child, body.poll table tbody tr td:last-child, @@ -63,6 +63,13 @@ body.poll table tbody tr th.name { padding: .25em .5em; text-align: right; } body.poll table tbody tr td.yes { background-color: #AFA; } body.poll table tbody tr td.no { background-color: #FAA; } body.poll table tbody tr td.maybe { background-color: #FFA; } +body.poll table tbody tr td.edit { text-align: left; font-size: .875em; } + +body.poll table tbody tr.votecount td { padding: .375em .25em;} +body.poll table tbody tr th.name button[name=delete] { font-size: .625em; line-height: 1.5em; background-color: #FAA; } + +body.poll table tbody tr.new td:first-child { text-align: right; } +body.poll table tbody tr.new td input[name=name] { min-width: 100%; width: 4em; } body.poll table td input[type=radio] { display: none; } body.poll table td input[type=radio] + label { -- 2.39.2