From 1c641d9c92981bab0e0fe9ad2e89bdf2e6d3f088 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 29 Sep 2011 23:58:12 +0200 Subject: [PATCH] use Google Calendar ical file as source file and add reservations in CouchDB --- angular-server.pl | 40 ++++++++++ public/app/reservations/calendar.html | 101 ++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 public/app/reservations/calendar.html diff --git a/angular-server.pl b/angular-server.pl index 276265f..9487599 100755 --- a/angular-server.pl +++ b/angular-server.pl @@ -224,6 +224,46 @@ get '/json/:database/:entity' => sub { _render_jsonp( $self, $docs ) }; +# app/resevations +use Encode; +use iCal::Parser; + +get '/reservations/get/(*url)' => sub { + my $self = shift; + + my $text = $client->get( 'http://' . $self->param('url') )->res->body; + warn "# get ", $self->param('url'), dump($text); + + $text = decode( 'utf-8', $text ); + $text =~ s{\\,}{,}gs; + $text =~ s{\\n}{ }gs; + + my $c = iCal::Parser->new->parse_strings( $text ); + + warn "# iCal::Parser = ",dump($c); + + my $ical = { + cal => $c->{cals}->[0], # FIXME assume single calendar + }; + + my $e = $c->{events}; + my @events; + + foreach my $yyyy ( sort keys %$e ) { + foreach my $mm ( sort keys %{ $e->{$yyyy} } ) { + foreach my $dd ( sort keys %{ $e->{$yyyy}->{$mm} } ) { + push @events, values %{ $e->{$yyyy}->{$mm}->{$dd} }; + } + } + } + + $ical->{events} = [ sort { + $a->{DTSTART} cmp $b->{DTSTART} + } @events ]; + + _render_jsonp( $self, $ical ); +}; + app->start; __DATA__ diff --git a/public/app/reservations/calendar.html b/public/app/reservations/calendar.html new file mode 100644 index 0000000..0f5b2b2 --- /dev/null +++ b/public/app/reservations/calendar.html @@ -0,0 +1,101 @@ + + + + + + + + + +Reservations + + + + + + +
+ +

{{data.cal['X-WR-CALNAME']}}

+ +
{{data.cal['X-WR-CALDESC'] | html}}
+ + + + +
+ +
+Popunite vašu prijavu za +{{reservation.event.SUMMARY}} + +
+ +
+Vaša prijava za +{{reservation.event.SUMMARY}} + +
+ +
+ime: +
+prezime: +
+e-mail: +
+odsjek: +
+zvanje: +
+područke/tema zaninimanja: +
+ +
{{reservation}}
+
+ + +
+data={{data}}
+reservation={{reservation}}
+
+ +
+ + + + -- 2.20.1