Show purchased date

This commit is contained in:
jableader 2024-05-21 09:57:49 +10:00
parent 313e4dd5be
commit 626500efb1
4 changed files with 25 additions and 5 deletions

View file

@ -31,7 +31,7 @@
<h2>Sides & Additional Ingredients</h2> <h2>Sides & Additional Ingredients</h2>
<editable-ingredients-panel :ingredients="meal.extra_ingredients" @on-add="addIngredient" @on-delete="deleteIngredient" @on-update-ingredient="updateIngredient" /> <editable-ingredients-panel :ingredients="meal.extra_ingredients" @on-add="addIngredient" @on-delete="deleteIngredient" @on-update-ingredient="updateIngredient" />
</div> </div>
<button @click="saveMeal">Save</button> <button @click="saveMeal" v-if="!meal.purchase_date">Save</button>
</div> </div>
</template> </template>

View file

@ -39,6 +39,9 @@
</span> </span>
<span v-if="!meal.consumers.length">somebody?</span> <span v-if="!meal.consumers.length">somebody?</span>
</p> </p>
<p v-if="meal.purchase_date">
Purchased {{ formatDate(meal.purchase_date) }}
</p>
</div> </div>
</template> </template>
@ -67,6 +70,25 @@ export default {
default: default:
return ', '; return ', ';
} }
},
formatDate(datetime) {
// If its less than a week, use "2 minutes ago" style
const diff = new Date() - datetime;
if (diff < 1000 * 60 * 60 * 24 * 7) {
const minutes = Math.floor(diff / 1000 / 60);
if (minutes < 60) {
return `${minutes} minute${minutes === 1 ? '' : 's'} ago`;
}
const hours = Math.floor(minutes / 60);
if (hours < 24) {
return `${hours} hour${hours === 1 ? '' : 's'} ago`;
}
const days = Math.floor(hours / 24);
return `${days} day${days === 1 ? '' : 's'} ago`;
}
// Otherwise, use a date format with the day of week prepended
return `${datetime.toLocaleDateString('en-au', { weekday: 'long' })} ${datetime.toLocaleDateString('en-au', { month: 'numeric', day: 'numeric' })}`;
} }
} }
} }

View file

@ -54,8 +54,6 @@ input[type="checkbox"]:checked + label {
} }
input[type="checkbox"]:disabled + label { input[type="checkbox"]:disabled + label {
background-color: rgba(255, 255, 255, 0.5);
color: #ccc;
cursor: not-allowed; cursor: not-allowed;
} }

View file

@ -1,7 +1,7 @@
const BASE_URL = window.location.href.replace(/^(http:\/\/[^/:]+).*/, "$1:8000") const BASE_URL = window.location.href.replace(/^(http:\/\/[^/:]+).*/, "$1:8000")
const datesToFix = { const datesToFix = {
Meal: { fields: [ "meal_date" ] }, Meal: { fields: [ "meal_date", "purchase_date" ] },
ShoppingList: { fields: [ "created_date", "purchased_date" ], dependants: l => ({ ShoppingListResult: l.results, ShoppingListRequest: l.requests }) }, ShoppingList: { fields: [ "created_date", "purchased_date" ], dependants: l => ({ ShoppingListResult: l.results, ShoppingListRequest: l.requests }) },
ShoppingListResult: { fields: [ "found_date", "created_date" ], }, ShoppingListResult: { fields: [ "found_date", "created_date" ], },
ShoppingListRequest: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) }, ShoppingListRequest: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },