Permalink
Browse files

Made some stupid views for starters.

  • Loading branch information...
cfox committed Mar 27, 2012
1 parent 1b0bc4f commit ec984de4cdb85d45997d43575de77d201c9280e2
Showing with 56 additions and 2 deletions.
  1. +6 −0 src/mc/db.clj
  2. +50 −2 src/mc/views/welcome.clj
View
@@ -39,3 +39,9 @@
[]
(maybe-init)
(map :id (fetch :tournaments :only [:id])))
+
+(defn load-tournament-summaries
+ "Load some summary data for saved tournaments."
+ []
+ (maybe-init)
+ (fetch :tournaments :only [:id :name :date] :sort {:date -1}))
View
@@ -1,10 +1,58 @@
(ns mc.views.welcome
(:require [mc.views.common :as common]
[noir.content.pages :as pages])
- (:use noir.core
+ (:use mc.db
+ noir.core
hiccup.core
hiccup.page-helpers))
(defpage "/welcome" []
(common/layout
- [:p "Welcome to magicluster"]))
+ [:p "Welcome to magicluster"]))
+
+(defpartial tournament-link [{:keys [id name date]}]
+ (let [formatter (java.text.SimpleDateFormat. "MM/dd")]
+ [:a {:href (str "/tournament/" id)}
+ (.format formatter date) " " name]))
+
+(defpartial tournament-summary-list-item [ts]
+ [:li.tournamentSummary (tournament-link ts)])
+
+(defpartial tournament-summary-list [tss]
+ [:ul.tournamentSummaries
+ (map tournament-summary-list-item tss)])
+
+(defpage "/tournaments" []
+ (let [tss (load-tournament-summaries)]
+ (tournament-summary-list tss)))
+
+(defpartial table-header [val]
+ [:th val])
+
+(defpartial card-list-item [card]
+ [:li card])
+
+(defpartial deck-cell-chunks [count ss]
+ (let [cards (sort (map :card (filter #(= (:count %) count) ss)))]
+ [:td [:ul (map card-list-item cards)]]))
+
+(defpartial deck-block [ss]
+ (let [counts (reverse (sort (set (map :count ss))))]
+ [:table
+ [:tr (map table-header counts)]
+ [:tr (map deck-cell-chunks counts (repeat ss))]
+ ]))
+
+(defpartial deck-detail [d]
+ [:div (:player d)]
+ [:div.main (deck-block (:main d))]
+ [:div.sideboard (deck-block (:sideboard d))])
+
+(defpartial tournament-detail [t]
+ [:div (tournament-link t)]
+ [:ul.decks (map deck-detail (:decks t))]
+ [:pre (str t)])
+
+(defpage "/tournament/:id" {tournament-id :id}
+ (let [t (load-tournament tournament-id)]
+ (tournament-detail t)))

0 comments on commit ec984de

Please sign in to comment.