4 title => 'words cheat sheet admin',
11 grid: auto-flow / min-content repeat(10, auto);
16 border-spacing: 0 2px;
25 form > ul > li > label {
29 form > ul > li > label + * {
35 box-sizing: border-box;
38 font-family: monospace;
44 padding: .3rem .2rem; /* TODO: input */
58 background: rgba(0, 0, 0, .8);
59 border: 1px solid #CCC;
68 margin: 0 -1ex; /* inner gap */
78 -margin-left: 1em; /* flex gap */
84 display: inline-block;
88 <script src="/writer.js"></script>
92 use List::Util qw( pairs pairkeys );
96 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
97 ) or die "database not configured\n";
99 DBIx::Simple->new(@dbinfo[0..2], {
103 } or Abort('Database error', 501, $@);
108 ref => undef, # included with cat
111 cover => undef, # included with prio
114 wptitle => 'Wikipedia',
116 thumb => 'Convert options',
118 my @prioenum = qw( essential basic common distinctive rare invisible );
120 nld => "\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}",
121 eng => "\N{REGIONAL INDICATOR SYMBOL LETTER G}\N{REGIONAL INDICATOR SYMBOL LETTER B}",
122 epo => '<span style="color:green">★</span>',
124 my ($find) = map {{id => $_}} $fields{id} || $Request || ();
128 $row = $db->select(word => '*', $find)->hash
129 or Abort("Word not found", 404);
132 if (exists $get{copy}) {
133 $row = {%{$row}{ qw(prio lang cat) }};
135 elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
137 $row = {%post{ pairkeys @wordcols }};
138 $_ = length ? $_ : undef for values %{$row};
141 my %res = (returning => '*');
142 my $query = $find ? $db->update(word => $row, $find, \%res) :
143 $db->insert(word => $row, \%res);
146 Alert("Entry could not be saved", $@);
150 my $imgpath = "data/word/org/$row->{id}.jpg";
152 ($row->{source} // '') ne ($replace->{source} // '') or return;
153 # copy changed remote url to local file
154 unlink $imgpath if -e $imgpath;
155 my $download = $row->{source} or return 1;
156 require LWP::UserAgent;
157 my $ua = LWP::UserAgent->new;
159 my $status = $ua->mirror($download, $imgpath);
161 or die "Download from <q>$download</q> failed: ".$status->status_line."\n";
163 !$@ or Alert(["Source image not found", $@]);
165 $reimage ||= $row->{thumb} ~~ $replace->{thumb}; # different convert
166 $reimage ||= $row->{cover} ~~ $replace->{cover}; # resize
167 $reimage++ if $fields{rethumb}; # force refresh
169 my $thumbpath = "data/word/eng/$row->{form}.jpg";
172 my $xyres = $row->{cover} ? '600x400' : '300x200';
173 my @cmds = @{ $row->{thumb} // [] };
176 -delete => '1--1', -background => 'white',
177 -gravity => @cmds ? 'northwest' : 'center',
179 -resize => "$xyres^", -extent => $xyres,
180 '-strip', -quality => '60%', -interlace => 'plane',
181 $imgpath => $thumbpath
186 IPC::Run::run(\@cmds, '<' => \undef, '>&' => \$output)
188 ($? & 127 ? "signal $?" : "error code ".($? >> 8))."\n";
190 "Thumbnail image not generated",
191 "Failed to convert source image.",
201 $row->{$_} = $get{$_} for keys %get;
204 my $title = $row->{id} ? "entry <small>#$row->{id}</small>" : 'new entry';
206 <h1>Words <:= $title :></h1>
210 <form action="?" method="post">
211 <input id="id" name="id" value="<:= $row->{id} // '' :>" type="hidden" />
215 for my $colinfo (pairs @wordcols) {
216 my ($col, $title) = @{$colinfo};
217 defined $title or next;
218 my $val = $row->{$col} // '';
219 $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY';
220 printf '<li><label for="%s">%s</label><p>', $col, $title;
221 printf '<span class=inline>';
222 if ($col eq 'prio') {
223 printf '<select id="%s" name="%1$s">', $col;
224 printf('<option value="%s"%s>%s</option>',
225 $_, $row->{$col} eq $_ && ' selected', $prioenum[$_]
226 ) for 0 .. $#prioenum;
231 '<input id="%1$s" name="%1$s" value="0" type="hidden" />',
232 '<input id="%s" name="%1$s" value="1" type="checkbox"%s>',
235 'cover', !!$row->{cover} && ' checked', 'Highlighted'
237 printf('<label for="%s">%s</label><input id="%1$s" name="%1$s" value="%s" type="number" />',
238 'grade', 'Order', Entity($row->{grade})
242 printf '<input id="%s" name="%1$s" value="%s" />', $col, Entity($val);
243 -e and printf '<img src="/%s" alt="%s" />', $_, $row->{form}
244 for $col eq 'thumb' ? "data/word/eng/$row->{form}.jpg" : ();
245 printf('<label for="%s">%s</label><input id="%1$s" name="%1$s" value="%s" />',
246 'ref', 'Reference', Entity($row->{ref})
250 -e and printf('<img id="%spreview" src="/%s" alt="%s" hidden />',
251 $col, $_, $row->{form}
252 ) for $col eq 'source' ? "data/word/org/$row->{id}.jpg" : ();
257 my $children = $db->select(word => '*', {ref => $row->{id}}, 'lang, id');
258 printf '<li><label>%s</label><div><ul class="inline">', 'Translations';
259 while (my $row = $children->hash) {
260 printf '<li><label for="%s">%s</label> <a id="%1$s" href="%s">%s</a></li>',
261 "trans-$row->{lang}", $langflag{$row->{lang}},
262 "/writer/$row->{id}", Entity($row->{form});
264 say '</ul></div></li>';
269 <input type="submit" value="Save" />
270 <input type="submit" value="New" formaction="/writer?copy=cat" />
282 my $parents = $db->select(word => '*', {id => $row->{cat}});
283 while (my $ref = $parents->hash) {
284 printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
286 say "<li><strong>$row->{form}</strong></li>";
287 my $children = $db->select(word => '*', {cat => $row->{id}}, 'grade, id');
288 while (my $ref = $children->hash) {
289 printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
292 <li><form action="/writer">
293 <input type="hidden" name="cat" value="<:= $row->{id} :>" />
294 <input type="hidden" name="lang" value="<:= $row->{lang} :>" />
295 <input type="submit" value="Add" />