<commit_before>(ns ixinfestor.omut

  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [cljs.core.async :refer [put! chan <!]]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]

            ;;[sablono.core :as html :refer-macros [html]]

            [ixinfestor.net :as ixnet]

            ))




(def modal-app-init
  {:show false})

(defn modal-show [app]
  (om/transact!
   app [:show]
   (fn [i] (if i (inc i) 0))))

(defn modal-hide [app]
  (om/transact!
   app [:show]
   (fn [_] false)))

(defonce modal-id-seq (atom 0))
(defn- modal-id- []
  (str "modal-" (swap! modal-id-seq inc)))

(defn modal [app owner {:keys [id
                               label
                               header
                               body
                               footer
                               class+]
                        :or {id (modal-id-)
                             label "Пустая пометка"
                             header (dom/h4 #js {:className "modal-title"} "Пустой заголовок")
                             body (dom/p #js {:className "text-info"}
                                         "Пустое пространство диалога. Можно наполнить элементами")
                             footer (dom/button #js {:className "btn btn-default"
                                                     :type "button"
                                                     :onClick (fn [_] (om/update! app :show false) 1)
                                                     :data-dismiss "modal"}
                                                "Закрыть")
                             class+ ""}}]
  (let [d-id  (name id)
        qd-id (str "#" d-id)]
    (reify
      om/IDidUpdate
      (did-update [this prev-props prev-state]
        (if-let [show (get-in app [:show] false)]
          (-> qd-id js/jQuery (.modal "show"))
          (-> qd-id js/jQuery (.modal "hide"))))
      om/IRender
      (render [this]
        (dom/div
         nil
         (dom/div #js {:id d-id
                       :aria-hidden "true"
                       :aria-labelledby label
                       :className "modal fade "
                       :role "dialog"
                       :tabIndex "-1"}
                  (dom/div #js {:className (str "modal-dialog " class+)}
                           (dom/div #js {:className "modal-content"}
                                    (dom/div #js {:className "modal-header"} header)
                                    (dom/div #js {:className "modal-body"} body)
                                    (dom/div #js {:className "modal-footer"} footer)))))))))










(def helper-p-app-init
  {:text-muted nil
   :text-primary nil
   :text-success nil
   :text-info nil
   :text-warning nil
   :text-danger nil})


(defn helper-p [app _]
  (reify<commit_msg>Переработал модальные диалоги, теперь без JQuery<commit_after>(ns ixinfestor.omut

  (:import [goog.dom query])

  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [cljs.core.async :refer [put! chan <!]]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]

            [goog.dom.classes :as aclasses]
            ;;[sablono.core :as html :refer-macros [html]]

            [ixinfestor.net :as ixnet]

            ))



(def modal-app-init
  {:show false})

(defn modal-show [app]
  (om/transact!
   app :show
   (fn [i] (if i (inc i) 0))))

(defn modal-hide [app]
  (om/transact!
   app :show
   (fn [_] false)))


(defonce modals-ids (atom 0))
(defn get-modal-id [] (swap! modals-ids inc))

(defonce modals-status (atom #{}))
(add-watch
 modals-status :log
 (fn [_ _ old new]
   (when (not= old new)
     (println "modals-status: " new)
     (let[tag-body (aget (query "body") 0)]
       (if (empty? new)
         (goog.dom.classes/remove tag-body "modal-open")
         (goog.dom.classes/add    tag-body "modal-open"))))))

(defn modal [app owner {:keys [label
                               header
                               body
                               footer
                               class+]
                        :or {label "Пустая пометка"
                             header (dom/h4 #js {:className "modal-title"} "Пустой заголовок")
                             body (dom/p #js {:className "text-info"}
                                         "Пустое пространство диалога. Можно наполнить элементами")
                             footer (dom/button #js {:className "btn btn-default"
                                                     :type "button"
                                                     :onClick (fn [_] (om/update! app :show false) 1)
                                                     :data-dismiss "modal"}
                                                "Закрыть")
                             class+ ""}}]
  (reify
    om/IInitState
    (init-state [_]
      {:id (get-modal-id)})
    om/IWillUnmount
    (will-unmount [_]
      (swap! modals-status disj (om/get-state owner :id)))
    om/IRenderState
    (render-state [this {id :id}]
      (println "modal id:" id)
      (let [show? (:show app)]
        (swap! modals-status (if show? conj disj) id)
        (dom/div #js {:aria-hidden "true"
                      :aria-labelledby label
                      :style (if show?
                               #js {:display "block" :paddingLeft 0}
                               #js {:display "none" })
                      :className (if show? "modal in" "modal")
                      :role "dialog"
                      :tabIndex "-1"}
                 (dom/div #js {:className (str "modal-dialog " class+)}
                          (dom/div #js {:className "modal-content"}
                                   (dom/div #js {:className "modal-header"} header)
                                   (dom/div #js {:className "modal-body"}   body)
                                   (dom/div #js {:className "modal-footer"} footer))))))))







(def helper-p-app-init
  {:text-muted nil
   :text-primary nil
   :text-success nil
   :text-info nil
   :text-warning nil
   :text-danger nil})


(defn helper-p [app _]
  (reify
{'fraction_non_alphanumeric': 0.12920895762848397, 'fraction_numerical': 0.0019333011116481392, 'mean_word_length': 1.2139800285306706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5911970', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1796, 'n_words': 466}