JuliaGizmos / Escher.jl

Composable Web UIs in Julia
https://juliagizmos.github.io/Escher.jl
Other
337 stars 63 forks source link

How to use mongo commands in escher.jl? #175

Closed n-raghu closed 8 years ago

n-raghu commented 8 years ago

Hi, I have created below sample code to display mongo collection in browser but could not succeed. Can someone identify where am I doing wrong?

import Escher: @api, render
using Mongo,LibBSON, FactCheck

cli = MongoClient("mongodb://localhost:64116")
org = MongoCollection(cli, "FFC", "Org")
stack = find(org, Dict())

app = 
for doc in stack
  println(doc)
end

main(window) = begin
    push!(window.assets, "layout2")
    push!(window.assets, "icons")
    push!(window.assets, "widgets")

    t, p = wire(tabs([hbox(icon("home"), hskip(1em), "Home"),
                      hbox(icon("info-outline"), hskip(1em),  "Notifications"),
                      hbox(icon("info"), hskip(1em), "About")]),
                pages([app, "NO Notifications", "About"]), :tabschannel, :selected)

    vbox(toolbar(["FFC", flex(), iconbutton("face")]),
         maxwidth(116em, t),
         Escher.pad(1em, p))
end

edit: formatting

shashi commented 8 years ago

What should app be? in your case it will be nothing because a for loop always returns nothing. You might want to use join(map(string, stack), "\n") instead.

You don't need import Escher: @api, render or using FactCheck

n-raghu commented 8 years ago

Thank you, shashi, it works. Even though, we use "\n", I don't see a carriage return applied, all the docs get piled up. Any work around for this?

shashi commented 8 years ago

vbox(map(string, stack)) should do it. Or vbox(intersperse(vskip(1em), map(string, stack))) to give some space between them.

n-raghu commented 8 years ago

perfect vbox(map(string, stack)) works for me. Thanks for the quick solution.