From 612cf7de0edd2dbdf4d73e3b9eb300520fa7a5c2 Mon Sep 17 00:00:00 2001 From: dumpfmprod Date: Sat, 2 Oct 2010 19:58:48 -0400 Subject: timb: irl: fwd, altars: fix off by one, add previous paging --- src/site.clj | 51 +++++++++++++++++++++++++--------------- src/tags.clj | 34 ++++++++++++++++----------- template/altar_log.st | 57 +++++++++++++++++++++++++++++++++++++++++++++ template/altar_user_log.st | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 33 deletions(-) create mode 100644 template/altar_log.st create mode 100644 template/altar_user_log.st diff --git a/src/site.clj b/src/site.clj index 620756d..f28aae0 100644 --- a/src/site.clj +++ b/src/site.clj @@ -850,22 +850,11 @@ WHERE u.user_id = ANY(?)" ;; Altars (defn altar-log [session params] - (let [id (params :id) - st (fetch-template "altar_log" session) - raw-dumps (tags/fetch-altars :message-id id :amount (+ 1 *dumps-per-page*)) - dumps (map tags/add-favorited-flag (take *dumps-per-page* raw-dumps) (repeat session)) - dumps (map tags/remove-tags-for-output dumps) - dumps (map process-message-for-output dumps)] - (.setAttribute st "dumps" dumps) - (if (> (count raw-dumps) *dumps-per-page*) - (.setAttribute st "next" ((last raw-dumps) :message_id))) - (.toString st))) - -(defn altar-log-by-nick [session params] (let [id (params :id) nick (params :nick) - user-id (user-id-from-nick nick) - st (fetch-template "altar_user_log" session) + user-id (if nick (user-id-from-nick nick) nil) + template (if user-id "altar_user_log" "altar_log") + st (fetch-template template session) raw-dumps (tags/fetch-altars :message-id id :amount (+ 1 *dumps-per-page*) :user-id user-id) dumps (map tags/add-favorited-flag (take *dumps-per-page* raw-dumps) (repeat session)) dumps (map tags/remove-tags-for-output dumps) @@ -874,6 +863,8 @@ WHERE u.user_id = ANY(?)" (.setAttribute st "nick" nick) (if (> (count raw-dumps) *dumps-per-page*) (.setAttribute st "next" ((last raw-dumps) :message_id))) + (if id + (.setAttribute st "prev" ((first raw-dumps) :message_id))) (.toString st))) ;; Tags @@ -1247,7 +1238,20 @@ WHERE u.user_id = ANY(?)" (defroutes static (GET "/static/*" (serve-static "static" (params :*))) (GET "/images/*" (serve-static *image-directory* (params :*))) - (GET "/avatars/*" (serve-static *avatar-directory* (params :*)))) + (GET "/avatars/*" (serve-static *avatar-directory* (params :*))) +;; irl + (GET "/irl" (redirect-to "/irl/")) + (GET "/irl/" (serve-static "static/319" "index.html")) + (GET "/irl/*" (serve-static "static/319" (params :*))) + (GET "/irl2" (redirect-to "/irl2/")) + (GET "/irl2/" (serve-static "static/319" "res.html")) + (GET "/irl2/*" (serve-static "static/319" (params :*))) + (GET "/irlhell" (redirect-to "/irhell/")) + (GET "/irhell" (redirect-to "/irhell/")) + (GET "/irhell/" (serve-static "static/319" "irhell.html")) + (GET "/irhell/*" (serve-static "static/319" (params :*)))) + + (defroutes pichat (GET "http://:sub.dump.fm/" (validated-chat session (params :sub))) @@ -1292,9 +1296,12 @@ WHERE u.user_id = ANY(?)" (POST "/cmd/tag/add" (validated-add-tag session params)) (POST "/cmd/tag/rm" (validated-remove-tag session params)) + ;; Altars (GET "/altars" (altar-log session params)) (GET "/altars/" (altar-log session params)) - (GET "/altars/:id" (altar-log session params)) + (GET "/altars/:id" (if (maybe-parse-int (params :id) false) + (altar-log session params) + (redirect-to (str "/" (params :id) "/altars")))) ;; redirect /altars/timb to /timb/altars ;; Events (GET "/event" (current-event session)) @@ -1346,9 +1353,9 @@ WHERE u.user_id = ANY(?)" ;; Put username routes below all others in priority (GET "/:nick" (profile session (params :nick))) (GET "/:nick/" (profile session (params :nick))) - (GET "/:nick/altars" (altar-log-by-nick session params)) - (GET "/:nick/altars/" (altar-log-by-nick session params)) - (GET "/:nick/altars/:id" (altar-log-by-nick session params)) + (GET "/:nick/altars" (altar-log session params)) + (GET "/:nick/altars/" (altar-log session params)) + (GET "/:nick/altars/:id" (altar-log session params)) (GET "/:nick/tag/:tag" (tagged-dumps-by-nick session params (request-url request))) (GET "/:nick/tag/:tag/:offset" (tagged-dumps-by-nick session params (request-url request))) (GET "/:nick/favorites" (favorites-handler session (params :nick) nil nil)) @@ -1419,6 +1426,12 @@ WHERE u.user_id = ANY(?)" "/static/*" (servlet static) "/images/*" (servlet static) "/avatars/*" (servlet static) + "/irl" (servlet static) + "/irl2" (servlet static) + "/irl/*" (servlet static) + "/irl2/*" (servlet static) + "/irhell" (servlet static) + "/irhell/*" (servlet static) "/upload/*" (servlet multipart) "/*" (servlet pichat))) diff --git a/src/tags.clj b/src/tags.clj index 6354e37..299328d 100644 --- a/src/tags.clj +++ b/src/tags.clj @@ -300,7 +300,7 @@ WHERE EXISTS AND r.room_id = m.room_id " (if include-vip "" "AND r.admin_only = false"))) -(defnk fetch-altars-query [:with-tags true :with-message-id false :with-user-id false] (str +(defnk fetch-altars-query [:with-tags true :page-type false :with-user-id false] (str " SELECT m.content, m.message_id, m.created_on, u.nick, u.avatar, r.key " @@ -310,16 +310,19 @@ WHERE EXISTS WHERE message_id = m.message_id AND tags.user_id = users.user_id), ' ') as tags " "") " FROM (SELECT message_id - FROM image_altars " - (if (and with-message-id (not with-user-id)) "WHERE message_id < ? " "") ;; todo: fix awful code - (if (and (not with-message-id) with-user-id) "WHERE user_id = ? " "") - (if (and with-message-id with-user-id) "WHERE message_id < ? AND user_id = ? " "") - " ORDER BY message_id DESC - LIMIT ? OFFSET ? + FROM image_altars WHERE TRUE " ;; just have this so i can assume there's an AND in front of each cond. + (if (= page-type :next) "AND message_id <= ? " "") + (if (= page-type :prev) "AND message_id >= ? " "") + (if with-user-id "AND user_id = ? " "") + (if (= page-type :prev) + " ORDER BY message_id ASC" + " ORDER BY message_id DESC") + " LIMIT ? OFFSET ? ) as sq, messages m, users u, rooms r WHERE m.message_id = sq.message_id AND m.user_id = u.user_id - AND r.room_id = m.room_id " + AND r.room_id = m.room_id + ORDER BY message_id DESC " ;; needed in case subquery was selected ASC )) @@ -328,14 +331,17 @@ WHERE EXISTS (let [rows (do-select [query (maybe-parse-int m-id -1)])] (first (map parse-tags-from-row-as-tag-map rows))))) -(defnk fetch-altars [:message-id 0 :user-id 0 :amount *dumps-per-page* :offset 0] +(defnk fetch-altars [:message-id 0 :user-id false :amount *dumps-per-page* :offset 0] (let [message-id (maybe-parse-int message-id 0) - with-message-id (> message-id 0) - with-user-id (> user-id 0) - query (fetch-altars-query :with-message-id with-message-id :with-user-id with-user-id) + abs-m-id (if (neg? message-id) (- message-id) message-id) + page-type (cond + (> message-id 0) :next + (< message-id 0) :prev + :else false) + query (fetch-altars-query :page-type page-type :with-user-id user-id) query-vars [amount offset] - query-vars (if with-user-id (concat [user-id] query-vars) query-vars) - query-vars (if with-message-id (concat [message-id] query-vars) query-vars) + query-vars (if user-id (concat [user-id] query-vars) query-vars) + query-vars (if page-type (concat [abs-m-id] query-vars) query-vars) rows (do-select (vec (concat [query] query-vars)))] (map parse-tags-from-row-as-tag-map rows))) diff --git a/template/altar_log.st b/template/altar_log.st new file mode 100644 index 0000000..5d826ef --- /dev/null +++ b/template/altar_log.st @@ -0,0 +1,57 @@ + + + dump.fm log +$head()$ + + + +$banner()$ +
+
+
+

dump altars


+
+
+ + $if(dumps)$ +
+ $dumps: { d | $log_dump(dump=d)$ }$ +
+ $if(json_tags)$ + + $endif$ + $else$ + No dumps! + $endif$ +
+ + +
+
+ +$if(prev)$ + +$else$ + +$endif$ +$if(next)$ + +$else$ + +$endif$ + + +
+
+ $footer()$ +
+
+
+ + + diff --git a/template/altar_user_log.st b/template/altar_user_log.st new file mode 100644 index 0000000..75159a6 --- /dev/null +++ b/template/altar_user_log.st @@ -0,0 +1,58 @@ + + + dump.fm log + $head()$ + + + + $banner()$ +
+
+
+

dump altars


+
+
+ + $if(dumps)$ + + $dumps: { d | $log_dump(dump=d)$ }$ + + $if(json_tags)$ + + $endif$ + $else$ + No dumps! + $endif$ +
+ + +
+
+ + $if(prev)$ + + $else$ + + $endif$ + + $if(next)$ + + $else$ + + $endif$ + + +
+
+ $footer()$ +
+
+
+ + + -- cgit v1.2.3-70-g09d2