Ag-grid clojurescript sortable key doesn't work - ag-grid

I am trying to make a grid with ag-grid and activate sortable and filter, but it doesn't work towards localhost. In the columndefinition, I use
''':sortable true'''
''':filter true''''
But nothing happens. Does anyone know what is wrong?
(ns reagent-ag-grid-ex.core
(:require
[reagent.core :as r]
[cljsjs.ag-grid-react]
[reagent-ag-grid-ex.state :as state]))
;; -------------------------
;; Views
(def ag-adapter (r/adapt-react-class (.-AgGridReact js/agGridReact) ))
;;(defn get-cols [entry]
;; (into [] (map #(hash-map :headerName (-> % key name) :field (-> % key name)) entry)))
;;columnDefs: [ {headerName: "Make", field: "make"}, {headerName: "Model", field: "model"}, {headerName: "Price", field: "price"} ]
;;rowData: [ {make: "Toyota", model: "Celica", price: 35000}, {make: "Ford", model: "Mondeo", price: 32000}, {make: "Porsche", model: "Boxter", price: 72000}]
(def deafult-col-w 200)
(defn width-helper [lst]
(+ (* deafult-col-w (count lst)) 2))
(defn home-page []
[:div [:h2 "Ekspono tag-model"]
[:p "My portfolio / Top Index " [:a {:style {:background-color "#C0C0C0" :float "right" :color "black"}
:href "https://www.google.com" :target "_blank"} "Show problems"]]
[:div {:className "ag-theme-balham" :style {:height 200 :width (width-helper state/cols) :color "purple"}}
[ag-adapter {"columnDefs" state/cols
"rowData" state/rows
"defaultColDef" {:sortable true
:width deafult-col-w}}]]
[:div [:a {:href "https://www.tabyenskilda.se/fredrik-cumlin/" :target "_blank"}
"#copyright Fredrik Cumlin"]]])
;; -------------------------
;; Initialize app
(defn mount-root []
(r/render [home-page] (.getElementById js/document "app")))
(defn init! []
(mount-root))

Upgrade to latest ag-grid-react cljsjs distribution (21.0.1-1) - e.g. using lein project.clj switch dep to [cljsjs/ag-grid-react "21.0.1-1"]. Should work on this version.
Also as a side note, no need to specify prop keys with strings, you can use keywords - it's a bit more idiomatic.

Related

Elixir ecto: check if postgresql map column has key

To use json/jsonb data type ecto suggets to use fragments.
In my case, I've to use PostgreSQL ? operator to see if the map has such key, this however it will become something like:
where(events, [e], e.type == 1 and not fragment("???", e.qualifiers, "?", "2"))
but of course fragment reads the PostgreSQL ? as a placeholder. How can I check if the map has such key?
You need to escape the middle ? and pass a total of three arguments to fragment:
fragment("? \\? ?", e.qualifiers, "2")
Demo:
iex(1)> MyApp.Repo.insert! %MyApp.Food{name: "Foo", meta: %{price: 1}}
iex(2)> MyApp.Repo.insert! %MyApp.Food{name: "Foo", meta: %{}}
iex(3)> MyApp.Repo.all from(f in MyApp.Food, where: fragment("? \\? ?", f.meta, "price"))
[debug] SELECT f0."id", f0."name", f0."meta", f0."inserted_at", f0."updated_at" FROM "foods" AS f0 WHERE (f0."meta" ? 'price') [] OK query=8.0ms
[%MyApp.Food{__meta__: #Ecto.Schema.Metadata<:loaded>, id: 1,
inserted_at: #Ecto.DateTime<2016-06-19T03:51:40Z>, meta: %{"price" => 1},
name: "Foo", updated_at: #Ecto.DateTime<2016-06-19T03:51:40Z>}]
iex(4)> MyApp.Repo.all from(f in MyApp.Food, where: fragment("? \\? ?", f.meta, "a"))
[debug] SELECT f0."id", f0."name", f0."meta", f0."inserted_at", f0."updated_at" FROM "foods" AS f0 WHERE (f0."meta" ? 'a') [] OK query=0.8ms
[]
I'm not sure if this is documented anywhere, but I found the method from this test.

I'm attempting to connect to MongoDB with a Clojure application, via Docker

I have the following docker-compose rules...
catalog-service:
build: ./services/catalog
ports:
- "2000:3000"
depends_on:
- catalog-datastore
restart: always
catalog-datastore:
image: mongo:3.0
command: mongod --smallfiles --quiet --logpath=/dev/null
ports:
- "27017:27017"
The following Dockerfile for the clojure app...
FROM clojure
COPY . /usr/src/app
WORKDIR /usr/src/app
CMD ["lein", "ring", "server"]
And the following connection code in my app...
(ns catalog.handler
(:import com.mchange.v2.c3p0.ComboPooledDataSource)
(:use compojure.core)
(:use cheshire.core)
(:use ring.util.response)
(:require [compojure.handler :as handler]
[ring.middleware.json :as middleware]
[clojure.java.jdbc :as sql]
[compojure.route :as route]
[somnium.congomongo :as m]))
(def conn
(m/make-connection "catalog"
:host "catalog-datastore"
:port 27017))
(defn get-all []
(m/fetch :catalog))
(defn get-single [id]
(m/fetch-one
:catalog
:where{:_id (Long/parseLong id)}))
(defroutes app-routes
(context "/catalog" [] (defroutes catalog-routes
(GET "/" [] (get-all))
(GET "/:id", [id] (get-single)))))
(def app
(-> (handler/api app-routes)
(middleware/wrap-json-body)
(middleware/wrap-json-response)))
When I try to run the app I get the error...
java.lang.AssertionError
Assert failed: (connection? conn)
From the docs:
set the connection globally
(m/set-connection! conn)
or locally
(m/with-mongo conn
(m/insert! :robots {:name "robby"}))
Looks like you missed that bit. :p

Helm multi-selection pre select multiple candidates

I have a helm source:
(setq helm-source
`((name . "My source")
(candidates . ("Option 1" "Option 2" "Option 3" "Option 4"))
(action . (lambda (candidate) (helm-marked-candidates)))))
And later get the selected options like this:
(setq result (helm :sources '(helm-source)))
I want that "Option 2" and "Option 3" are already marked in the same way I could mark them with C-SPC.

Clojure JDBC: Failing to Find Postgres Driver

I am working on a web service that needs to talk to a database, so I am tooling up my basic libraries to give me access to postgres on my desktop.
Jun 5, 2013 1:27:46 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask#15c313da -- Acquisition
Attempt Failed!!! Clearing pending acquires.
While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
In my db library I have the following
(ns myapp.db
(:import [com.mchange.v2.c3p0 ComboPooledDataSource]))
(def specification {
:classname "postgresql"
:subprotocol "org.postgresql.Driver"
:subname "//localhost:5432;database=test"
})
(defn pooled-data-source [specification]
(let [datasource (ComboPooledDataSource.)]
(.setDriverClass datasource (:classname specification))
(.setJdbcUrl datasource (str "jdbc:" (:subprotocol specification) ":" (:subname specification)))
(.setUser datasource (:user specification))
(.setPassword datasource (:password specification))
(.setMaxIdleTimeExcessConnections datasource (* 30 60))
(.setMaxIdleTime datasource (* 3 60 60))
{:datasource datasource}))
(def connection-pool
(delay
(pooled-data-source specification)))
(defn connection [] #connection-pool)
Then in my unit test:
(ns myapp.db-test
(:use clojure.test)
(:require [myapp.db]
[clojure.java.jdbc :as jdbc]))
(let [db (myapp.db/connection)]
(jdbc/with-connection db)
(jdbc/with-query-results rs ["select * from foo"]
(doseq [row rs]
(println row)))))
However this does work in the REPL so at least I know the database is up and accepting connections:
user=> (require '[clojure.java.jdbc :as sql])
user=> (sql/with-connection "postgresql://localhost:5432/test"
(sql/with-query-results results ["select * from foo"]
(doseq [result results] (println result))))
{:y 2, :x 1}
nil
user=>
Help with this is greatly appreciated!
My project.clj is as follows
(defproject myapp "0.1.0"
:description "myapp"
:dependencies [
[org.clojure/clojure "1.5.1"]
[org.clojure/java.jdbc "0.3.0-alpha4"]
[postgresql "9.1-901.jdbc4"]
[c3p0/c3p0 "0.9.1.2"]])
I'd suggest to fix your specification
(def specification {
:subprotocol "postgresql"
:classname "org.postgresql.Driver"
:subname "//localhost:5432/test"})
there might be other issues as well (i'm very much a clojure novice), but you definitely have :classname and :subprotocol inverted in your specification. :classname should be "org.postgresql.Driver". :subprotocol should be "postgresql".

How to update / insert a MongoDB sub document with Monger?

I'm using Clojure's Monger library to connect to a MongeoDB database.
I want to update, insert & remove subdocuments in my Mongo database. MongoDB's $push modifier lets me do this on the root of the searched document. But I want to be able to $push onto a sub-collection. Looking at Monger's tests, it looks possible. But I want to be sure I can push to the child-collection of the 3rd parent. Can Monger do something like this?
(mgcol/update mycollection { :my-criteria-key "my-criteria-value" } { $push { "parent.3.child-collection" "fubar" }} )
Even better would be the ability to have a $where clause in my $push. Is something like this possible?
(mgcol/update mycollection
{ :doc-criteria-key "doc-criteria-value" }
{ $push
{ { $where { parent.child.lastname: 'Smith' } }
"fubar" } }
)
But even on a basic level, when I try the following command in my repl, I get the below error.
The "fubar" database definitely exists
I'm definitely connected to the DB
The { :owner "fubar#gmail.com" } criteria is definitely valid; and
I tried both "content.1.content" and "content.$.content":
repl => (mc/update "fubar" { :owner "fubar#gmail.com" } { $push { "content.1.content" { "fu" "bar" } } } )
ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB monger.collection/update (collection.clj:310)
repl =>
repl =>
repl => (clojure.repl/pst *e)
ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB
monger.collection/update (collection.clj:310)
bkell.run.run-ring/eval2254 (NO_SOURCE_FILE:46)
clojure.lang.Compiler.eval (Compiler.java:6406)
clojure.lang.Compiler.eval (Compiler.java:6372)
clojure.core/eval (core.clj:2745)
clojure.main/repl/read-eval-print--6016 (main.clj:244)
clojure.main/repl/fn--6021 (main.clj:265)
clojure.main/repl (main.clj:265)
user/eval27/acc--3869--auto----30/fn--32 (NO_SOURCE_FILE:1)
java.lang.Thread.run (Thread.java:619)
Had anyone come across this and solved it?
Thanks
You have a three part question, with some inconsistencies and holes in the description. So here is my best guess, hope that it is close.
I can get all three to work given schema matched to your update requests, see test/core.clj below for complete details.
First part: Yes, you can push to the child-collection of the 3rd parent, exactly as you have written.
Second part: You want to move your "$where" clause into the criteria, and use $ in the objNew.
Third part: Yes, your basic update works for me below, exactly as you have written.
The output of "lein test" follows at the bottom. All the best to you in your endeavors.
test/core.clj
(ns free-11749-clojure-subdoc.test.core
(:use [free-11749-clojure-subdoc.core])
(:use [clojure.test])
(:require [monger.core :as mg] [monger.collection :as mgcol] [monger.query])
(:use [monger.operators])
(:import [org.bson.types ObjectId] [com.mongodb DB WriteConcern]))
(deftest monger-sub-document
(mg/connect!)
(mg/set-db! (mg/get-db "test"))
(def mycollection "free11749")
;; first part
(mgcol/remove mycollection)
(is (= 0 (mgcol/count mycollection)))
(def doc1 {
:my-criteria-key "my-criteria-value"
:parent [
{ :child-collection [ "cc0" ] }
{ :child-collection [ "cc1" ] }
{ :child-collection [ "cc2" ] }
{ :child-collection [ "cc3" ] }
{ :child-collection [ "cc4" ] }
]
}
)
(mgcol/insert mycollection doc1)
(is (= 1 (mgcol/count mycollection)))
(mgcol/update mycollection { :my-criteria-key "my-criteria-value" } { $push { "parent.3.child-collection" "fubar" }} )
(def mymap1 (first (mgcol/find-maps mycollection { :my-criteria-key "my-criteria-value" })))
(is (= "fubar" (peek (:child-collection (get (:parent mymap1) 3)))))
(prn (mgcol/find-maps mycollection { :my-criteria-key "my-criteria-value" }))
;; second part
(mgcol/remove mycollection)
(is (= 0 (mgcol/count mycollection)))
(def doc2 {
:doc-criteria-key "doc-criteria-value"
:parent [
{ :child { :lastname [ "Alias" ] } }
{ :child { :lastname [ "Smith" ] } }
{ :child { :lastname [ "Jones" ] } }
]
}
)
(mgcol/insert mycollection doc2)
(is (= 1 (mgcol/count mycollection)))
(mgcol/update mycollection { :doc-criteria-key "doc-criteria-value" "parent.child.lastname" "Smith"} { $push { :parent.$.child.lastname "fubar" } } )
(def mymap2 (first (mgcol/find-maps mycollection { :doc-criteria-key "doc-criteria-value" })))
(is (= "fubar" (peek (:lastname (:child (get (:parent mymap2) 1))))))
(prn (mgcol/find-maps mycollection { :doc-criteria-key "doc-criteria-value" }))
;; third part
(mgcol/remove "fubar")
(is (= 0 (mgcol/count "fubar")))
(def doc3 {
:owner "fubar#gmail.com"
:content [
{ :content [ "cc0" ] }
{ :content [ "cc1" ] }
{ :content [ "cc2" ] }
]
}
)
(mgcol/insert "fubar" doc3)
(is (= 1 (mgcol/count "fubar")))
(mgcol/update "fubar" { :owner "fubar#gmail.com" } { $push { "content.1.content" { "fu" "bar" } } } )
(def mymap3 (first (mgcol/find-maps "fubar" { :owner "fubar#gmail.com" })))
(is (= { :fu "bar" } (peek (:content (get (:content mymap3) 1)))))
(prn (mgcol/find-maps "fubar" { :owner "fubar#gmail.com" }))
)
lein test
Testing free-11749-clojure-subdoc.test.core
({:_id #<ObjectId 4fb3e98447281968f7d42cac>, :my-criteria-key "my-criteria-value", :parent [{:child-collection ["cc0"]} {:child-collection ["cc1"]} {:child-collection ["cc2"]} {:child-collection ["cc3" "fubar"]} {:child-collection ["cc4"]}]})
({:_id #<ObjectId 4fb3e98447281968f7d42cad>, :doc-criteria-key "doc-criteria-value", :parent [{:child {:lastname ["Alias"]}} {:child {:lastname ["Smith" "fubar"]}} {:child {:lastname ["Jones"]}}]})
({:_id #<ObjectId 4fb3e98447281968f7d42cae>, :content [{:content ["cc0"]} {:content ["cc1" {:fu "bar"}]} {:content ["cc2"]}], :owner "fubar#gmail.com"})
Ran 1 tests containing 9 assertions.
0 failures, 0 errors.