<commit_before>(ns communitics.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [goog.events :as events]
            [cljs.reader :as reader]
            [om-sync.util :refer [edn-xhr]]
            [weasel.repl :as repl])
  (:import [goog.net XhrIo]
           goog.net.EventType
           [goog.events EventType]))

(when-not (repl/alive?)
  (repl/connect "ws://localhost:9001"))


(enable-console-print!)

(defonce app-state (atom {:title "Communitics"
                          :users ["no result"]}))

(def serveraddress "http://localhost:10555")

(defn call-server [cb command]
  (edn-xhr
    {:method :get
     :url (str serveraddress command)
     :data {}
     :on-complete cb}))


(om/root
  (fn [app owner]
    (reify
      om/IRender
      (render [_]
        (dom/div
          nil
          (dom/div nil
                   (dom/h1 nil (:title app))
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (om/transact! app :users (fn [_] res))
                                (println "Found users:" (count (:users @app))))
                              "/users"))}
                     "List users")
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (om/transact! app :crawl-result (fn [_] res))
                                (println "Craw github:" (:crawl-result @app)))
                              "/crawl"))}
                     "Crawl Github")
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (println "Triggered database clearing")
                                (om/transact! app :clear-database-result (fn [_] res))
                                (println "Clear database: " (:clear-database-result @app) " datom deleted"))
                              "/clear-database"))}
                     "Clear database")
                   (dom/label nil (str "Crawled and imported " (pr-str (:import-count (:crawl-result app))) " users."))
                   #_(dom/textarea #js {:value (pr-str (:users app))}))
          (dom/div nil
                   (dom/h1 nil "Github")
                   (dom/h3 nil (count (:users app)) " users")
                   (apply dom/ul nil
                          (map #(dom/li nil (pr-str %)) (:users app)))))
        )))
  app-state
  {:target (. js/document (getElementById "app"))})


(defn foo [v]
  (swap! app-state assoc :title v))
<commit_msg>Split rendering into Om components<commit_after>(ns communitics.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [goog.events :as events]
            [cljs.reader :as reader]
            [om-sync.util :refer [edn-xhr]]
            [weasel.repl :as repl])
  (:import [goog.net XhrIo]
           goog.net.EventType
           [goog.events EventType]))

(when-not (repl/alive?)
  (repl/connect "ws://localhost:9001"))


(enable-console-print!)

(defonce app-state (atom {:title "Communitics"
                          :users ["no result"]}))

(def serveraddress "http://localhost:10555")

(defn call-server [cb command]
  (edn-xhr
    {:method :get
     :url (str serveraddress command)
     :data {}
     :on-complete cb}))


(defn user-view [user]
  (reify
    om/IRender
    (render [_]
      (dom/li nil (pr-str user)))))

(defn users-view [users]
  (reify
    om/IRender
    (render [_]
      (dom/div nil
               (dom/h1 nil "Github")
               (dom/h3 nil (count users) " users")
               (apply dom/ul nil
                      (om/build-all user-view users))))))

(om/root
  (fn [app owner]
    (reify
      om/IRender
      (render [_]
        (dom/div
          nil
          (dom/div nil
                   (dom/h1 nil (:title app))
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (om/transact! app :users (fn [_] res))
                                (println "Found users:" (count (:users @app))))
                              "/users"))}
                     "List users")
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (println "Start crawling github for users")
                                (om/transact! app :crawl-result (fn [_] res))
                                (println "Crawled github, found " (:crawl-result @app)))
                              "/crawl"))}
                     "Crawl Github")
                   (dom/button
                     #js {:className "pure-button pure-button-primary"
                          :onClick
                          (fn [_]
                            (call-server
                              (fn [res]
                                (println "Triggered database clearing")
                                (om/transact! app :clear-database-result (fn [_] res))
                                (println "Clear database: " (:clear-database-result @app) " datom deleted"))
                              "/clear-database"))}
                     "Clear database")
                   (dom/label nil (str "Crawled and imported " (pr-str (:import-count (:crawl-result app))) " users."))
                   #_(dom/textarea #js {:value (pr-str (:users app))})
                   (om/build users-view (:users app)))
          ))))
  app-state
  {:target (. js/document (getElementById "app"))})




(defn foo [v]
  (swap! app-state assoc :title v))

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0037220843672456576, 'mean_word_length': 1.1088947024198823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805663', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1710, 'n_words': 431}