-
-
Save bredov/57e7f71802294bca5ced to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns learning.views.admin | |
(:require [learning.views.common :as common] | |
[learning.models.admin :as admin] | |
[learning.models.request :as requests] | |
[noir.validation :as vali]) | |
(:use [noir.core] | |
[hiccup.core])) | |
(println "\n\n\n======== Begin compiling views/admin.clj ========\n\n\n") | |
(pre-route "/admin*" [] | |
(when-not (admin/logged?) | |
(noir.response/redirect "/login"))) | |
;; | |
;; Login/Logout | |
;; | |
(defpage login "/login" [] | |
(common/layout | |
(vali/on-error :password common/error-box) | |
[:form {:method "POST" :action (url-for login)} | |
[:input {:type "password" :name "password" :id "password"}] | |
[:input {:type "submit"}]])) | |
(defpage [:post "/login"] {:as admin-user} | |
(admin/login! (:password admin-user))) | |
(defpage logout "/admin/logout" [] | |
(admin/logout!)) | |
;; | |
;; Helpers | |
;; | |
(defpartial request-item [date name] | |
[:tr [:td (.toString date)] [:td name]]) | |
;; | |
;; Requests | |
;; | |
(defn closest-day [] | |
(requests/next-exact-day #(or (requests/monday? %) | |
(requests/friday? %) | |
(requests/saturday? %)))) | |
(defpage request-list "/admin/requests" [] | |
(common/layout | |
[:table {:border "1px" :align "center" :width "70%" :cellpadding "10px"} | |
(for [request (requests/all)] | |
(request-item (:date request) (:name request)))])) | |
(defpage closest "/admin/closest" [] | |
(common/layout | |
[:table {:border "1px" :align "center" :width "70%" :cellpadding "10px"} | |
(for [request (requests/date->requests (closest-day))] | |
(request-item (:date request) (:name request)))])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; common.clj | |
(alias 'admin-view 'learning.views.admin) | |
;; ... | |
(def admin-links [[(url-for admin-view/request-list) "Заявки на участие"] | |
[(url-for admin-view/closest) "Заявки на ближайший экзамен"] | |
[(url-for admin-view/logout) "Выйти"]]) | |
;; ... | |
(defpartial layout-footer [] | |
[:div.layout-footer {:style "padding: 20px;"} | |
(when (admin/logged?) | |
(for [[url title] admin-links] | |
(link-to {:id "navigation"} url title)))]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment