diff --git a/db/db copy.sqlite3 b/db/db copy.sqlite3 new file mode 100644 index 0000000..a531d5d Binary files /dev/null and b/db/db copy.sqlite3 differ diff --git a/db/db.sqlite3 b/db/db.sqlite3 index ab7acf5..d4757bc 100644 Binary files a/db/db.sqlite3 and b/db/db.sqlite3 differ diff --git a/src/page.rs b/src/page.rs index 603c9a5..505199c 100644 --- a/src/page.rs +++ b/src/page.rs @@ -1,8 +1,9 @@ +use actix_web::http::header::ContentType; use actix_web::{get, put, Responder}; use actix_web::{web, HttpResponse}; +use serde::Deserialize; use std::fs; -use std::io::Write; use askama_actix::Template; use askama_actix::TemplateToResponse; @@ -19,10 +20,12 @@ pub struct PageTemplate { pub init: String, } -#[get("/page/{page}")] -async fn page(path: web::Path<(String,)>, data: web::Data) -> impl Responder { - let pagename = &path.0; +#[derive(Debug, Deserialize)] +struct QueryParams { + pub data: Option, +} +async fn get_data(data: & web::Data, pagename: String) -> String { let fut_page_datas = db::get_page_by_name(&data.pool, pagename.to_owned()); let page_datas = fut_page_datas.await.unwrap(); let md; @@ -41,10 +44,32 @@ async fn page(path: web::Path<(String,)>, data: web::Data) -> impl Resp } Some(dat) => md = (*dat.page_text).to_string(), } + md +} + +#[get("/page/{page}")] +async fn page( + path: web::Path<(String,)>, + data: web::Data, + params: web::Query, +) -> impl Responder { + let pagename = &path.0; + + let md = get_data(&data, pagename.to_owned()).await; + + match ¶ms.data { + Some(_) => { + return HttpResponse::Ok() + .content_type(ContentType::plaintext()) + .body(md) + } + None => {} + } - let name = data.name.to_owned() + " " + pagename.as_str(); + let name = data.name.to_owned() + " - " + pagename.as_str(); let root = data.root.to_owned(); - let init = String::from("init();"); + //let init = String::from("init();"); + let init = format!("init();"); PageTemplate { name, root, diff --git a/static/cheezenotes.css b/static/cheezenotes.css index db88620..1f0cacc 100644 --- a/static/cheezenotes.css +++ b/static/cheezenotes.css @@ -7,21 +7,11 @@ url(/static/MaterialIconsOutlined-Regular.otf) format('woff'); } -html { - font-family: system-ui; - font-size: 12pt; -} - -body { - margin: 0; - background-color: #dddddd; -} - .material-icons { font-family: 'Material Icons'; font-weight: normal; font-style: normal; - font-size: 24px; /* Preferred icon size */ + font-size: 22px; /* Preferred icon size */ display: inline-block; line-height: 1; text-transform: none; @@ -35,27 +25,71 @@ body { font-feature-settings: 'liga'; } +html { + font-family: system-ui; + font-size: 12pt; +} + +body { + margin: 0; + background-color: #dddddd; +} + +div#content { + position: absolute; + margin: 0; + padding: 0; + top: 0; + left: 0; + bottom: 0; + right: 0; + overflow: auto; +} + +div #margindiv { + max-width: 1200px; + margin-left: auto; + margin-right: auto; + top: 0; + bottom: 0; +} + +div#cheezenotes { + position: static; + margin: 0; + margin-top: 0; + margin-bottom: 3rem; + padding-top: 1rem; + padding-left: 3rem; + padding-right: 3rem; + padding-bottom: 1rem; + background-color: #ffffff; + min-height: 100%; + overflow-x: auto; +} + div#buttons { + position: sticky; white-space: nowrap; overflow-x: auto; box-sizing: border-box; - padding: .2rem; - position: fixed; + padding-top: .2rem; + padding-bottom: .2rem; background-color: #dddddd; top: 0; left: 0; right: 0; margin-left: auto; margin-right: auto; - max-width: 1200; + max-width: 1200px; } div#buttons button.button { color: #444444; padding: 0; margin: 0; - height: 2.8rem; - width: 2.8rem; + height: 2.6rem; + width: 2.6rem; background-color: #eeeeee; border: 1px solid #cccccc; border-right: none; @@ -69,12 +103,13 @@ div#buttons button.separator { color: #bbbbbb; border: none; border-left: 1px solid #cccccc; - height: 2.8rem; + height: 2.6rem; margin: 0; padding: 0; } div#buttons button.text { + line-height: 1; color: #444444; font-size: 18px; vertical-align: bottom; @@ -109,7 +144,7 @@ div#buttons #lockButtonLabel { div.ta { margin-left: auto; margin-right: auto; - max-width: 1200; + max-width: 1200px; } textarea#ta { @@ -123,21 +158,6 @@ textarea#ta { background-color: #cceeff; } -div#cheezenotes { - margin-top: 3rem; - margin-left: auto; - margin-right: auto; - max-width: 1200; - padding-top: 1rem; - padding-left: 3rem; - padding-right: 3rem; - padding-bottom: 1rem; - margin-bottom: 3rem; - background-color: #ffffff; - min-height: 90%; - overflow-x: auto; -} - /*div#cheezenotes div.cheezenotes_line {*/ /* Pour firefox : white-space: pre; */ /*}*/ diff --git a/static/modules/cheezenotes.js b/static/modules/cheezenotes.js index e409ba4..3778801 100644 --- a/static/modules/cheezenotes.js +++ b/static/modules/cheezenotes.js @@ -118,15 +118,10 @@ function onsave(e) { let saveButton = document.getElementById('saveButton'); saveButton.disabled = true; let text = save(document.getElementById('ta'), document.getElementById('cheezenotes')); - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function () { - if (this.readyState == 4 && this.status != 200) { - saveButton.disabled = false; - alert(xhttp.responseText); - } - } - xhttp.open("PUT", document.location.href, true); - xhttp.send(text); + fetch(document.location.href, { method: "PUT", body: text }).catch((error) => { + saveButton.disabled = false; + alert(error); + }) } function onload(e) { @@ -338,11 +333,33 @@ function onfocus() { enableFormatButtons(); } -function init(pagename = null) { +function onpopstate(e) { + let top = 0; + let left = 0; + if (e.state.top) { + top = e.state.top; + } + if (e.state.left) { + left = e.state.left; + } + fetch(document.location.href + "?data=").then((response) => { + let ta = document.getElementById('ta'); + response.text().then((data) => { + ta.value = data; + load(document.getElementById('ta'), document.getElementById('cheezenotes')); + let content = document.getElementById('content'); + content.scrollTop = top; + content.scrollLeft = left; + }); + }).catch((error) => { alert(error); }); +} + +function init() { let cheezenotes = document.getElementById('cheezenotes'); dpwidth(cheezenotes); + window.addEventListener('popstate', onpopstate); cheezenotes.addEventListener('input', onedit); cheezenotes.addEventListener('keyup', onkeyup); cheezenotes.addEventListener('keypress', onkeypress); @@ -366,7 +383,7 @@ function init(pagename = null) { addButton('h1Button', 'H1', onh1button); addButton('h2Button', 'H2', onh2button); addButton('h3Button', 'H3', onh3button); - lastButton(addButton('bqButton', ':format_quote', onbqbutton)); + addButton('bqButton', ':format_quote', onbqbutton); addSeparator(); addOnOffButton('editModeButton', ':edit_note', ':visibility', function (e) { @@ -380,6 +397,13 @@ function init(pagename = null) { disableFormatButtons(); + /*if (pagename != null) { + fetch(pagename + "?data=").then((response) => { + let ta = document.getElementById('ta'); + response.text().then((data) => { ta.value = data; onload(); }); + }).catch((error) => { alert(error); }); + }*/ + onload(); } diff --git a/static/modules/md.js b/static/modules/md.js index ad4a12e..203d130 100644 --- a/static/modules/md.js +++ b/static/modules/md.js @@ -32,7 +32,7 @@ function appendData(div, data) { newline = formatLine(lineBegin + lines[0]); line.parentNode.replaceChild(newline, line); let prevline = newline; - for(let i=1; i { alert(error); }); } return false; } else { @@ -106,7 +120,7 @@ function onlinkout(e) { let cheezenotes = document.getElementById('cheezenotes'); if (cheezenotes.contentEditable == 'false') { cheezenotes.contentEditable = true; - } + } } function formatLine(line) { @@ -205,7 +219,7 @@ function formatLine(line) { if (elem.getElementsByClassName('tablerow').length > 0) { if (elem.childNodes[0].childNodes.length > 0) { let child = elem.childNodes[0].childNodes[0]; - while(child != null) { + while (child != null) { if (child.nodeType == 3) { let newchild = document.createElement('span'); newchild.innerText = child.nodeValue; @@ -219,7 +233,7 @@ function formatLine(line) { elem.classList.add('tablerow'); } let links = elem.getElementsByClassName('link'); - for (let i=0; i`' + mono + '`' + line.substring(matches[i]+2, line.length); + line = line.substring(0, matches[i]) + '`' + mono + '`' + line.substring(matches[i] + 2, line.length); } return line; } @@ -471,7 +485,7 @@ function removeLink(line) { if (listLink == null) { return [line, null]; } - + line = line.replace(/(\[([^\]]*?)\]\(([^\)]*?)\))/g, "[]()"); return [line, listLink.reverse()]; } @@ -492,8 +506,8 @@ function addLink(line, listLink) { cpt++; } matches = matches.reverse(); - for(let i=0; i - - - - - - - - - {{name}} - - - - -
- + + + + + + + + + + {{name}} + + + + + +
+
+
+
+
-
-
- - - +
+ + + + \ No newline at end of file