<commit_before>﻿var firstRender = true;

var firstDay = null;
if (!Grocy.CalendarFirstDayOfWeek.isEmpty())
{
	firstDay = parseInt(Grocy.CalendarFirstDayOfWeek);
}

var calendar = $("#calendar").fullCalendar({
	"themeSystem": "bootstrap4",
	"header": {
		"left": "title",
		"center": "",
		"right": "prev,today,next"
	},
	"weekNumbers": false,
	"eventLimit": true,
	"eventSources": fullcalendarEventSources,
	"defaultView": ($(window).width() < 768) ? "basicDay" : "basicWeek",
	"firstDay": firstDay,
	"viewRender": function(view)
	{
		if (firstRender)
		{
			firstRender = false
		}
		else
		{
			UpdateUriParam("week", view.start.format("YYYY-MM-DD"));
		}

		$(".fc-day-header").append('<a class="ml-1 btn btn-outline-dark btn-xs my-1 add-recipe-button" href="#"><i class="fas fa-plus"></i></a>');

		var weekRecipeName = view.start.year().toString() + "-" + (view.start.week() - 1).toString();
		var weekRecipe = FindObjectInArrayByPropertyValue(internalRecipes, "name", weekRecipeName);

		var weekCosts = 0;
		var weekRecipeOrderMissingButtonHtml = "";
		var weekRecipeConsumeButtonHtml = "";
		if (weekRecipe !== null)
		{
			weekCosts = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).costs;

			var weekRecipeOrderMissingButtonDisabledClasses = "";
			if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled_with_shopping_list == 1)
			{
				weekRecipeOrderMissingButtonDisabledClasses = "disabled";
			}
			var weekRecipeConsumeButtonDisabledClasses = "";
			if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled == 0)
			{
				weekRecipeConsumeButtonDisabledClasses = "disabled";
			}
			weekRecipeOrderMissingButtonHtml = '<a class="ml-1 btn btn-outline-primary btn-xs recipe-order-missing-button ' + weekRecipeOrderMissingButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Put missing products on shopping list") + '" data-recipe-id="' + weekRecipe.id.toString() + '" data-recipe-name="' + weekRecipe.name + '" data-recipe-type="' + weekRecipe.type + '"><i class="fas fa-cart-plus"></i></a>'
			weekRecipeConsumeButtonHtml = '<a class="ml-1 btn btn-outline-success btn-xs recipe-consume-button ' + weekRecipeConsumeButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Consume all ingredients needed by this recipe") + '" data-recipe-id="' + weekRecipe.id.toString() + '" data-recipe-name="' + weekRecipe.name + '" data-recipe-type="' + weekRecipe.type + '"><i class="fas fa-utensils"></i></a>'
		}
		$(".fc-header-toolbar .fc-center").html("<h4>" + __t("Week costs") + ': <span class="locale-number locale-number-currency">' + weekCosts.toString() + "</span> " + weekRecipeOrderMissingButtonHtml + weekRecipeConsumeButtonHtml + "</h4>");
	},
	"eventRender": function(event, element)
	{
		var recipe = JSON.parse(event.recipe);
		if (recipe === null || recipe === undefined)
		{
			return false;
		}

		var mealPlanEntry = JSON.parse(event.mealPlanEntry);
		var resolvedRecipe = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", recipe.id);

		element.removeClass("fc-event");
		element.addClass("text-center");

		element.attr("data-recipe", event.recipe);
		element.attr("data-meal-plan-entry", event.mealPlanEntry);

		var recipeOrderMissingButtonDisabledClasses = "";
		if (resolvedRecipe.need_fulfilled_with_shopping_list == 1)
		{
			recipeOrderMissingButtonDisabledClasses = "disabled";
		}

		var recipeConsumeButtonDisabledClasses = "";
		if (resolvedRecipe.need_fulfilled == 0)
		{
			recipeConsumeButtonDisabledClasses = "disabled";
		}

		var fulfillmentInfoHtml = __t('Enough in stock');
		var fulfillmentIconHtml = '<i class="fas fa-check text-success"></i>';
		if (resolvedRecipe.need_fulfilled != 1)
		{
			fulfillmentInfoHtml = __t('Not enough in stock');
			var fulfillmentIconHtml = '<i class="fas fa-times text-danger"></i>';
		}

		element.html(' \
			<div> \
				<h5 class="text-truncate">' + recipe.name + '<h5> \
				<h5 class="small text-truncate">' + __n(mealPlanEntry.servings, "%s serving", "%s servings") + '</h5> \
				<h5 class="small timeago-contextual text-truncate">' + fulfillmentIconHtml + " " + fulfillmentInfoHtml + '</h5> \
				<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + resolvedRecipe.costs + '</span> ' + __t('per serving') + '<h5> \
				<h5> \
					<a class="ml-1 btn btn-outline-danger btn-xs remove-recipe-button" href="#"><i class="fas fa-trash"></i></a> \
					<a class="ml-1 btn btn-outline-primary btn-xs recipe-order-missing-button ' + recipeOrderMissingButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Put missing products on shopping list") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-cart-plus"></i></a> \
					<a class="ml-1 btn btn-outline-success btn-xs recipe-consume-button ' + recipeConsumeButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Consume all ingredients needed by this recipe") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-utensils"></i></a> \
					<a class="ml-1 btn btn-outline-secondary btn-xs recipe-popup-button" href="#" data-toggle="tooltip" title="' + __t("Display recipe") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-eye"></i></a> \
				</h5> \
			</div>');

		if (recipe.picture_file_name && !recipe.picture_file_name.isEmpty())
		{<commit_msg>Check for Price Tracking in mealplan.js (#469)<commit_after>﻿var firstRender = true;

var firstDay = null;
if (!Grocy.CalendarFirstDayOfWeek.isEmpty())
{
	firstDay = parseInt(Grocy.CalendarFirstDayOfWeek);
}

var calendar = $("#calendar").fullCalendar({
	"themeSystem": "bootstrap4",
	"header": {
		"left": "title",
		"center": "",
		"right": "prev,today,next"
	},
	"weekNumbers": false,
	"eventLimit": true,
	"eventSources": fullcalendarEventSources,
	"defaultView": ($(window).width() < 768) ? "basicDay" : "basicWeek",
	"firstDay": firstDay,
	"viewRender": function(view)
	{
		if (firstRender)
		{
			firstRender = false
		}
		else
		{
			UpdateUriParam("week", view.start.format("YYYY-MM-DD"));
		}

		$(".fc-day-header").append('<a class="ml-1 btn btn-outline-dark btn-xs my-1 add-recipe-button" href="#"><i class="fas fa-plus"></i></a>');

		var weekRecipeName = view.start.year().toString() + "-" + (view.start.week() - 1).toString();
		var weekRecipe = FindObjectInArrayByPropertyValue(internalRecipes, "name", weekRecipeName);

		var weekCosts = 0;
		var weekRecipeOrderMissingButtonHtml = "";
		var weekRecipeConsumeButtonHtml = "";
		if (weekRecipe !== null)
		{
			var weekCostsHtml = "";
			if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
			{
				weekCosts = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).costs;
				weekCostsHtml = __t("Week costs") + ': <span class="locale-number locale-number-currency">' + weekCosts.toString() + "</span> ";
			}

			var weekRecipeOrderMissingButtonDisabledClasses = "";
			if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled_with_shopping_list == 1)
			{
				weekRecipeOrderMissingButtonDisabledClasses = "disabled";
			}
			var weekRecipeConsumeButtonDisabledClasses = "";
			if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled == 0)
			{
				weekRecipeConsumeButtonDisabledClasses = "disabled";
			}
			weekRecipeOrderMissingButtonHtml = '<a class="ml-1 btn btn-outline-primary btn-xs recipe-order-missing-button ' + weekRecipeOrderMissingButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Put missing products on shopping list") + '" data-recipe-id="' + weekRecipe.id.toString() + '" data-recipe-name="' + weekRecipe.name + '" data-recipe-type="' + weekRecipe.type + '"><i class="fas fa-cart-plus"></i></a>'
			weekRecipeConsumeButtonHtml = '<a class="ml-1 btn btn-outline-success btn-xs recipe-consume-button ' + weekRecipeConsumeButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Consume all ingredients needed by this recipe") + '" data-recipe-id="' + weekRecipe.id.toString() + '" data-recipe-name="' + weekRecipe.name + '" data-recipe-type="' + weekRecipe.type + '"><i class="fas fa-utensils"></i></a>'
		}
		$(".fc-header-toolbar .fc-center").html("<h4>" + weekCostsHtml + weekRecipeOrderMissingButtonHtml + weekRecipeConsumeButtonHtml + "</h4>");
	},
	"eventRender": function(event, element)
	{
		var recipe = JSON.parse(event.recipe);
		if (recipe === null || recipe === undefined)
		{
			return false;
		}

		var mealPlanEntry = JSON.parse(event.mealPlanEntry);
		var resolvedRecipe = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", recipe.id);

		element.removeClass("fc-event");
		element.addClass("text-center");

		element.attr("data-recipe", event.recipe);
		element.attr("data-meal-plan-entry", event.mealPlanEntry);

		var recipeOrderMissingButtonDisabledClasses = "";
		if (resolvedRecipe.need_fulfilled_with_shopping_list == 1)
		{
			recipeOrderMissingButtonDisabledClasses = "disabled";
		}

		var recipeConsumeButtonDisabledClasses = "";
		if (resolvedRecipe.need_fulfilled == 0)
		{
			recipeConsumeButtonDisabledClasses = "disabled";
		}

		var fulfillmentInfoHtml = __t('Enough in stock');
		var fulfillmentIconHtml = '<i class="fas fa-check text-success"></i>';
		if (resolvedRecipe.need_fulfilled != 1)
		{
			fulfillmentInfoHtml = __t('Not enough in stock');
			var fulfillmentIconHtml = '<i class="fas fa-times text-danger"></i>';
		}
		var costPerServing = ""
		if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
		{
			costPerServing = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + resolvedRecipe.costs + '</span> ' + __t('per serving') + '<h5>';
		}

		element.html(' \
			<div> \
				<h5 class="text-truncate">' + recipe.name + '<h5> \
				<h5 class="small text-truncate">' + __n(mealPlanEntry.servings, "%s serving", "%s servings") + '</h5> \
				<h5 class="small timeago-contextual text-truncate">' + fulfillmentIconHtml + " " + fulfillmentInfoHtml + '</h5> \
				' + costPerServing + ' \
				<h5> \
					<a class="ml-1 btn btn-outline-danger btn-xs remove-recipe-button" href="#"><i class="fas fa-trash"></i></a> \
					<a class="ml-1 btn btn-outline-primary btn-xs recipe-order-missing-button ' + recipeOrderMissingButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Put missing products on shopping list") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-cart-plus"></i></a> \
					<a class="ml-1 btn btn-outline-success btn-xs recipe-consume-button ' + recipeConsumeButtonDisabledClasses + '" href="#" data-toggle="tooltip" title="' + __t("Consume all ingredients needed by this recipe") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-utensils"></i></a> \
					<a class="ml-1 btn btn-outline-secondary btn-xs recipe-popup-button" href="#" data-toggle="tooltip" title="' + __t("Display recipe") + '" data-recipe-id="' + recipe.id.toString() + '" data-recipe-name="' + recipe.name + '" data-recipe-type="' + recipe.type + '"><i class="fas fa-eye"></i></a> \
				</h5> \
			</div>');

		if (recipe.picture_file_name && !recipe.picture_file_name.isEmpty())
		{
{'fraction_non_alphanumeric': 0.17870852170946003, 'fraction_numerical': 0.0055446558048281155, 'mean_word_length': 4.798219584569733, 'pattern_counts': {'":': 24, '<': 105, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1276859', 'n_tokens_mistral': 4246, 'n_tokens_neox': 3873, 'n_words': 706}