Skip to content

Commit

Permalink
#906 - Choose action to execute on NFC tag / QR-Code
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Feb 11, 2025
1 parent 0d9ce6d commit a448614
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ion-select-option value="{{BEAN_CODE_ACTION.START_BREW_CHOOSE_PREPARATION}}">{{"BEAN_CODE_ACTION.START_BREW_CHOOSE_PREPARATION" | translate}}</ion-select-option>
<ion-select-option value="{{BEAN_CODE_ACTION.DETAIL}}">{{"BEAN_CODE_ACTION.DETAIL" | translate}}</ion-select-option>
<ion-select-option value="{{BEAN_CODE_ACTION.EDIT}}">{{"BEAN_CODE_ACTION.EDIT" | translate}}</ion-select-option>
<ion-select-option value="{{BEAN_CODE_ACTION.CHOOSE_ACTION}}">{{"BEAN_CODE_ACTION.CHOOSE_ACTION" | translate}}</ion-select-option>
</ion-select>
</ion-item>

Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,8 @@
"START_BREW": "Start brew",
"START_BREW_CHOOSE_PREPARATION": "Start brew and choose preparation method",
"DETAIL": "Detail view",
"EDIT": "Edit bean"
"EDIT": "Edit bean",
"CHOOSE_ACTION": "Choose action on scan"
},
"DOWNLOAD_QR_CODE": "Download QR code",
"NFC": {
Expand Down Expand Up @@ -1420,5 +1421,6 @@
"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_SORT_RECENTLY_USED": "Last used"
"BEAN_SORT_RECENTLY_USED": "Last used",
"BEAN_CODE_ON_ACTION_SCANNED_TITLE": "Choose action"
}
1 change: 1 addition & 0 deletions src/enums/beans/beanCodeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export enum BEAN_CODE_ACTION {
START_BREW_CHOOSE_PREPARATION = 'START_BREW_CHOOSE_PREPARATION',
DETAIL = 'DETAIL',
EDIT = 'EDIT',
CHOOSE_ACTION = 'CHOOSE_ACTION',
}
9 changes: 8 additions & 1 deletion src/services/intentHandler/intent-handler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class IntentHandlerService {
const data = url.split('int/')[1].split('/');
const actionType = data[0];
const id = data[1];
const action = data[2];
let action = data[2];
try {
this.uiAnalytics.trackEvent(
IntentHandlerTracking.TITLE,
Expand All @@ -152,6 +152,13 @@ export class IntentHandlerService {
);
} catch (ex) {}
if (actionType === 'bean') {
if (
(action as BEAN_CODE_ACTION) === BEAN_CODE_ACTION.CHOOSE_ACTION
) {
//We overwrite action here :)
action = await this.uiBeanHelper.chooseNFCTagAction();
}

if ((action as BEAN_CODE_ACTION) === BEAN_CODE_ACTION.DETAIL) {
await this.uiBeanHelper.detailBeanByInternalShareCode(id);
} else if (
Expand Down
75 changes: 63 additions & 12 deletions src/services/uiBeanHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { Bean } from '../classes/bean/bean';
import BEAN_TRACKING from '../data/tracking/beanTracking';
import { BeansAddComponent } from '../app/beans/beans-add/beans-add.component';
import { UIAnalytics } from './uiAnalytics';
import { ModalController, Platform } from '@ionic/angular';
import {
ActionSheetController,
ModalController,
Platform,
} from '@ionic/angular';
import { BeanArchivePopoverComponent } from '../app/beans/bean-archive-popover/bean-archive-popover.component';
import { BeansEditComponent } from '../app/beans/beans-edit/beans-edit.component';
import { BeansDetailComponent } from '../app/beans/beans-detail/beans-detail.component';
Expand All @@ -31,6 +35,8 @@ import { BeanPopoverFreezeComponent } from '../app/beans/bean-popover-freeze/bea

import { BeanPopoverListComponent } from '../app/beans/bean-popover-list/bean-popover-list.component';
import { BeanInternalShareCodeGeneratorComponent } from '../app/beans/bean-internal-share-code-generator/bean-internal-share-code-generator.component';
import { BEAN_CODE_ACTION } from '../enums/beans/beanCodeAction';
import { TranslateService } from '@ngx-translate/core';

/**
* Handles every helping functionalities
Expand All @@ -52,7 +58,9 @@ export class UIBeanHelper {
private readonly uiAlert: UIAlert,
private readonly uiToast: UIToast,
private readonly uiSettingsStorage: UISettingsStorage,
private readonly uiHelper: UIHelper
private readonly uiHelper: UIHelper,
private readonly actionSheetCtrl: ActionSheetController,
private readonly translate: TranslateService,
) {
this.uiBrewStorage.attachOnEvent().subscribe((_val) => {
// If an brew is deleted, we need to reset our array for the next call.
Expand Down Expand Up @@ -109,7 +117,8 @@ export class UIBeanHelper {

const roastedBeans = this.allStoredBeans.filter(
(e) =>
e.bean_roast_information && e.bean_roast_information.bean_uuid === _uuid
e.bean_roast_information &&
e.bean_roast_information.bean_uuid === _uuid,
);
return roastedBeans;
}
Expand All @@ -123,7 +132,7 @@ export class UIBeanHelper {
const roastedBeans = this.allStoredBeans.filter(
(e) =>
e.bean_roast_information &&
e.bean_roast_information.roaster_machine === _uuid
e.bean_roast_information.roaster_machine === _uuid,
);
return roastedBeans;
}
Expand All @@ -145,7 +154,7 @@ export class UIBeanHelper {
if (_scannedQRBean.error === null) {
this.uiAnalytics.trackEvent(
QR_TRACKING.TITLE,
QR_TRACKING.ACTIONS.SCAN_SUCCESSFULLY
QR_TRACKING.ACTIONS.SCAN_SUCCESSFULLY,
);
this.uiToast.showInfoToast('QR.BEAN_SUCCESSFULLY_SCANNED');
await this.uiAlert.showLoadingSpinner();
Expand All @@ -169,28 +178,28 @@ export class UIBeanHelper {
'QR.SERVER.ERROR_OCCURED',
'ERROR_OCCURED',
undefined,
true
true,
);
}
} else {
this.uiAnalytics.trackEvent(
QR_TRACKING.TITLE,
QR_TRACKING.ACTIONS.SCAN_FAILED
QR_TRACKING.ACTIONS.SCAN_FAILED,
);
await this.uiAlert.hideLoadingSpinner();
if (_scannedQRBean.error.errorCode === 'beannotapproved') {
this.uiAlert.showMessage(
'QR.SERVER.BEAN_NOT_APPROVED',
'ERROR_OCCURED',
undefined,
true
true,
);
} else {
this.uiAlert.showMessage(
'QR.SERVER.ERROR_OCCURED',
'ERROR_OCCURED',
undefined,
true
true,
);
}
}
Expand Down Expand Up @@ -311,7 +320,7 @@ export class UIBeanHelper {
'USER_BEAN_SHARINGSHARING_ERROR',
'ERROR_OCCURED',
undefined,
true
true,
);
}
} catch (ex) {
Expand Down Expand Up @@ -353,7 +362,7 @@ export class UIBeanHelper {
private findBeanByInternalShareCode(internalShareCode: string) {
const allEntries = this.uiBeanStorage.getAllEntries();
const bean = allEntries.find(
(b) => b.internal_share_code === internalShareCode
(b) => b.internal_share_code === internalShareCode,
);
return bean;
}
Expand All @@ -363,6 +372,48 @@ export class UIBeanHelper {
await this.detailBean(bean);
}
}

public async chooseNFCTagAction() {
const actionSheet = await this.actionSheetCtrl.create({
header: this.translate.instant('BEAN_CODE_ON_ACTION_SCANNED_TITLE'),
buttons: [
{
text: this.translate.instant('BEAN_CODE_ACTION.START_BREW'),
data: {
action: BEAN_CODE_ACTION.DETAIL,
},
},
{
text: this.translate.instant(
'BEAN_CODE_ACTION.START_BREW_CHOOSE_PREPARATION',
),
data: {
action: BEAN_CODE_ACTION.START_BREW_CHOOSE_PREPARATION,
},
},
{
text: this.translate.instant('BEAN_CODE_ACTION.DETAIL'),
data: {
action: BEAN_CODE_ACTION.DETAIL,
},
},
{
text: this.translate.instant('BEAN_CODE_ACTION.EDIT'),
data: {
action: BEAN_CODE_ACTION.EDIT,
},
},
],
});

await actionSheet.present();

const data = await actionSheet.onWillDismiss();
if (data && data.data !== undefined) {
return data.data.action;
}
return undefined;
}
public async editBeanByInternalShareCode(internalShareCode: string) {
const bean = this.findBeanByInternalShareCode(internalShareCode);
if (bean) {
Expand All @@ -383,7 +434,7 @@ export class UIBeanHelper {
public async archiveBeanWithRatingQuestion(_bean: Bean) {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.ARCHIVE
BEAN_TRACKING.ACTIONS.ARCHIVE,
);

const modal = await this.modalController.create({
Expand Down

0 comments on commit a448614

Please sign in to comment.