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;
41 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 form => 'Translation',
110 wptitle => 'Wikipedia',
111 source => 'Image URL',
112 thumb => 'Convert options',
114 cover => undef, # included with prio
117 my @prioenum = qw( essential basic common distinctive rare invisible );
118 my ($find) = map {{id => $_}} $fields{id} || $Request || ();
122 $row = $db->select(word => '*', $find)->hash
123 or Abort("Word not found", 404);
126 if (exists $get{copy}) {
127 $row = {%{$row}{ qw(prio lang cat) }};
129 elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
131 $row = {%post{ pairkeys @wordcols }};
132 $_ = length ? $_ : undef for values %{$row};
135 my %res = (returning => '*');
136 my $query = $find ? $db->update(word => $row, $find, \%res) :
137 $db->insert(word => $row, \%res);
140 Alert("Entry could not be saved", $@);
144 my $imgpath = "data/word/org/$row->{id}.jpg";
146 ($row->{source} // '') ne ($replace->{source} // '') or return;
147 # copy changed remote url to local file
148 unlink $imgpath if -e $imgpath;
149 my $download = $row->{source} or return 1;
150 require LWP::UserAgent;
151 my $ua = LWP::UserAgent->new;
153 my $status = $ua->mirror($download, $imgpath);
155 or die "Download from <q>$download</q> failed: ".$status->status_line."\n";
157 !$@ or Alert(["Source image not found", $@]);
159 $reimage ||= $row->{thumb} ~~ $replace->{thumb}; # different convert
160 $reimage ||= $row->{cover} ~~ $replace->{cover}; # resize
161 $reimage++ if $fields{rethumb}; # force refresh
163 my $thumbpath = "data/word/eng/$row->{form}.jpg";
166 my $xyres = $row->{cover} ? '600x400' : '300x200';
167 my @cmds = @{ $row->{thumb} // [] };
170 -delete => '1--1', -background => 'white',
171 -gravity => @cmds ? 'northwest' : 'center',
173 -resize => "$xyres^", -extent => $xyres,
174 '-strip', -quality => '60%', -interlace => 'plane',
175 $imgpath => $thumbpath
180 IPC::Run::run(\@cmds, '<' => \undef, '>&' => \$output)
182 ($? & 127 ? "signal $?" : "error code ".($? >> 8))."\n";
184 "Thumbnail image not generated",
185 "Failed to convert source image.",
195 $row->{$_} = $get{$_} for keys %get;
198 my $title = $row->{id} ? "entry <small>#$row->{id}</small>" : 'new entry';
200 <h1>Words <:= $title :></h1>
204 <form action="?" method="post">
205 <input id="id" name="id" value="<:= $row->{id} // '' :>" type="hidden" />
209 for my $colinfo (pairs @wordcols) {
210 my ($col, $title) = @{$colinfo};
211 defined $title or next;
212 my $val = $row->{$col} // '';
213 $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY';
214 printf '<li><label for="%s">%s</label><p>', $col, $title;
215 printf '<span class=inline>';
216 if ($col eq 'prio') {
217 printf '<select id="%s" name="%1$s">', $col;
218 printf('<option value="%s"%s>%s</option>',
219 $_, $row->{$col} eq $_ && ' selected', $prioenum[$_]
220 ) for 0 .. $#prioenum;
225 '<input id="%1$s" name="%1$s" value="0" type="hidden" />',
226 '<input id="%s" name="%1$s" value="1" type="checkbox"%s>',
229 'cover', !!$row->{cover} && ' checked', 'Highlighted'
233 printf '<input id="%s" name="%1$s" value="%s" />', $col, Entity($val);
234 -e and printf '<img src="/%s" alt="%s" />', $_, $row->{form} for
235 $col eq 'source' ? "data/word/org/$row->{id}.jpg" :
236 $col eq 'thumb' ? "data/word/eng/$row->{form}.jpg" :
245 <input type="submit" value="Save" />
246 <input type="submit" value="New" formaction="/writer?copy=cat" />
258 my $parents = $db->select(word => '*', {id => $row->{cat}});
259 while (my $ref = $parents->hash) {
260 printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
262 say "<li><strong>$row->{form}</strong></li>";
263 my $children = $db->select(word => '*', {cat => $row->{id}});
264 while (my $ref = $children->hash) {
265 printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
268 <li><form action="/writer">
269 <input type="hidden" name="cat" value="<:= $row->{id} :>" />
270 <input type="hidden" name="lang" value="<:= $row->{lang} :>" />
271 <input type="submit" value="Add" />