Unverified Commit f4d71b4d authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

obtain autocompletion from database

parent 559a1ced
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2397,6 +2397,7 @@ sub startup {
	$r->get( '/p/:name/j/:id' => 'public_journey' )
	  ->to('profile#journey_details');
	$r->get('/.well-known/webfinger')->to('account#webfinger');
	$r->get('/dyn/:av/autocomplete.js')->to('api#autocomplete');
	$r->post('/api/v1/import')->to('api#import_v1');
	$r->post('/api/v1/travel')->to('api#travel_v1');
	$r->post('/action')->to('traveling#travel_action');
+18 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Mojo::Base 'Mojolicious::Controller';

use DateTime;
use List::Util;
use Mojo::JSON qw(encode_json);
use UUID::Tiny qw(:std);

# Internal Helpers
@@ -648,4 +649,21 @@ sub set_token {
	$self->redirect_to('account');
}

sub autocomplete {
	my ($self) = @_;

	$self->res->headers->cache_control('max-age=86400, immutable');

	my $output
	  = "document.addEventListener('DOMContentLoaded',function(){M.Autocomplete.init(document.querySelectorAll('.autocomplete'),{\n";
	$output .= 'minLength:3,limit:50,data:';
	$output .= encode_json( $self->stations->get_for_autocomplete );
	$output .= "\n});});\n";

	$self->render(
		format => 'js',
		data   => $output
	);
}

1;
+13 −0
Original line number Diff line number Diff line
@@ -50,6 +50,19 @@ sub add_or_update {
	);
}

sub get_for_autocomplete {
	my ($self) = @_;

	my $res = $self->{pg}->db->select( 'stations', ['name'] );
	my %ret;

	while ( my $row = $res->hash ) {
		$ret{ $row->{name} } = undef;
	}

	return \%ret;
}

# Fast
sub get_by_eva {
	my ( $self, $eva, %opt ) = @_;

public/static/js/autocomplete.js

deleted100644 → 0
+0 −9744

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −1

File deleted.

Preview size limit exceeded, changes collapsed.

Loading