From 2196f5f902b82b34caf3adcff27b8fe724bb9828 Mon Sep 17 00:00:00 2001 From: Brian Duggan Date: Wed, 5 Apr 2023 19:20:53 -0400 Subject: [PATCH] simplify --- leafpad | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/leafpad b/leafpad index e72ef3a..21b28c0 100755 --- a/leafpad +++ b/leafpad @@ -34,25 +34,27 @@ any '/' => sub ($c) { my $send = [ map +{ geojson => $_, label => 'shape' }, @geodata ]; $c->stash( geodata => $send ); $c->stash( csv_files => [ $data_dir->list->grep(sub { /.csv/ })->sort->each ]); - $c->stash( csv_data => [] ); $c->stash( csv_cols => [] ); $c->render(template => 'index'); } => 'index'; get '/show/csv/:name' => sub ($c) { - my %seen; # uniqify names - my $name = $c->param('name'); + my $name = $c->stash('name'); $c->stash(zoom => $c->param('zoom') || $default_zoom); $c->stash( csv_files => [ ] ); - + my $io = $data_dir->child("$name"); + if (-d $io) { + my @csvs = $io->list->grep(sub { /\.csv/ })->each; + die @csvs; + } my $csv = Text::CSV_XS->new(); - my $file = $data_dir->child("$name.csv"); + my $file = $io . '.csv'; open my $fh, "<", "$file" or die "$!"; + my %seen; my @header = $csv->header($fh, { munge_column_names => sub { $seen{$_[0]}++ ? $_[0] . '-' . $seen{$_[0]} : $_[0] }}); $csv->parse("$file") or die $!; my $data = $csv->getline_hr_all($fh); close $fh; - $c->stash(csv_data => $data); $c->stash(csv_cols => \@header); $c->stash(geodata => $data); $c->stash(lat => $c->param('lat') || $data->[0]{latitude} || $data->[0]{lat} || $default_lat); @@ -101,7 +103,7 @@ __DATA__ % } % my $row_index = 0; - % for my $row (@$csv_data) { + % for my $row (@$geodata) { % for my $col (@$csv_cols) {
<%= $row->{$col} %>
-- 2.45.2