use crate::pcontent::{
PLabelId, pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
preferenceurl::PReferenceUrl
};
#[derive(Debug, Clone, Default, PartialEq)]
pub enum PStatusType {
#[default]
Backlog,
Todo,
Waiting,
Blocked,
Ongoing,
Done,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentStatus{
p_type: PStatusType,
}
impl PContentStatus {
pub fn new(status_type: &PStatusType) -> Self{
PContentStatus {
p_type: status_type.clone(),
}
}
pub fn get_type(&self) -> &PStatusType{
&self.p_type
}
}
impl PAbstractContent for PContentStatus{
fn has_embeded_label(&self) -> bool{
false
}
fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
PReferenceUrl::from_text(current_file, id, &String::from(&format!("PContentStatus {}", id)))
}
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
match self.p_type {
PStatusType::Backlog => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_backlog.svg\" alt=\"backlog\" />", id.get_id())),
PStatusType::Todo => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_todo.svg\" alt=\"todo\" />", id.get_id())),
PStatusType::Waiting => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_waiting.svg\" alt=\"waiting\" />", id.get_id())),
PStatusType::Blocked => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_blocked.svg\" alt=\"blocked\" />", id.get_id())),
PStatusType::Ongoing => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_ongoing.svg\" alt=\"ongoing\" />", id.get_id())),
PStatusType::Done => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_done.svg\" alt=\"done\" />", id.get_id())),
}
}
}
#[cfg(test)]
mod tests{
use super::*;
use crate::pcontent::pstrbackend::PStrBackend;
fn test_pcontent_status_type(status_type: &PStatusType, expected_output: &String){
let content_status: PContentStatus = PContentStatus::new(status_type);
let mut backend = PStrBackend::new();
content_status.to_html(&mut backend, &PLabelId::new(42));
assert_eq!(backend.get_body(), expected_output);
}
#[test]
fn test_pcontent_status(){
test_pcontent_status_type(&PStatusType::Backlog, &String::from("<img id=\"42\" src=\"book/images/status_backlog.svg\" alt=\"backlog\" />"));
test_pcontent_status_type(&PStatusType::Todo, &String::from("<img id=\"42\" src=\"book/images/status_todo.svg\" alt=\"todo\" />"));
test_pcontent_status_type(&PStatusType::Waiting, &String::from("<img id=\"42\" src=\"book/images/status_waiting.svg\" alt=\"waiting\" />"));
test_pcontent_status_type(&PStatusType::Blocked, &String::from("<img id=\"42\" src=\"book/images/status_blocked.svg\" alt=\"blocked\" />"));
test_pcontent_status_type(&PStatusType::Ongoing, &String::from("<img id=\"42\" src=\"book/images/status_ongoing.svg\" alt=\"ongoing\" />"));
test_pcontent_status_type(&PStatusType::Done, &String::from("<img id=\"42\" src=\"book/images/status_done.svg\" alt=\"done\" />"));
}
}