4 title => 'words cheat sheet admin',
13 font-family: monospace;
17 display: inline-block;
18 box-sizing: border-box;
22 vertical-align: text-top;
28 use List::Util qw( pairs pairkeys );
32 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
33 ) or die "database not configured\n";
35 DBIx::Simple->new(@dbinfo[0..2], {
39 } or Abort('Database error', 501, $@);
42 form => 'Translation',
46 source => 'Image URL',
47 thumb => 'Convert options',
48 wptitle => 'Wikipedia',
50 my $find = $Request ? {id => $Request} : undef;
53 if ($ENV{REQUEST_METHOD} eq 'POST') {
54 $row = {%post{ pairkeys @wordcols }};
55 $_ = length ? $_ : undef for values %{$row};
57 my %res = (returning => $Request ? '*' : 'lang, cat');
58 my $query = $find ? $db->update(word => $row, $find, \%res) :
59 $db->insert(word => $row, \%res);
61 } or Alert("Entry could not be saved", $@);
64 $row = $db->select(word => '*', $find)->hash
65 or Abort("Word not found", 404);
68 my $title = $find ? "entry <small>#$Request</small>" : 'new entry';
70 <h1>Words <:= $title :></h1>
72 <form action="" method="post">
76 for my $col (pairs @wordcols) {
77 my $val = $row->{$col->key} // '';
78 $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY';
79 printf '<dt><label for="%s">%s</label></dt>'
80 . '<dd><input id="%1$s" name="%1$s" value="%s" />',
81 $col->key, $col->value, $val;
86 <p><input type="submit" value="Save" /></p>