Rename list to note throughout the application

This commit is contained in:
Paul van Tilburg 2018-01-26 21:18:04 +01:00
parent 2c46179f4f
commit 67d55cadc4
18 changed files with 309 additions and 244 deletions

10
notes/_test.note Normal file
View File

@ -0,0 +1,10 @@
* Eerste item
* Tweede item
---
#### Nog veel meer, maar later
* Dit
* Dat
---
Nog een lijn?

1
notes/leeg.note Normal file
View File

@ -0,0 +1 @@

20
notes/markdown.note Normal file
View File

@ -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

11
notes/quoot.note Normal file
View File

@ -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

23
notes/zandbak.note Normal file
View File

@ -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 <textarea>HTML nesting</textarea>?
~Nee, dat werkt niet~
##### Kop 5
* [ ] Item a
* [ ] Item b
* [x] Item c
UTF8 test⸘
3.1.3 2 continuation bytes: "<22><>" |
3.1.4 3 continuation bytes: "<22><><EFBFBD>" |
3.1.5 4 continuation bytes: "<22><><EFBFBD><EFBFBD>" |
3.1.6 5 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD>" |
3.1.7 6 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
3.1.8 7 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |

View File

@ -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<HashMap<&'a str, &'a str>>
notes: Vec<HashMap<&'a str, &'a str>>
}
#[get("/")]
fn index(lists: State<ListStore>) -> 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<NoteStore>) -> 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("<span id=\"list-name\">Test</span>"));
assert!(body.contains("<span id=\"note-name\">Test</span>"));
}
}

View File

@ -1,3 +1,3 @@
pub mod home;
pub mod list;
pub mod note;
pub mod static_files;

View File

@ -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<ListStore>) -> Option<Json<Vec<List>>> {
let lists = lists.read().unwrap();
Some(Json(lists.clone()))
fn index(notes: State<NoteStore>) -> Option<Json<Vec<Note>>> {
let notes = notes.read().unwrap();
Some(Json(notes.clone()))
}
#[get("/<list_id>", format = "text/html")]
fn show_html(list_id: String, lists: State<ListStore>) -> Option<String> {
let lists = lists.read().unwrap();
let list = lists.iter().find( |list| list.id == list_id )?;
Some(list.to_html())
#[get("/<note_id>", format = "text/html")]
fn show_html(note_id: String, notes: State<NoteStore>) -> Option<String> {
let notes = notes.read().unwrap();
let note = notes.iter().find( |note| note.id == note_id )?;
Some(note.to_html())
}
#[get("/<list_id>", format = "application/json")]
fn show_json(list_id: String, lists: State<ListStore>) -> Option<Json<List>> {
let lists = lists.read().unwrap();
let list = lists.iter().find( |list| list.id == list_id )?;
Some(Json(list.clone()))
#[get("/<note_id>", format = "application/json")]
fn show_json(note_id: String, notes: State<NoteStore>) -> Option<Json<Note>> {
let notes = notes.read().unwrap();
let note = notes.iter().find( |note| note.id == note_id )?;
Some(Json(note.clone()))
}
#[put("/<list_id>", format = "application/json", data = "<new_list>")]
fn update(list_id: String, new_list: Json<List>, lists: State<ListStore>) -> Option<Json<List>> {
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("/<note_id>", format = "application/json", data = "<new_note>")]
fn update(note_id: String, new_note: Json<Note>, notes: State<NoteStore>) -> Option<Json<Note>> {
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::<Vec<List>>(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::<Vec<Note>>(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::<List>(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::<Note>(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::<List>(body.as_str()).unwrap();
assert_eq!(list.data, "Some content");
let note = serde_json::from_str::<Note>(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::<List>(body.as_str()).unwrap();
assert_eq!(list.data, new_data);
let note = serde_json::from_str::<Note>(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();

View File

@ -15,17 +15,17 @@ mod models;
use rocket::Rocket;
use std::sync::RwLock;
type ListStore = RwLock<Vec<models::list::List>>;
type NoteStore = RwLock<Vec<models::note::Note>>;
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())
}

View File

@ -1 +1 @@
pub mod list;
pub mod note;

View File

@ -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<Self> {
let mut lists : Vec<List> = vec![];
pub fn load_all(note_path: Option<&str>) -> Vec<Self> {
let mut notes : Vec<Note> = 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#"<p>This is a test list</p>
assert_eq!(note.to_html(), r#"<p>This is a test list</p>
<ul>
<li>One</li>
<li>Two</li>
@ -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"));
}
}

View File

@ -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!",
"<p>Kan de lijsten niet laden!</p>" +
@ -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('<div class="collapse list-more"/>')
listHtmlElem.append('<div class="row justify-content-center">' +
'<button class="btn btn-sm btn-light text-dark list-more-toggle" '+
.wrapAll('<div class="collapse note-more"/>')
noteHtmlElem.append('<div class="row justify-content-center">' +
'<button class="btn btn-sm btn-light text-dark note-more-toggle" '+
'data-toggle="collapse" ' +
'data-target=".list[data-list-id=\'' + listId + '\'] .list-more">' +
'data-target=".note[data-note-id=\'' + noteId + '\'] .note-more">' +
'Meer…</button>' +
'</div>');
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("<h3><i>Kan lijst niet tonen!</i></h3>" +
noteHtmlElem.html("<h3><i>Kan lijst niet tonen!</i></h3>" +
"<p class='pt-2'><small><i>(Technische foutmelding: " + error +
" (" + textMsg + "))<i></small></p>");
});
}
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!",
"<p>Kan de lijst niet opslaan! Probeer later nog eens of " +
"annuleer de bewerking.</p>" +
@ -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!",
"<p>Het is niet mogelijk om de lijsten te verversen als er " +
"op dit moment een lijst bewerkt wordt.</p>" +
@ -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'

View File

@ -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;
}

View File

@ -34,7 +34,7 @@
{% block body %}
<nav class="navbar navbar-expand-md fixed-top navbar-dark bg-dark text-light" role="navigation">
<div class="container">
<a class="navbar-brand list-select" href="#">Online Prikbord</a>
<a class="navbar-brand note-select" href="#">Online Prikbord</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

View File

@ -3,13 +3,13 @@
{% block navbar %}
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
{% for list in lists %}
{% for note in notes %}
<li class="nav-item">
<a class="nav-link list-select" data-list-id="{{ list.id }}" href="#{{ list.id }}">{{ list.name }}</a>
<a class="nav-link note-select" data-note-id="{{ note.id }}" href="#{{ note.id }}">{{ note.name }}</a>
</li>
{% endfor %}
</ul>
<button class="btn btn-sm btn-light lists-refresh" title="Verversen">
<button class="btn btn-sm btn-light notes-refresh" title="Verversen">
<i class="fas fa-sync-alt"></i> Verversen
</button>
</div>
@ -18,27 +18,27 @@
{% block content %}
<div class="card-columns">
{% for list in lists %}
<div class="card list mb-3" style="display:none"; data-list-id="{{ list.id }}">
{% for note in notes %}
<div class="card note mb-3" style="display:none"; data-note-id="{{ note.id }}">
<div class="card-header">
<h1 class= "mb-0">
<span id="list-name">{{ list.name }}</span>
<div class="btn-toolbar float-right mt-1" role="toolbar" aria-label="List buttons">
<div class="btn-group list-edit-mode-buttons"
<span id="note-name">{{ note.name }}</span>
<div class="btn-toolbar float-right mt-1" role="toolbar" aria-label="Note buttons">
<div class="btn-group note-edit-mode-buttons"
role="group" aria-label="Edit mode buttons">
<button class="btn btn-dark list-edit-button" title="Bewerken">
<button class="btn btn-dark note-edit-button" title="Bewerken">
<i class="fas fa-edit"></i>
</button>
</div>
<div class="btn-group list-edit-buttons" role="group"
aria-label="Edit list buttons">
<button class="btn btn-light list-edit-help" title="Opmaakhulp">
<div class="btn-group note-edit-buttons" role="group"
aria-label="Edit note buttons">
<button class="btn btn-light note-edit-help" title="Opmaakhulp">
<i class="fas fa-question-circle"></i>
</button>
<button class="btn btn-light list-cancel-button" title="Annuleren">
<button class="btn btn-light note-cancel-button" title="Annuleren">
<i class="fas fa-ban"></i>
</button>
<button class="btn btn-dark list-save-button" title="Opslaan">
<button class="btn btn-dark note-save-button" title="Opslaan">
<i class="fas fa-save"></i>
</button>
</div>
@ -46,9 +46,9 @@
</h1>
</div>
<div class="card-body">
<div class="card-text list-html"></div>
<div class="card-text note-html"></div>
<div class="card-text">
<textarea class="form-control list-data" rows="16"
<textarea class="form-control note-data" rows="16"
data-title="Opmaakhulp"
data-content="<pre class='mb-0'>
## Kop 2
@ -76,7 +76,7 @@ Horizontale lijn<pre>"></textarea>
<p class="card-text">
<small>
<i class="fas fa-clock"></i>
<i class="list-updated-at"></i>
<i class="note-updated-at"></i>
</small>
</p>
</div>