From: Paul Hänsch Date: Fri, 22 Jan 2021 23:30:54 +0000 (+0100) Subject: (re)introduced categories section X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=3a37ee43475797d728772ccb0633eb87979cd218;p=lobster (re)introduced categories section --- diff --git a/cards/categories/categories.css b/cards/categories/categories.css deleted file mode 100644 index 0a7f41f..0000000 --- a/cards/categories/categories.css +++ /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 . -*/ - -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 index 75223bb..0000000 --- a/cards/categories/categories.html.sh +++ /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 . - -cat_listing(){ - list_categories | while read cat; do - printf '
  • %s
  • \n' \ - "$(htmlsafe "$cat")" "$(attribsafe "$cat")" "$(l10n cat_remove)" - done -} - -list_catsel(){ - card="$1" - cats="$(get_categories "$card")" - - list_categories |while read cat; do - printf '
  • ' \ - "$(printf %s "$cats" |grep -qF "$cat" && printf 'checked="checked"')" \ - "$(attribsafe "$card")" "$(attribsafe "$cat")" "$(htmlsafe "$cat")" - done -} - -display_catsel(){ - card="$1" - printf '
  • %s

      ' "$(htmlsafe "$(get_name "$card")")" - list_catsel "$card" - printf '
  • ' -} - -cat < - -

    $(l10n categories_label)

    - -
      - $(cat_listing) -
    • - - -
    • -
    - - -
    -
    - -
    -
      -EOF -listcards \ -| while read card; do - display_catsel "$card" -done -cat < -
      - -
      - -EOF - diff --git a/cards/categories/categories.sh b/cards/categories/categories.sh deleted file mode 100755 index e875eef..0000000 --- a/cards/categories/categories.sh +++ /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 . - -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' -} diff --git a/cards/widgets.sh b/cards/widgets.sh index 1ead03e..52fca4e 100755 --- a/cards/widgets.sh +++ b/cards/widgets.sh @@ -38,7 +38,7 @@ cat <>"$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 index 0000000..236b1e3 --- /dev/null +++ b/categories/index.cgi @@ -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 . + +. $_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 <. -item_name[cat_remove]="-" -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 "-";; + 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 +} diff --git a/cards/categories/update_categories.sh b/categories/update_categories.sh similarity index 55% rename from cards/categories/update_categories.sh rename to categories/update_categories.sh index c3b2e4c..944c3d2 100755 --- a/cards/categories/update_categories.sh +++ b/categories/update_categories.sh @@ -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. # @@ -17,35 +17,25 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -. "$_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/ diff --git a/style.css b/style.css index e0faba6..80227ed 100644 --- 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; +}