mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
support fraction display
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
<td style="width: 1%; text-wrap: nowrap" class="pa-0">
|
<td style="width: 1%; text-wrap: nowrap" class="pa-0">
|
||||||
<v-checkbox-btn v-model="i.checked" color="success" v-if="!i.isHeader"></v-checkbox-btn>
|
<v-checkbox-btn v-model="i.checked" color="success" v-if="!i.isHeader"></v-checkbox-btn>
|
||||||
</td>
|
</td>
|
||||||
<td style="width: 1%; text-wrap: nowrap" class="pr-1">{{ i.amount * props.ingredientFactor }}</td>
|
<td style="width: 1%; text-wrap: nowrap" class="pr-1" v-html="calculateFoodAmount(i.amount, props.ingredientFactor, useUserPreferenceStore().userSettings.useFractions)"></td>
|
||||||
<td style="width: 1%; text-wrap: nowrap" class="pr-1">
|
<td style="width: 1%; text-wrap: nowrap" class="pr-1">
|
||||||
<template v-if="i.unit"> {{ i.unit.name }}</template>
|
<template v-if="i.unit"> {{ i.unit.name }}</template>
|
||||||
</td>
|
</td>
|
||||||
@@ -59,6 +59,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {Ingredient} from "@/openapi";
|
import {Ingredient} from "@/openapi";
|
||||||
import {computed} from "vue";
|
import {computed} from "vue";
|
||||||
|
import {calculateFoodAmount} from "../../utils/number_utils";
|
||||||
|
import {useUserPreferenceStore} from "../../stores/UserPreferenceStore";
|
||||||
|
|
||||||
const ingredients = defineModel<Ingredient[]>({required: true})
|
const ingredients = defineModel<Ingredient[]>({required: true})
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
|
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
number: Number,
|
number: Number,
|
||||||
factor: {
|
factor: {
|
||||||
@@ -22,6 +24,6 @@ import {calculateFoodAmount} from "@/utils/number_utils.ts";
|
|||||||
* @return {number | string}
|
* @return {number | string}
|
||||||
*/
|
*/
|
||||||
function calculateAmount(x) {
|
function calculateAmount(x) {
|
||||||
return calculateFoodAmount(x, props.factor) // TODO reactive bind props
|
return calculateFoodAmount(x, props.factor, useUserPreferenceStore().userSettings.useFractions)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
function getUserPreference(pref: string) {
|
|
||||||
return false // TODO only placeholder, add real function
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* round to the number of decimals specified in user preferences
|
* round to the number of decimals specified in user preferences
|
||||||
* @param num number to round
|
* @param num number to round
|
||||||
@@ -16,9 +11,10 @@ export function roundDecimals(num: number) {
|
|||||||
* calculates the amount of food, based on the factor and converts it to a fraction if that is the users preference
|
* calculates the amount of food, based on the factor and converts it to a fraction if that is the users preference
|
||||||
* @param amount food amount to calculate based upon
|
* @param amount food amount to calculate based upon
|
||||||
* @param factor factor to scale food amount by
|
* @param factor factor to scale food amount by
|
||||||
|
* @param useFractions if the returned value should be a fraction or not
|
||||||
*/
|
*/
|
||||||
export function calculateFoodAmount(amount: number, factor: number) {
|
export function calculateFoodAmount(amount: number, factor: number, useFractions: boolean = false) {
|
||||||
if (getUserPreference("use_fractions")) {
|
if (useFractions) {
|
||||||
let return_string = ""
|
let return_string = ""
|
||||||
let fraction = frac(amount * factor, 16, true)
|
let fraction = frac(amount * factor, 16, true)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user