aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-03-01 00:06:04 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-03-01 00:06:04 +0100
commitf3342af8c57225091ff32d6747a45783df62f9c3 (patch)
tree482abbf583d146d784b1e79a5ce6b59de171f6c5
parent1ba409614d25599594d360fd9ac5a18ae19f5ff8 (diff)
Add a unified feed/entry list view and make it the default page.
-rw-r--r--cljssss-g.clj114
-rw-r--r--index.st26
2 files changed, 91 insertions, 49 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj
index fd76625..ad466d0 100644
--- a/cljssss-g.clj
+++ b/cljssss-g.clj
@@ -60,51 +60,71 @@
"htmlurl" link})
results)}))))))
-(defn lynxy-feedlist [feed]
- (with-dbt
- (sql/with-query-results
- results
- [(str "SELECT feed.id, feed.uri, feed.link, user_feed_link.title"
- " FROM feed, user_feed_link"
- " WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?"
- " ORDER BY user_feed_link.title")
- feed]
- (.toString (doto (.getInstanceOf templates "simple-feed-list")
- (.setAttributes {"feeds"
- (map (fn [{title :title
- id :id
- link :link}]
- {"title" title
- "id" id
- "link" link})
- results)}))))))
+(defn select-feeds [user]
+ (sql/with-query-results
+ results
+ [(str "SELECT feed.id, feed.uri, feed.link, user_feed_link.title"
+ " FROM feed, user_feed_link"
+ " WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?"
+ " ORDER BY user_feed_link.title")
+ user]
+ (doall (map (fn [{title :title
+ id :id
+ link :link}]
+ {"title" title
+ "id" id
+ "link" link})
+ results))))
+
+(defn select-feed-name [user feed-id]
+ (sql/with-query-results [{feed-name :title}]
+ [(str "SELECT user_feed_link.title"
+ " FROM feed, user_feed_link"
+ " WHERE user_feed_link.feed = ?"
+ " AND user_feed_link.user = ?")
+ feed-id user]
+ feed-name))
+
+(defn select-entries [user feed-id active-entry-id]
+ (sql/with-query-results
+ results
+ [(str "SELECT entry.link, entry.title, entry.id"
+ " FROM entry, feed_entry_link, user_feed_link"
+ " WHERE entry.id = feed_entry_link.entry"
+ " AND feed_entry_link.feed = user_feed_link.feed"
+ " AND user_feed_link.user = ?"
+ " AND user_feed_link.feed = ?"
+ " ORDER BY entry.published DESC")
+ user feed-id]
+ (doall (map (fn [{title :title
+ link :link
+ id :id}]
+ {"title" title
+ "link" link
+ "id" id
+ "active_p" (= active-entry-id id)})
+ results))))
+
+(defn lynxy-feedlist [user]
+ (with-db
+ (.toString (doto (.getInstanceOf templates "simple-feed-list")
+ (.setAttributes {"feeds" (select-feeds user)})))))
(defn lynxy-showfeed [user feed]
- (with-dbt
- (sql/with-query-results [{feed-name :title}]
- [(str "SELECT user_feed_link.title"
- " FROM feed, user_feed_link"
- " WHERE user_feed_link.feed = ?"
- " AND user_feed_link.user = ?")
- feed user]
- (sql/with-query-results
- results
- [(str "SELECT entry.link, entry.title"
- " FROM entry, feed_entry_link, user_feed_link"
- " WHERE entry.id = feed_entry_link.entry"
- " AND feed_entry_link.feed = user_feed_link.feed"
- " AND user_feed_link.user = ?"
- " AND user_feed_link.feed = ?"
- " ORDER BY entry.published DESC")
- user feed]
- (.toString (doto (.getInstanceOf templates "simple-entry-list")
- (.setAttributes {"feed_name" feed-name
- "entries"
- (map (fn [{title :title
- link :link}]
- {"title" title
- "link" link})
- results)})))))))
+ (with-db
+ (.toString (doto (.getInstanceOf templates "simple-entry-list")
+ (.setAttributes {"feed_name" (select-feed-name user feed)
+ "entries" (select-entries user feed nil)})))))
+
+(defn show-subscriptions [user feed active-entry-id]
+ (with-db
+ (.toString (doto (.getInstanceOf templates "index")
+ (.setAttributes {"feeds" (select-feeds user)
+ "entries" (when feed (select-entries user
+ feed
+ active-entry-id))
+ "active_feed_id" feed
+ "title" "Subscriptions"})))))
(defmacro with-session
"Rebind Compojure's magic lexical variables as vars."
@@ -137,11 +157,9 @@
(with-session
(lynxy-showfeed (session :id) (Integer/parseInt (params :feed)))))
(GET "/"
- (with-session
- (.toString
- (doto (.getInstanceOf templates "index")
- (.setAttributes {"title" "Subscriptions",
- "mainParagraph" "Hi there!"})))))
+ (with-session (show-subscriptions (session :id) (params :feed) nil)))
+ (GET "/entries/*"
+ (with-session (show-subscriptions (session :id) (params :feed) 5)))
(ANY "*"
(page-not-found)))
diff --git a/index.st b/index.st
index cd0351b..c00eea9 100644
--- a/index.st
+++ b/index.st
@@ -1,7 +1,31 @@
$header(title=title)$
<h1 class="title">$title$</h1>
-<p>$mainParagraph$</p>
+
+<div id="feed-list">
+ <h2>Feeds</h2>
+ <ul>
+ $feeds:{feed |
+ <li><a href="/?feed=$feed.id$">$feed.title$</a></li>
+ }$
+ </ul>
+</div>
+
+$if(entries)$
+<div id="feed-content">
+ <h2>Entries</h2>
+ <ul>
+ $entries:{entry |
+ $if(entry.active_p)$
+ $! FIXME: Show content inline if possible. !$
+ <li><a id="entry-$entry.id$" href="/entries/$entry.id$?feed=$active_feed_id$#entry-$entry.id$">$entry.title$</a></li>
+ $else$
+ <li><a id="entry-$entry.id$" href="/entries/$entry.id$?feed=$active_feed_id$#entry-$entry.id$">$entry.title$</a></li>
+ $endif$
+ }$
+ </ul>
+</div>
+$endif$
$footer()$