Compare commits

...

2 Commits

Author SHA1 Message Date
Elias Jansson
465f9afc99 Bunch of fixes and session extensions
All checks were successful
continuous-integration/drone/push Build is passing
2025-06-10 18:59:04 +02:00
Elias Jansson
e3eb2dc7cb Budget page improvements
All checks were successful
continuous-integration/drone/push Build is passing
2025-06-09 16:11:59 +02:00
14 changed files with 407 additions and 109 deletions

View File

@@ -11,10 +11,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{423CD237-7404-4355-868F-CE5861835258}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{423CD237-7404-4355-868F-CE5861835258}.Debug|Any CPU.Build.0 = Debug|Any CPU
{423CD237-7404-4355-868F-CE5861835258}.Release|Any CPU.ActiveCfg = Release|Any CPU
{423CD237-7404-4355-868F-CE5861835258}.Release|Any CPU.Build.0 = Release|Any CPU
{F5586986-B726-4E05-B31B-2E24CA5B2B89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5586986-B726-4E05-B31B-2E24CA5B2B89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5586986-B726-4E05-B31B-2E24CA5B2B89}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@@ -99,7 +99,7 @@ namespace Aberwyn.Areas.Identity.Pages.Account
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false);
var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, isPersistent: true, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");

View File

@@ -20,21 +20,33 @@ namespace Aberwyn.Controllers
}
[HttpGet]
public IActionResult View(int id, bool edit = false)
public IActionResult View(int? id, bool edit = false)
{
var service = _menuService;
var meal = service.GetMealById(id);
Meal meal;
ViewData["IsEditing"] = edit; // → här
if (meal == null)
if (id.HasValue)
{
return NotFound();
meal = _menuService.GetMealById(id.Value);
if (meal == null)
return NotFound();
}
else
{
meal = new Meal
{
Name = "",
Description = "",
Ingredients = new List<Ingredient>(),
IsAvailable = true,
CreatedAt = DateTime.Now
};
}
ViewData["IsEditing"] = edit;
return View("View", meal);
}
[HttpGet]
[Route("Meal/Tooltip/{id}")]
public IActionResult Tooltip(int id)

View File

@@ -77,9 +77,7 @@ public class MenuService
}
public void SaveMeal(Meal meal)
public void SaveMeal2(Meal meal)
{
if (string.IsNullOrWhiteSpace(meal?.Name)) return;
@@ -104,7 +102,38 @@ public class MenuService
_context.SaveChanges();
}
public int GenerateMissingThumbnails()
public void SaveMeal(Meal meal)
{
if (string.IsNullOrWhiteSpace(meal?.Name)) return;
meal.Name = meal.Name.Trim();
meal.CreatedAt = meal.CreatedAt == default ? DateTime.Now : meal.CreatedAt;
if (meal.Id == 0)
{
// Ny måltid
_context.Meals.Add(meal);
}
else
{
// Uppdatera existerande utan tracking-krockar
var existing = _context.Meals
.Include(m => m.Ingredients)
.FirstOrDefault(m => m.Id == meal.Id);
if (existing != null)
{
_context.Entry(existing).CurrentValues.SetValues(meal);
// OBS: Ingredienser hanteras separat
}
}
_context.SaveChanges();
}
public int GenerateMissingThumbnails()
{
var updatedCount = 0;
var meals = _context.Meals
@@ -173,10 +202,17 @@ public int GenerateMissingThumbnails()
{
var existing = _context.Ingredients.Where(i => i.MealId == mealId);
_context.Ingredients.RemoveRange(existing);
foreach (var ing in ingredients)
{
ing.MealId = mealId;
}
_context.Ingredients.AddRange(ingredients);
_context.SaveChanges();
}
public List<Meal> GetMeals()
{
return _context.Meals.ToList();
@@ -216,6 +252,8 @@ public int GenerateMissingThumbnails()
public void SaveOrUpdateMealWithIngredients(Meal meal)
{
var isNew = meal.Id == 0;
SaveMeal(meal);
if (meal.Ingredients != null && meal.Ingredients.Count > 0)
@@ -224,6 +262,7 @@ public int GenerateMissingThumbnails()
}
}
public List<Meal> GetMealsByCategory(string category)
{
return _context.Meals

View File

@@ -60,31 +60,31 @@ public class WeeklyMenu
public string LunchMealName { get; set; }
public string DinnerMealName { get; set; }
}
public class Meal
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public class Meal
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; } // Behåll som obligatorisk
public string Name { get; set; } // Behåll som obligatorisk
public string? Description { get; set; }
public string? ProteinType { get; set; }
public string? Category { get; set; }
public string? CarbType { get; set; }
public string? RecipeUrl { get; set; }
public string? ImageUrl { get; set; }
public string? Description { get; set; }
public string? ProteinType { get; set; }
public string? Category { get; set; }
public string? CarbType { get; set; }
public string? RecipeUrl { get; set; }
public string? ImageUrl { get; set; }
public bool IsAvailable { get; set; }
public DateTime CreatedAt { get; set; }
public byte[]? ThumbnailData { get; set; }
public bool IsAvailable { get; set; }
public DateTime CreatedAt { get; set; }
public byte[]? ThumbnailData { get; set; }
public byte[]? ImageData { get; set; }
public string? ImageMimeType { get; set; }
public string? Instructions { get; set; }
public byte[]? ImageData { get; set; }
public string? ImageMimeType { get; set; }
public string? Instructions { get; set; }
public List<Ingredient> Ingredients { get; set; } = new();
}
public List<Ingredient> Ingredients { get; set; } = new();
}
public class Ingredient
{

View File

@@ -149,6 +149,9 @@ builder.Services.Configure<VapidOptions>(builder.Configuration.GetSection("Vapid
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Identity/Account/Login";
options.ExpireTimeSpan = TimeSpan.FromDays(30);
options.SlidingExpiration = true;
options.Cookie.IsEssential = true;
});
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@@ -244,6 +247,9 @@ if (setup.IsConfigured)
await IdentityDataInitializer.SeedData(services, setup);
}
}
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage(); // Detta ger stacktraces i browsern
}
app.Run();

View File

@@ -34,13 +34,57 @@
</div>
</div>
<div class="summary-cards" ng-if="budget && budget.categories.length > 0" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 24px 0;">
<div class="summary-card income">Totalt inkomst<br><strong>{{ getTotalIncome() | number:0 }}</strong></div>
<div class="summary-card expense">Total utgift<br><strong>({{ getTotalExpense() | number:0 }})</strong></div>
<div class="summary-card savings">Sparande<br><strong>{{ getTotalSaving() | number:0 }}</strong></div>
<div class="summary-card leftover">Pengar kvar<br><strong>{{ getLeftover() | number:0 }}</strong></div>
<div class="budget-overview-row" ng-if="budget && budget.categories.length > 0">
<!-- Vänster: Summering -->
<div class="budget-summary-box compact">
<h3>Sammanställning</h3>
<ul class="summary-list">
<li><span>💰 Inkomst:</span> {{ getTotalIncome() | number:0 }} kr</li>
<li><span>💸 Utgift:</span> {{ getTotalExpense() | number:0 }} kr</li>
<li><span>🏦 Sparande:</span> {{ getTotalSaving() | number:0 }} kr</li>
<p>
📈 Kvar:
<span class="highlight leftover" ng-class="{'plus': getLeftover() >= 0, 'minus': getLeftover() < 0}">
{{ getLeftover() | number:0 }} kr
</span>
</p>
</ul>
<hr>
<ul class="category-summary-list">
<li ng-repeat="cat in budget.categories">
<span style="color: {{ cat.color }}">{{ cat.name }}</span>
<span>{{ getCategorySum(cat) | number:0 }} kr</span>
</li>
</ul>
</div>
<!-- Höger: Diagramväxling -->
<div class="budget-chart-box compact">
<div class="chart-row">
<div class="chart-legend">
<h4>Utgifter</h4>
<p style="font-size: 12px; margin: 4px 0 10px;">
Totalt: <strong>{{ getTotalExpense() | number:0 }} kr</strong>
</p>
<p ng-if="topExpenseCategory" style="font-size: 12px; margin-bottom: 12px;">
Största kategori: <br>
<strong>{{ topExpenseCategory.name }}</strong> ({{ topExpenseCategory.percent | number:1 }}%)
</p>
</div>
<div class="chart-area">
<canvas id="expenseChart"></canvas>
</div>
</div>
</div>
</div>
<div class="budget-grid" ng-if="budget && budget.categories">
<div class="budget-card"
ng-repeat="cat in budget.categories"
@@ -185,6 +229,7 @@
</div>
<link rel="stylesheet" href="~/css/budget.css" />
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" />
<script src="~/js/budget.js"></script>

View File

@@ -143,8 +143,9 @@
</aside>
<datalist id="meals-list">
@foreach (var m in ViewBag.AvailableMeals as List<Aberwyn.Models.Meal>) {
<option value="@m.Name" />
@foreach (var meal in (List<Meal>)ViewBag.AvailableMeals)
{
<option value="@meal.Id">@meal.Name</option>
}
</datalist>
</form>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>Offline</title>
<style>
body { font-family: sans-serif; text-align: center; padding: 2rem; background: #1F2C3C; color: white; }
</style>
</head>
<body>
<h1>🌐 Du är offline</h1>
<p>LEWEL är inte tillgänglig just nu. Kontrollera din internetanslutning och försök igen.</p>
</body>
</html>

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Aberwyn.Views.Home
{
public class OfflineModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@@ -64,6 +64,10 @@
<label for="CarbType">Kolhydrat</label>
<input type="text" name="CarbType" value="@Model.CarbType" class="form-control" />
</div>
<div class="form-group">
<label for="Category">Kategori</label>
<input type="text" name="Category" value="@Model.Category" class="form-control" />
</div>
<div class="form-group">
<label for="RecipeUrl">Receptlänk</label>
@@ -79,7 +83,7 @@
<div class="form-group">
<label>Ingredienser</label>
<div id="ingredients-list">
@for (int i = 0; i < Model.Ingredients.Count; i++)
@for (int i = 0; i < (Model.Ingredients?.Count ?? 0); i++)
{
<div class="ingredient-row">
<input type="text" name="Ingredients[@i].Quantity" placeholder="Mängd" value="@Model.Ingredients[i].Quantity" class="form-control ingredient-qty" />
@@ -215,7 +219,7 @@
closeImageModal();
}
});
$(document).ready(function () {
$(document).ready(function () {
if ($('#Instructions').length > 0) {
$('#Instructions').trumbowyg({
autogrow: true,
@@ -223,35 +227,6 @@
});
}
});
if ('serviceWorker' in navigator && 'PushManager' in window) {
navigator.serviceWorker.register('/service-worker.js')
.then(function (registration) {
console.log('Service Worker registered', registration);
return registration.pushManager.getSubscription()
.then(async function (subscription) {
if (subscription) {
console.log('Already subscribed to push notifications.');
return subscription;
}
const response = await fetch('/api/push/vapid-public-key');
const vapidPublicKey = await response.text();
const convertedVapidKey = urlBase64ToUint8Array(vapidPublicKey);
return registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: convertedVapidKey
});
});
}).then(function (subscription) {
return fetch('/api/push/subscribe', {
method: 'POST',
body: JSON.stringify(subscription),
headers: {
'Content-Type': 'application/json'
}
});
});
}
</script>

View File

@@ -88,40 +88,7 @@ body {
background-color: #cbd5e1;
}
.summary-cards {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
margin: 16px 0 12px;
}
.summary-card {
background-color: var(--bg-card);
padding: 8px 10px;
border-radius: 10px;
text-align: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
font-weight: 600;
font-size: 13px;
min-width: 130px;
}
.summary-card.income {
border-top: 3px solid var(--card-income);
}
.summary-card.expense {
border-top: 3px solid var(--card-expense);
color: var(--card-expense);
}
.summary-card.savings {
border-top: 3px solid var(--card-savings);
}
.summary-card.leftover {
border-top: 3px solid var(--card-leftover);
}
.budget-grid {
display: grid;
@@ -535,3 +502,170 @@ color: var(--btn-check);
.suggestion-list li:hover {
background: #334155;
}
/* Summary */
.budget-overview-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin: 8px 0 16px;
}
.budget-summary-box,
.budget-chart-box {
flex: 1 1 250px;
background-color: var(--bg-card);
padding: 8px 12px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
min-width: 220px;
}
.budget-summary-box h3,
.budget-chart-box h3 {
margin: 0 0 6px;
font-size: 13px;
font-weight: 600;
color: var(--text-main);
}
.summary-list,
.category-summary-list {
list-style: none;
padding: 0;
margin: 0;
}
.summary-list li,
.category-summary-list li {
display: flex;
justify-content: space-between;
padding: 1px 0;
font-size: 12px;
font-weight: 500;
line-height: 1.4;
color: var(--text-main);
}
.summary-list li span:first-child {
font-weight: 600;
color: var(--text-sub);
}
.category-summary-list li {
border-top: 1px dashed var(--border-color);
padding: 3px 0;
font-size: 11.5px;
}
.highlight {
font-weight: 700;
}
.highlight.leftover.plus {
color: #15803d;
}
.highlight.leftover.minus {
color: #dc2626;
}
/* chart */
.chart-area {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.chart-legend h4 {
margin: 0 0 6px;
font-size: 13px;
font-weight: 600;
}
.chart-area {
flex: 1;
min-width: 200px;
max-width: 340px;
}
canvas {
max-width: 100%;
height: auto;
}
@media (min-width: 769px) {
.budget-overview-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
align-items: start;
}
.budget-chart-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 300px;
text-align: center;
}
.budget-chart-box .chart-row {
display: flex;
justify-content: center;
align-items: center;
}
.budget-chart-box .chart-area {
flex: 1;
max-width: 420px;
width: 100%;
}
.budget-chart-box canvas {
max-width: 100%;
height: auto;
}
}
@media (max-width: 768px) {
.budget-overview-row {
display: flex;
flex-direction: column;
gap: 12px;
}
.budget-summary-box,
.budget-chart-box {
width: 100%;
}
.chart-row {
flex-direction: column;
align-items: center;
}
.chart-area {
max-width: 100%;
}
.chart-legend {
width: 100%;
text-align: center;
padding-bottom: 10px;
}
.chart-area canvas {
max-width: 240px;
height: auto;
}
}

View File

@@ -5,6 +5,7 @@ app.controller('BudgetController', function ($scope, $http) {
$scope.loading = false;
$scope.error = null;
$scope.menuOpen = false;
$scope.chartMode = "pie";
const today = new Date();
$scope.selectedYear = today.getFullYear();
@@ -140,6 +141,7 @@ app.controller('BudgetController', function ($scope, $http) {
})
.finally(function () {
$scope.loading = false;
setTimeout($scope.drawCategoryChart, 0);
});
};
@@ -760,8 +762,70 @@ $scope.addItemFromDefinition = function (cat) {
});
};
$scope.isExpenseCategory = function (cat) {
return cat.items.some(i => i.isExpense);
};
$scope.drawCategoryChart = function () {
const ctx = document.getElementById("expenseChart");
if (!ctx || !$scope.budget?.categories) return;
const labels = [];
const data = [];
const colors = [];
$scope.budget.categories.forEach(cat => {
const sum = cat.items
.filter(i => i.isExpense)
.reduce((acc, i) => acc + i.amount, 0);
if (sum > 0) {
labels.push(cat.name);
data.push(sum);
colors.push(cat.color || "#94a3b8");
}
});
const total = data.reduce((a, b) => a + b, 0);
const topIndex = data.indexOf(Math.max(...data));
$scope.topExpenseCategory = topIndex !== -1 ? {
name: labels[topIndex],
value: data[topIndex],
percent: (data[topIndex] / total) * 100
} : null;
if (window.expenseChart && typeof window.expenseChart.destroy === 'function') {
window.expenseChart.destroy();
}
window.expenseChart = new Chart(ctx, {
type: 'pie',
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: colors
}]
},
options: {
responsive: true,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: ctx => `${ctx.label}: ${ctx.formattedValue} kr`
}
}
}
}
});
};
$scope.loadItemDefinitions().then(() => {
$scope.loadBudget();
});
});

View File

@@ -4,7 +4,7 @@
"start_url": "/",
"display": "standalone",
"background_color": "#1F2C3C",
"theme_color": "#6a0dad",
"theme_color": "#1F2C3C",
"icons": [
{
"src": "/images/lewel-icon.png",