Compare commits
3 Commits
8da7888933
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b2041d2bf | ||
|
|
60c8f9b34e | ||
|
|
7b3c0998a0 |
@@ -25,6 +25,7 @@ namespace Aberwyn.Controllers
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Route("budget/{name}")]
|
[Route("budget/{name}")]
|
||||||
public IActionResult Index(string name)
|
public IActionResult Index(string name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using System.Globalization;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@@ -112,6 +113,70 @@ namespace Aberwyn.Controllers
|
|||||||
#region Skolmat
|
#region Skolmat
|
||||||
[HttpGet("skolmat")]
|
[HttpGet("skolmat")]
|
||||||
public async Task<IActionResult> GetSkolmat(int week, [FromQuery] string sensor = "sensor.engelbrektsskolan")
|
public async Task<IActionResult> GetSkolmat(int week, [FromQuery] string sensor = "sensor.engelbrektsskolan")
|
||||||
|
{
|
||||||
|
var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3M2Q5ODIyYzU4ZWI0MjM4OWEyMGQ2MWQ2MWVhOWYzYyIsImlhdCI6MTc0OTE1MzY1MCwiZXhwIjoyMDY0NTEzNjUwfQ.8C_dKm7P1BbFVJKc_wT76YnQqiZxkP9EzrsLbfD0Ml8";
|
||||||
|
var client = new HttpClient();
|
||||||
|
client.BaseAddress = new Uri("https://ha.zcz.se");
|
||||||
|
client.DefaultRequestHeaders.Authorization =
|
||||||
|
new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
var res = await client.GetAsync($"/api/states/{sensor}");
|
||||||
|
|
||||||
|
if (!res.IsSuccessStatusCode)
|
||||||
|
return StatusCode((int)res.StatusCode, $"Kunde inte hämta data för {sensor}");
|
||||||
|
|
||||||
|
var json = await res.Content.ReadAsStringAsync();
|
||||||
|
using var doc = JsonDocument.Parse(json);
|
||||||
|
|
||||||
|
var attr = doc.RootElement.GetProperty("attributes");
|
||||||
|
|
||||||
|
if (!attr.TryGetProperty("calendar", out var calendar))
|
||||||
|
return NotFound("Ingen kalender hittades i attributen");
|
||||||
|
|
||||||
|
var result = new List<SchoolMealDto>();
|
||||||
|
var culture = CultureInfo.InvariantCulture;
|
||||||
|
var calendarSystem = culture.Calendar;
|
||||||
|
|
||||||
|
foreach (var property in calendar.EnumerateObject())
|
||||||
|
{
|
||||||
|
var dateString = property.Name; // t.ex 2026-02-09
|
||||||
|
if (!DateTime.TryParse(dateString, out var date))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int weekNumber = calendarSystem.GetWeekOfYear(
|
||||||
|
date,
|
||||||
|
CalendarWeekRule.FirstFourDayWeek,
|
||||||
|
DayOfWeek.Monday);
|
||||||
|
|
||||||
|
if (weekNumber != week)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var dishes = property.Value.EnumerateArray()
|
||||||
|
.Select(x => x.GetProperty("dish").GetString())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
result.Add(new SchoolMealDto
|
||||||
|
{
|
||||||
|
Weekday = date.ToString("dddd", new CultureInfo("sv-SE")),
|
||||||
|
Date = date.ToString("yyyy-MM-dd"),
|
||||||
|
Courses = dishes
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.Any())
|
||||||
|
return NotFound("Ingen skolmat för vecka " + week);
|
||||||
|
|
||||||
|
return Ok(result.OrderBy(x => x.Date));
|
||||||
|
}
|
||||||
|
public class SchoolMealDto
|
||||||
|
{
|
||||||
|
public string Weekday { get; set; }
|
||||||
|
public string Date { get; set; }
|
||||||
|
public List<string> Courses { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> GetSkolmatv0(int week, [FromQuery] string sensor = "sensor.engelbrektsskolan")
|
||||||
{
|
{
|
||||||
var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3M2Q5ODIyYzU4ZWI0MjM4OWEyMGQ2MWQ2MWVhOWYzYyIsImlhdCI6MTc0OTE1MzY1MCwiZXhwIjoyMDY0NTEzNjUwfQ.8C_dKm7P1BbFVJKc_wT76YnQqiZxkP9EzrsLbfD0Ml8";
|
var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3M2Q5ODIyYzU4ZWI0MjM4OWEyMGQ2MWQ2MWVhOWYzYyIsImlhdCI6MTc0OTE1MzY1MCwiZXhwIjoyMDY0NTEzNjUwfQ.8C_dKm7P1BbFVJKc_wT76YnQqiZxkP9EzrsLbfD0Ml8";
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace Aberwyn.Data
|
|||||||
throw new Exception("Midsummer not found");
|
throw new Exception("Midsummer not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static DateTime GetEasterSunday(int year)
|
private static DateTime GetEasterSunday(int year)
|
||||||
{
|
{
|
||||||
// Meeus/Jones/Butcher
|
// Meeus/Jones/Butcher
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace Aberwyn.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ValidateNever]
|
[ValidateNever]
|
||||||
public BudgetPeriod BudgetPeriod { get; set; }
|
public BudgetPeriod BudgetPeriod { get; set; }
|
||||||
|
|
||||||
public List<BudgetItem> Items { get; set; } = new();
|
public List<BudgetItem> Items { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@attribute [Authorize(Roles = "Budget")]
|
@attribute [Authorize(Roles = "Budget")]
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Budget";
|
ViewData["Title"] = "Budget";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,8 @@
|
|||||||
<div class="card-container" ng-show="school.expanded">
|
<div class="card-container" ng-show="school.expanded">
|
||||||
<div class="meal-card" ng-repeat="day in school.days">
|
<div class="meal-card" ng-repeat="day in school.days">
|
||||||
<div class="card-content school-meal-card-content">
|
<div class="card-content school-meal-card-content">
|
||||||
<div class="day">{{ day.weekday }}</div>
|
<div class="day">{{ day.Weekday }}</div>
|
||||||
<div class="meal" ng-repeat="meal in day.courses">{{ meal }}</div>
|
<div class="meal" ng-repeat="meal in day.Courses">{{ meal }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ h1 {
|
|||||||
|
|
||||||
.school-meal-card-content .meal {
|
.school-meal-card-content .meal {
|
||||||
font-size: clamp(0.55rem, 1.0vw, 0.8rem);
|
font-size: clamp(0.55rem, 1.0vw, 0.8rem);
|
||||||
line-height: 1.2;
|
line-height: 1.3;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ app.controller('BudgetController', function ($scope, $http) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.showToast = function (message, isError = false) {
|
$scope.showToast = function (message, isError = false) {
|
||||||
const toast = document.createElement("div");
|
const toast = document.createElement("div");
|
||||||
toast.className = "toast" + (isError ? " error" : "") + " show";
|
toast.className = "toast" + (isError ? " error" : "") + " show";
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ angular.module('mealMenuApp', ['ngSanitize'])
|
|||||||
$scope.schoolMealsBySchool = [];
|
$scope.schoolMealsBySchool = [];
|
||||||
|
|
||||||
$scope.schoolSensors = [
|
$scope.schoolSensors = [
|
||||||
{ name: "William – Engelbrektsskolan", entity: "sensor.engelbrektsskolan" },
|
{ name: "William – Engelbrektsskolan", entity: "sensor.william_lunch" },
|
||||||
{ name: "Louise - Nyeds skolan", entity: "sensor.nyedsskola" },
|
{ name: "Louise - Nyeds skolan", entity: "sensor.louise_lunch" },
|
||||||
{ name: "Ludwig - Skogsgläntan", entity: "sensor.skogsglantan" }
|
{ name: "Ludwig - Skogsgläntan", entity: "sensor.ludwig_lunch" }
|
||||||
];
|
];
|
||||||
|
|
||||||
$scope.schoolMealsBySchool = [];
|
$scope.schoolMealsBySchool = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user