mod draft;
mod proposal;
pub use draft::Draft;
pub use proposal::Proposing;
use super::Model;
use crate::verbs::Where;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Configuring {
pub at: Option<Where>,
pub draft: Option<Draft>,
pub workflow: String,
pub proposal: Option<Proposing>,
}
impl Model {
pub fn begin_configuring(&mut self) {
if self.aim.is_some() {
self.configuring = Some(Configuring::default());
}
}
pub fn close_configuring(&mut self) {
self.configuring = None;
}
pub fn configured(&self) -> Option<Where> {
self.configuring.as_ref()?.at.clone()
}
pub fn read_config(&mut self, at: &Where) {
let Some(pane) = self.configuring.as_mut() else {
return;
};
pane.at = Some(at.clone());
pane.draft = None;
self.config = None;
}
pub fn draft_config(&mut self, answered: &str) {
let Some(pane) = self.configuring.as_mut() else {
return;
};
match pane.draft.as_mut() {
Some(draft) => draft.settle(answered),
None => pane.draft = Some(Draft::of(answered)),
}
}
pub(crate) fn draft_box(&mut self) -> Option<&mut String> {
Some(&mut self.configuring.as_mut()?.draft.as_mut()?.text)
}
pub(crate) fn workflow_box(&mut self) -> Option<&mut String> {
Some(&mut self.configuring.as_mut()?.workflow)
}
pub fn workflow_named(&self) -> String {
self.configuring
.as_ref()
.map(|pane| pane.workflow.trim().to_owned())
.unwrap_or_default()
}
pub fn drafted(&self) -> Option<Draft> {
self.configuring.as_ref()?.draft.clone()
}
pub fn revert_config(&mut self, answered: &str) {
let Some(pane) = self.configuring.as_mut() else {
return;
};
pane.draft = Some(Draft::of(answered));
}
pub fn write_config(&mut self, at: &Where, text: String) {
let posted = super::Posted::act(crate::verbs::write(at, text));
let posted = if at.addresses_a_workspace() {
posted
} else {
let Some(down) = self.channel() else {
return;
};
posted.down(down)
};
self.outbox.push(posted);
}
pub(super) fn retire_configuring(&mut self) {
self.configuring = None;
self.config = None;
self.lineages = None;
self.proposals = None;
}
}
#[cfg(test)]
mod tests;