|
11 | 11 | [foreclojure.template :only [def-page content-page]]
|
12 | 12 | [foreclojure.social :only [tweet-link]]
|
13 | 13 | [foreclojure.feeds :only [create-feed]]
|
14 |
| - [foreclojure.users :only [golfer? get-user-id disable-codebox?]] |
| 14 | + [foreclojure.users :only [golfer? get-user-id disable-codebox? get-ranked-users]] |
15 | 15 | [foreclojure.solutions :only [save-solution get-solution]]
|
16 | 16 | [clojail.core :exclude [safe-read]]
|
17 | 17 | [clojail.testers :only [secure-tester blacklist-symbols]]
|
@@ -338,35 +338,57 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
|
338 | 338 | " to view unapproved problems")))
|
339 | 339 | (error "No such problem!"))))
|
340 | 340 |
|
| 341 | +(defn solution-block [username code] |
| 342 | + [:div.follower-solution |
| 343 | + [:div.solution-username |
| 344 | + (link-to (str "/user/" username) username) |
| 345 | + "'s solution:"] |
| 346 | + [:pre.solution-code |
| 347 | + (escape-html code)]]) |
| 348 | + |
341 | 349 | (def-page show-solutions-page [problem-id]
|
342 | 350 | {:title "4Clojure - Problem Solutions"
|
343 | 351 | :content
|
344 | 352 | (list
|
345 | 353 | [:div.message (session/flash-get :message)]
|
346 | 354 | [:div#problems-error.error (session/flash-get :error)]
|
347 |
| - [:h3 {:style "margin-top: -20px;"} "Solutions:"] |
| 355 | + [:h3 {:style "margin-top: -20px;"} "Your solution"] |
348 | 356 | (with-user [{:keys [_id following]}]
|
349 | 357 | (list
|
350 | 358 | (let [user-code (get-solution :public _id problem-id)]
|
351 | 359 | [:pre.solution-code.solution-user-code
|
352 | 360 | (escape-html user-code)])
|
353 |
| - (if (empty? following) |
354 |
| - [:p "You can only see solutions of users whom you follow. Click on any name from the " (link-to "/users" "users") " listing page to see their profile, and click follow from there."] |
355 |
| - (if (some (complement nil?) (map #(get-solution :public % problem-id) following)) |
356 |
| - (interpose [:hr.solution] |
357 |
| - (for [f-user-id following |
358 |
| - :let [f-user (:user (from-mongo |
359 |
| - (fetch-one :users |
360 |
| - :where {:_id f-user-id} |
361 |
| - :only [:user]))) |
362 |
| - f-code (get-solution :public |
363 |
| - f-user-id problem-id)] |
364 |
| - :when f-code] |
365 |
| - [:div.follower-solution |
366 |
| - [:div.solution-username (str f-user "'s solution:")] |
367 |
| - [:pre.solution-code |
368 |
| - (escape-html f-code)]])) |
369 |
| - [:p "None of the users you follow have solved this problem yet!"])))))}) |
| 361 | + |
| 362 | + [:h3 "Your followers' solutions"] |
| 363 | + (if (some (complement nil?) (map #(get-solution :public % problem-id) following)) |
| 364 | + (interpose |
| 365 | + [:hr.solution] |
| 366 | + (for [f-user-id following |
| 367 | + :let [f-user (:user (from-mongo |
| 368 | + (fetch-one :users |
| 369 | + :where {:_id f-user-id} |
| 370 | + :only [:user]))) |
| 371 | + f-code (get-solution :public |
| 372 | + f-user-id problem-id)] |
| 373 | + :when f-code] |
| 374 | + (solution-block f-user f-code))) |
| 375 | + [:p "None of the users you follow have solved this problem yet!"]) |
| 376 | + |
| 377 | + [:h3 "Top users' solutions"] |
| 378 | + [:p "These solutions were written by some of the top users of 4Clojure."] |
| 379 | + (interpose |
| 380 | + [:hr.solution] |
| 381 | + (let [top-users (take 15 (get-ranked-users)) |
| 382 | + top-users-m (zipmap (map :_id top-users) top-users) |
| 383 | + |
| 384 | + solns (fetch :solutions |
| 385 | + :where {:user {:$in (map :_id top-users)} |
| 386 | + :code {:$ne nil}} |
| 387 | + :limit 5)] |
| 388 | + (for [soln solns |
| 389 | + :let [username (:user (top-users-m (:user soln))) |
| 390 | + code (:code soln)]] |
| 391 | + (solution-block username code)))))))}) |
370 | 392 |
|
371 | 393 | (defn show-solutions [id]
|
372 | 394 | (let [problem-id (Integer. id)
|
|
0 commit comments