word/quiz: poc js asks random images with 4 translations
[sheet.git] / word.plp
index 4d60f9a445da3fd40e177b1a07fb14ef63e6465a..b5a07bf60a9fe9b0f24f49a5df6048a1bfc2ce23 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,26 @@
 <(common.inc.plp)><:
 
-my $wordlist = 'wordlist.en.inc.pl';
+if ($Request and $Request =~ s{^edit/?}{}) {
+       Include 'writer.plp';
+       exit;
+}
+
+if ($Request and $Request =~ s{^quiz/?}{}) {
+       Html({
+               raw => <<'EOT',
+<script src="/wordquiz.js"></script>
+<style>
+.wrong {background: red}
+.good {background: green}
+</style>
+EOT
+       });
+       say '<h1>quiz</h1><p id="quiz">test</p>';
+       exit;
+}
+
+my $lang = $get{lang} || 'en';
+my $wordlist = "data/wordlist.$lang.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
 
 Html({
@@ -93,7 +113,18 @@ sub printimgs {
 
 say '<section class="gallery">';
 if (exists $get{q}) {
-       my @rows = map {@$_} values %{$table}; # flatten categories
+       my @rows;
+       if ($Request) {
+               my @query = $Request;
+               while (@query) {
+                       push @rows, grep { (split /:/)[1] <= $limit } @query;
+                       s/:.*// for @query;
+                       @query = map {$_ ? @{$_} : ()} @{$table}{@query};
+               }
+       }
+       else {
+               @rows = map {ref ? @$_ : $_} values %{$table}; # flatten categories
+       }
        @rows = sort { rand <=> .5 } @rows;
        $table = {};
        printimgs(@rows);