]> git.plutz.net Git - confetti/commitdiff
reimplemented card listing
authorPaul Hänsch <paul@plutz.net>
Wed, 6 Feb 2019 01:44:01 +0000 (02:44 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 6 Feb 2019 01:44:01 +0000 (02:44 +0100)
cards/l10n.sh
cards/list.sh [new file with mode: 0755]
cards/main.cgi
cards/view_card.sh [deleted file]

index c9161733bbf8b14385605141eed975e005bf7497..48ee59ee4b706f2362c5586b26b06e5aefd7b18c 100755 (executable)
@@ -16,7 +16,9 @@
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
 l10n(){
-  case $1 in
+  local word
+  [ $# -eq 0 ] && read -r word || word="$1"
+  case $word in
     PHOTO) printf %s "Foto";;
     LOGO) printf %s "Logo";;
     FN) printf %s "Voller Name";;
@@ -89,10 +91,10 @@ l10n(){
     new_prescription) printf %s "Neue Verordnung";;
     no_icd) printf %s "Kein ICD Code";;
   
-    X-ZACK-JOINDATE) printf %s "An&shy;mel&shy;de&shy;da&shy;tum";;
+    X-ZACK-JOINDATE)  printf %s "An&shy;mel&shy;de&shy;da&shy;tum";;
     X-ZACK-LEAVEDATE) printf %s "Ab&shy;mel&shy;de&shy;da&shy;tum";;
-    label_join) printf %s "Anm.";;
-    label_leave) printf %s "Abm.";;
+    X-ZACK-JOINDATE_short)  printf %s "Anm.";;
+    X-ZACK-LEAVEDATE_short) printf %s "Abm.";;
   
     edit) printf %s "Bearbeiten";;
     edit_categories) printf %s "Kategorien Bearbeiten";;
diff --git a/cards/list.sh b/cards/list.sh
new file mode 100755 (executable)
index 0000000..cb33637
--- /dev/null
@@ -0,0 +1,125 @@
+#!/bin/sh
+
+. "${_EXEC}"/pdiread.sh
+
+card_fullname(){
+  local card="$1" n1 n2 n3 n4 n5
+
+  local N="$(pdi_value "$card" N)"
+  local FN="$(pdi_value "$card" FN)"
+  local NICKNAME="$(pdi_value "$card" NICKNAME)"
+
+  if [ "$FN" ]; then
+    printf %s "$FN"
+  elif [ "$N" ]; then
+    IFS=\; read n1 n2 n3 n4 n5 <<-EOF
+       $(pdi_value "$card" N)
+       EOF
+    printf '%s %s %s %s %s' "$n4" "$n2" "$n3" "$n1" "$n5"
+  elif [ "$NICKNAME" ]; then
+    printf '"%s"' "$NICKNAME"
+  fi
+}
+
+card_item(){
+  local card="$1"
+  local item cnt c
+  shift 1
+
+  for item in $@; do
+    cnt="$(pdi_count "$card" "$item")"
+
+    case $item in
+      FN) printf '[h2 .item .FN &shy;%s]' "$(card_fullname "$card" |HTML)"
+        ;;
+      GENDER) printf '[span .item .GENDER &shy;%s]' "$(pdi_value "$card" GENDER |l10n)"
+        ;;
+      NICKNAME) seq 1 $cnt |while read c; do
+          printf '[span .item .NICKNAME &shy;aka. "%s"]' \
+                 "$(pdi_value "$card" NICKNAME $c |HTML)"
+        done
+        ;;
+      X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then
+          printf '[span .item .%s [b %s:] %s]' \
+                 "$item" "$(l10n "${item}_short")" \
+                 "$(pdi_value "$card" "$item" |HTML)"
+        fi
+        ;;
+      BDAY) if [ $cnt -gt 0 ]; then
+          printf '[span .item .BDAY [b *:] %s]' \
+                 "$(pdi_value "$card" BDAY |grep -xE '[0-9-]+')"
+        fi
+        ;;
+      SOUND) if [ $cnt -gt 0 ]; then
+          printf '[audio .item .SOUND controls="controls"
+                    [source type="audio/ogg" src="data:audio/ogg;base64,%s"]
+                  ]' \
+                 "$(pdi_value "$card" SOUND |grep -xE '[a-zA-Z0-9/+=]+')"
+        fi
+        ;;
+      PHOTO|LOGO) if [ $cnt -gt 0 ]; then 
+          printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \
+                 "$(pdi_attrib "$card" "$item" |sed -r 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \
+                 "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')"
+        fi
+        ;;
+      EMAIL) if [ $cnt -gt 0 ]; then
+          printf '[h3 %s]' "$(l10n EMAIL)"
+          seq 1 $cnt |while read c; do
+            printf '[a .item .EMAIL href="mailto:%s" &shy;%s]' \
+                   "$(pdi_value "$card" EMAIL $c |HTML)" \
+                   "$(pdi_value "$card" EMAIL $c |HTML)"
+          done
+        fi
+        ;;
+      *) if [ $cnt -gt 0 ]; then
+          printf '[h3 %s]' "$(l10n "$item")"
+          seq 1 $cnt |while read c; do
+            printf '[span .item .%s &shy;%s]' "$item" \
+                   "$(pdi_value "$card" "$item" $c |HTML)"
+          done
+        fi
+        ;;
+    esac
+  done
+}
+
+print_card(){
+  local cardfile="$1"
+  local cachefile="${_DATA}/cache/${cardfile##*/}.cache"
+
+  if [ "$cachefile" -nt "$cardfile" -a "$cachefile" -nt "${_EXEC}/cards" ]; then
+    cat "$cachefile"
+  else
+    local card="$(pdi_load "$cardfile")"
+    tee "$cachefile" <<-EOF
+    [div .card #${cardfile##*/}
+      [div .section .basic &shy;$(
+        card_item "$card" FN GENDER NICKNAME BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE SOUND PHOTO LOGO
+      )]
+      [div .section .phone   &shy;$(card_item "$card" TEL)]
+      [div .section .message &shy;$(card_item "$card" EMAIL IMPP URL)]
+      [div .section .address &shy;$(card_item "$card" ADR)]
+      [div .section .note    &shy;$(card_item "$card" NOTE)]
+      [div .section .attendance [h3 $(l10n course_attendance) ] [ul &shy;
+        $(grep -F "    ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do
+          printf '[li [a .item .attendance href="/courses#%s" &shy;%s]]' \
+                 "$each" \
+                 "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY |HTML)"
+        done)]
+        $(card_item "$card" CATEGORIES)
+      ]
+      [div .control
+        [a .item href="/cards/${cardfile##*/}?action=edit" $(l10n edit)]
+        [a .item href="/cards/${cardfile##*/}?action=export" $(l10n vcf_export)]
+      ]
+    ]
+       EOF
+  fi
+}
+
+list_cards(){
+  for cardfile in "${_DATA}"/vcard/*.vcf; do
+    print_card "$cardfile"
+  done
+}
index bfc574f25d50998a8af7bd31b88c7f20ce58b64d..3cf8a23e0b1889a5418083a1ae1878d9124fdbe4 100755 (executable)
@@ -12,13 +12,14 @@ fi
 . $_EXEC/pdiread.sh
 . $_EXEC/cards/l10n.sh
 . $_EXEC/cards/widgets.sh
+. $_EXEC/cards/list.sh
 
 filter="$(GET filter)"
 order="$(GET order)"
 
 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
 
-$_EXEC/cgilite/html-sh.sed <<EOF
+{ cat <<EOF
 [!DOCTYPE XHTML]
 [html [head
   [title Cards]
@@ -31,6 +32,9 @@ $_EXEC/cgilite/html-sh.sed <<EOF
   [form class="newcard" action="?action=new_card" method="POST"
     [button type="submit" $(l10n newcard)]
   ]
-
-]]
 EOF
+list_cards
+printf ']]'
+
+} | "$_EXEC/cgilite/html-sh.sed"
+$_EXEC/cgilite/html-sh.sed <<EOF
diff --git a/cards/view_card.sh b/cards/view_card.sh
deleted file mode 100755 (executable)
index 13dbab7..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-# Copyright 2014 - 2017 Paul Hänsch
-#
-# This file is part of Confetti.
-# 
-# Confetti is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-# 
-# Confetti is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-# 
-# You should have received a copy of the GNU Affero General Public License
-# along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
-
-list_items(){
-  item="$1"
-  [ -n "${values[$item]+x}" ] && \
-    printf '<h3>%s</h3>\n' "$(l10n $item)"
-  for n in "$item" "$item"{0..100}; do
-    if [ -z "${values[$n]+x}" ]; then
-      break
-    else case "$item" in
-      EMAIL)
-        printf '<a class="item EMAIL" href="mailto:%s">%s</a>\n' \
-          "$(attribsafe "${values[$n]}")" "$(htmlsafe "${values[$n]}")"
-        ;;
-      *)
-        printf '<span class="item %s">%s</span>\n' \
-          "$item" "$(htmlsafe ${values[$n]})"
-        ;;
-    esac; fi
-  done
-}
-
-list_section(){
-  printf '<div class="section %s">' "$1"
-  shift 1
-  for each in $@; do
-    list_items "$each"
-  done
-  printf '</div>'
-}
-
-n=$(printf %s "$values[N+3] $values[N+1] $values[N+2] $values[N+0] $values[N+4]" \
-    | sed -r ':X;$!{N;bX}; s;^[\n ]+;;; s;[\n ]+$;;; s;[\r\t\n ]+; ;g;'
-   )
-fullname="${n:-${values[FN]:-${values[NICKNAME]}}}"
-
-hi_company="${values[X-HEALTH-INSURANCE+0]}"
- hi_number="${values[X-HEALTH-INSURANCE+1]}"
- hi_status="${values[X-HEALTH-INSURANCE+2]}"
-
-printf '<div class="section basic">
-    <h2 class="item FN">%s</h2>
-' "$fullname"
-[ -n "$values[GENDER]" ] && printf '
-  <span class="item GENDER">%s</span>
-  ' "$(l10n "$values[GENDER]")"
-
-for n in NICKNAME NICKNAME{0..100}; do
-  [ -z "${values[$n]+x}" ] && break \
-  || printf '
-      <span class="item NICKNAME">aka. %s</span>
-  ' "$(htmlsafe ${values[$n]})"
-done
-
-[ -n "$values[BDAY]" ] && printf '
-  <span class="item BDAY"><b>*:</b> %s</span>
-  ' "$(htmlsafe "$values[BDAY]")"
-[ -n "$values[X-ZACK-JOINDATE]" ] && printf '
-  <span class="item X-ZACK-JOINDATE"><b>%s:</b> %s</span>
-  ' "$(l10n label_join)" "$(htmlsafe "$values[X-ZACK-JOINDATE]")"
-[ -n "$values[X-ZACK-LEAVEDATE]" ] && printf '
-  <span class="item X-ZACK-LEAVEDATE"><b>%s:</b >%s</span>
-  ' "$(l10n label_leave)" "$(htmlsafe "$values[X-ZACK-LEAVEDATE]")"
-
-[ -n "$values[SOUND]" ] && printf '
-  <audio controls="controls" class="item SOUND">
-    <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
-  </audio>' "$values[SOUND]"
-
-[ -n "$values[PHOTO]" ] && printf '
-  <img class="item PHOTO" src="data:image/%s;base64,%s" />
-  ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
-
-[ -n "$values[LOGO]" ] && printf '
-  <img class="item PHOTO" src="data:image/%s;base64,%s" />
-  ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
-
-if [ "$PROFILE" = circus ]; then
-  printf '</div>'
-
-  list_section phone TEL
-  list_section message EMAIL IMPP URL
-  list_section address ADR
-  list_section note NOTE
-
-  printf '<div class="section attendance"><h3>%s</h3><ul>' "$(l10n course_attendance)"
-  sed -rn 's:(.*)\t'"$id"'$:\1:p' "$_DATA/mappings/attendance" |while read each; do
-    cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
-    printf '   <li><a class="item attendance" href="?p=courses#%s">%s</a></li>' "$each" "$(htmlsafe $cname)"
-  done
-  printf '</ul>'
-  list_items CATEGORIES
-  printf '</div>'
-
-elif [ "$PROFILE" = medical ]; then
-  list_items ADR
-  list_items URL
-  printf '</div>'
-
-  list_section phone TEL EMAIL IMPP
-
-  printf '<div class="section insurance"><h3>%s</h3>' "$(l10n X-HEALTH-INSURANCE)"
-  [ -n "$hi_company" ] && printf '<span class="item hi_comapany">%s</span>' \
-    "$(htmlsafe "$hi_company")"
-  [ -n "$hi_number" ] && printf '<span class="item hi_number"><label>%s:</label> %s</span>' \
-    "$(l10n hi_number)" "$(htmlsafe "$hi_number")"
-  [ -n "$hi_status" ] && printf '<span class="item hi_status"><label>%s:</label> %s</span>' \
-    "$(l10n hi_status)" "$(htmlsafe "$hi_status")"
-  printf '</div>'
-
-  list_section note NOTE X-CLIENT-REFERRAL
-
-  printf '<div class="section prescriptions"><h3>%s</h3><ul>' "$(l10n prescriptions)"
-  declare -A mpx
-  find "$_DATA/prescriptions/" -name "${id%.vcf}.*.mpx" \
-  | while read pfile; do
-    mpx=(); cat "$pfile" |while read -r line; do
-      val="${line#*:}"
-      mpx[${line%%:*}]="$(htmlsafe "${val//\\n/$BR}")"
-    done
-    printf '<li><a href="?p=prescriptions&amp;client=%s#%s" >%s: %s - %s</a></li>' \
-      "${id}" "${pfile##*/}" "${mpx[date]}" "${mpx[indicator]}" \
-      "$([ -n "${mpx[remidy]}" ] && printf '%s %s' "${mpx[quantity]}" "${mpx[remidy]}" 
-         for n in {0..10}; do
-           [ -n "${mpx[remidy${n}]}" ] && printf ', %s %s' "${mpx[quantity${n}]}" "${mpx[remidy${n}]}" 
-         done
-       )"
-  done |sort -r
-  printf '</ul></div>'
-fi