Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Browse: add jump by name #86

  • Loading branch information...
commit 1581b0454202e04389ac085457fd3ce2394d57be 1 parent fbe6135
@ato authored
View
22 resources/public/stylesheets/screen.css
@@ -238,3 +238,25 @@ p.hint {
.page-description {
color: #444;
}
+
+.browse-from {
+ display: inline;
+}
+
+.browse-from label {
+ color: #444;
+ font-size: 60%;
+ font-weight: normal;
+ margin-left: 10px;
+ margin-right: 5px;
+}
+
+.browse-from input#from {
+ display: inline;
+ width: 200px;
+ margin-bottom: 0;
+}
+
+.browse-from input#jump {
+ display: none;
+}
View
10 src/clojars/db.clj
@@ -158,6 +158,16 @@
first
:count))
+(defn count-projects-before [s]
+ (-> (exec-raw
+ [(str "select count(*) count from"
+ " (select distinct group_name, jar_name from jars"
+ " order by group_name, jar_name)"
+ " where group_name || '/' || jar_name < ?")
+ [s]] :results)
+ first
+ :count))
+
(defn browse-projects [current-page per-page]
(vec
(map
View
39 src/clojars/web/browse.clj
@@ -1,20 +1,29 @@
(ns clojars.web.browse
(:require [clojars.web.common :refer [html-doc jar-link user-link format-date
- page-nav page-description]]
- [clojars.db :refer [browse-projects count-all-projects]]
- [hiccup.core :refer [h]]))
+ page-nav page-description jar-name]]
+ [clojars.db :refer [browse-projects count-all-projects
+ count-projects-before]]
+ [hiccup.core :refer [h]]
+ [hiccup.form :refer [label submit-button]]
+ [ring.util.response :refer [redirect]]))
- (defn browse [account params]
- (let [page (Integer. (or (:page params) 1))
- per-page 20
- project-count (count-all-projects)
- total-pages (-> (/ project-count per-page) Math/ceil .intValue)]
- (html-doc account "All projects"
- [:h1 "All projects"]
+(defn browse-page [account page per-page]
+ (let [project-count (count-all-projects)
+ total-pages (-> (/ project-count per-page) Math/ceil .intValue)
+ projects (browse-projects page per-page)]
+ (html-doc account "All projects"
+ [:h1 "All projects"
+ [:form.browse-from {:method :get :action "/projects"}
+ (label :from "starting from")
+ [:input {:type :text :name :from :id :from
+ :placeholder (jar-name (first projects))}]
+ [:input {:type :submit :value "Jump" :id :jump}]
+ (submit-button "Jump")]]
(page-description page per-page project-count)
[:ul
- (for [jar (browse-projects page per-page)]
+ (for [[i jar] (map-indexed vector projects)]
[:li.browse-results
+ [:a {:name i}]
(jar-link jar) " " (h (:version jar))
[:br]
(when (seq (:description jar))
@@ -26,3 +35,11 @@
(if-let [created (:created jar)]
[:td (format-date created)])]])]
(page-nav page total-pages))))
+
+(defn browse [account params]
+ (let [per-page 20]
+ (if-let [from (:from params)]
+ (let [i (count-projects-before from)
+ page (inc (int (/ i per-page)))]
+ (redirect (str "/projects?page=" page "#" (mod i per-page))))
+ (browse-page account (Integer. (or (:page params) 1)) per-page))))
View
16 test/clojars/test/integration/web.clj
@@ -5,7 +5,8 @@
[clojars.test.integration.steps :refer :all]
[clojars.web :as web]
[clojars.db :as db]
- [clojars.test.test-helper :as help]))
+ [clojars.test.test-helper :as help]
+ [net.cgrand.enlive-html :as enlive]))
(help/use-fixtures)
@@ -43,3 +44,16 @@
(has (text? "Huh")))
(within [:.page-nav :.current]
(has (text? "2")))))
+
+(deftest browse-page-can-jump
+ (doseq [i (range 100 125)]
+ (db/add-jar
+ "test-user"
+ {:name (str "tester" i "a") :group "tester" :version "0.1" :description "Huh" :authors ["Zz"]}))
+ (-> (session web/clojars-app)
+ (visit "/projects")
+ (fill-in "starting from" "tester/tester123")
+ (press "Jump")
+ (follow-redirect)
+ (within [[:li.browse-results (enlive/nth-of-type 3)] [:a (enlive/nth-of-type 2)]]
+ (has (text? "tester/tester123a")))))
View
14 test/clojars/test/unit/db.clj
@@ -317,7 +317,19 @@
{:version "0.1", :jar_name "scissors", :group_name "tester"})
(->>
(db/browse-projects 2 2)
- ( map #(select-keys % [:group_name :jar_name :version]))))))
+ ( map #(select-keys % [:group_name :jar_name :version]))))))
+
+(deftest count-projects-works
+ (db/add-jar "test-user" {:name "rock" :group "jester" :version "0.1"})
+ (db/add-jar "test-user" {:name "rock" :group "tester" :version "0.1"})
+ (db/add-jar "test-user" {:name "rock" :group "tester" :version "0.2"})
+ (db/add-jar "test-user" {:name "paper" :group "tester" :version "0.1"})
+ (db/add-jar "test-user" {:name "scissors" :group "tester" :version "0.1"})
+ (is (= (db/count-all-projects) 4))
+ (is (= (db/count-projects-before "a") 0))
+ (is (= (db/count-projects-before "tester/rock") 2))
+ (is (= (db/count-projects-before "tester/rocks") 3))
+ (is (= (db/count-projects-before "z") 4)))
;; TODO: search tests?
;; TODO: recent-versions
Please sign in to comment.
Something went wrong with that request. Please try again.