Compare commits
3 Commits
130d791e1b
...
57bea7b54c
| Author | SHA1 | Date | |
|---|---|---|---|
| 57bea7b54c | |||
|
|
465f9afc99 | ||
|
|
e3eb2dc7cb |
@@ -11,10 +11,6 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
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.ActiveCfg = Debug|Any CPU
|
||||||
{F5586986-B726-4E05-B31B-2E24CA5B2B89}.Debug|Any CPU.Build.0 = 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
|
{F5586986-B726-4E05-B31B-2E24CA5B2B89}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace Aberwyn.Areas.Identity.Pages.Account
|
|||||||
{
|
{
|
||||||
// This doesn't count login failures towards account lockout
|
// This doesn't count login failures towards account lockout
|
||||||
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
// 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)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("User logged in.");
|
_logger.LogInformation("User logged in.");
|
||||||
|
|||||||
@@ -24,21 +24,33 @@ namespace Aberwyn.Controllers
|
|||||||
return View("Index");
|
return View("Index");
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult View(int id, bool edit = false)
|
public IActionResult View(int? id, bool edit = false)
|
||||||
{
|
{
|
||||||
var service = _menuService;
|
Meal meal;
|
||||||
var meal = service.GetMealById(id);
|
|
||||||
|
|
||||||
ViewData["IsEditing"] = edit; // → här
|
if (id.HasValue)
|
||||||
|
|
||||||
if (meal == null)
|
|
||||||
{
|
{
|
||||||
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);
|
return View("View", meal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("Meal/Tooltip/{id}")]
|
[Route("Meal/Tooltip/{id}")]
|
||||||
public IActionResult Tooltip(int id)
|
public IActionResult Tooltip(int id)
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ namespace Aberwyn.Controllers
|
|||||||
_pizzaNotifier = pizzaNotifier;
|
_pizzaNotifier = pizzaNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("notify-pizza")]
|
[HttpPost("notify-pizza")]
|
||||||
public async Task<IActionResult> NotifyPizza()
|
public async Task<IActionResult> NotifyPizza()
|
||||||
{
|
{
|
||||||
var count = await _pizzaNotifier.NotifyPizzaSubscribersAsync("Capricciosa", User.Identity.Name);
|
var count = await _pizzaNotifier.NotifyPizzaSubscribersAsync("Capricciosa", User.Identity.Name);
|
||||||
|
|
||||||
return Ok(new { message = $"Skickade pizzanotiser till {count} användare." });
|
return Ok(new { message = $"Skickade pizzanotiser till {count} användare." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost("subscribe")]
|
[HttpPost("subscribe")]
|
||||||
|
|||||||
@@ -77,9 +77,7 @@ public class MenuService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SaveMeal2(Meal meal)
|
||||||
|
|
||||||
public void SaveMeal(Meal meal)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(meal?.Name)) return;
|
if (string.IsNullOrWhiteSpace(meal?.Name)) return;
|
||||||
|
|
||||||
@@ -104,7 +102,38 @@ public class MenuService
|
|||||||
_context.SaveChanges();
|
_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 updatedCount = 0;
|
||||||
var meals = _context.Meals
|
var meals = _context.Meals
|
||||||
@@ -199,10 +228,17 @@ public List<Meal> GetMealsSlim(bool includeThumbnail = false)
|
|||||||
{
|
{
|
||||||
var existing = _context.Ingredients.Where(i => i.MealId == mealId);
|
var existing = _context.Ingredients.Where(i => i.MealId == mealId);
|
||||||
_context.Ingredients.RemoveRange(existing);
|
_context.Ingredients.RemoveRange(existing);
|
||||||
|
|
||||||
|
foreach (var ing in ingredients)
|
||||||
|
{
|
||||||
|
ing.MealId = mealId;
|
||||||
|
}
|
||||||
|
|
||||||
_context.Ingredients.AddRange(ingredients);
|
_context.Ingredients.AddRange(ingredients);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Meal> GetMeals()
|
public List<Meal> GetMeals()
|
||||||
{
|
{
|
||||||
return _context.Meals.ToList();
|
return _context.Meals.ToList();
|
||||||
@@ -242,6 +278,8 @@ public List<Meal> GetMealsSlim(bool includeThumbnail = false)
|
|||||||
|
|
||||||
public void SaveOrUpdateMealWithIngredients(Meal meal)
|
public void SaveOrUpdateMealWithIngredients(Meal meal)
|
||||||
{
|
{
|
||||||
|
var isNew = meal.Id == 0;
|
||||||
|
|
||||||
SaveMeal(meal);
|
SaveMeal(meal);
|
||||||
|
|
||||||
if (meal.Ingredients != null && meal.Ingredients.Count > 0)
|
if (meal.Ingredients != null && meal.Ingredients.Count > 0)
|
||||||
@@ -250,6 +288,7 @@ public List<Meal> GetMealsSlim(bool includeThumbnail = false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Meal> GetMealsByCategory(string category)
|
public List<Meal> GetMealsByCategory(string category)
|
||||||
{
|
{
|
||||||
return _context.Meals
|
return _context.Meals
|
||||||
|
|||||||
@@ -60,31 +60,31 @@ public class WeeklyMenu
|
|||||||
public string LunchMealName { get; set; }
|
public string LunchMealName { get; set; }
|
||||||
public string DinnerMealName { get; set; }
|
public string DinnerMealName { get; set; }
|
||||||
}
|
}
|
||||||
public class Meal
|
public class Meal
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public int Id { get; set; }
|
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? Description { get; set; }
|
||||||
public string? ProteinType { get; set; }
|
public string? ProteinType { get; set; }
|
||||||
public string? Category { get; set; }
|
public string? Category { get; set; }
|
||||||
public string? CarbType { get; set; }
|
public string? CarbType { get; set; }
|
||||||
public string? RecipeUrl { get; set; }
|
public string? RecipeUrl { get; set; }
|
||||||
public string? ImageUrl { get; set; }
|
public string? ImageUrl { get; set; }
|
||||||
|
|
||||||
public bool IsAvailable { get; set; }
|
public bool IsAvailable { get; set; }
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
public byte[]? ThumbnailData { get; set; }
|
public byte[]? ThumbnailData { get; set; }
|
||||||
|
|
||||||
public byte[]? ImageData { get; set; }
|
public byte[]? ImageData { get; set; }
|
||||||
public string? ImageMimeType { get; set; }
|
public string? ImageMimeType { get; set; }
|
||||||
public string? Instructions { get; set; }
|
public string? Instructions { get; set; }
|
||||||
|
|
||||||
public List<Ingredient> Ingredients { get; set; } = new();
|
public List<Ingredient> Ingredients { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Ingredient
|
public class Ingredient
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ builder.Services.Configure<VapidOptions>(builder.Configuration.GetSection("Vapid
|
|||||||
builder.Services.ConfigureApplicationCookie(options =>
|
builder.Services.ConfigureApplicationCookie(options =>
|
||||||
{
|
{
|
||||||
options.LoginPath = "/Identity/Account/Login";
|
options.LoginPath = "/Identity/Account/Login";
|
||||||
|
options.ExpireTimeSpan = TimeSpan.FromDays(30);
|
||||||
|
options.SlidingExpiration = true;
|
||||||
|
options.Cookie.IsEssential = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
@@ -244,6 +247,9 @@ if (setup.IsConfigured)
|
|||||||
await IdentityDataInitializer.SeedData(services, setup);
|
await IdentityDataInitializer.SeedData(services, setup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage(); // Detta ger stacktraces i browsern
|
||||||
|
}
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -34,13 +34,57 @@
|
|||||||
</div>
|
</div>
|
||||||
</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="budget-overview-row" ng-if="budget && budget.categories.length > 0">
|
||||||
<div class="summary-card income">Totalt inkomst<br><strong>{{ getTotalIncome() | number:0 }}</strong></div>
|
<!-- Vänster: Summering -->
|
||||||
<div class="summary-card expense">Total utgift<br><strong>({{ getTotalExpense() | number:0 }})</strong></div>
|
<div class="budget-summary-box compact">
|
||||||
<div class="summary-card savings">Sparande<br><strong>{{ getTotalSaving() | number:0 }}</strong></div>
|
<h3>Sammanställning</h3>
|
||||||
<div class="summary-card leftover">Pengar kvar<br><strong>{{ getLeftover() | number:0 }}</strong></div>
|
<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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="budget-grid" ng-if="budget && budget.categories">
|
<div class="budget-grid" ng-if="budget && budget.categories">
|
||||||
<div class="budget-card"
|
<div class="budget-card"
|
||||||
ng-repeat="cat in budget.categories"
|
ng-repeat="cat in budget.categories"
|
||||||
@@ -185,6 +229,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<link rel="stylesheet" href="~/css/budget.css" />
|
<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>
|
<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" />
|
<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>
|
<script src="~/js/budget.js"></script>
|
||||||
|
|||||||
@@ -143,8 +143,9 @@
|
|||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<datalist id="meals-list">
|
<datalist id="meals-list">
|
||||||
@foreach (var m in ViewBag.AvailableMeals as List<Aberwyn.Models.Meal>) {
|
@foreach (var meal in (List<Meal>)ViewBag.AvailableMeals)
|
||||||
<option value="@m.Name" />
|
{
|
||||||
|
<option value="@meal.Id">@meal.Name</option>
|
||||||
}
|
}
|
||||||
</datalist>
|
</datalist>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
14
Aberwyn/Views/Home/Offline.cshtml
Normal file
14
Aberwyn/Views/Home/Offline.cshtml
Normal 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>
|
||||||
12
Aberwyn/Views/Home/Offline.cshtml.cs
Normal file
12
Aberwyn/Views/Home/Offline.cshtml.cs
Normal 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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,6 +64,10 @@
|
|||||||
<label for="CarbType">Kolhydrat</label>
|
<label for="CarbType">Kolhydrat</label>
|
||||||
<input type="text" name="CarbType" value="@Model.CarbType" class="form-control" />
|
<input type="text" name="CarbType" value="@Model.CarbType" class="form-control" />
|
||||||
</div>
|
</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">
|
<div class="form-group">
|
||||||
<label for="RecipeUrl">Receptlänk</label>
|
<label for="RecipeUrl">Receptlänk</label>
|
||||||
@@ -79,7 +83,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Ingredienser</label>
|
<label>Ingredienser</label>
|
||||||
<div id="ingredients-list">
|
<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">
|
<div class="ingredient-row">
|
||||||
<input type="text" name="Ingredients[@i].Quantity" placeholder="Mängd" value="@Model.Ingredients[i].Quantity" class="form-control ingredient-qty" />
|
<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();
|
closeImageModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
if ($('#Instructions').length > 0) {
|
if ($('#Instructions').length > 0) {
|
||||||
$('#Instructions').trumbowyg({
|
$('#Instructions').trumbowyg({
|
||||||
autogrow: true,
|
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -88,40 +88,7 @@ body {
|
|||||||
background-color: #cbd5e1;
|
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 {
|
.budget-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -535,3 +502,170 @@ color: var(--btn-check);
|
|||||||
.suggestion-list li:hover {
|
.suggestion-list li:hover {
|
||||||
background: #334155;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ app.controller('BudgetController', function ($scope, $http) {
|
|||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.error = null;
|
$scope.error = null;
|
||||||
$scope.menuOpen = false;
|
$scope.menuOpen = false;
|
||||||
|
$scope.chartMode = "pie";
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
$scope.selectedYear = today.getFullYear();
|
$scope.selectedYear = today.getFullYear();
|
||||||
@@ -140,6 +141,7 @@ app.controller('BudgetController', function ($scope, $http) {
|
|||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
$scope.loading = false;
|
$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.loadItemDefinitions().then(() => {
|
||||||
$scope.loadBudget();
|
$scope.loadBudget();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"start_url": "/",
|
"start_url": "/",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"background_color": "#1F2C3C",
|
"background_color": "#1F2C3C",
|
||||||
"theme_color": "#6a0dad",
|
"theme_color": "#1F2C3C",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/images/lewel-icon.png",
|
"src": "/images/lewel-icon.png",
|
||||||
|
|||||||
Reference in New Issue
Block a user