diff --git a/README.md b/README.md index e69de29..196e0a7 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,5 @@ +# compile and run +``` +nim c -d:release -r main.nim +``` + diff --git a/code/joplin_utils.nim b/code/joplin_utils.nim index 7823f0a..d3320f2 100644 --- a/code/joplin_utils.nim +++ b/code/joplin_utils.nim @@ -1,7 +1,68 @@ import std/[asyncdispatch, httpclient] +import std/json +import std/options +import strformat +import jester -proc get_joplin_notebooks*(): Future[string] {.async.} = +type + joplin_tags* = object + id: seq[string] + parent_id: seq[string] + title: seq[string] + +# Setup user data +type + joplin_notebooks* = object + id*, parent_id*, title*: seq[string] + req*: Request + +proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} = + + # Variables + var j_nb: joplin_notebooks + var has_more: bool = true + var page: int = 1 + var url: string var client = newAsyncHttpClient() - return await client.getContent("http://localhost:41184/folders?token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f") + + # make sure to check all pages + while has_more == true: + + # request joplin API for notebooks + url = fmt"http://localhost:41184/folders?page={page}&token={token}" + var json = await client.getContent(url) -# echo waitFor get_joplin_notebooks() \ No newline at end of file + # parse jason + let joplin_notebooks_Json = parseJson(json) + + # valider qu'il n'y a plus de page + if not joplin_notebooks_Json["has_more"].getBool: + has_more = false + + # store json info into an object + var count: int = 1 + for nb in joplin_notebooks_Json["items"]: + j_nb.id.add(nb["id"].getstr) + j_nb.parent_id.add(nb["parent_id"].getstr) + j_nb.title.add(nb["title"].getstr) + count += 1 + + # aller à la page suivante + page += 1 + + return j_nb + +proc get_joplin_tags*(): Future[joplin_tags] {.async.} = + var j_tags: joplin_tags + var count = 0 + var client = newAsyncHttpClient() + var json = await client.getContent("http://localhost:41184/tags?token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f") + + let joplin_tags_Json = parseJson(json) + + for tag in joplin_tags_Json["items"]: + j_tags.id.add(tag["id"].getstr) + j_tags.parent_id.add(tag["parent_id"].getstr) + j_tags.title.add(tag["title"].getstr) + count += 1 + return j_tags \ No newline at end of file diff --git a/config/config.cfg b/config/config.cfg index 760179e..2017aca 100644 --- a/config/config.cfg +++ b/config/config.cfg @@ -8,5 +8,8 @@ pass = "" [Server] website = "https://myurl.org" title = "Joplin The New Web" -url = "127.0.0.1" -port = "7000" \ No newline at end of file +url = "0.0.0.0" +port = "7000" + +[Joplin] +token = "e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f" diff --git a/main.nim b/main.nim index 9e0c3ad..1084002 100644 --- a/main.nim +++ b/main.nim @@ -1,4 +1,5 @@ # Copyright 2019 - Thomas T. Jarløv +# [LINK] debug url : http://127.0.0.1:7000/ import db_sqlite # SQLite import jester # Our webserver @@ -9,6 +10,7 @@ import strutils # Basic functions import times # Time and date import uri # We need to encode urls: encodeUrl() + import code/database_utils # Utils used in the database import code/password_utils # Our file with password utils import code/joplin_utils @@ -29,6 +31,7 @@ let mainURL = dict.getSectionValue("Server", "url") let mainPort = parseInt dict.getSectionValue("Server", "port") let mainWebsite = dict.getSectionValue("Server", "website") +let joplin_token = dict.getSectionValue("Joplin", "token") # Database var var db: DbConn @@ -139,11 +142,6 @@ proc logout(c: var TData) = const query = sql"DELETE FROM session WHERE ip = ? AND key = ?" exec(db, query, c.req.ip, c.req.cookies["sid"]) -proc testproc(): string = - result = "" - result = "voici des infos de la proc testproc !" - - # Do the check inside our routes template createTFD() = ## Check if logged in and assign data to user @@ -204,8 +202,11 @@ routes: get "/secret": createTFD() + echo c.loggedIn if c.loggedIn: - resp genSecret(c) + var all_notebooks: joplin_notebooks + all_notebooks = waitFor get_joplin_notebooks(joplin_token) + resp Http200, {"Access-Control-Allow-Origin": "http://192.168.1.251:7000"}, genSecret(c,all_notebooks) get "/login": createTFD() @@ -232,8 +233,11 @@ routes: get "/test_notebooks": createTFD() - var all_notebooks = "" - all_notebooks = waitFor get_joplin_notebooks() - # info("route de test :") + + var all_notebooks: joplin_notebooks + all_notebooks = waitFor get_joplin_notebooks(joplin_token) + + for title in all_notebooks.title: + echo title resp test_notebooks(c, all_notebooks) diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..ed63204 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/styles.css b/public/styles.css index 32a8555..e2c61c9 100755 --- a/public/styles.css +++ b/public/styles.css @@ -43,6 +43,33 @@ body { } +/* Create two equal columns that floats next to each other */ +.column { + float: left; + padding: 10px; + height: calc(100vh - var(--header-height)); + /* flex: 50%; */ + width: 100%; +} +.left { + width: 25%; +} + +.right { + width: 75%; +} +.row { + display: flex; + width: 100%; +} + +/* Clear floats after the columns */ +.row:after { + content: ""; + display: table; + clear: both; +} + .menu-icon-btn { background: none; border: none; diff --git a/test/oop_example b/test/oop_example new file mode 100755 index 0000000..2fcc3db Binary files /dev/null and b/test/oop_example differ diff --git a/test/oop_example.nim b/test/oop_example.nim new file mode 100644 index 0000000..11a16c8 --- /dev/null +++ b/test/oop_example.nim @@ -0,0 +1,33 @@ +# type +# Notebook = object +# id: string +# title: string + +# var notebooks = newSeq[Notebook]() +# notebooks.add(Notebook(id:"12345", title: "un notebook titre")) + +# echo notebooks + + + +type + Notebook2 = ref object of RootObj + id: seq[string] + title: seq[string] + Notebooks = ref object of Notebook2 + nb_list: seq[int] + +var nb: Notebooks + +# nb.add(Notebook2(id:"123456", title: "mon titre")) + +# nb.id.add("toto") +# nb.title.add("tata") +# nb.nb_list.add(0) + + +echo nb.id +echo nb.title +echo nb.nb_list + + diff --git a/test/oop_example2 b/test/oop_example2 new file mode 100755 index 0000000..d027e31 Binary files /dev/null and b/test/oop_example2 differ diff --git a/test/oop_example2.nim b/test/oop_example2.nim new file mode 100644 index 0000000..093c1ff --- /dev/null +++ b/test/oop_example2.nim @@ -0,0 +1,26 @@ +type + Node = ref object of RootObj + value: string + active: bool + +type + NumNode = ref object of Node + +type + BinOp = ref object of Node + left, op, right: string + +var numnum = NumNode(value: "3", active: true) + +echo numnum[] +# > (value: "3", active: true) + +var add = BinOp( + left: "7", + op: "+", + right: "9", + active: true +) + +echo add[] +# > (left: "7", op: "+", right: "9", value: "", active: true)) \ No newline at end of file diff --git a/test/testJson b/test/testJson new file mode 100755 index 0000000..8b882ae Binary files /dev/null and b/test/testJson differ diff --git a/test/testJson.nim b/test/testJson.nim new file mode 100644 index 0000000..adab464 --- /dev/null +++ b/test/testJson.nim @@ -0,0 +1,84 @@ +import std/[asyncdispatch, httpclient] +import std/json +import std/options +import std/strformat +import jester + +# type +# joplin_notebooks* = object +# id: seq[string] +# parent_id: seq[string] +# title: seq[string] + + +# proc get_joplin_notebooks*(): Future[joplin_notebooks] {.async.} = +# var j_nb: joplin_notebooks +# var count = 0 +# var client = newAsyncHttpClient() +# var json = await client.getContent("http://localhost:41184/folders?token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f") + +# let joplin_notebooks_Json = parseJson(json) + +# for nb in joplin_notebooks_Json["items"]: +# j_nb.id.add(nb["id"].getstr) +# j_nb.parent_id.add(nb["parent_id"].getstr) +# j_nb.title.add(nb["title"].getstr) +# count += 1 + +# echo joplin_notebooks_Json["has_more"] + +# return j_nb + + +# Setup user data +type + joplin_notebooks* = object + id*, parent_id*, title*: seq[string] + req*: Request + +proc get_joplin_notebooks*(token:string): Future[joplin_notebooks] {.async.} = + + # Variables + var j_nb: joplin_notebooks + var has_more: bool = true + var page: int = 1 + var url: string + var client = newAsyncHttpClient() + + # make sure to check all pages + while has_more == true: + + # request joplin API for notebooks + url = fmt"http://localhost:41184/folders?page={page}&token={token}" + var json = await client.getContent(url) + + # parse jason + let joplin_notebooks_Json = parseJson(json) + + # valider qu'il n'y a plus de page + if not joplin_notebooks_Json["has_more"].getBool: + has_more = false + + # store json info into an object + var count: int = 1 + for nb in joplin_notebooks_Json["items"]: + j_nb.id.add(nb["id"].getstr) + j_nb.parent_id.add(nb["parent_id"].getstr) + j_nb.title.add(nb["title"].getstr) + count += 1 + + # aller à la page suivante + page += 1 + + return j_nb + + +# var all_notebooks = "" +var nb: joplin_notebooks +nb = waitFor get_joplin_notebooks("e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f") +# echo nb.title[1] + +for i in nb.title: + echo i + +echo nb.title \ No newline at end of file diff --git a/tmpl/snippet_html.nim b/tmpl/snippet_html.nim new file mode 100644 index 0000000..2b97c66 --- /dev/null +++ b/tmpl/snippet_html.nim @@ -0,0 +1,10 @@ +import templates + +proc templ_title* (title: string): string = tmpli html""" +

$title!

+ """ +# proc testPage (name: string): string = tmpli html""" +# +#

Hello $name!

+# +# """ \ No newline at end of file diff --git a/tmpl/snippet_icons.nim b/tmpl/snippet_icons.nim new file mode 100644 index 0000000..9ccfc97 --- /dev/null +++ b/tmpl/snippet_icons.nim @@ -0,0 +1,274 @@ +import templates + +proc Menu_icon* (): string = tmpli html""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + +proc NewNote_icon*(): string = tmpli html""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + +proc Search_icon*(): string = tmpli html""" + + + + + + """ + +proc Shortcuts_icon*(): string = tmpli html""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + +proc Notes_icon*(): string = tmpli html""" + + + + """ + +proc Notebooks_icon*(): string = tmpli html""" + + + + + + + + + + + + """ + +proc Tags_icon*(): string = tmpli html""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + +proc Settings_icon*(): string = tmpli html""" + + + + + """ + +proc Logout_icon*(): string = tmpli html""" + + + + + """ + +proc SendFeedback_icon*(): string = tmpli html""" + + + + + + """ \ No newline at end of file diff --git a/tmpl/test.tmpl b/tmpl/test.tmpl index fe869e7..b410e25 100644 --- a/tmpl/test.tmpl +++ b/tmpl/test.tmpl @@ -1,15 +1,26 @@ #? stdtmpl | standard -# -#proc test_notebooks(c: var TData, all_notebooks: var string): string = +# import snippet_html +#proc test_notebooks(c: var TData, all_notebooks: var joplin_notebooks): string = # result = "" - - - - -

-${all_notebooks} -

+ + + + + + + Document + + + + + + # var title = templ_title("NOTEBOOKS") +
${title}
+ # for i in all_notebooks.title: +

${i}

+ # end for + - + #end proc \ No newline at end of file diff --git a/tmpl/website.tmpl b/tmpl/website.tmpl index ae74bac..42b63f2 100644 --- a/tmpl/website.tmpl +++ b/tmpl/website.tmpl @@ -1,5 +1,4 @@ #? stdtmpl | standard -# #proc genMain(c: var TData): string = # result = "" @@ -8,7 +7,9 @@ #end proc # -#proc genSecret(c: var TData): string = +# import snippet_html +# import snippet_icons +#proc genSecret(c: var TData, all_notebooks: var joplin_notebooks): string = # result = "" @@ -23,63 +24,10 @@
@@ -91,64 +39,23 @@
-
Windows Info !!
+
+
+ # var title = templ_title("NOTEBOOKS") + ${title} + # for i in all_notebooks.title: +

${i}

+ # end for +
+
+

Column 2

+

Some text..

+
+