db et modifs page

main
Nicolas Sanchez 3 years ago
parent 705e4274e0
commit 1f3437b99c

142
Cargo.lock generated

@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -220,7 +220,7 @@ dependencies = [
"actix-router", "actix-router",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -316,35 +316,41 @@ checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
[[package]] [[package]]
name = "askama" name = "askama"
version = "0.11.1" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" checksum = "47cbc3cf73fa8d9833727bbee4835ba5c421a0d65b72daf9a7b5d0e0f9cfb57e"
dependencies = [ dependencies = [
"askama_derive", "askama_derive",
"askama_escape", "askama_escape",
"askama_shared", "humansize",
"num-traits",
"percent-encoding",
] ]
[[package]] [[package]]
name = "askama_actix" name = "askama_actix"
version = "0.13.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c52f74f8382a142ecfc052100b21abc33f2c069e20fe345808e7ed914b179449" checksum = "e4b0dd17cfe203b00ba3853a89fba459ecf24c759b738b244133330607c78e55"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"askama", "askama",
"askama_shared",
] ]
[[package]] [[package]]
name = "askama_derive" name = "askama_derive"
version = "0.11.2" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" checksum = "c22fbe0413545c098358e56966ff22cdd039e10215ae213cfbd65032b119fc94"
dependencies = [ dependencies = [
"askama_shared", "basic-toml",
"mime",
"mime_guess",
"nom",
"proc-macro2", "proc-macro2",
"syn", "quote",
"serde",
"syn 2.0.10",
] ]
[[package]] [[package]]
@ -353,26 +359,6 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "askama_shared"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
dependencies = [
"askama_escape",
"humansize",
"mime",
"mime_guess",
"nom",
"num-traits",
"percent-encoding",
"proc-macro2",
"quote",
"serde",
"syn",
"toml",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.64" version = "0.1.64"
@ -381,7 +367,7 @@ checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -408,6 +394,15 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "basic-toml"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c0de75129aa8d0cceaf750b89013f0e08804d6ec61416da787b35ad0d7cddf1"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -508,6 +503,7 @@ dependencies = [
"actix-web", "actix-web",
"askama", "askama",
"askama_actix", "askama_actix",
"chrono",
"clap", "clap",
"git2", "git2",
"lazy_static", "lazy_static",
@ -523,9 +519,9 @@ dependencies = [
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.23" version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
dependencies = [ dependencies = [
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
@ -571,7 +567,7 @@ dependencies = [
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -685,7 +681,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"scratch", "scratch",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -702,7 +698,7 @@ checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -726,7 +722,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim", "strsim",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -737,7 +733,7 @@ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -754,7 +750,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -767,7 +763,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustc_version 0.4.0", "rustc_version 0.4.0",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -799,7 +795,7 @@ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -900,7 +896,7 @@ checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -1095,9 +1091,12 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]] [[package]]
name = "humansize" name = "humansize"
version = "1.1.1" version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
dependencies = [
"libm",
]
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
@ -1265,6 +1264,12 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "libm"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb"
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.25.2" version = "0.25.2"
@ -1660,7 +1665,7 @@ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
"version_check", "version_check",
] ]
@ -1677,9 +1682,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.50" version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1692,9 +1697,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.23" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1808,6 +1813,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"chrono",
"fallible-iterator", "fallible-iterator",
"fallible-streaming-iterator", "fallible-streaming-iterator",
"hashlink", "hashlink",
@ -1962,7 +1968,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -2008,7 +2014,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -2117,6 +2123,17 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "2.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aad1363ed6d37b84299588d62d3a7d95b5a5c2d9aad5c85609fda12afaa1f40"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "take_mut" name = "take_mut"
version = "0.2.2" version = "0.2.2"
@ -2149,7 +2166,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -2233,7 +2250,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -2261,15 +2278,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.37" version = "0.1.37"
@ -2344,7 +2352,7 @@ checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
] ]
[[package]] [[package]]
@ -2481,7 +2489,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2503,7 +2511,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.107",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]

@ -14,8 +14,8 @@ uuid = {version = "1.3.0", features=["v4", "fast-rng"]}
actix-web = "4" actix-web = "4"
actix-files = "0.6.2" actix-files = "0.6.2"
actix-session = { version = "0.7.2", features = ["cookie-session"] } actix-session = { version = "0.7.2", features = ["cookie-session"] }
askama = { version = "0.11.1", features = ["with-actix-web"] } askama = { version = "0.12.0", features = ["with-actix-web"] }
askama_actix = "0.13.0" askama_actix = "0.14.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
@ -26,7 +26,8 @@ regex = "1"
r2d2 = "0.8" r2d2 = "0.8"
r2d2_sqlite = "0.21.0" r2d2_sqlite = "0.21.0"
rusqlite = {version = "0.28.0", features=["bundled"]} chrono = "0.4.24"
rusqlite = {version = "0.28.0", features=["bundled", "chrono"]}
lazy_static = "1.4.0" lazy_static = "1.4.0"
mongodb = "2.3.1" mongodb = "2.3.1"

@ -3,6 +3,10 @@ create table pages (
page_name text, page_name text,
page_text text, page_text text,
active boolean default true not null, active boolean default true not null,
creation_date date,
modification_date date,
parent_domain text,
parent_page text,
primary key (domain, page_name) primary key (domain, page_name)
); );

Binary file not shown.

@ -14,6 +14,7 @@ fn uuid4() -> String {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Page { pub struct Page {
pub domain: String, pub domain: String,
pub domain_name: String,
pub page_name: String, pub page_name: String,
pub page_text: String, pub page_text: String,
} }
@ -45,6 +46,34 @@ pub async fn get_domains(pool: &Pool) -> Result<Vec<Domain>, Error> {
.map_err(error::ErrorInternalServerError) .map_err(error::ErrorInternalServerError)
} }
pub async fn get_pages_by_domain(
pool: &Pool,
domain: String,
) -> Result<Vec<Page>, Error> {
let pool = pool.clone();
let conn = web::block(move || pool.get())
.await?
.map_err(error::ErrorInternalServerError)?;
web::block(move || {
let mut stmt = conn
.prepare("SELECT domain, REPLACE(domain, '_', ' '), page_name from pages WHERE active=true and domain=?")?;
stmt.query_map([domain], |row| {
Ok(Page {
domain: row.get(0)?,
domain_name: row.get(1)?,
page_name: row.get(2)?,
page_text: String::from(""),
})
})
.and_then(Iterator::collect)
})
.await?
.map_err(error::ErrorInternalServerError)
}
pub async fn get_page_by_name( pub async fn get_page_by_name(
pool: &Pool, pool: &Pool,
domain: String, domain: String,
@ -58,13 +87,14 @@ pub async fn get_page_by_name(
web::block(move || { web::block(move || {
let mut stmt = conn let mut stmt = conn
.prepare("SELECT domain, page_name, page_text from pages WHERE active=true and domain=? and page_name=?")?; .prepare("SELECT domain, REPLACE(domain, '_', ' '), page_name, page_text from pages WHERE active=true and domain=? and page_name=?")?;
stmt.query_map([domain, pagename], |row| { stmt.query_map([domain, pagename], |row| {
Ok(Page { Ok(Page {
domain: row.get(0)?, domain: row.get(0)?,
page_name: row.get(1)?, domain_name: row.get(1)?,
page_text: row.get(2)?, page_name: row.get(2)?,
page_text: row.get(3)?,
}) })
}) })
.and_then(Iterator::collect) .and_then(Iterator::collect)
@ -78,6 +108,8 @@ pub async fn update_page(
domain: String, domain: String,
page_name: String, page_name: String,
page_text: String, page_text: String,
parent_domain: Option<&str>,
parent_page: Option<&str>
) -> Result<usize, Error> { ) -> Result<usize, Error> {
let pool = pool.clone(); let pool = pool.clone();
@ -85,10 +117,20 @@ pub async fn update_page(
.await? .await?
.map_err(error::ErrorInternalServerError)?; .map_err(error::ErrorInternalServerError)?;
let parent_domain = match parent_domain {
Some(pd) => pd,
None => ""
}.to_owned();
let parent_page = match parent_page {
Some(pp) => pp,
None => ""
}.to_owned();
web::block(move || { web::block(move || {
let mut stmt = conn let mut stmt = conn
.prepare("insert or replace into pages (domain, page_name, page_text, active) values (?, ?, ?, true)")?; .prepare("insert or replace into pages (domain, page_name, page_text, active, parent_domain, parent_page) values (?, ?, ?, true, ?, ?)")?;
stmt.execute([domain, page_name, page_text, ]) stmt.execute([domain.to_owned(), page_name.to_owned(), page_text.to_owned(), parent_domain, parent_page ])
}) })
.await? .await?
.map_err(error::ErrorInternalServerError) .map_err(error::ErrorInternalServerError)

@ -0,0 +1,29 @@
use actix_web::web;
use actix_web::{Responder, get};
use askama_actix::Template;
use askama_actix::TemplateToResponse;
use crate::commons::AppData;
use crate::db;
use crate::db::Page;
#[derive(Template)]
#[template(path = "domain.html")]
pub struct DomainTemplate {
pub app_name: String,
pub base_url: String,
pub domain: String,
pub pages: Vec<Page>,
}
#[get("/{domaine}")]
async fn domain(path: web::Path<String>, data: web::Data<AppData>) -> impl Responder {
let app_name = data.app_name.to_owned();
let base_url = data.base_url.to_owned();
let domain = path.to_string();
let pages = db::get_pages_by_domain(&data.db_pool, domain.to_owned()).await.unwrap();
DomainTemplate { app_name, base_url, domain: domain.to_owned(), pages }.to_response()
}

@ -1,4 +1,5 @@
pub mod page; pub mod page;
pub mod index; pub mod index;
pub mod domain;
pub mod commons; pub mod commons;
pub mod db; pub mod db;

@ -5,7 +5,7 @@ use r2d2::Pool;
use r2d2_sqlite::{self, SqliteConnectionManager}; use r2d2_sqlite::{self, SqliteConnectionManager};
use cheezenotes::commons::{Arguments, AppData}; use cheezenotes::commons::{Arguments, AppData};
use cheezenotes::{ page, index }; use cheezenotes::{ page, index, domain };
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
@ -34,6 +34,7 @@ async fn main() -> std::io::Result<()> {
.service(actix_files::Files::new("/static/modules", "./static/modules")) .service(actix_files::Files::new("/static/modules", "./static/modules"))
.service(page::page) .service(page::page)
.service(page::save_page) .service(page::save_page)
.service(domain::domain)
}) })
.bind((ip, port))? .bind((ip, port))?
.run() .run()

@ -1,8 +1,9 @@
use actix_web::body::BoxBody;
use actix_web::http::header::ContentType; use actix_web::http::header::ContentType;
use actix_web::web::Query; use actix_web::web::Query;
use actix_web::{get, put, Responder}; use actix_web::{get, put, Responder, HttpRequest};
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
use serde::Deserialize; use serde::{Deserialize, Serialize};
use askama_actix::Template; use askama_actix::Template;
use askama_actix::TemplateToResponse; use askama_actix::TemplateToResponse;
@ -27,6 +28,27 @@ struct QueryParams {
pub fromPage: Option<String>, pub fromPage: Option<String>,
} }
#[derive(Serialize, Deserialize)]
pub struct Page {
pub domain: String,
pub page: String,
pub page_text: String,
pub parent_domain: String,
pub parent_page: String,
}
impl Responder for Page {
type Body = BoxBody;
fn respond_to(self, _req: &HttpRequest) -> HttpResponse<Self::Body> {
let res_body = serde_json::to_string(&self).unwrap();
// Create HttpResponse and set Content Type
HttpResponse::Ok()
.content_type(ContentType::json())
.body(res_body)
}
}
fn new_page_text( fn new_page_text(
page_name: String, page_name: String,
domain_from: &Option<String>, domain_from: &Option<String>,
@ -98,7 +120,7 @@ async fn save_page(
if pagename == "index" { if pagename == "index" {
return HttpResponse::Ok(); return HttpResponse::Ok();
} }
db::update_page(&data.db_pool, domain.to_owned(), pagename.to_owned(), body) db::update_page(&data.db_pool, domain.to_owned(), pagename.to_owned(), body.to_owned(), None, None)
.await .await
.unwrap(); .unwrap();
HttpResponse::Ok() HttpResponse::Ok()

@ -27,6 +27,9 @@
html { html {
font-family: system-ui; font-family: system-ui;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
/*font-family: "Freestyle script",Ubuntu;*/
font-size: 12pt; font-size: 12pt;
} }
@ -184,6 +187,7 @@ div#cheezenotes:focus {
div#cheezenotes input.checkbox { div#cheezenotes input.checkbox {
vertical-align: bottom; vertical-align: bottom;
margin-right: 1em;
} }
div#cheezenotes div.line { div#cheezenotes div.line {

@ -356,6 +356,10 @@ function onpopstate(e) {
}).catch((error) => { alert(error); }); }).catch((error) => { alert(error); });
} }
function onparentbutton(e) {
}
function init(domain, page) { function init(domain, page) {
let cheezenotes = document.getElementById('cheezenotes'); let cheezenotes = document.getElementById('cheezenotes');
window.domain = domain; window.domain = domain;
@ -378,6 +382,16 @@ function init(domain, page) {
let saveButton = addButton('saveButton', ':save', onsave); let saveButton = addButton('saveButton', ':save', onsave);
saveButton.disabled = true; saveButton.disabled = true;
addOnOffButton('editModeButton', ':edit_note', ':visibility',
function (e) {
if (editModeButton.classList.contains('buttonon')) {
cheezenotes.contentEditable = false;
} else {
cheezenotes.contentEditable = true;
}
}, true);
addOnOffButton('taButton', ':notes', ':notes', ontextarea);
addButton('parentButton', ':arrow_upward', onparentbutton);
addSeparator(); addSeparator();
addButton('boldButton', ':format_bold', onboldbutton); addButton('boldButton', ':format_bold', onboldbutton);
addButton('italicButton', ':format_italic', onitalicbutton); addButton('italicButton', ':format_italic', onitalicbutton);
@ -387,27 +401,10 @@ function init(domain, page) {
addButton('h1Button', 'H1', onh1button); addButton('h1Button', 'H1', onh1button);
addButton('h2Button', 'H2', onh2button); addButton('h2Button', 'H2', onh2button);
addButton('h3Button', 'H3', onh3button); addButton('h3Button', 'H3', onh3button);
addButton('bqButton', ':format_quote', onbqbutton); lastButton(addButton('bqButton', ':format_quote', onbqbutton));
addSeparator();
addOnOffButton('editModeButton', ':edit_note', ':visibility',
function (e) {
if (editModeButton.classList.contains('buttonon')) {
cheezenotes.contentEditable = false;
} else {
cheezenotes.contentEditable = true;
}
}, true);
lastButton(addOnOffButton('taButton', ':notes', ':notes', ontextarea));
disableFormatButtons(); 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(); onload();
} }

@ -15,6 +15,7 @@ function load(textarea, div) {
let lines = textarea.value.split('\n'); let lines = textarea.value.split('\n');
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
let line = lines[i]; let line = lines[i];
line.replace('<', '&lt;');
let elem = formatLine(line); let elem = formatLine(line);
div.append(elem); div.append(elem);
} }
@ -125,11 +126,6 @@ function onlink(e) {
window.page = page; window.page = page;
load(document.getElementById('ta'), cheezenotes); load(document.getElementById('ta'), cheezenotes);
/*let editModeButton = document.getElementById('editModeButton');
if (editModeButton.classList.contains('buttonoff')) {
let cheezenotes = document.getElementById('cheezenotes');
cheezenotes.contentEditable = false;
}*/
content.scrollTop = 0; content.scrollTop = 0;
content.scrollLeft = 0; content.scrollLeft = 0;
}); });
@ -148,6 +144,19 @@ function onlinkout(e) {
} }
} }
function oncheckbox(e) {
let cb = e.currentTarget;
let line = cb.parentNode;
let text = line.innerText;
if (cb.checked) {
text = text.replace(/^(\s*)(\[\])/, "$1[v]");
} else {
text = text.replace(/^(\s*)(\[[vVxX]\])/, "$1[]");
}
let newline = formatLine(text);
line.parentNode.replaceChild(newline, line);
}
function formatLine(line) { function formatLine(line) {
let token = null; let token = null;
let elem = document.createElement('div'); let elem = document.createElement('div');
@ -255,6 +264,15 @@ function formatLine(line) {
line = addLink(line, listLink); line = addLink(line, listLink);
line = addMono(line, listMono); line = addMono(line, listMono);
elem.innerHTML = line; elem.innerHTML = line;
let checkboxes = elem.getElementsByClassName('checkbox');
for (let i = 0; i < checkboxes.length; i++) {
let checkbox = checkboxes[i];
checkbox.addEventListener('mouseover', onlinkin);
checkbox.addEventListener('change', oncheckbox);
checkbox.addEventListener('mouseout', onlinkout);
}
if (elem.getElementsByClassName('tablerow').length > 0) { if (elem.getElementsByClassName('tablerow').length > 0) {
if (elem.childNodes[0].childNodes.length > 0) { if (elem.childNodes[0].childNodes.length > 0) {
let child = elem.childNodes[0].childNodes[0]; let child = elem.childNodes[0].childNodes[0];
@ -551,14 +569,6 @@ function addLink(line, listLink) {
return line; return line;
} }
/*function formatLink(link) {
link = link.replace(/(\[!([^\]]*?)\]\(([^\)]+?)\))/i, '<span class="token">[!</span><img style="vertical-align: top; max-height: 1rem;" class="image" src="$3">$2</img><span class="token">]($3)</span>');
link = link.replace(/(\[([^\]]+?)\]\(([^\)]+?)\))/i, '<span class="token">[</span><a class="link" data-href="$3" href="$3">$2</a><span class="token">]($3)</span>');
link = link.replace(/(\[([^\]]+?)\]\(\))/i, '<span class="token">[</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">]()</span>');
link = link.replace(/(\[\]\(([^\)]+?)\))/i, '<span class="token">[](</span><a class="link" data-href="$2" href="$2">$2</a><span class="token">)</span>');
return link;
}*/
function formatLink(link) { function formatLink(link) {
let matches = link.match(/\[(.*)\]\((.*)\)/); let matches = link.match(/\[(.*)\]\((.*)\)/);
let libelle = matches[1]; let libelle = matches[1];

@ -0,0 +1,19 @@
<html>
<head>
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="fr">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>{{app_name}} {{ domain }}</title>
<link rel="stylesheet" href="{{ base_url|safe }}static/cheezenotes.css">
</head>
<body>
<h1>{{app_name}} {{ domain }}</h1>
{% for page in pages %}
<p class="page"><a href="{{ base_url|safe }}{{ page.domain }}/{{ page.page_name }}">{{ page.page_name }}</a></p>
{% endfor %}
</body>
</html>
Loading…
Cancel
Save