Skip to content

Commit

Permalink
#905 - Sort by recently used beans
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Feb 11, 2025
1 parent 330f8e0 commit 0d9ce6d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app/beans/bean-sort/bean-sort.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<ion-icon name="beanconqueror-clock" slot="start"></ion-icon>
<ion-label>{{"BEAN_SORT_BEAN_AGE" | translate}}</ion-label>
</ion-item>
<ion-item (click)="setSortAfter(beanSortAfterEnum.RECENTLY_USED)" [class.active]="isSortActive(beanSortAfterEnum.RECENTLY_USED)" class="ion-margin-top" lines="none" tappable>
<ion-icon name="beanconqueror-clock" slot="start"></ion-icon>
<ion-label>{{"BEAN_SORT_RECENTLY_USED" | translate}}</ion-label>
</ion-item>

<ion-list-header>
<ion-item style="width: 100%;margin-left: 0px;--background: #ffffff;" (click)="toggleExtendSort()" class="ion-margin-top" lines="none" tappable>
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,5 +1419,6 @@
"SMART_SCALE_ACAIA_CONNECTION_MODE_V2": "V2 - New connection mode",
"SMART_SCALE_ACAIA_CONNECTION_MODE_V1": "V1 - Old connection mode",
"BEAN_DATA_CO2E_KG": "CO2e (kg) per kg roasted coffee",
"BEAN_DATA_CO2E_KG_TOOLTIP": "The released CO2e (kg) released per kg roasted coffee"
"BEAN_DATA_CO2E_KG_TOOLTIP": "The released CO2e (kg) released per kg roasted coffee",
"BEAN_SORT_RECENTLY_USED": "Last used"
}
10 changes: 10 additions & 0 deletions src/classes/bean/bean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ export class Bean implements IBean {
return 0;
}

public getLastUsed(): number {
const beanHelper: UIBeanHelper = UIBeanHelper.getInstance();
let relatedBrews = beanHelper.getAllBrewsForThisBean(this.config.uuid);
if (relatedBrews.length > 0) {
relatedBrews = UIBrewHelper.sortBrews(relatedBrews);
return relatedBrews[0].config.unix_timestamp;
}
return -1;
}

/**
* Get the calculated bean age for this brew
*/
Expand Down
1 change: 1 addition & 0 deletions src/enums/beans/beanSortAfter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export enum BEAN_SORT_AFTER {
WEIGHT_REMAINING = 'WEIGHT_REMAINING',
OPEN_DATE = 'OPEN_DATE',
BUY_DATE = 'BUY_DATE',
RECENTLY_USED = 'RECENTLY_USED',
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ export class BeanSortFilterHelperService {
return 0;
});
break;
case BEAN_SORT_AFTER.RECENTLY_USED:
filterBeans = filterBeans.sort((a, b) => {
if (a.getLastUsed() < b.getLastUsed()) {
return -1;
}
if (a.getLastUsed() > b.getLastUsed()) {
return 1;
}
return 0;
});
break;
case BEAN_SORT_AFTER.BEAN_ROASTING_TYPE:
filterBeans = filterBeans.sort((a, b) => {
const nameA = a.bean_roasting_type.toUpperCase();
Expand Down

0 comments on commit 0d9ce6d

Please sign in to comment.