update documentation
This commit is contained in:
parent
b782d97920
commit
9005a446fe
@ -28,6 +28,7 @@ macro_rules! unwrap_or_return {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Setup the page
|
||||||
pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model {
|
pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model {
|
||||||
log!(url);
|
log!(url);
|
||||||
orders.send_msg(Msg::Query(QueryMsg::Fetch));
|
orders.send_msg(Msg::Query(QueryMsg::Fetch));
|
||||||
@ -99,8 +100,7 @@ pub enum EditMsg {
|
|||||||
DeletedLink(Status),
|
DeletedLink(Status),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Panics
|
/// React to environment changes
|
||||||
/// Sould only panic on bugs.
|
|
||||||
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::Query(msg) => process_query_messages(msg, model, orders),
|
Msg::Query(msg) => process_query_messages(msg, model, orders),
|
||||||
@ -118,8 +118,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Panics
|
/// Process all messages for loading the information from the server.
|
||||||
/// Sould only panic on bugs.
|
|
||||||
pub fn process_query_messages(msg: QueryMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
pub fn process_query_messages(msg: QueryMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||||
match msg {
|
match msg {
|
||||||
QueryMsg::Fetch => {
|
QueryMsg::Fetch => {
|
||||||
@ -194,8 +193,10 @@ pub fn process_query_messages(msg: QueryMsg, model: &mut Model, orders: &mut imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perform a request to the server to load the links from the server.
|
||||||
fn load_links(model: &Model, orders: &mut impl Orders<Msg>) {
|
fn load_links(model: &Model, orders: &mut impl Orders<Msg>) {
|
||||||
let data = model.formconfig.clone(); // complicated way to move into the closure
|
let data = model.formconfig.clone();
|
||||||
orders.perform_cmd(async {
|
orders.perform_cmd(async {
|
||||||
let data = data;
|
let data = data;
|
||||||
let request = unwrap_or_return!(
|
let request = unwrap_or_return!(
|
||||||
@ -223,6 +224,7 @@ fn load_links(model: &Model, orders: &mut impl Orders<Msg>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Process all the events related to editing links.
|
||||||
pub fn process_edit_messages(msg: EditMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
pub fn process_edit_messages(msg: EditMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||||
match msg {
|
match msg {
|
||||||
EditMsg::EditSelected(link) => {
|
EditMsg::EditSelected(link) => {
|
||||||
@ -271,16 +273,14 @@ pub fn process_edit_messages(msg: EditMsg, model: &mut Model, orders: &mut impl
|
|||||||
EditMsg::DeleteSelected(link) => {
|
EditMsg::DeleteSelected(link) => {
|
||||||
orders.perform_cmd(async {
|
orders.perform_cmd(async {
|
||||||
let data = link;
|
let data = link;
|
||||||
let response = unwrap_or_return!(
|
let request = unwrap_or_return!(
|
||||||
fetch(
|
|
||||||
Request::new("/admin/json/delete_link/")
|
Request::new("/admin/json/delete_link/")
|
||||||
.method(Method::Post)
|
.method(Method::Post)
|
||||||
.json(&data)
|
.json(&data),
|
||||||
.expect("serialization failed"),
|
Msg::SetMessage("serialization failed".to_string())
|
||||||
)
|
|
||||||
.await,
|
|
||||||
Msg::Edit(EditMsg::FailedToDeleteLink)
|
|
||||||
);
|
);
|
||||||
|
let response =
|
||||||
|
unwrap_or_return!(fetch(request).await, Msg::Edit(EditMsg::FailedToDeleteLink));
|
||||||
|
|
||||||
let response = unwrap_or_return!(
|
let response = unwrap_or_return!(
|
||||||
response.check_status(),
|
response.check_status(),
|
||||||
@ -306,13 +306,15 @@ pub fn process_edit_messages(msg: EditMsg, model: &mut Model, orders: &mut impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Save a link to the server.
|
||||||
fn save_link(model: &Model, orders: &mut impl Orders<Msg>) {
|
fn save_link(model: &Model, orders: &mut impl Orders<Msg>) {
|
||||||
let data = model
|
let edit_link = if let Some(e) = model.edit_link.as_ref() {
|
||||||
.edit_link
|
e
|
||||||
.as_ref()
|
} else {
|
||||||
.expect("should exist!")
|
orders.send_msg(Msg::SetMessage("Please enter a link".to_string()));
|
||||||
.borrow()
|
return;
|
||||||
.clone();
|
};
|
||||||
|
let data = edit_link.borrow().clone();
|
||||||
orders.perform_cmd(async {
|
orders.perform_cmd(async {
|
||||||
let data = data;
|
let data = data;
|
||||||
let request = unwrap_or_return!(
|
let request = unwrap_or_return!(
|
||||||
@ -342,6 +344,10 @@ fn save_link(model: &Model, orders: &mut impl Orders<Msg>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// view the page
|
||||||
|
/// * messages
|
||||||
|
/// * questions
|
||||||
|
/// * the table of links including sorting and searching
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn view(model: &Model) -> Node<Msg> {
|
pub fn view(model: &Model) -> Node<Msg> {
|
||||||
let lang = &model.i18n.clone();
|
let lang = &model.i18n.clone();
|
||||||
@ -410,6 +416,7 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create the headlines of the link table
|
||||||
fn view_link_table_head<F: Fn(&str) -> String>(t: F) -> Node<Msg> {
|
fn view_link_table_head<F: Fn(&str) -> String>(t: F) -> Node<Msg> {
|
||||||
tr![
|
tr![
|
||||||
th![
|
th![
|
||||||
@ -446,6 +453,7 @@ fn view_link_table_head<F: Fn(&str) -> String>(t: F) -> Node<Msg> {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create the filter fields in the table columns
|
||||||
fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> Node<Msg> {
|
fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> Node<Msg> {
|
||||||
tr![
|
tr![
|
||||||
C!["filters"],
|
C!["filters"],
|
||||||
@ -495,6 +503,7 @@ fn view_link_table_filter_input<F: Fn(&str) -> String>(model: &Model, t: F) -> N
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// display a single link
|
||||||
fn view_link(l: &FullLink) -> Node<Msg> {
|
fn view_link(l: &FullLink) -> Node<Msg> {
|
||||||
// Ugly hack
|
// Ugly hack
|
||||||
let link = LinkDelta::from(l.clone());
|
let link = LinkDelta::from(l.clone());
|
||||||
@ -538,6 +547,7 @@ fn view_link(l: &FullLink) -> Node<Msg> {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// display a link editing dialog with save and close button
|
||||||
fn edit_or_create_link<F: Fn(&str) -> String>(l: &RefCell<LinkDelta>, t: F) -> Node<Msg> {
|
fn edit_or_create_link<F: Fn(&str) -> String>(l: &RefCell<LinkDelta>, t: F) -> Node<Msg> {
|
||||||
let link = l.borrow();
|
let link = l.borrow();
|
||||||
div![
|
div![
|
||||||
|
Loading…
Reference in New Issue
Block a user