mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
fix filtered list getters
This commit is contained in:
parent
6393a20554
commit
6f82924b4f
2 changed files with 42 additions and 62 deletions
|
|
@ -39,35 +39,32 @@ impl Memory {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get Items match `request`
|
/// Get unordered Items vector where title or request match `request`
|
||||||
|
/// * this function is case insensitive
|
||||||
pub fn contains_request(&self, request: &str, limit: Option<usize>) -> Vec<Item> {
|
pub fn contains_request(&self, request: &str, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut items: Vec<Item> = Vec::new();
|
self.0
|
||||||
for (i, item) in self.0.iter().enumerate() {
|
.iter()
|
||||||
if limit.is_some_and(|l| i > l) {
|
.filter(|item| {
|
||||||
break;
|
let p = request.to_lowercase();
|
||||||
}
|
item.request.to_lowercase().contains(&p)
|
||||||
if item.request.contains(request) {
|
|| item
|
||||||
items.push(item.clone())
|
.title
|
||||||
}
|
.as_ref()
|
||||||
}
|
.is_some_and(|t| t.to_lowercase().contains(&p))
|
||||||
items
|
})
|
||||||
|
.take(limit.unwrap_or(usize::MAX))
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent Items vector sorted by `ID` DESC
|
/// Get recent Items vector sorted by `ID` DESC
|
||||||
pub fn recent(&self, limit: Option<usize>) -> Vec<Item> {
|
pub fn recent(&self, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut recent: Vec<Item> = Vec::new();
|
self.0
|
||||||
for (i, item) in self
|
|
||||||
.0
|
|
||||||
.iter()
|
.iter()
|
||||||
.sorted_by(|a, b| Ord::cmp(&b.request, &a.request))
|
.sorted_by(|a, b| Ord::cmp(&b.id, &a.id))
|
||||||
.enumerate()
|
.take(limit.unwrap_or(usize::MAX))
|
||||||
{
|
.cloned()
|
||||||
if limit.is_some_and(|l| i > l) {
|
.collect()
|
||||||
break;
|
|
||||||
}
|
|
||||||
recent.push(item.clone())
|
|
||||||
}
|
|
||||||
recent
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,7 @@ impl Memory {
|
||||||
|
|
||||||
/// Get recent Items vector sorted by `closed` DESC
|
/// Get recent Items vector sorted by `closed` DESC
|
||||||
pub fn recently_closed(&self, limit: Option<usize>) -> Vec<Item> {
|
pub fn recently_closed(&self, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut recent: Vec<Item> = Vec::new();
|
self.0
|
||||||
for (i, item) in self
|
|
||||||
.0
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| x.closed.is_some())
|
.filter(|x| x.closed.is_some())
|
||||||
.sorted_by(|a, b| {
|
.sorted_by(|a, b| {
|
||||||
|
|
@ -55,52 +53,37 @@ impl Memory {
|
||||||
&a.closed.as_ref().unwrap().time,
|
&a.closed.as_ref().unwrap().time,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.enumerate()
|
.take(limit.unwrap_or(usize::MAX))
|
||||||
{
|
.cloned()
|
||||||
if limit.is_some_and(|l| i >= l) {
|
.collect()
|
||||||
break;
|
|
||||||
}
|
|
||||||
recent.push(item.clone())
|
|
||||||
}
|
|
||||||
recent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent Items vector sorted by `opened` DESC
|
/// Get recent Items vector sorted by `opened` DESC
|
||||||
pub fn recently_opened(&self, limit: Option<usize>) -> Vec<Item> {
|
pub fn recently_opened(&self, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut recent: Vec<Item> = Vec::new();
|
self.0
|
||||||
for (i, item) in self
|
|
||||||
.0
|
|
||||||
.iter()
|
.iter()
|
||||||
.sorted_by(|a, b| Ord::cmp(&b.opened.time, &a.opened.time))
|
.sorted_by(|a, b| Ord::cmp(&b.opened.time, &a.opened.time))
|
||||||
.enumerate()
|
.take(limit.unwrap_or(usize::MAX))
|
||||||
{
|
.cloned()
|
||||||
if limit.is_some_and(|l| i >= l) {
|
.collect()
|
||||||
break;
|
|
||||||
}
|
|
||||||
recent.push(item.clone())
|
|
||||||
}
|
|
||||||
recent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get unordered Items vector contains `request`
|
/// Get unordered Items vector where title or request match `request`
|
||||||
/// * this function is case insensitive
|
/// * this function is case insensitive
|
||||||
pub fn contains_request(&self, request: &str, limit: Option<usize>) -> Vec<Item> {
|
pub fn contains_request(&self, request: &str, limit: Option<usize>) -> Vec<Item> {
|
||||||
let mut items: Vec<Item> = Vec::new();
|
self.0
|
||||||
for (i, item) in self.0.iter().enumerate() {
|
.iter()
|
||||||
if limit.is_some_and(|l| i >= l) {
|
.filter(|item| {
|
||||||
break;
|
|
||||||
}
|
|
||||||
let p = request.to_lowercase();
|
let p = request.to_lowercase();
|
||||||
if item.request.to_lowercase().contains(&p)
|
item.request.to_lowercase().contains(&p)
|
||||||
|| item
|
|| item
|
||||||
.title
|
.title
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|t| t.to_lowercase().contains(&p))
|
.is_some_and(|t| t.to_lowercase().contains(&p))
|
||||||
{
|
})
|
||||||
items.push(item.clone())
|
.take(limit.unwrap_or(usize::MAX))
|
||||||
}
|
.cloned()
|
||||||
}
|
.collect()
|
||||||
items
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn items(&self) -> &Vec<Item> {
|
pub fn items(&self) -> &Vec<Item> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue