CREATE TABLE word (
form text NOT NULL,
+ lang text NOT NULL DEFAULT 'eng',
cat integer REFERENCES word (id),
+ ref integer REFERENCES word (id),
source text,
thumb text[],
+ wptitle text,
created timestamptz DEFAULT now(),
id serial NOT NULL PRIMARY KEY
);
COMMENT ON COLUMN word.form IS 'preferred textual representation';
+COMMENT ON COLUMN word.lang IS 'ISO 639-3 language code';
COMMENT ON COLUMN word.cat IS 'hierarchical classification';
+COMMENT ON COLUMN word.ref IS 'reference to equivalent eng translation';
COMMENT ON COLUMN word.source IS 'URI of downloaded image';
COMMENT ON COLUMN word.thumb IS 'ImageMagick convert options to create thumbnail from source image';
+COMMENT ON COLUMN word.wptitle IS 'reference Wikipedia article';
--- /dev/null
+<(common.inc.plp)><:
+
+Html({
+ title => 'words cheat sheet admin',
+ version => '1.0',
+ nocache => 1,
+});
+
+use List::Util qw( pairs pairkeys );
+
+my $db = eval {
+ my @dbinfo = (
+ 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
+ ) or die "database not configured\n";
+ require DBIx::Simple;
+ DBIx::Simple->new(@dbinfo[0..2], {
+ RaiseError => 1,
+ pg_enable_utf8 => 1,
+ });
+} or Abort('Database error', 501, $@);
+
+my @wordcols = (
+ form => 'Translation',
+ ref => 'Reference',
+ cat => 'Category',
+ lang => 'Language',
+ source => 'Image URL',
+ thumb => 'Convert options',
+ wptitle => 'Wikipedia',
+);
+my $find = $Request ? {id => $Request} : undef;
+
+my $row;
+if ($ENV{REQUEST_METHOD} eq 'POST') {
+ $row = {%post{ pairkeys @wordcols }};
+ $_ = length ? $_ : undef for values %{$row};
+ eval {
+ my %res = (returning => $Request ? '*' : 'lang, cat');
+ my $query = $find ? $db->update(word => $row, $find, \%res) :
+ $db->insert(word => $row, \%res);
+ $row = $query->hash;
+ } or Alert("Entry could not be saved", $@);
+}
+elsif ($find) {
+ $row = $db->select(word => '*', $find)->hash
+ or Abort("Word not found", 404);
+}
+
+my $title = $find ? "entry <small>#$Request</small>" : 'new entry';
+:>
+<h1>Words <:= $title :></h1>
+
+<form action="" method="post">
+<dl>
+<:
+
+for my $col (pairs @wordcols) {
+ printf '<dt><label for="%s">%s</label></dt>'
+ . '<dd><input id="%1$s" name="%1$s" value="%s" />',
+ $col->key, $col->value, $row->{$col->key} // '';
+ say '</dd>';
+}
+:>
+</dl>
+<p><input type="submit" value="Save" /></p>
+</form>