X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/ae4ac683abb8a60d182b948bf7b5b6b31a729975..74d561810b2bf81617b84bc1581d8b59c359d5c9:/writer.plp diff --git a/writer.plp b/writer.plp index b549917..493f745 100644 --- a/writer.plp +++ b/writer.plp @@ -5,98 +5,7 @@ Html({ version => '1.0', nocache => 1, raw => <<'EOT', - - + EOT }); @@ -104,16 +13,9 @@ EOT 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, - }); + require Shiar_Sheet::DB; + Shiar_Sheet::DB->connect; } or Abort('Database error', 501, $@); -$db->abstract->{array_datatypes}++; my $user = eval { if (defined $post{username}) { @@ -178,9 +80,14 @@ my %wordcol = ( cat => [{-label => 'Category'}, 'ref'], ref => {-label => 'Reference'}, prio => [ - {-label => 'Level', -select => [qw( - essential basic common distinctive rare invisible - )]}, + {-label => 'Level', -select => sub { + my ($row) = @_; + my @enum = qw[ essential basic common distinctive optional invisible ]; + return { + ('' => 'parent') x (defined $row->{ref}), + map { $_ => $enum[$_] } 0 .. $#enum + }; + }}, 'cover', 'grade', ], cover => {-label => 'Highlighted', type => 'checkbox'}, @@ -250,6 +157,7 @@ elsif (defined $post{form}) {{ ref => $row->{id}, lang => $lang, form => $val, + prio => undef, ); $subrow{wptitle} = $1 if $subrow{form} =~ s/\h*\[(.*)\]$//; # [Link] shorthand $db->insert(word => \%subrow); @@ -297,12 +205,13 @@ elsif (defined $post{form}) {{ } @cmds = ( 'convert', + $imgpath, -delete => '1--1', -background => 'white', -gravity => @cmds ? 'northwest' : 'center', @cmds, -resize => "$xyres^", -extent => $xyres, '-strip', -quality => '60%', -interlace => 'plane', - $imgpath => $thumbpath + $thumbpath ); eval { require IPC::Run; @@ -321,9 +230,9 @@ elsif (defined $post{form}) {{ } }} else { - $row->{prio} //= 1; $row->{lang} //= $user->{editlang}->[0]; $row->{$_} = $get{$_} for keys %get; + $row->{prio} = defined $row->{ref} ? undef : 1 unless exists $row->{prio}; } my $title = $row->{id} ? "entry #$row->{id}" : 'new entry'; @@ -338,8 +247,7 @@ package Shiar_Sheet::FormRow { $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}}; if (my $options = $attr->{-select}) { - $options = { map {$_ => $options->[$_]} 0 .. $#{$options} } - if ref $options eq 'ARRAY'; + $options = $options->(@_) if ref $options eq 'CODE'; $options->{$val} //= "unknown ($val)"; # preserve current return ( sprintf('