summaryrefslogtreecommitdiff
path: root/lib/VN3/Staff/JS.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-07-25 14:30:04 +0200
committerYorhel <git@yorhel.nl>2019-07-25 14:36:21 +0200
commitf296495a912ce759df11c43e78b4552788bdbff2 (patch)
tree0c10802de65fb7c8475722e12234bff5eb980628 /lib/VN3/Staff/JS.pm
parent0f3cfeb85caec6424bcbea47142eefbf8011636b (diff)
Merge the v3 branch into separate namespace + fix Docker stuff (again)
I was getting tired of having to keep two branches up-to-date with the latest developments, so decided to throw v3 into the same branch - just different files (...which will get mostly rewritten again soon). The two versions aren't very different in terms of dependencies, build system and support code, so they can now properly share files. Added a section to the README to avoid confusion. This merge also makes it easier to quickly switch between the different versions, which is handy for development. It's even possible to run both at the same time, but my scripts use the same port so that needs a workaround. And it's amazing how often I break the Docker scripts.
Diffstat (limited to 'lib/VN3/Staff/JS.pm')
-rw-r--r--lib/VN3/Staff/JS.pm37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/VN3/Staff/JS.pm b/lib/VN3/Staff/JS.pm
new file mode 100644
index 00000000..02531ac1
--- /dev/null
+++ b/lib/VN3/Staff/JS.pm
@@ -0,0 +1,37 @@
+package Staff::JS;
+
+use VN3::Prelude;
+
+
+json_api '/js/staff.json', {
+ search => { maxlength => 500 }
+}, sub {
+ my $q = shift->{search};
+
+ # XXX: This query is kinda slow
+ my $qs = $q =~ s/[%_]//gr;
+ my $r = tuwf->dbAlli(
+ 'SELECT s.id, st.aid, st.name, st.original',
+ 'FROM (',
+ # ID search
+ $q =~ /^$SID_RE$/ ? ('SELECT 1, id, aid, name, original FROM staff_alias WHERE id =', \"$1", 'UNION ALL') : (),
+ # exact match
+ 'SELECT 2, id, aid, name, original FROM staff_alias WHERE lower(name) = lower(', \$q, ") OR lower(translate(original,' ', '')) = lower(", \($q =~ s/\s//gr), ')',
+ 'UNION ALL',
+ # prefix match
+ 'SELECT 3, id, aid, name, original FROM staff_alias WHERE name ILIKE', \"$qs%", ' OR original ILIKE', \"$qs%",
+ 'UNION ALL',
+ # substring match
+ 'SELECT 4, id, aid, name, original FROM staff_alias WHERE name ILIKE', \"%$qs%", ' OR original ILIKE', \"%$qs%",
+ ') AS st (ord, id, aid, name, original)',
+ 'JOIN staff s ON s.id = st.id',
+ 'WHERE NOT s.hidden',
+ 'GROUP BY s.id, st.aid, st.name, st.original',
+ 'ORDER BY MIN(st.ord), st.name',
+ 'LIMIT 20'
+ );
+
+ tuwf->resJSON({StaffResult => $r});
+};
+
+1;