]> git.plutz.net Git - busy/blob - Tasks.page
basic user interface for creating a task
[busy] / Tasks.page
1 #!/bin/zsh
2
3 info="$(egrep -o '(^|&)(i=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
4 edit="$(egrep -o '(^|&)(e=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&e=')"
5 search="$(egrep -o '(^|&)(s=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?s=::;s:\+: :g;s:%:\\x:g')"
6 search="$(echo -e "${search}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
7 new="$(egrep -o '(^|&)(n=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?n=::;s:\+: :g;s:%:\\x:g')"
8 new="$(echo -e "${new}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
9
10 cat <<TasksEND
11   <div id="LEFT">
12     <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
13       <input type="hidden" name="p" value="Tasks">
14       <input type="text" name="s" placeholder="Search"><br>
15       <input type="submit" value="Search Tasks">
16     </form>
17     <hr>
18 TasksEND
19 if [ -n "$search" ]; then
20   echo "<h1>Tasks search results for: $search</h1>"
21   for each in $(grep -ile "$search" Tasks/<0000000000-9999999999>_<000-999>.task); do
22     id=$(sed -r 's:^.*/::;s:.task$::' <<<$each)
23     echo "<div class='search'><a href='#task_$id'><h2>$(date -d @$(cut -d_ -f1 <<<"$id"))</h2></a>"
24     grep -C1 -ie "$search" "$each" |sed "s:$search:<b>&</b>:g;s:$:<br>:g"
25     echo '</div>'
26   done
27   echo '<hr>'
28 fi
29 echo '</div><div id="MAIN">'
30
31 [ -n "$new" ] && cat <<TaskEnd
32 <form class="Task" style="height:20em;" method="post" action="write/taskmeta.cgi" accept-charset="UTF-8">
33   <h1>$new</h1>
34   <input type="hidden" name="headline" value="$new">
35   <input type="hidden" name="status" value="new">
36   <div style="width:60%;left:3.5em;">
37     <b>Description:</b><br>
38     <textarea name="description" rows="11"></textarea>
39   </div><div style="width:30%;right:.5em;">
40     <b>Section:</b><br>
41     <select name="section" size="6" style="width:80%">
42     $(for each in $(egrep -x 'section=.+' Tasks/<0000000000-9999999999>_<000-999>.meta |sort -u); do
43         echo "<option>$(sed 's:section=::' <<<"$each")</option>"
44       done)
45     </select><br>
46     <b>other section:</b><br>
47     <input type="text" name="section">
48     <input type="submit" value="Create Task">
49   </div>
50 </form>
51 TaskEnd
52
53 [ -z "$new" ] && stat -c '' Tasks/<0000000000-9999999999>_<000-999>.meta && for each in Tasks/<0000000000-9999999999>_<000-999>.meta(.om); do
54   headline="$(egrep -x 'headline=.+' "$each" |sed 's:headline=::')"
55   status="$(egrep -x 'status=.+' "$each" |sed 's:status=::')"
56   section="$(egrep -x 'section=.+' "$each" |sed 's:section=::')"
57   attendant="$(egrep -x 'attendant=.+' "$each" |sed 's:attendant=::')"
58   cat <<TasksEND
59    <div class="Task">
60      <b>$headline</b><br>
61      <span><b>Status:</b> $status</span>
62      <span><b>Section:</b> $Section</span>
63      <span><b>Attendant:</b> $attendant</span>
64    </div>
65 TasksEND
66 done
67
68 echo '</div> <div id="RIGHT">'
69 $LOGIN && [ -z "$new" ] && cat <<TasksEND
70       <a id='newTask_button' class='function' href='#' onclick='javascript:show_screen("newTask");hide_screen("newTask_button");'>New Task</a>
71       <div id="newTask" style="display: none;">
72         <form action="/${SCRIPTNAME}" method="get" accept-charset="UTF-8">
73           <b>Headline:</b><br>
74           <input type="hidden" name="p" value="Tasks">
75           <textarea name="n" rows="2" style="width:99%;"></textarea><br>
76           <input type="submit" value="Submit">
77           <a class="function" href="#" onclick="javascript:hide_screen('newTask');show_screen('newTask_button');">Cancel</a>
78         </form>
79       </div>
80 TasksEND
81 echo '</div>'