use super::*;
#[cfg(feature = "gui")]
use mkentity::ProjectSource;
#[derive(Debug, Clone, Default)]
pub struct RoleMap(pub HashMap<ProductionRole, HashSet<Staff>>);
impl RoleMap {
pub fn all(&self) -> HashSet<Staff> {
let mut staff = HashSet::new();
for s in self.0.values() {
staff = staff.union(&s).map(|s| s.to_owned()).collect();
}
staff
}
pub fn supervisors(&self, includes_directors: bool) -> HashSet<Staff> {
let mut staff = HashSet::new();
for s in self.team_leads_or_empty().drain() {
staff.insert(s);
}
for s in self.art_producers_or_empty().drain() {
staff.insert(s);
}
if includes_directors {
for s in self.art_directors_or_empty().drain() {
staff.insert(s);
}
};
staff
}
pub fn supervisors_and_watchers(&self, includes_directors: bool) -> HashSet<Staff> {
self.supervisors(includes_directors)
.union(&self.watchers_or_empty())
.map(|s| s.to_owned())
.collect()
}
pub fn assignees_and_supervisors(
&self,
assignees: &HashSet<Staff>,
includes_directors: bool,
includes_watchers: bool,
) -> HashSet<Staff> {
if includes_watchers {
self.supervisors_and_watchers(includes_directors)
.union(assignees)
.map(|s| s.to_owned())
.collect()
} else {
self.supervisors(includes_directors)
.union(assignees)
.map(|s| s.to_owned())
.collect()
}
}
pub fn assignnees_supervisors_no_producers(
&self,
assignees: &HashSet<Staff>,
) -> HashSet<Staff> {
let mut staff = HashSet::new();
for s in self.team_leads_or_empty().drain() {
staff.insert(s);
}
for s in self.art_directors_or_empty().drain() {
staff.insert(s);
}
staff.union(assignees).map(|s| s.to_owned()).collect()
}
pub fn assignees_and_team_leads(&self, assignees: &HashSet<Staff>) -> HashSet<Staff> {
self.team_leads_or_empty()
.union(assignees)
.map(|s| s.to_owned())
.collect()
}
pub fn art_directors_or_empty(&self) -> HashSet<Staff> {
self.0
.get(&ProductionRole::ArtDirector)
.map(|s| s.to_owned())
.unwrap_or(HashSet::new())
}
pub fn art_producers_or_empty(&self) -> HashSet<Staff> {
self.0
.get(&ProductionRole::ArtProducer)
.map(|s| s.to_owned())
.unwrap_or(HashSet::new())
}
pub fn team_leads_or_empty(&self) -> HashSet<Staff> {
self.0
.get(&ProductionRole::TeamLead)
.map(|s| s.to_owned())
.unwrap_or(HashSet::new())
}
pub fn watchers_or_empty(&self) -> HashSet<Staff> {
self.0
.get(&ProductionRole::Watcher)
.map(|s| s.to_owned())
.unwrap_or(HashSet::new())
}
#[cfg(feature = "gui")]
pub fn into_trees(self, typ: &ProjectSource) -> Vec<MkTree<Staff>> {
let mut trees: Vec<MkTree<Staff>> = self
.0
.into_iter()
.map(|(role, users)| {
let mut users: Vec<Staff> = users.into_iter().collect();
users.sort();
MkTree::leaf_group(role.as_ref(), users, typ)
})
.collect();
trees.sort_by_key(|t| t.node_name());
trees
}
#[cfg(feature = "gui")]
pub fn into_trees_cb(self, typ: &ProjectSource) -> Vec<MkTreeCb<Staff>> {
let mut trees: Vec<MkTreeCb<Staff>> = self
.0
.into_iter()
.map(|(role, users)| {
let mut users: Vec<Staff> = users.into_iter().collect();
users.sort();
MkTreeCb::leaf_group(role.as_ref(), users, typ)
})
.collect();
trees.sort_by_key(|t| t.node_name());
trees
}
}