record all opened/closed history, change sort order to DESC

This commit is contained in:
yggverse 2025-03-08 21:15:35 +02:00
parent 268af30830
commit f90378a911
2 changed files with 11 additions and 11 deletions

View File

@ -5,8 +5,8 @@ pub struct Item {
pub id: i64,
pub request: GString,
pub created: DateTime,
pub opened: DateTime,
pub closed: Option<DateTime>,
pub opened: Vec<DateTime>,
pub closed: Vec<DateTime>,
}
impl Item {
@ -17,19 +17,19 @@ impl Item {
id,
request,
created: now(),
opened: now(),
closed: None,
opened: vec![now()],
closed: vec![],
}
}
// Actions
pub fn open(&mut self) {
self.opened = now()
self.opened.push(now())
}
pub fn close(&mut self) {
self.closed = Some(now())
self.closed.push(now())
}
}

View File

@ -42,14 +42,14 @@ impl Memory {
// Getters
/// Get recent Items vector sorted by `closed` ASC
/// Get recent Items vector sorted by `closed` DESC
pub fn recently_closed(&self, limit: Option<usize>) -> Vec<Item> {
let mut recent: Vec<Item> = Vec::new();
for (i, item) in self
.0
.iter()
.filter(|x| x.closed.is_some())
.sorted_by(|a, b| Ord::cmp(&a.closed, &b.closed))
.filter(|x| !x.closed.is_empty())
.sorted_by(|a, b| Ord::cmp(&b.closed.last(), &a.closed.last()))
.enumerate()
{
if limit.is_some_and(|l| i > l) {
@ -60,13 +60,13 @@ impl Memory {
recent
}
/// Get recent Items vector sorted by `opened` ASC
/// Get recent Items vector sorted by `opened` DESC
pub fn recently_opened(&self, limit: Option<usize>) -> Vec<Item> {
let mut recent: Vec<Item> = Vec::new();
for (i, item) in self
.0
.iter()
.sorted_by(|a, b| Ord::cmp(&a.opened, &b.opened))
.sorted_by(|a, b| Ord::cmp(&b.opened.last(), &a.opened.last()))
.enumerate()
{
if limit.is_some_and(|l| i > l) {