<commit_before>(ns org.dada2.web.table-view
  (import
   [com.vaadin.ui
    UI
    Label
    Table
    ]
   [com.vaadin.data
    Item
    Property
    ]
   )
  (use
   [org.dada2 core])
  )

;; metadata - list of tuples: [key type value-fn]

(defn- upsert [^Table table upsertion pk-fn vals-fn]
  (let [pk (pk-fn upsertion)]
    (if-let [^Item item (.getItem table pk)]
      (doall                            ;TODO - don't use map
       (map 
        (fn [id new-value]
          (let [^Property property (.getItemProperty item id)
                old-value (.getValue property)]
            (if (not (= old-value new-value))
              (.setValue property new-value))
            ))
        (.getItemPropertyIds item)
        (vals-fn upsertion)
        ))
      (.addItem table (into-array Object (vals-fn upsertion)) pk))))

(deftype TableView [^UI ui ^Table table pk-fn vals-fn]
  View
  (on-upsert [this upsertion]
    (.access ui (fn [] (upsert table upsertion pk-fn vals-fn)))
    this)
  (on-upserts [this upsertions] 
    (.access ui (fn [] (doseq [upsertion upsertions] (upsert table upsertion pk-fn vals-fn))))
    this)
  Object
  (^String toString [this] (.toString table))
  )

(defn table-view [^UI ui ^Table table pk-fn metadata]
  (doseq [[key type] metadata] (.addContainerProperty table (.toString key) Object nil))
  (TableView. ui table pk-fn vals))<commit_msg>give vaadin mode type info<commit_after>(ns org.dada2.web.table-view
  (import
   [com.vaadin.ui
    UI
    Label
    Table
    ]
   [com.vaadin.data
    Item
    Property
    ]
   )
  (use
   [org.dada2 core])
  )

;; metadata - list of tuples: [key type value-fn]

(defn- upsert [^Table table upsertion pk-fn vals-fn]
  (let [pk (pk-fn upsertion)]
    (if-let [^Item item (.getItem table pk)]
      (doall                            ;TODO - don't use map
       (map 
        (fn [id new-value]
          (let [^Property property (.getItemProperty item id)
                old-value (.getValue property)]
            (if (not (= old-value new-value))
              (.setValue property new-value))
            ))
        (.getItemPropertyIds item)
        (vals-fn upsertion)
        ))
      (.addItem table (into-array Object (vals-fn upsertion)) pk))))

(deftype TableView [^UI ui ^Table table pk-fn vals-fn]
  View
  (on-upsert [this upsertion]
    (.access ui (fn [] (upsert table upsertion pk-fn vals-fn)))
    this)
  (on-upserts [this upsertions] 
    (.access ui (fn [] (doseq [upsertion upsertions] (upsert table upsertion pk-fn vals-fn))))
    this)
  Object
  (^String toString [this] (.toString table))
  )

(defn table-view [^UI ui ^Table table pk-fn metadata]
  (doseq [[key type] metadata] (.addContainerProperty table (.toString key) type nil))
  (TableView. ui table pk-fn vals))

;; support for deleting rows
;; flash cells on update
;; sort columns
;; is this the best way to get what we want
;; why are all column headers inn caps
;; where is the mode name header ?
;; drill down by row and by cell

{'fraction_non_alphanumeric': 0.1266622340425532, 'fraction_numerical': 0.0013297872340425532, 'mean_word_length': 2.2885245901639344, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5559673', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1008, 'n_words': 319}