]> git.plutz.net Git - confetti/commitdiff
(re)introduced categories section
authorPaul Hänsch <paul@plutz.net>
Fri, 22 Jan 2021 23:30:54 +0000 (00:30 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 22 Jan 2021 23:30:54 +0000 (00:30 +0100)
cards/categories/categories.css [deleted file]
cards/categories/categories.html.sh [deleted file]
cards/categories/categories.sh [deleted file]
cards/widgets.sh
categories/edit_categories.sh [moved from cards/categories/edit_categories.sh with 81% similarity]
categories/index.cgi [new file with mode: 0755]
categories/l10n.sh [moved from cards/categories/text_categories.sh with 63% similarity, mode: 0644]
categories/update_categories.sh [moved from cards/categories/update_categories.sh with 55% similarity]
style.css

diff --git a/cards/categories/categories.css b/cards/categories/categories.css
deleted file mode 100644 (file)
index 0a7f41f..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
-# Copyright 2014, 2015, 2018 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/>. 
-*/
-
-form.categories {
-  display: block;
-  border: solid 1px;
-  border-radius: 4px 4px 0 0;
-  margin: .5em 2em .25em 2em;
-  padding: 0 2ex .5em 2ex;
-  background: #EFF;
-}
-
-form.categories h1 {
-  display: block;
-  font-weight: bold;
-  font-size: 1.25em;
-  border-style: none none solid none;
-  border-radius: 4px 4px 0 0;
-  border-width: 1px;
-  margin: 0 -1.625ex .5em -1.625ex;
-  padding: .125em 1ex;
-  background: #EEF;
-}
-
-form.categories ul { margin: 0; padding: 0; }
-form.categories ul li {
-  display: inline-block;
-  margin: 0 .25ex;
-  padding: .125em .25ex .125em 1ex;
-  border: 1px solid black;
-  background-color: #EEF;
-}
-form.categories ul li button {
-  margin: 0 0 0 1ex;
-  background-color: #FCC;
-  border: 1px solid black;
-  min-width: 3ex;
-  text-align: center;
-}
-form.categories ul li:last-of-type { padding: .125em .25ex .125em .25ex; }
-form.categories ul li:last-of-type button { background-color: #FFF; }
-
-form.namelist {
-  display: block;
-  margin: 1em 2em;
-  padding: 0;
-}
-form.namelist > fieldset {
-  display: block;
-  border: solid 1px;
-  border-radius: 4px 4px 0 0;
-  margin: 0; padding: .25em 2ex;
-  background: #EFF;
-  text-align: right;
-}
-form.namelist > fieldset:last-of-type {
-  border-radius: 0 0 4px 4px;
-}
-ul.namelist { margin: 0; padding: 0;}
-ul.namelist > li {
-  display: block;
-  border: solid 1px;
-  margin: -1px 0;
-  background: #FFF;
-}
-ul.namelist > li:nth-of-type(2n){ background: #EEE;}
-
-ul.namelist h2 {
-  font-size: 1em;
-  display: inline-block;
-  margin: 0;
-  padding: 0 1ex;
-  min-width: 30ex;
-}
-ul.namelist ul { margin: 0; padding: 0; display: inline-block;}
-ul.namelist ul li {
-  display: inline-block;
-  margin: 0 1ex 0 0;
-}
-
-.fakeorder {
-  position: absolute;
-  width: 0; height: 0;
-  left: -100%;
-}
diff --git a/cards/categories/categories.html.sh b/cards/categories/categories.html.sh
deleted file mode 100755 (executable)
index 75223bb..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-# Copyright 2015, 2017, 2018 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/>. 
-
-cat_listing(){
-  list_categories | while read cat; do
-    printf '<li>%s<button type="submit" name="remove" value="%s">%s</button></li>\n' \
-           "$(htmlsafe "$cat")" "$(attribsafe "$cat")" "$(l10n cat_remove)"
-  done
-}
-
-list_catsel(){
-  card="$1"
-  cats="$(get_categories "$card")"
-
-  list_categories |while read cat; do
-    printf '<li><label><input %s type="checkbox" name="%s" value="%s">%s</label></li>' \
-          "$(printf %s "$cats" |grep -qF "$cat" && printf 'checked="checked"')" \
-           "$(attribsafe "$card")" "$(attribsafe "$cat")" "$(htmlsafe "$cat")" 
-  done
-}
-
-display_catsel(){
-  card="$1"
-  printf '<li><h2>%s</h2><ul>' "$(htmlsafe "$(get_name "$card")")"
-  list_catsel "$card"
-  printf '</ul></li>'
-}
-
-cat <<EOF
-<form class="categories" action="?action=edit_categories" method="POST">
-  <input type="submit" class="fakeorder" name="add" value="add" />
-  <h1>$(l10n categories_label)</h1>
-  <input type="hidden" name="page" value="categories"/>
-  <ul>
-    $(cat_listing)
-    <li>
-      <input type="text" name="newcat" placeholder="$(l10n cat_newlabel)">
-      <button type="submit" name="add" value="add">$(l10n cat_add)</button>
-    </li>
-  </ul>
-</form>
-
-<form class="namelist" action="?action=update_categories" method="POST">
-  <fieldset>
-    <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
-  </fieldset>
-  <ul class="namelist">
-EOF
-listcards \
-| while read card; do
-  display_catsel "$card"
-done
-cat <<EOF
-  </ul>
-  <fieldset>
-    <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
-  </fieldset>
-</form>
-EOF
-
diff --git a/cards/categories/categories.sh b/cards/categories/categories.sh
deleted file mode 100755 (executable)
index e875eef..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/zsh
-
-# Copyright 2015, 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/>. 
-
-catfile="${_DATA}/mappings/categories"
-
-listcards() {
-  for file in "${_DATA}/vcard/"*.vcf; do
-    printf '%s\t%s\n' \
-      "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" \
-      "$file"
-  done \
-  | sort \
-  | sed -r 's;^.*\t(.*/)([^/]+)$;\2;'
-}
-
-get_name() {
-  cfile="${_DATA}/vcard/$1"
-  sed -rn 's;^N(\;[^":]+|\;"[^"]+")*:([^\;]*)(\;[^\;]*)(\;[^\;]*)?(\;[^\;]*)?(\;[^\;]*)?\r?$;\5 \3 \4 \2 \6;;
-           tX; b; :X s;[,\; ]+; ;g; p;' "$cfile"
-}
-
-get_categories(){
-  cfile="${_DATA}/vcard/$1"
-  sed -rn 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:(.+)\r?$;\2;;
-           tX; b; :X
-           s;(^|[^\\]+)((\\\\)+),;\1\2\n;g;
-           s;(^|[^\\]),;\1\n;g; s;(^|[^\\]+)((\\\\)+),;\1\2\n;g;
-           s;(^|[^\\]),;\1\n;g; s;\\,;,;g; p;' "$cfile" \
-  | sort -u
-}
-
-list_categories() {
-  sort -u "$catfile" \
-  | sed -r '/^[\t ]*$/d'
-}
index 1ead03ec284c487ecd8331ccafce146f138954ea..52fca4e25e9b9e52e8fd9df0cb526fd1e5f896e6 100755 (executable)
@@ -38,7 +38,7 @@ cat <<EOF
                  "$(printf %s "$cat" |grep -qxEe "$2" && printf checked )" \
                  "$(HTML "$cat")"
       done)
-      [a href="/cards/categories.sh" $(l10n edit_categories)]
+      [a href="/categories/" $(l10n edit_categories)]
     ]
   ]
 EOF
similarity index 81%
rename from cards/categories/edit_categories.sh
rename to categories/edit_categories.sh
index 2c34d264d224e4d0ec65369eb5de4ddc3786dbb9..fe97790135a852feac12b1408800267e22ddd7dc 100755 (executable)
 
 catfile="${_DATA}/mappings/categories"
 
-remove="${_POST[remove]}"
-newcat="${_POST[newcat]}"
+remove="$(POST remove)"
+newcat="$(POST newcat)"
 
-if [ "${_POST[add]}" = "add" ]; then
+if [ "$(POST add)" = "add" ]; then
   printf %s\\n "$newcat" >>"$catfile"
-elif [ -n "$remove" ]; then
-  sed -ri '/^'"${remove}"'$/d' $catfile
+elif [ "$remove" ]; then
+  sed -Ei '/^'"${remove}"'$/d' "$catfile"
 fi
 
-redirect "?p=categories"
+REDIRECT "/categories/"
diff --git a/categories/index.cgi b/categories/index.cgi
new file mode 100755 (executable)
index 0000000..236b1e3
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Copyright 2015, 2017, 2018, 2021 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/>. 
+
+. $_EXEC/pdiread.sh
+. $_EXEC/categories/l10n.sh
+
+catfile="${_DATA}/mappings/categories"
+
+list_categories() {
+  grep -vxE '[  ]*' "$catfile" |sort -u
+}
+
+list_catsel(){
+  local vcf="$1" card="$2" n=1 cats="${BR}"
+  while cats="${cats}${BR}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n + 1)); done
+
+  list_categories |while read cat; do
+    printf '[li [label [input %s type="checkbox" name="%s" value="%s"] %s]]' \
+          "$([ "${cats%*${BR}${cat}${BR}*}" != "$cats" ] && printf checked=checked)" \
+           "$(HTML "$card")" "$(HTML "$cat")" "$(HTML "$cat")" 
+  done
+}
+
+cat <<EOF |yield_page categories
+[form .categories action="edit_categories.sh" method="POST"
+  [h1 $(l10n categories_label)]
+  [input type="hidden" name="page" value="categories"]
+  [ul
+    $(list_categories | while read cat; do
+      printf '[li . %s [button type="submit" name="remove" value="%s" . %s]]\n' \
+             "$(HTML "$cat")" "$(HTML "$cat")" "$(l10n cat_remove)"
+    done)
+    [li
+      [input type="text" name="newcat" placeholder="$(l10n cat_newlabel)"]
+      [button type="submit" name="add" value="add" . $(l10n cat_add)]
+    ]
+  ]
+]
+
+[form .namelist action="update_categories.sh" method="POST"
+  [fieldset
+    [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
+  ]
+  [ul .namelist
+  $(for vcffile in "$_DATA"/vcard/*vcf; do
+    vcf="$(pdi_load "$vcffile")"
+    printf '    [li [h2 . %s][ul ' "$(pdi_value "$vcf" FN)"
+    list_catsel "$vcf" "${vcffile##*/}"
+    printf ']]\n'
+  done |sort)
+  ]
+  [fieldset
+    [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
+  ]
+]
+EOF
old mode 100755 (executable)
new mode 100644 (file)
similarity index 63%
rename from cards/categories/text_categories.sh
rename to categories/l10n.sh
index 00c61ce..c0e6421
@@ -1,4 +1,4 @@
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014, 2015, 2016, 2019, 2021 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
-item_name[cat_remove]="&#45;"
-item_name[cat_add]="+"
-item_name[cat_newlabel]="neue Kategorie"
-item_name[cat_update]="Zuweisungen übernehmen"
-item_name[categories_label]="Kategorien"
+l10n(){
+  local word
+  [ $# -eq 0 ] && read -r word || word="$*"
+  case $word in
+    cat_remove) printf %s "&#45;";;
+    cat_add) printf %s "+";;
+    cat_newlabel) printf %s "neue Kategorie";;
+    cat_update) printf %s "Zuweisungen übernehmen";;
+    categories_label) printf %s "Kategorien";;
+
+    *) l10n_global "$word";;
+  esac
+}
similarity index 55%
rename from cards/categories/update_categories.sh
rename to categories/update_categories.sh
index c3b2e4c3f71dc9709b16b21322134e27cf31d0ef..944c3d2616601f2cbb83930b590168c25b4f39e2 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/zsh
+#!/bin/sh
 
-# Copyright 2016 Paul Hänsch
+# Copyright 2016, 2021 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
-. "$_EXEC"/pages/categories.sh
+. "$_EXEC"/cgilite/storage.sh
+. "$_EXEC"/pdiread.sh
 
 catfile="${_DATA}/mappings/categories"
 
-set_categories(){
-  card="${_DATA}/vcard/$1"
-  cats="$2"
-  cardcats="$(sed -nr 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:([^\r]+)\r?$;\2;p' "$card")"
+for card in "${_DATA}"/vcard/*.vcf; do
+  n='' postcats='' cardcats=''
+  vcf="$(pdi_load "$card")"
 
-  debug "CARD: $card"
-  debug "CATS: $cardcats"
-  debug "NEW:  $cats"
-  if [ "$cats" != "$cardcats" ]; then
+  n=1; while postcats="${postcats}${postcats:+,}$(POST "${card##*/}" $n)"; do n=$((n+1)); done
+  n=1; while cardcats="${cardcats}${cardcats:+,}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n+1)); done
+
+  if [ "${postcats}" != "${cardcats}" ] && LOCK "$card"; then
     sed -ri '
       /^CATEGORIES[;:]/d
-      /^END:VCARD *\r?$/iCATEGORIES:'"$cats"'\r
+      /^END;?:VCARD *\r?$/iCATEGORIES:'"${postcats%,}"'\r
     ' "${card}"
+    RELEASE "$card"
   fi
-}
-
-listcards |while read card; do
-  cardcats=''
-  for n in "$card" "$card"{0..100}; do
-    if [ -z "${_POST[$n]}" ]; then
-      set_categories "$card" "$cardcats"
-      break
-    fi
-    cardcats="${cardcats}${cardcats:+,}${_POST[$n]}"
-  done
 done
 
-redirect "?p=categories"
+REDIRECT /categories/
index e0faba6c7957635392d0700320ecfe774c51f393..80227ede548d5be7c2f9819263e8a4dff356b581 100644 (file)
--- a/style.css
+++ b/style.css
@@ -1,6 +1,7 @@
 * {
   position: relative;
   box-sizing: border-box;
+  max-width: 100%;
   font-family: sans-serif;
   font-weight: normal;
   font-size: initial;
@@ -117,6 +118,7 @@ body.courses > .menu a[href="/courses/"] {
 
 /* =========== FILTER AND SEARCH Headers ========= */
 
+form.categories,
 form.search, form.sort, form.filter, form.newcard, form.newcourses {
   margin-top: 1em; padding: 0 1em;
   z-index: 1;
@@ -132,6 +134,7 @@ form.filter fieldset.item input[type=radio] + label {
   background-color: #EEE;
   border-style: solid;
   border-width: .5pt .25pt 0 .25pt;
+  white-space: normal;
 }
 form.filter fieldset.item input[type=radio] + label:first-of-type {
   border-left: 1pt solid;
@@ -403,3 +406,41 @@ form.course .attendance label {
   margin-bottom: 0;
 }
 form.course .attendance input { margin-top: .375em; }
+
+/* ======== Categories Page ======== */
+
+body.categories form ul { list-style: none; margin: 0; }
+
+form.categories li {
+  display: inline-block;
+  background-color: #EEE;
+  margin-right: .5em; margin-bottom: .5em;
+  padding-left: .5em;
+  box-shadow: .125em .125em .25em;
+}
+form.categories li button[name=remove] {
+  font-size: .75em;
+  width: 2.5em;
+  background-color: #FBB;
+  overflow: hidden;
+  white-space: pre;
+}
+form.categories li button[name=remove]:before {
+  content: '\274C ';
+  margin-right: 3em;
+}
+
+form.categories li:last-child { padding-left: 0 }
+
+body.categories form.namelist ul.namelist > li:nth-of-type(2n + 1) { background-color: #EEE; }
+body.categories form.namelist ul.namelist > li h2,
+body.categories form.namelist ul.namelist > li ul {
+  display: inline-block;
+}
+body.categories form.namelist ul.namelist > li h2 {
+  width: 20%;
+  min-width: 10em;
+}
+body.categories form.namelist ul.namelist > li ul li {
+  display: inline-block;
+}