Created
July 8, 2014 12:05
-
-
Save mokevnin/afcc17add296aab6c91d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hexlet.terminal.components | |
(:require | |
[cljs.core.async :as a] | |
[hexlet.shared :refer [chan]] | |
[quiescent :as q :include-macros true] | |
[quiescent.dom :as d] | |
[components.rails :as rails] | |
[hexlet.helpers :as h] | |
[hexlet.terminal.actions :as actions])) | |
(enable-console-print!) | |
(q/defcomponent TerminalStatBox | |
[{:keys [jquery-terminal finished unpassed-terminals current lesson] :as state} push] | |
(q/wrapper (let [terminal (:terminal current) | |
terminals-count (:terminals_count h/gon) | |
percent (.toFixed (* 100 (/ (- terminals-count (count unpassed-terminals)) terminals-count)) 0) | |
formatted-percent (str percent "%")] | |
(d/div {} | |
(d/div {} | |
(d/div {:className "progress"} | |
(d/div {:className "progress-bar" :style {:width formatted-percent}} | |
formatted-percent))) | |
(d/p {} (js/t "web.lessons.terminal.terminals_count") terminals-count) | |
(d/p {} (js/t "web.lessons.terminal.rest_terminals_count") (count unpassed-terminals)) | |
(when terminal | |
(d/div {} | |
(d/h4 {} (js/t "web.lessons.terminal.task")) | |
(d/p {} (:description terminal)) | |
(when (:result current) | |
(d/input {:type "submit" | |
:className "btn btn-success" | |
:onClick #(push actions/set-next-terminal % {:target (.-target %)}) | |
:value (js/t "web.lessons.terminal.next")})))) | |
(when (and finished (not (:finished_part h/gon))) | |
(d/div {:className "text-center"} | |
(rails/ButtonTo (js/t "web.lessons.terminal.finish") | |
(.finish_current_unit_lesson_path js/Routes (:slug lesson)) | |
{:className "btn btn-info" :method "patch"}))))) | |
:onMount #(when (not finished) (actions/attach-current-terminal state)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment