From 44ecb7e512f09cf017bd5f887d122f9b2f38dd74 Mon Sep 17 00:00:00 2001 From: Benjamin 'blindCoder' Schieder Date: Sat, 22 Apr 2017 21:28:21 +0200 Subject: [PATCH] implement en/disabling feeds --- .gitignore | 1 + Tweetodon/Entry.pm | 17 +++++++++++++++++ Tweetodon/Feed.pm | 23 +++++++++++++++++++++++ Tweetodon/Website/Dashboard.pm | 19 ++++++++++++++++++- Tweetodon/Website/EditFeed.pm | 7 ++----- static/js/Dashboard.js | 18 ++++++++++++++++++ static/templates/Dashboard.html | 9 ++++++++- static/templates/Login.html | 2 +- 8 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 Tweetodon/Entry.pm diff --git a/.gitignore b/.gitignore index 23c2594..238b716 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ tweetodon.conf.json +*.swp diff --git a/Tweetodon/Entry.pm b/Tweetodon/Entry.pm new file mode 100644 index 0000000..ee0691b --- /dev/null +++ b/Tweetodon/Entry.pm @@ -0,0 +1,17 @@ +# vim: set foldmarker={,}: +use strict; +use Tweetodon::Base; + +package Tweetodon::Entry; +@Tweetodon::Entry::ISA = qw(Tweetodon::Base); +use JSON; +use Data::Dumper; + +sub dbTable :lvalue { "entries"; } +sub orderBy :lvalue { "posted_at ASC"; } + +# Class functions + +# Object methods + +1; diff --git a/Tweetodon/Feed.pm b/Tweetodon/Feed.pm index 0fdfc72..93e19bf 100644 --- a/Tweetodon/Feed.pm +++ b/Tweetodon/Feed.pm @@ -7,6 +7,9 @@ package Tweetodon::Feed; use JSON; use Data::Dumper; use Tweetodon::Filter; +use Tweetodon::Entry; +use XML::Feed; +use URI; sub dbTable :lvalue { "feeds"; } sub orderBy :lvalue { "url ASC"; } @@ -26,6 +29,19 @@ sub get_by_user_instance { return @retVal; } +sub create_and_fetch { + my $class = shift; + my %data = @_; + + my $self = $class->create(%data); + my $feeddata = $self->fetch_entries(); + foreach my $entry ($feeddata->items){ + my %ne; + $ne{feed_id} = $self->{data}->{ID}; + $ne{entry_link} = $entry->link(); + Tweetodon::Entry->create(%ne); + } +} # Object methods sub filters { @@ -39,4 +55,11 @@ sub filters { return @retVal; } +sub fetch_entries { + my $self = shift; + + $XML::Feed::MULTIPLE_ENCLOSURES = 1; + return XML::Feed->parse(URI->new($self->{data}->{url})); +} + 1; diff --git a/Tweetodon/Website/Dashboard.pm b/Tweetodon/Website/Dashboard.pm index 5182e4f..90a6b48 100644 --- a/Tweetodon/Website/Dashboard.pm +++ b/Tweetodon/Website/Dashboard.pm @@ -18,8 +18,17 @@ sub requires_authentication { sub fill_content { my $class = shift; my $output = shift; - my @feeds = Tweetodon::Feed->get_by_user_instance($main::CURRENTUSER->{data}->{acct}, $main::FORM{instance}); + if ($main::FORM{inputURL}){ + my %nf; + $nf{url} = $main::FORM{inputURL}; + $nf{username} = $main::CURRENTUSER->{data}->{acct}; + $nf{instance} = $main::FORM{instance}; + $nf{enabled} = "n"; + my $feed = Tweetodon::Feed->create_and_fetch(%nf); + } + + my @feeds = Tweetodon::Feed->get_by_user_instance($main::CURRENTUSER->{data}->{acct}, $main::FORM{instance}); my @param_feeds; my $count = 0; FEED: foreach my $feed (@feeds){ @@ -30,6 +39,14 @@ sub fill_content { my %r; $count++; $r{"count"} = $count; + if ($main::FORM{enable} and "x".$main::FORM{enable} eq "x".$feed->{data}->{ID}){ + $feed->{data}->{enabled} = "1"; + $feed->save(); + } + if ($main::FORM{disable} and "x".$main::FORM{disable} eq "x".$feed->{data}->{ID}){ + $feed->{data}->{enabled} = "0"; + $feed->save(); + } foreach my $key (keys %{$feed->{data}}){ $r{$key} = $feed->{data}->{$key}; } diff --git a/Tweetodon/Website/EditFeed.pm b/Tweetodon/Website/EditFeed.pm index 87ab162..453d75e 100644 --- a/Tweetodon/Website/EditFeed.pm +++ b/Tweetodon/Website/EditFeed.pm @@ -10,8 +10,6 @@ use Tweetodon::Website; package Tweetodon::Website::EditFeed; use Data::Dumper; -use XML::Feed; -use URI; @Tweetodon::Website::EditFeed::ISA = qw(Tweetodon::Website); sub requires_authentication { @@ -60,10 +58,9 @@ sub fill_content { } } - $XML::Feed::MULTIPLE_ENCLOSURES = 1; - my $feeddata = XML::Feed->parse(URI->new($feed->{data}->{url})); my @param_entries; my @filters = $feed->filters(); + my $feeddata = $feed->fetch_entries(); foreach my $entry ($feeddata->items){ my %entry; $entry{title} = $entry->title(); @@ -75,7 +72,7 @@ sub fill_content { $entry{id} = $entry->id(); $entry{tags} = join(", ", $entry->tags()); - $entry{class} = "green"; + $entry{class} = "red"; foreach my $filter (@filters){ if ($filter->apply($entry)){ if ($filter->{data}->{type} eq "white"){ diff --git a/static/js/Dashboard.js b/static/js/Dashboard.js index 9f63279..e605fea 100644 --- a/static/js/Dashboard.js +++ b/static/js/Dashboard.js @@ -1,4 +1,5 @@ function TweetodonOnReady(){ + $("form#addFeed").hide(); $("a.deleteFeed").on("click", function(){ var btn = $(this); if (confirm("Really delete this feed?")){ @@ -6,4 +7,21 @@ function TweetodonOnReady(){ document.location.href=l; } }); + + $("a.addFeed").on("click", function(){ + var btn=$(this); + $("form#addFeed").show(); + btn.hide(); + }); + + $("a.enable").on("click", function(){ + var btn = $(this); + var l = "index.pl?mode=Dashboard&enable="+btn.data("id"); + document.location.href=l; + }); + $("a.disable").on("click", function(){ + var btn = $(this); + var l = "index.pl?mode=Dashboard&disable="+btn.data("id"); + document.location.href=l; + }); } diff --git a/static/templates/Dashboard.html b/static/templates/Dashboard.html index 4cbb020..ff3df0d 100644 --- a/static/templates/Dashboard.html +++ b/static/templates/Dashboard.html @@ -48,13 +48,20 @@ + " href="#">Disable" href="#">Enable ">Edit ">Delete - Add new feed + Add new feed +
+ "> + + + +
diff --git a/static/templates/Login.html b/static/templates/Login.html index d19a390..692400a 100644 --- a/static/templates/Login.html +++ b/static/templates/Login.html @@ -4,7 +4,7 @@