<commit_before>(ns kixi.hecuba.widgets.map
  (:require
   [kixi.hecuba.tabs.slugs :as slugs]
   [om.core :as om :include-macros true]
   [om.dom :as dom :include-macros true]
   [clojure.string :as str]
   [kixi.hecuba.common :refer (log)]))

(defn- ->lat-long [{:keys [latitude longitude]}]
  (when (and latitude longitude)
    (.latLng js/L latitude longitude)))

(defn add-marker [map latlng popup]
  (when latlng
    (-> (.marker js/L latlng)
        (.addTo map)
        (.bindPopup popup))))

(defn draw-map
  [cursor node]
  (let [map   (-> (.map js/L node)
                  (.setView (.latLng js/L 53.0 -1.5) 6))
        tiles (.tileLayer js/L "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
                          {:attribution "Map data &copy; 2011 OpenStreetMap contributors, Imagery."})]
    (.addTo tiles map)
    map))

;; TODO I want to build the html using sablono, but it doesn't seem to play nice with leaflet.addMarker().
;;      solutions from YOU! dear reader are most welcome.
(defn build-popup [owner {:keys [property_data name photos entity_id] :as e}]
  (let [{:keys [address_street address_street_two address_region address_country description tech-icons]} property_data
        full-address (slugs/postal-address property_data)
        title (:property_code property_data) ;; TODO what should go here?
        img-url (:uri (first photos))
        entity-url (str "/search#" entity_id)
        tech-icons (apply str (for [i (:technology_icons property_data) :when i]
                                (str "<div class=\"col-xs-1 tech-icon-container-sm\">"
                                     "<img alt=\" \" class=\"img-responsive tech-icon\" src=\"" i "\"></div>")))]
    (str "<div class=\"container-fluid container-xs-height\">
            <div class=\"panel panel-default\">
              <div class=\"panel-heading\">
                <h3 class=\"panel-title\">" title "</h3>
              </div>
              <div class=\"panel-body\">
                <div class=\"row row-xs-height\">
                  <div class=\"col-xs-12 col-xs-height\">
                    <div class=\"row row-xs-height\">
                      <div class=\"col-xs-4 col-xs-height\">
                        <img class=\"img-responsive\" alt=\" \" src=\"" img-url "\" ></img>
                        <a href=\"" entity-url "\">view</a>
                      </div>
                      <div class=\"col-xs-8 col-xs-height\">
                      " full-address "
                      </div>
                    </div>
                    <div class=\"row row-xs-height\">
                      " tech-icons "
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>")))

(defn map-item
  [cursor owner]
  (reify
    om/IRender
    (render [_]
      (dom/div nil))<commit_msg>Better map popup layout.<commit_after>(ns kixi.hecuba.widgets.map
  (:require
   [kixi.hecuba.tabs.slugs :as slugs]
   [om.core :as om :include-macros true]
   [om.dom :as dom :include-macros true]
   [clojure.string :as str]
   [kixi.hecuba.common :refer (log)]))

(defn- ->lat-long [{:keys [latitude longitude]}]
  (when (and latitude longitude)
    (.latLng js/L latitude longitude)))

(defn add-marker [map latlng popup]
  (when latlng
    (-> (.marker js/L latlng)
        (.addTo map)
        (.bindPopup popup))))

(defn draw-map
  [cursor node]
  (let [map   (-> (.map js/L node)
                  (.setView (.latLng js/L 53.0 -1.5) 6))
        tiles (.tileLayer js/L "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
                          {:attribution "Map data &copy; 2011 OpenStreetMap contributors, Imagery."})]
    (.addTo tiles map)
    map))

;; TODO I want to build the html using sablono, but it doesn't seem to play nice with leaflet.addMarker().
;;      solutions from YOU! dear reader are most welcome.
(defn build-popup [owner {:keys [property_data name photos entity_id] :as e}]
  (let [{:keys [address_street address_street_two address_region address_country description tech-icons]} property_data
        full-address (slugs/postal-address property_data)
        title (:property_code property_data) ;; TODO what should go here?
        img-url (:uri (first photos))
        entity-url (str "/search#" entity_id)
        tech-icons (apply str (for [i (:technology_icons property_data) :when i]
                                (str "<img alt=\" \" src=\"" i "\">")))]
    (str "<div class=\"container-fluid container-xs-height\">
            <div class=\"panel panel-default\">
              <div class=\"panel-heading\">
                <h3 class=\"panel-title\">" title "</h3>
              </div>
              <div class=\"panel-body\">
                <div class=\"panel\">
                  <div class=\"\">" full-address "</div>
                  <div class=\"tech-icon-container-sm\">" tech-icons "</div>
                </div>
                <img class=\"img-responsive\" alt=\" \" src=\"" img-url "\" ></img>
                <a href=\"" entity-url "\">view</a>
              </div>
            </div>
          </div>")))

(defn map-item
  [cursor owner]
  (reify
    om/IRender
    (render [_]
      (dom/div nil))
{'fraction_non_alphanumeric': 0.15938697318007664, 'fraction_numerical': 0.005555555555555556, 'mean_word_length': 1.840587595212187, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597460', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1607, 'n_words': 437}