From 67d55cadc4ca90062405f4389e6936cd4b48139c Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 26 Jan 2018 21:18:04 +0100 Subject: [PATCH] Rename list to note throughout the application --- {lists => notes}/.keep | 0 notes/_test.note | 10 + notes/leeg.note | 1 + notes/markdown.note | 20 ++ notes/quoot.note | 11 + notes/zandbak.note | 23 ++ src/handlers/home.rs | 24 +-- src/handlers/mod.rs | 2 +- src/handlers/{list.rs => note.rs} | 116 +++++----- src/main.rs | 14 +- src/models/mod.rs | 2 +- src/models/{list.rs => note.rs} | 86 ++++---- static/js/pinboard.js | 198 +++++++++--------- static/scss/pinboard.scss | 10 +- templates/_layout.html.tera | 2 +- templates/index.html.tera | 34 +-- test/{lists/test.list => notes/test.note} | 0 .../updatable.list => notes/updatable.note} | 0 18 files changed, 309 insertions(+), 244 deletions(-) rename {lists => notes}/.keep (100%) create mode 100644 notes/_test.note create mode 100644 notes/leeg.note create mode 100644 notes/markdown.note create mode 100644 notes/quoot.note create mode 100644 notes/zandbak.note rename src/handlers/{list.rs => note.rs} (50%) rename src/models/{list.rs => note.rs} (54%) rename test/{lists/test.list => notes/test.note} (100%) rename test/{lists/updatable.list => notes/updatable.note} (100%) diff --git a/lists/.keep b/notes/.keep similarity index 100% rename from lists/.keep rename to notes/.keep diff --git a/notes/_test.note b/notes/_test.note new file mode 100644 index 0000000..13a9c5e --- /dev/null +++ b/notes/_test.note @@ -0,0 +1,10 @@ +* Eerste item +* Tweede item + +--- +#### Nog veel meer, maar later +* Dit +* Dat + +--- +Nog een lijn? \ No newline at end of file diff --git a/notes/leeg.note b/notes/leeg.note new file mode 100644 index 0000000..2c247f3 --- /dev/null +++ b/notes/leeg.note @@ -0,0 +1 @@ +… diff --git a/notes/markdown.note b/notes/markdown.note new file mode 100644 index 0000000..5fa4306 --- /dev/null +++ b/notes/markdown.note @@ -0,0 +1,20 @@ +## Kop 2 +### Kop 3 +#### Kop 4 + +_Schuingedrukt_ +**Vetgedruk** +~Doorgestreept~ + +* Item 1 +* Item 2 + +##### +* [ ] Wil ik graag +* [ ] Wil ik ook graag +* [x] Heb ik al! + +[Linktekst](http://google.nl) + +--- +Horizontale lijn \ No newline at end of file diff --git a/notes/quoot.note b/notes/quoot.note new file mode 100644 index 0000000..6b422ca --- /dev/null +++ b/notes/quoot.note @@ -0,0 +1,11 @@ +Wat zullen we eens wegzetten? Dit, misschien: + +> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do +> eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut +> enim ad minim veniam, quis nostrud exercitation ullamco laboris +> nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in +> reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla +> pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +> culpa qui officia deserunt mollit anim id est laborum. + +Van http://lipsum.com \ No newline at end of file diff --git a/notes/zandbak.note b/notes/zandbak.note new file mode 100644 index 0000000..66e904d --- /dev/null +++ b/notes/zandbak.note @@ -0,0 +1,23 @@ +_Niets!_ +**Echt niets?** + +Hier is een link: http://rust-lang.org/, maar deze is mooier: [Rust homepage](http://rust-lang.org) + +Tralalaaaa! + +Leuke ? +~Nee, dat werkt niet~ + +##### Kop 5 + +* [ ] Item a +* [ ] Item b +* [x] Item c + +UTF8 test⸘ +3.1.3 2 continuation bytes: "��" | +3.1.4 3 continuation bytes: "���" | +3.1.5 4 continuation bytes: "����" | +3.1.6 5 continuation bytes: "�����" | +3.1.7 6 continuation bytes: "������" | +3.1.8 7 continuation bytes: "�������" | diff --git a/src/handlers/home.rs b/src/handlers/home.rs index 442b4f7..7cfe6b5 100644 --- a/src/handlers/home.rs +++ b/src/handlers/home.rs @@ -1,27 +1,27 @@ use rocket::State; use rocket_contrib::Template; use std::collections::HashMap; -use super::super::ListStore; +use super::super::NoteStore; #[derive(Serialize)] struct IndexTemplateContext<'a> { app_version: &'a str, - lists: Vec> + notes: Vec> } #[get("/")] -fn index(lists: State) -> Template { - let lists = lists.read().unwrap(); - let mut list_kvs = vec![]; - for list in lists.iter() { - let mut list_kv = HashMap::new(); - list_kv.insert("id", list.id.as_ref()); - list_kv.insert("name", list.name.as_ref()); - list_kvs.push(list_kv); +fn index(notes: State) -> Template { + let notes = notes.read().unwrap(); + let mut note_kvs = vec![]; + for note in notes.iter() { + let mut note_kv = HashMap::new(); + note_kv.insert("id", note.id.as_ref()); + note_kv.insert("name", note.name.as_ref()); + note_kvs.push(note_kv); } let context = IndexTemplateContext { app_version: env!("CARGO_PKG_VERSION"), - lists: list_kvs + notes: note_kvs }; Template::render("index", &context) } @@ -42,6 +42,6 @@ mod tests { let body = res.body_string().unwrap(); println!("body: {}", body); - assert!(body.contains("Test")); + assert!(body.contains("Test")); } } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index c053b88..a026161 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,3 +1,3 @@ pub mod home; -pub mod list; +pub mod note; pub mod static_files; diff --git a/src/handlers/list.rs b/src/handlers/note.rs similarity index 50% rename from src/handlers/list.rs rename to src/handlers/note.rs index 1788952..e468780 100644 --- a/src/handlers/list.rs +++ b/src/handlers/note.rs @@ -1,34 +1,34 @@ use rocket::State; use rocket_contrib::Json; -use super::super::ListStore; -use super::super::models::list::List; +use super::super::NoteStore; +use super::super::models::note::Note; #[get("/", format = "application/json")] -fn index(lists: State) -> Option>> { - let lists = lists.read().unwrap(); - Some(Json(lists.clone())) +fn index(notes: State) -> Option>> { + let notes = notes.read().unwrap(); + Some(Json(notes.clone())) } -#[get("/", format = "text/html")] -fn show_html(list_id: String, lists: State) -> Option { - let lists = lists.read().unwrap(); - let list = lists.iter().find( |list| list.id == list_id )?; - Some(list.to_html()) +#[get("/", format = "text/html")] +fn show_html(note_id: String, notes: State) -> Option { + let notes = notes.read().unwrap(); + let note = notes.iter().find( |note| note.id == note_id )?; + Some(note.to_html()) } -#[get("/", format = "application/json")] -fn show_json(list_id: String, lists: State) -> Option> { - let lists = lists.read().unwrap(); - let list = lists.iter().find( |list| list.id == list_id )?; - Some(Json(list.clone())) +#[get("/", format = "application/json")] +fn show_json(note_id: String, notes: State) -> Option> { + let notes = notes.read().unwrap(); + let note = notes.iter().find( |note| note.id == note_id )?; + Some(Json(note.clone())) } -#[put("/", format = "application/json", data = "")] -fn update(list_id: String, new_list: Json, lists: State) -> Option> { - let mut lists = lists.write().unwrap(); - let list = lists.iter_mut().find( |list| list.id == list_id )?; - list.update_data(&new_list.data); - Some(Json(list.clone())) +#[put("/", format = "application/json", data = "")] +fn update(note_id: String, new_note: Json, notes: State) -> Option> { + let mut notes = notes.write().unwrap(); + let note = notes.iter_mut().find( |note| note.id == note_id )?; + note.update_data(&new_note.data); + Some(Json(note.clone())) } #[cfg(test)] @@ -43,21 +43,21 @@ mod tests { fn index() { let client = Client::new(rocket(Some("test"))).unwrap(); - // Try to get all the lists - let mut res = client.get("/lists").header(Accept::JSON).dispatch(); + // Try to get all the notes + let mut res = client.get("/notes").header(Accept::JSON).dispatch(); assert_eq!(res.status(), Status::Ok); let body = res.body_string().unwrap(); - let lists = serde_json::from_str::>(body.as_str()).unwrap(); - assert_eq!(lists[0].id, "test"); - assert_eq!(lists[0].index, 0); - assert_eq!(lists[0].name, "Test"); - assert_eq!(lists[0].data, "This is a test list\n\n* One\n* Two\n* Three\n"); + let notes = serde_json::from_str::>(body.as_str()).unwrap(); + assert_eq!(notes[0].id, "test"); + assert_eq!(notes[0].index, 0); + assert_eq!(notes[0].name, "Test"); + assert_eq!(notes[0].data, "This is a test list\n\n* One\n* Two\n* Three\n"); // The mtime field can vary, don't test for it // The path field is private, also don't test for it - // Cannot get the lists in HTML format - let res = client.get("/lists").header(Accept::HTML).dispatch(); + // Cannot get the notes in HTML format + let res = client.get("/notes").header(Accept::HTML).dispatch(); assert_eq!(res.status(), Status::NotFound); } @@ -65,8 +65,8 @@ mod tests { fn show_html() { let client = Client::new(rocket(Some("test"))).unwrap(); - // Try to get the list and verify the body - let mut res = client.get("/lists/test").header(Accept::HTML).dispatch(); + // Try to get the note and verify the body + let mut res = client.get("/notes/test").header(Accept::HTML).dispatch(); assert_eq!(res.status(), Status::Ok); let body = res.body_string().unwrap(); @@ -84,21 +84,21 @@ mod tests { fn show_json() { let client = Client::new(rocket(Some("test"))).unwrap(); - // Try to get the list and verify the body - let mut res = client.get("/lists/test").header(Accept::JSON).dispatch(); + // Try to get the note and verify the body + let mut res = client.get("/notes/test").header(Accept::JSON).dispatch(); assert_eq!(res.status(), Status::Ok); let body = res.body_string().unwrap(); - let list = serde_json::from_str::(body.as_str()).unwrap(); - assert_eq!(list.id, "test"); - assert_eq!(list.index, 0); - assert_eq!(list.name, "Test"); - assert_eq!(list.data, "This is a test list\n\n* One\n* Two\n* Three\n"); + let note = serde_json::from_str::(body.as_str()).unwrap(); + assert_eq!(note.id, "test"); + assert_eq!(note.index, 0); + assert_eq!(note.name, "Test"); + assert_eq!(note.data, "This is a test list\n\n* One\n* Two\n* Three\n"); // The mtime field can vary, don't test for it // The path field is private, also don't test for it - // Try to get a list that doesn't exist - let res = client.get("/lists/doesntexit").header(Accept::JSON).dispatch(); + // Try to get a note that doesn't exist + let res = client.get("/notes/doesntexit").header(Accept::JSON).dispatch(); assert_eq!(res.status(), Status::NotFound); // FIXME: Test that there is some kind of error in the JSON @@ -108,13 +108,13 @@ mod tests { fn update() { let client = Client::new(rocket(Some("test"))).unwrap(); - // Try to get the list and determine what to change it to - let mut res = client.get("/lists/updatable").header(Accept::JSON).dispatch(); + // Try to get the note and determine what to change it to + let mut res = client.get("/notes/updatable").header(Accept::JSON).dispatch(); let body = res.body_string().unwrap(); - let list = serde_json::from_str::(body.as_str()).unwrap(); - assert_eq!(list.data, "Some content"); + let note = serde_json::from_str::(body.as_str()).unwrap(); + assert_eq!(note.data, "Some content"); - // Try to change the list data, then verify it was changed + // Try to change the note data, then verify it was changed let new_data = "New content"; let mut new_json: serde_json::Value = json!({ "id": "updatable", @@ -125,45 +125,45 @@ mod tests { "nanos_since_epoch": 0 }, "name": "Updatable", - "path": "test/lists/updatablelist" + "path": "test/notes/updatablenote" }); - let res = client.put("/lists/updatable") + let res = client.put("/notes/updatable") .header(ContentType::JSON) .body(new_json.to_string()) .dispatch(); assert_eq!(res.status(), Status::Ok); - let mut res = client.get("/lists/updatable") + let mut res = client.get("/notes/updatable") .header(Accept::JSON) .dispatch(); let body = res.body_string().unwrap(); - let list = serde_json::from_str::(body.as_str()).unwrap(); - assert_eq!(list.data, new_data); + let note = serde_json::from_str::(body.as_str()).unwrap(); + assert_eq!(note.data, new_data); // ... and change it back *new_json.get_mut("data").unwrap() = json!("Some content"); - let res = client.put("/lists/updatable") + let res = client.put("/notes/updatable") .header(ContentType::JSON) .body(new_json.to_string()) .dispatch(); assert_eq!(res.status(), Status::Ok); - // Try to change a list that doesn't exist - let res = client.put("/lists/doesntexit") + // Try to change a note that doesn't exist + let res = client.put("/notes/doesntexit") .header(ContentType::JSON) .body(new_json.to_string()) .dispatch(); assert_eq!(res.status(), Status::NotFound); - // Try to change a list without a proper body - let res = client.put("/lists/updatable") + // Try to change a note without a proper body + let res = client.put("/notes/updatable") .header(ContentType::JSON) .body(r#"{}"#) .dispatch(); assert_eq!(res.status(), Status::BadRequest); - // Try to change a list without a proper type (i.e. not JSON) - let res = client.put("/lists/updatable") + // Try to change a note without a proper type (i.e. not JSON) + let res = client.put("/notes/updatable") .header(ContentType::Plain) .body("foo bar baz") .dispatch(); diff --git a/src/main.rs b/src/main.rs index c26f10c..b6bedd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,17 +15,17 @@ mod models; use rocket::Rocket; use std::sync::RwLock; -type ListStore = RwLock>; +type NoteStore = RwLock>; -fn rocket(lists_path: Option<&str>) -> Rocket { - let lists = models::list::List::load_all(lists_path); +fn rocket(notes_path: Option<&str>) -> Rocket { + let notes = models::note::Note::load_all(notes_path); rocket::ignite() - .manage(RwLock::new(lists)) + .manage(RwLock::new(notes)) .mount("/", routes![handlers::home::index, handlers::static_files::all]) - .mount("/lists", routes![handlers::list::index, - handlers::list::show_html, handlers::list::show_json, - handlers::list::update]) + .mount("/notes", routes![handlers::note::index, + handlers::note::show_html, handlers::note::show_json, + handlers::note::update]) .attach(rocket_contrib::Template::fairing()) } diff --git a/src/models/mod.rs b/src/models/mod.rs index d17e233..f20ccb5 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1 +1 @@ -pub mod list; +pub mod note; diff --git a/src/models/list.rs b/src/models/note.rs similarity index 54% rename from src/models/list.rs rename to src/models/note.rs index 91fc5b9..0bc15da 100644 --- a/src/models/list.rs +++ b/src/models/note.rs @@ -7,23 +7,23 @@ use std::path::PathBuf; use std::time::SystemTime; #[derive(Clone, Debug, Serialize, Deserialize)] -/// Structure for representing a wish list -pub struct List { - /// The ID of the list (unique string) +/// Structure for representing a wish note +pub struct Note { + /// The ID of the note (unique string) pub id: String, - /// The index of the list (unique number) + /// The index of the note (unique number) pub index: i8, - /// The raw list data + /// The raw note data pub data: String, - /// The time the list was last modified + /// The time the note was last modified pub mtime: SystemTime, - /// The name of the list, i.e. the person it is for + /// The name of the note, i.e. the person it is for pub name: String, - /// The path to the list file + /// The path to the note file path: PathBuf } -impl List { +impl Note { pub fn to_html(&self) -> String { let mut options = comrak::ComrakOptions::default(); options.ext_strikethrough = true; @@ -36,10 +36,10 @@ impl List { pub fn update_data(&mut self, data : &String) { let mut file = File::create(&self.path) - .expect(&format!("Cannot open list file {}", + .expect(&format!("Cannot open note file {}", self.path.to_str().unwrap())); file.write_all(data.as_bytes()) - .expect(&format!("Cannot write list file {}", + .expect(&format!("Cannot write note file {}", self.path.to_str().unwrap())); self.data = data.clone(); @@ -47,12 +47,12 @@ impl List { self.mtime = metadata.modified().unwrap(); } - pub fn load_all(list_path: Option<&str>) -> Vec { - let mut lists : Vec = vec![]; + pub fn load_all(note_path: Option<&str>) -> Vec { + let mut notes : Vec = vec![]; let mut index = 0; - let path_glob = match list_path { - Some(dir) => format!("{}/lists/*.list", dir), - None => format!("lists/*.list") + let path_glob = match note_path { + Some(dir) => format!("{}/notes/*.note", dir), + None => format!("notes/*.note") }; for entry in glob(path_glob.as_str()).unwrap().filter_map(Result::ok) { let file_name = entry.file_name().unwrap().to_str().unwrap(); @@ -62,13 +62,13 @@ impl List { }; let mut data = String::new(); let mut file = File::open(&entry) - .expect(&format!("Cannot open list file {}", file_name)); + .expect(&format!("Cannot open note file {}", file_name)); file.read_to_string(&mut data) - .expect(&format!("Cannot read list file {}", file_name)); + .expect(&format!("Cannot read note file {}", file_name)); let metadata = file.metadata() - .expect(&format!("Cannot get metadata of list file {}", file_name)); + .expect(&format!("Cannot get metadata of note file {}", file_name)); - let mut list = List { + let mut note = Note { id: String::from(name), index : index, data: data, @@ -76,10 +76,10 @@ impl List { name: String::from(name).to_title_case(), path: entry.clone() }; - lists.push(list); + notes.push(note); index += 1; } - lists + notes } } @@ -88,20 +88,20 @@ mod tests { use super::*; #[test] - fn loads_all_lists() { - let lists = List::load_all(Some("test")); - let list_ids: Vec<&str> = lists.iter() - .map(|list| list.id.as_ref()).collect(); - assert_eq!(list_ids, vec!["test", "updatable"]); + fn loads_all_notes() { + let notes = Note::load_all(Some("test")); + let note_ids: Vec<&str> = notes.iter() + .map(|note| note.id.as_ref()).collect(); + assert_eq!(note_ids, vec!["test", "updatable"]); } #[test] fn converts_to_html() { - let lists = List::load_all(Some("test")); - let list = lists.iter() - .find(|list| list.id == "test") + let notes = Note::load_all(Some("test")); + let note = notes.iter() + .find(|note| note.id == "test") .unwrap(); - assert_eq!(list.to_html(), r#"

This is a test list

+ assert_eq!(note.to_html(), r#"

This is a test list

  • One
  • Two
  • @@ -112,26 +112,26 @@ mod tests { #[test] fn updates_data() { - let mut lists = List::load_all(Some("test")); - let list = lists.iter_mut() - .find(|list| list.id == "updatable") + let mut notes = Note::load_all(Some("test")); + let note = notes.iter_mut() + .find(|note| note.id == "updatable") .unwrap(); - assert_eq!(list.data, "Some content"); + assert_eq!(note.data, "Some content"); // Update the data van verify it has changed let new_data = "New content"; - list.update_data(&String::from(new_data)); - assert_eq!(list.data, new_data); + note.update_data(&String::from(new_data)); + assert_eq!(note.data, new_data); - // Verify that the data is written to the file of the list by + // Verify that the data is written to the file of the note by // loading them again - let mut lists = List::load_all(Some("test")); - let list = lists.iter_mut() - .find(|list| list.id == "updatable") + let mut notes = Note::load_all(Some("test")); + let note = notes.iter_mut() + .find(|note| note.id == "updatable") .unwrap(); - assert_eq!(list.data, new_data); + assert_eq!(note.data, new_data); // ... and change it back again - list.update_data(&String::from("Some content")); + note.update_data(&String::from("Some content")); } } diff --git a/static/js/pinboard.js b/static/js/pinboard.js index 548fbac..c35ba83 100644 --- a/static/js/pinboard.js +++ b/static/js/pinboard.js @@ -1,9 +1,9 @@ -var lists; +var notes; var bgColors = ["info", "primary", "danger", "success", "warning", "secondary"]; var textColors = ["light", "light", "light", "light", "dark", "dark" ]; -function getUrlListId() { +function getUrlNoteId() { var hash = window.location.hash; if (hash.length <= 1) { return undefined; @@ -24,16 +24,16 @@ function showErrorDialog(title, html, buttons) { errorDialog.modal(); } -function initLists() { +function initNotes() { $.ajax({ - url: '/lists', + url: '/notes', headers: { 'Accept': 'application/json' } - }).done(function(allLists) { - lists = allLists; - lists.forEach(updateList); + }).done(function(allNotes) { + notes = allNotes; + notes.forEach(updateNote); - var curListId = getUrlListId(); - selectList(curListId); + var curNoteId = getUrlNoteId(); + selectNote(curNoteId); }).fail(function(jqXHR, textMsg, error) { showErrorDialog("Laden mislukt!", "

    Kan de lijsten niet laden!

    " + @@ -44,100 +44,100 @@ function initLists() { }); } -function getListElem(listId) { - return $('.list[data-list-id="' + listId + '"]'); +function getNoteElem(noteId) { + return $('.note[data-note-id="' + noteId + '"]'); } -function selectList(listId) { - if (listId) { - console.debug("Selecting list " + listId); - lists.forEach(function(list) { - var listElem = getListElem(list.id); - if (list.id == listId) { - listElem.show(200); +function selectNote(noteId) { + if (noteId) { + console.debug("Selecting note " + noteId); + notes.forEach(function(note) { + var noteElem = getNoteElem(note.id); + if (note.id == noteId) { + noteElem.show(200); } else { - listElem.hide(200); + noteElem.hide(200); } }); } else { - console.debug("Showing all lists"); - lists.forEach(function(list) { - var listElem = getListElem(list.id); - listElem.show(200); + console.debug("Showing all notes"); + notes.forEach(function(note) { + var noteElem = getNoteElem(note.id); + noteElem.show(200); }); } $("#navbarNav").collapse('hide'); } -function updateList(list) { - var listElem = $('.list[data-list-id="' + list.id + '"]'); - listElem.addClass("bg-" + bgColors[list.index]) - .addClass("text-" + textColors[list.index]); - $('.list-name', listElem).text(list.name); - mtime = new Date(list.mtime.secs_since_epoch * 1000); - $('.list-updated-at', listElem).text('Laatste aanpassing op ' + +function updateNote(note) { + var noteElem = $('.note[data-note-id="' + note.id + '"]'); + noteElem.addClass("bg-" + bgColors[note.index]) + .addClass("text-" + textColors[note.index]); + $('.note-name', noteElem).text(note.name); + mtime = new Date(note.mtime.secs_since_epoch * 1000); + $('.note-updated-at', noteElem).text('Laatste aanpassing op ' + mtime.toLocaleDateString("nl") + ' om ' + mtime.toLocaleTimeString("nl")); - $('.list-data', listElem).val(list.data); + $('.note-data', noteElem).val(note.data); - updateListHTML(listElem); + updateNoteHTML(noteElem); - disableListEditMode(listElem); + disableNoteEditMode(noteElem); } -function updateListHTML(listElem) { - var listId = listElem.data("list-id"); - var listHtmlElem = $('.list-html', listElem) +function updateNoteHTML(noteElem) { + var noteId = noteElem.data("note-id"); + var noteHtmlElem = $('.note-html', noteElem) $.ajax({ - url: '/lists/' + listId, + url: '/notes/' + noteId, headers: { 'Accept': 'text/html' } }).done(function(html) { - listHtmlElem.html(html); - $("ul > li", listHtmlElem).has('input[type="checkbox"]') + noteHtmlElem.html(html); + $("ul > li", noteHtmlElem).has('input[type="checkbox"]') .parent() - .addClass("tasklist"); - if (listHtmlElem.find('hr').length) { - listHtmlElem.find('hr') + .addClass("tasknote"); + if (noteHtmlElem.find('hr').length) { + noteHtmlElem.find('hr') .nextAll() - .wrapAll('
    ') - listHtmlElem.append('
    ' + - '' + '
    '); - var listMoreButton = listHtmlElem.find(".list-more-toggle"); - listHtmlElem.find('.list-more') + var noteMoreButton = noteHtmlElem.find(".note-more-toggle"); + noteHtmlElem.find('.note-more') .on('shown.bs.collapse', function() { - listMoreButton.text('Minder…'); + noteMoreButton.text('Minder…'); }).on('hidden.bs.collapse', function() { - listMoreButton.text('Meer…'); + noteMoreButton.text('Meer…'); }); } }).fail(function(html, textMsg, error) { - listHtmlElem.html("

    Kan lijst niet tonen!

    " + + noteHtmlElem.html("

    Kan lijst niet tonen!

    " + "

    (Technische foutmelding: " + error + " (" + textMsg + "))

    "); }); } -function saveListChanges(listElem) { - var listId = listElem.data("list-id"); - var list = lists.find(function(list) { return list.id == listId }); - var old_data = list.data; - list.data = $('.list-data', listElem).val(); +function saveNoteChanges(noteElem) { + var noteId = noteElem.data("note-id"); + var note = notes.find(function(note) { return note.id == noteId }); + var old_data = note.data; + note.data = $('.note-data', noteElem).val(); $.ajax({ method: 'PUT', - url: '/lists/' + listId, + url: '/notes/' + noteId, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, - data: JSON.stringify(list) - }).done(updateList) + data: JSON.stringify(note) + }).done(updateNote) .fail(function(jqXHR, textMsg, error) { - list.data = old_data; + note.data = old_data; showErrorDialog("Opslaan mislukt!", "

    Kan de lijst niet opslaan! Probeer later nog eens of " + "annuleer de bewerking.

    " + @@ -147,35 +147,35 @@ function saveListChanges(listElem) { }); } -function revertListChanges(listElem) { - var listId = listElem.data("list-id"); - var list = lists.find(function(list) { return list.id == listId }); +function revertNoteChanges(noteElem) { + var noteId = noteElem.data("note-id"); + var note = notes.find(function(note) { return note.id == noteId }); - disableListEditMode(listElem); + disableNoteEditMode(noteElem); - $('.list-data', listElem).val(list.data); + $('.note-data', noteElem).val(note.data); } -function disableListEditMode(listElem) { - $('.list-data', listElem).hide(200) +function disableNoteEditMode(noteElem) { + $('.note-data', noteElem).hide(200) .popover('hide'); - $('.list-html', listElem).show(200); - $('.list-edit-buttons', listElem).hide(200); - $('.list-edit-mode-buttons', listElem).show(200); - $('.list-edit-help', listElem).removeClass('active') + $('.note-html', noteElem).show(200); + $('.note-edit-buttons', noteElem).hide(200); + $('.note-edit-mode-buttons', noteElem).show(200); + $('.note-edit-help', noteElem).removeClass('active') .popover('hide'); } -function enableListEditMode(listElem) { - $('.list-data', listElem).show(200); - $('.list-html', listElem).hide(200); - $('.list-edit-mode-buttons', listElem).hide(200); - $('.list-edit-buttons', listElem).show(200); +function enableNoteEditMode(noteElem) { + $('.note-data', noteElem).show(200); + $('.note-html', noteElem).hide(200); + $('.note-edit-mode-buttons', noteElem).hide(200); + $('.note-edit-buttons', noteElem).show(200); } $(function() { - $('.lists-refresh').on('click', function() { - if ($(".list-data:visible").length) { + $('.notes-refresh').on('click', function() { + if ($(".note-data:visible").length) { showErrorDialog("Kan niet verversen tijdens bewerken!", "

    Het is niet mogelijk om de lijsten te verversen als er " + "op dit moment een lijst bewerkt wordt.

    " + @@ -183,41 +183,41 @@ $(function() { "bewerking.", true); } else { - initLists(); + initNotes(); } }); - $('.list-cancel-button').on('click', function() { - var listElem = $(this).parents(".list"); - console.debug("Cancelling the edit of list " + listElem.data("list-id")); - revertListChanges(listElem); + $('.note-cancel-button').on('click', function() { + var noteElem = $(this).parents(".note"); + console.debug("Cancelling the edit of note " + noteElem.data("note-id")); + revertNoteChanges(noteElem); }); - $('.list-edit-button').on('click', function() { - var listElem = $(this).parents(".list"); - console.debug("Going to edit list " + listElem.data("list-id")); - enableListEditMode(listElem); + $('.note-edit-button').on('click', function() { + var noteElem = $(this).parents(".note"); + console.debug("Going to edit note " + noteElem.data("note-id")); + enableNoteEditMode(noteElem); }); - $('.list-edit-help').on('click', function() { - var listElem = $(this).parents(".list"); - var listDataElem = $('.list-data', listElem); + $('.note-edit-help').on('click', function() { + var noteElem = $(this).parents(".note"); + var noteDataElem = $('.note-data', noteElem); $(this).toggleClass('active') - listDataElem.popover('toggle'); + noteDataElem.popover('toggle'); }); - $('.list-save-button').on('click', function() { - var listElem = $(this).parents(".list"); - console.debug("Saving the changes for list " + listElem.data("list-id")); - saveListChanges(listElem); + $('.note-save-button').on('click', function() { + var noteElem = $(this).parents(".note"); + console.debug("Saving the changes for note " + noteElem.data("note-id")); + saveNoteChanges(noteElem); }); - $('.list-select').on('click', function() { - listId = $(this).data('list-id'); - selectList(listId); + $('.note-select').on('click', function() { + noteId = $(this).data('note-id'); + selectNote(noteId); }); - initLists(); + initNotes(); $('textarea').popover({ html: true, trigger: 'manual' diff --git a/static/scss/pinboard.scss b/static/scss/pinboard.scss index 48c4c2e..4c15399 100644 --- a/static/scss/pinboard.scss +++ b/static/scss/pinboard.scss @@ -21,14 +21,14 @@ footer { line-height: 24px; } -// Reduce the large padding for lists -.list-html ul, -.list-html ol { +// Reduce the large padding for notes +.note-html ul, +.note-html ol { padding-left: 1.2rem; } -.list-html ul.tasklist { - list-style-type: none; +.note-html ul.tasknote { + note-style-type: none; padding-left: 0; } diff --git a/templates/_layout.html.tera b/templates/_layout.html.tera index 6b8c246..40fc1da 100644 --- a/templates/_layout.html.tera +++ b/templates/_layout.html.tera @@ -34,7 +34,7 @@ {% block body %}