Skip to content

Commit

Permalink
#837 - Removing functions, setting to variables for faster rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Nov 10, 2024
1 parent d0cf93b commit f7125aa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 59 deletions.
20 changes: 10 additions & 10 deletions src/app/dashboard/dashboard.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<ion-col size="6">
<ion-card [routerLink]="['/home/brews']" class="dashboard ion-no-margin" tappable>
<ion-card-header class="ion-no-padding ion-no-margin">
<ion-card-title> {{uiStatistic.getBrewsDrunk()}}</ion-card-title>
<ion-card-title> {{getBrewsDrunk}}</ion-card-title>
<ion-card-subtitle>
<span *ngIf="uiStatistic.getBrewsDrunk() == 1">
<span *ngIf="getBrewsDrunk == 1">
{{"PAGE_HOME_TOTAL_BREW" | translate}}
</span>
<span *ngIf="uiStatistic.getBrewsDrunk() != 1">
<span *ngIf="getBrewsDrunk != 1">
{{"PAGE_HOME_TOTAL_BREWS" | translate}}
</span>
</ion-card-subtitle>
Expand All @@ -35,9 +35,9 @@
<ion-col size="6">
<ion-card [routerLink]="['/statistic']" class="dashboard ion-no-margin no-border" tappable>
<ion-card-header class="ion-no-padding ion-no-margin">
<ion-card-title> {{uiStatistic.getTimePassedSinceLastBrew()}}</ion-card-title>
<ion-card-title> {{getTimePassedSinceLastBrew}}</ion-card-title>
<ion-card-subtitle>
{{uiStatistic.getTimePassedSinceLastBrewMessage()}} {{"WITHOUT_COFFEE" | translate}}
{{getTimePassedSinceLastBrewMessage}} {{"WITHOUT_COFFEE" | translate}}
</ion-card-subtitle>

</ion-card-header>
Expand All @@ -50,12 +50,12 @@
<ion-col size="6">
<ion-card [routerLink]="['/home/beans']" class="dashboard ion-no-margin" tappable>
<ion-card-header class="ion-no-padding ion-no-margin">
<ion-card-title> {{uiStatistic.getBeansCount()}}</ion-card-title>
<ion-card-title> {{getBeansCount}}</ion-card-title>
<ion-card-subtitle>
<span *ngIf="uiStatistic.getBeansCount() == 1">
<span *ngIf="getBeansCount == 1">
{{"PAGE_HOME_BEAN_EXPLORED" | translate}}
</span>
<span *ngIf="uiStatistic.getBeansCount() != 1">
<span *ngIf="getBeansCount != 1">
{{"PAGE_HOME_BEANS_EXPLORED" | translate}}
</span>
</ion-card-subtitle>
Expand All @@ -66,8 +66,8 @@
<ion-col size="6">
<ion-card [routerLink]="['/home/beans']" class="dashboard ion-no-margin no-border" tappable>
<ion-card-header class="ion-no-padding ion-no-margin">
<ion-card-title *ngIf='settings.freeze_coffee_beans === true'><ion-icon color='accent-secondary' style="top: 3px;position: relative;" name="thermometer-outline"></ion-icon> {{openBeansLeftOverCount()}}<br/><ion-icon color='accent-secondary' style="top: 3px;position: relative;" name="snow-outline"></ion-icon> {{openFrozenBeansLeftOverCount()}}</ion-card-title>
<ion-card-title *ngIf='settings.freeze_coffee_beans === false'> {{openBeansLeftOverCount()}}</ion-card-title>
<ion-card-title *ngIf='settings.freeze_coffee_beans === true'><ion-icon color='accent-secondary' style="top: 3px;position: relative;" name="thermometer-outline"></ion-icon> {{leftOverBeansWeight}}<br/><ion-icon color='accent-secondary' style="top: 3px;position: relative;" name="snow-outline"></ion-icon> {{leftOverFrozenBeansWeight}}</ion-card-title>
<ion-card-title *ngIf='settings.freeze_coffee_beans === false'> {{leftOverBeansWeight}}</ion-card-title>
<ion-card-subtitle>
{{"BEANS_WEIGHT_AVAILABLE" | translate}}
</ion-card-subtitle>
Expand Down
91 changes: 42 additions & 49 deletions src/app/dashboard/dashboard.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import { UIMillStorage } from '../../services/uiMillStorage';
})
export class DashboardPage implements OnInit {
public brews: Array<Brew> = [];
private leftOverBeansWeight: number = undefined;
private leftOverFrozenBeansWeight: number = undefined;
public leftOverBeansWeight: string = undefined;
public leftOverFrozenBeansWeight: string = undefined;
public getBeansCount: number = undefined;
public getBrewsDrunk: number = undefined;
public getTimePassedSinceLastBrew: string = undefined;
public getTimePassedSinceLastBrewMessage: string = undefined;
public settings: Settings;

constructor(
Expand All @@ -42,25 +46,19 @@ export class DashboardPage implements OnInit {

public ngOnInit() {
this.settings = this.uiSettingsStorage.getSettings();
this.uiBrewStorage.attachOnEvent().subscribe((_val) => {
this.reloadBrews();
});

this.uiBeanStorage.attachOnEvent().subscribe((_val) => {
this.reloadBrews();
});
this.uiPreparationStorage.attachOnEvent().subscribe((_val) => {
this.reloadBrews();
});
this.uiMillStorage.attachOnEvent().subscribe((_val) => {
this.reloadBrews();
});
}

private reloadBrews() {
// If an brew is deleted, we need to reset our array for the next call.
this.leftOverBeansWeight = undefined;
this.leftOverFrozenBeansWeight = undefined;
this.setOpenFrozenBeansLeftOverCount();
this.setOpenBeansLeftOverCount();
this.getBeansCount = this.uiStatistic.getBeansCount();
this.getBrewsDrunk = this.uiStatistic.getBrewsDrunk();
this.getTimePassedSinceLastBrew =
this.uiStatistic.getTimePassedSinceLastBrew();
this.getTimePassedSinceLastBrewMessage =
this.uiStatistic.getTimePassedSinceLastBrewMessage();

this.brews = [];
/**Short timeout needed, else the filter pipe is not working correctly**/
setTimeout(() => {
Expand Down Expand Up @@ -113,49 +111,44 @@ export class DashboardPage implements OnInit {
this.loadBrews();
}

public openBeansLeftOverCount(): string {
public setOpenBeansLeftOverCount() {
// #183
if (this.leftOverBeansWeight === undefined) {
let leftOverCount: number = 0;
const openBeans: Array<Bean> = this.uiBeanStorage
.getAllEntries()
.filter((bean) => !bean.finished && bean.isFrozen() === false);
for (const bean of openBeans) {
if (bean.weight > 0) {
leftOverCount += bean.weight - this.getUsedWeightCount(bean);
}
let leftOverCount: number = 0;
const openBeans: Array<Bean> = this.uiBeanStorage
.getAllEntries()
.filter((bean) => !bean.finished && bean.isFrozen() === false);
for (const bean of openBeans) {
if (bean.weight > 0) {
leftOverCount += bean.weight - this.getUsedWeightCount(bean);
}

this.leftOverBeansWeight = leftOverCount;
}
if (this.leftOverBeansWeight < 1000) {
return Math.round(this.leftOverBeansWeight * 100) / 100 + ' g';

if (leftOverCount < 1000) {
this.leftOverBeansWeight = Math.round(leftOverCount * 100) / 100 + ' g';
} else {
return Math.round((this.leftOverBeansWeight / 1000) * 100) / 100 + ' kg';
this.leftOverBeansWeight =
Math.round((leftOverCount / 1000) * 100) / 100 + ' kg';
}
}

public openFrozenBeansLeftOverCount(): string {
public setOpenFrozenBeansLeftOverCount() {
// #183
if (this.leftOverFrozenBeansWeight === undefined) {
let leftOverCount: number = 0;
const openBeans: Array<Bean> = this.uiBeanStorage
.getAllEntries()
.filter((bean) => !bean.finished && bean.isFrozen() === true);
for (const bean of openBeans) {
if (bean.weight > 0) {
leftOverCount += bean.weight - this.getUsedWeightCount(bean);
}
}

this.leftOverFrozenBeansWeight = leftOverCount;
let leftOverCount: number = 0;
const openBeans: Array<Bean> = this.uiBeanStorage
.getAllEntries()
.filter((bean) => !bean.finished && bean.isFrozen() === true);
for (const bean of openBeans) {
if (bean.weight > 0) {
leftOverCount += bean.weight - this.getUsedWeightCount(bean);
}
}
if (this.leftOverFrozenBeansWeight < 1000) {
return Math.round(this.leftOverFrozenBeansWeight * 100) / 100 + ' g';
if (leftOverCount < 1000) {
this.leftOverFrozenBeansWeight =
Math.round(leftOverCount * 100) / 100 + ' g';
} else {
return (
Math.round((this.leftOverFrozenBeansWeight / 1000) * 100) / 100 + ' kg'
);
this.leftOverFrozenBeansWeight =
Math.round((leftOverCount / 1000) * 100) / 100 + ' kg';
}
}

Expand Down

0 comments on commit f7125aa

Please sign in to comment.