Compare commits

..

18 Commits

Author SHA1 Message Date
tai
4b2041d2bf CSS fix for school
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-11 21:14:28 +01:00
tai
60c8f9b34e Skolmat update
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-11 21:01:45 +01:00
Elias Jansson
7b3c0998a0 Same same
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-11 19:56:31 +01:00
Elias Jansson
8da7888933 Merge branch 'master' of https://gitea.zcz.se/Tai/Aberwyn
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-11 19:43:46 +01:00
Elias Jansson
9e34e45748 Budget changes (payout date) 2026-02-11 19:26:20 +01:00
tai
f531bf54af CSS changes
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-03 12:47:30 +01:00
tai
b85d0d025d Padding
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-03 12:45:31 +01:00
tai
e4081cc078 Test
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-02 21:57:45 +01:00
Elias Jansson
d287367283 Securty
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 20:57:06 +01:00
Elias Jansson
37b5e96742 Deluge download folder again
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 20:52:32 +01:00
Elias Jansson
ae2a04e83b Deluge fix folder
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 20:46:59 +01:00
Elias Jansson
eeeadd0ff2 Updates to deluge
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 20:10:05 +01:00
Elias Jansson
9295dc2e98 Updated deluge again
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 19:49:26 +01:00
Elias Jansson
53fd6ed875 Test changes
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-27 19:21:39 +01:00
Elias Jansson
3e6366071f New docker compose
Some checks failed
continuous-integration/drone/push Build is failing
2026-01-27 19:13:50 +01:00
Elias Jansson
22dc00ee8b New drone
Some checks failed
continuous-integration/drone/push Build is failing
2026-01-27 19:11:56 +01:00
Elias Jansson
b75928e73d Yaml update
Some checks failed
continuous-integration/drone/push Build is failing
2026-01-27 19:08:51 +01:00
Elias Jansson
163ee7beea Deluge update
Some checks failed
continuous-integration/drone/push Build is failing
2026-01-27 19:02:17 +01:00
20 changed files with 238 additions and 61 deletions

View File

@@ -21,8 +21,8 @@ steps:
commands:
- export DOCKER_BUILDKIT=1
- docker buildx create --use --driver docker-container || true
- echo "$GITEA_TOKEN" | docker login 192.168.1.9:3000 -u "$GITEA_USERNAME" --password-stdin
- docker buildx build --builder default --tag 192.168.1.9:3000/tai/aberwyn/aberwyn:latest --tag 192.168.1.9:3000/tai/aberwyn/aberwyn:${DRONE_COMMIT_SHA:0:7} --cache-from=type=registry,ref=192.168.1.9:3000/tai/aberwyn/aberwyn:buildcache --push -f Aberwyn/Dockerfile .
- echo "$GITEA_TOKEN" | docker login gitea.zcz.se -u "$GITEA_USERNAME" --password-stdin
- docker buildx build --builder default --tag gitea.zcz.se/tai/aberwyn/aberwyn:latest --tag gitea.zcz.se/tai/aberwyn/aberwyn:${DRONE_COMMIT_SHA:0:7} --cache-from=type=registry,ref=gitea.zcz.se/tai/aberwyn/aberwyn:buildcache --push -f Aberwyn/Dockerfile .
- name: notify-result
image: alpine
@@ -34,7 +34,7 @@ steps:
- apk add --no-cache curl
- |
if [ "$DRONE_BUILD_STATUS" = "success" ]; then
curl -X POST http://192.168.1.196:8123/api/webhook/aberwyn_update_success
curl -X POST https://ha.zcz.se/api/webhook/aberwyn_update_success
else
curl -X POST http://192.168.1.196:8123/api/webhook/aberwyn_update_failed
curl -X POST https://ha.zcz.se/api/webhook/aberwyn_update_failed
fi

2
.gitignore vendored
View File

@@ -366,3 +366,5 @@ FodyWeavers.xsd
infrastructure/setup.json
Aberwyn/Infrastructure/setup.json
/Aberwyn/Data/infrastructure/setup2.json
/Aberwyn/Data/infrastructure/setup.json
/Aberwyn/Infrastructure/setup.json

View File

@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32616.157
# Visual Studio Version 18
VisualStudioVersion = 18.3.11426.168 d18.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aberwyn", "Aberwyn\Aberwyn.csproj", "{F5586986-B726-4E05-B31B-2E24CA5B2B89}"
EndProject

View File

@@ -11,8 +11,8 @@ steps:
- name: build-docker
image: plugins/docker
settings:
registry: 192.168.1.9:3000
repo: 192.168.1.9:3000/tai/aberwyn/aberwyn
registry: gitea.zcz.se
repo: gitea.zcz.se/tai/aberwyn/aberwyn
username:
from_secret: gitea_username
password:
@@ -33,9 +33,9 @@ steps:
- apk add --no-cache curl
- |
if [ "$DRONE_BUILD_STATUS" = "success" ]; then
curl -X POST http://192.168.1.196:8123/api/webhook/aberwyn_update_success
curl -X POST https://ha.zcz.se/api/webhook/aberwyn_update_success
else
curl -X POST http://192.168.1.196:8123/api/webhook/aberwyn_update_failed
curl -X POST https://ha.zcz.se/api/webhook/aberwyn_update_failed
fi
trigger:

View File

@@ -1,6 +1,8 @@
using Aberwyn.Models;
using Aberwyn.Data;
using Aberwyn.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Globalization;
namespace Aberwyn.Controllers
{
@@ -12,6 +14,9 @@ namespace Aberwyn.Controllers
{
ViewBag.Year = year;
ViewBag.Month = month;
DateTime payDate = SalaryDateService.GetSalaryPayDate(year, month -1);
ViewBag.Paydate = payDate.ToString("d MMMM", new CultureInfo("sv-SE"));
return View();
}
[Route("budget/list")]
@@ -20,6 +25,7 @@ namespace Aberwyn.Controllers
return View();
}
[Route("budget/{name}")]
public IActionResult Index(string name)
{
@@ -39,9 +45,19 @@ namespace Aberwyn.Controllers
public IActionResult Index()
{
var now = DateTime.Now;
return RedirectToAction("Index", new { year = now.Year, month = now.Month });
return RedirectToAction("Index", new { year = now.Year, month = now.Month + 1 });
}
[HttpGet("api/budget/{year:int}/{month:int}/salary-date")]
public IActionResult SalaryDate(int year, int month)
{
var date = SalaryDateService.GetSalaryPayDate(year, month);
return Ok(new
{
iso = date.ToString("yyyy-MM-dd"),
display = date.ToString("d MMMM yyyy", new CultureInfo("sv-SE"))
});
}
}
}

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Globalization;
using System.Net.Http.Headers;
using System.Text.Json;
@@ -111,11 +112,75 @@ namespace Aberwyn.Controllers
#region 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 client = new HttpClient();
client.BaseAddress = new Uri("http://192.168.1.196:8123/");
client.BaseAddress = new Uri("https://ha.zcz.se");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var res = await client.GetAsync($"/api/states/{sensor}");

View File

@@ -1,5 +1,6 @@
using Aberwyn.Data;
using BencodeNET.Torrents;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@@ -24,7 +25,7 @@ public class RssController : Controller
_movieMetadataService = movieMetadataService;
_context = context;
}
[Authorize(Roles = "Admin")]
[HttpGet]
public async Task<IActionResult> Index(int page = 1, string sort = "date", string range = "all")
{
@@ -105,13 +106,13 @@ public class RssController : Controller
}
[Authorize(Roles = "Admin")]
[HttpPost]
public async Task<IActionResult> Add(string torrentUrl)
{
try
{
if (await _deluge.LoginAsync("deluge1"))
if (await _deluge.LoginAsync("deluge1", "http://192.168.10.7:8112"))
{
var success = await _deluge.AddTorrentUrlAsync(torrentUrl);
@@ -159,12 +160,12 @@ public class RssController : Controller
catch (Exception ex)
{
_logger.LogError(ex, "Fel vid tillägg av torrent");
return Json(new { success = false, message = "Ett fel uppstod vid tillägg av torrent." });
return Json(new { success = false, message = "Ett fel uppstod vid tillägg av torrent. Meddelande: " + ex.Message });
}
}
[Authorize(Roles = "Admin")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(TorrentUploadViewModel model)
@@ -211,7 +212,7 @@ public class RssController : Controller
return View("Index", model);
}
}
[Authorize(Roles = "Admin")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> RefreshStats(string infoHash, string scrapeUrl)

View File

@@ -6,16 +6,15 @@ namespace Aberwyn.Data
public class DelugeClient
{
private readonly HttpClient _http;
private readonly string _url;
private string _sessionId;
public DelugeClient(HttpClient httpClient, string baseUrl = "http://192.168.10.7:8112/json")
private string _url;
//should fix settings password
public DelugeClient(HttpClient httpClient)
{
_http = httpClient;
_url = baseUrl;
}
public async Task<bool> LoginAsync(string password)
public async Task<bool> LoginAsync(string password, string url)
{
var payload = new
{
@@ -23,10 +22,10 @@ namespace Aberwyn.Data
@params = new object[] { password },
id = 1
};
_url = url + "/json";
var response = await _http.PostAsJsonAsync(_url, payload);
var json = await response.Content.ReadFromJsonAsync<JsonElement>();
// spara sessioncookie för framtida requests
if (response.Headers.TryGetValues("Set-Cookie", out var cookies))
{
@@ -38,6 +37,7 @@ namespace Aberwyn.Data
return json.GetProperty("result").GetBoolean();
}
/*
public async Task<bool> AddMagnetAsync(string magnetLink)
{
var payload = new
@@ -50,7 +50,8 @@ namespace Aberwyn.Data
var response = await _http.PostAsJsonAsync(_url, payload);
var json = await response.Content.ReadFromJsonAsync<JsonElement>();
return json.GetProperty("result").ValueKind != JsonValueKind.Null;
}
}*/
public async Task<bool> AddTorrentUrlAsync(string torrentUrl)
{
var payload = new
@@ -61,7 +62,7 @@ namespace Aberwyn.Data
torrentUrl,
new
{
download_location = "/download/incomplete",
download_location = "/downloads/Incomplete",
move_completed = true,
move_completed_path = "/media/Movies",
}

View File

@@ -0,0 +1,97 @@
using Aberwyn.Data;
namespace Aberwyn.Data
{
public class PayoutService
{
}
public static class SwedishHolidays
{
public static bool IsRedDay(DateTime date)
{
var year = date.Year;
var fixedHolidays = new[]
{
new DateTime(year, 1, 1), // Nyårsdagen
new DateTime(year, 1, 6), // Trettondedag jul
new DateTime(year, 5, 1), // Första maj
new DateTime(year, 6, 6), // Nationaldagen
new DateTime(year, 12, 25), // Juldagen
new DateTime(year, 12, 26), // Annandag jul
};
if (fixedHolidays.Contains(date.Date))
return true;
// Rörliga helgdagar
var easter = GetEasterSunday(year);
var movable = new[]
{
easter.AddDays(-2), // Långfredagen
easter, // Påskdagen
easter.AddDays(1), // Annandag påsk
easter.AddDays(39), // Kristi himmelsfärd
easter.AddDays(49), // Pingstdagen
GetMidsummerDay(year),
};
return movable.Contains(date.Date);
}
private static DateTime GetMidsummerDay(int year)
{
// Lördag mellan 2026 juni
for (int day = 20; day <= 26; day++)
{
var d = new DateTime(year, 6, day);
if (d.DayOfWeek == DayOfWeek.Saturday)
return d;
}
throw new Exception("Midsummer not found");
}
private static DateTime GetEasterSunday(int year)
{
// Meeus/Jones/Butcher
int a = year % 19;
int b = year / 100;
int c = year % 100;
int d = b / 4;
int e = b % 4;
int f = (b + 8) / 25;
int g = (b - f + 1) / 3;
int h = (19 * a + b - d - g + 15) % 30;
int i = c / 4;
int k = c % 4;
int l = (32 + 2 * e + 2 * i - h - k) % 7;
int m = (a + 11 * h + 22 * l) / 451;
int month = (h + l - 7 * m + 114) / 31;
int day = ((h + l - 7 * m + 114) % 31) + 1;
return new DateTime(year, month, day);
}
}
}
public static class SalaryDateService
{
public static DateTime GetSalaryPayDate(int year, int month)
{
var payDate = new DateTime(year, month, 25);
while (payDate.DayOfWeek == DayOfWeek.Saturday ||
payDate.DayOfWeek == DayOfWeek.Sunday ||
SwedishHolidays.IsRedDay(payDate))
{
payDate = payDate.AddDays(-1);
}
return payDate;
}
}

View File

@@ -1,11 +0,0 @@
{
"AdminUsername": "admin",
"AdminEmail": "admin@localhost",
"AdminPassword": "Admin123!",
"IsConfigured": true,
"DbHost": "192.168.1.108",
"DbPort": 3306,
"DbName": "lewel_prod",
"DbUser": "lewel",
"DbPassword": "W542.Hl;)%ta"
}

View File

@@ -2,7 +2,7 @@ version: '3.8'
services:
aberwyn-app:
image: 192.168.1.9:3000/tai/aberwyn/aberwyn:latest
image: gitea.zcz.se/tai/aberwyn/aberwyn:latest
container_name: aberwyn-app-prod
ports:
- "8080:80"

View File

@@ -1,11 +0,0 @@
{
"AdminUsername": "admin",
"AdminEmail": "admin@localhost",
"AdminPassword": "Admin123!",
"IsConfigured": true,
"DbHost": "192.168.1.108",
"DbPort": 3306,
"DbName": "lewel_prod",
"DbUser": "lewel",
"DbPassword": "W542.Hl;)%ta"
}

View File

@@ -27,7 +27,6 @@ namespace Aberwyn.Models
[JsonIgnore]
[ValidateNever]
public BudgetPeriod BudgetPeriod { get; set; }
public List<BudgetItem> Items { get; set; } = new();
}
@@ -127,4 +126,6 @@ namespace Aberwyn.Models
public string Color { get; set; } // standardfärg, kan modifieras per period
}
}

View File

@@ -1,6 +1,7 @@
@attribute [Authorize(Roles = "Budget")]
@using Microsoft.AspNetCore.Authorization
@{
ViewData["Title"] = "Budget";
}
@@ -51,6 +52,7 @@
<div class="budget-summary-box compact">
<h3>Sammanställning</h3>
<ul class="summary-list">
<li><span>Utbetalning:</span>{{ salaryPayDate || '' }}</li>
<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>

View File

@@ -79,8 +79,8 @@
<div class="card-container" ng-show="school.expanded">
<div class="meal-card" ng-repeat="day in school.days">
<div class="card-content school-meal-card-content">
<div class="day">{{ day.weekday }}</div>
<div class="meal" ng-repeat="meal in day.courses">{{ meal }}</div>
<div class="day">{{ day.Weekday }}</div>
<div class="meal" ng-repeat="meal in day.Courses">{{ meal }}</div>
</div>
</div>
</div>

View File

@@ -24,12 +24,14 @@ body {
font-family: 'Segoe UI', sans-serif;
font-size: 14px;
font-weight: 500;
}
.budget-page {
padding: 16px 24px;
margin-left: 0;
max-width: unset;
}
.budget-header {
@@ -63,6 +65,7 @@ body {
.menu-container {
position: relative;
}
.month-picker-dropdown select,
@@ -100,7 +103,6 @@ body {
grid-template-columns: repeat(auto-fit, minmax(220px, 300px));
gap: 10px;
align-items: stretch;
}

View File

@@ -307,7 +307,7 @@ h1 {
.school-meal-card-content .meal {
font-size: clamp(0.55rem, 1.0vw, 0.8rem);
line-height: 1.2;
line-height: 1.3;
text-align: center;
word-break: break-word;
overflow-y: auto;

View File

@@ -155,6 +155,7 @@ body {
position: relative;
z-index: 0;
overflow: visible !important;
}
.main-panel {
@@ -171,6 +172,7 @@ body {
font-size: 16px;
line-height: 1.7;
margin-top: 0;
padding: 5px 5px 0 5px;
position: static !important;
z-index: auto !important;
}
@@ -360,6 +362,7 @@ body {
.main-panel {
position: relative !important;
z-index: 1 !important;
padding: 0 5px 0 5px;
}
.main-nav {

View File

@@ -60,6 +60,15 @@ app.controller('BudgetController', function ($scope, $http) {
$scope.loadBudget();
};
$scope.loadSalaryDate = function () {
const year = $scope.selectedYear;
const month = $scope.selectedMonth -1;
$http.get(`/api/budget/${year}/${month}/salary-date`)
.then(function (res) {
$scope.salaryPayDate = res.data.display;
});
};
$scope.setItemType = function (item, type) {
if (type === 'expense') {
@@ -126,7 +135,6 @@ app.controller('BudgetController', function ($scope, $http) {
$scope.showToast = function (message, isError = false) {
const toast = document.createElement("div");
toast.className = "toast" + (isError ? " error" : "") + " show";
@@ -216,6 +224,7 @@ app.controller('BudgetController', function ($scope, $http) {
}
})
.finally(function () {
$scope.loadSalaryDate();
$scope.loading = false;
setTimeout($scope.drawCategoryChart, 0);
});

View File

@@ -51,9 +51,9 @@ angular.module('mealMenuApp', ['ngSanitize'])
$scope.schoolMealsBySchool = [];
$scope.schoolSensors = [
{ name: "William Engelbrektsskolan", entity: "sensor.engelbrektsskolan" },
{ name: "Louise - Nyeds skolan", entity: "sensor.nyedsskola" },
{ name: "Ludwig - Skogsgläntan", entity: "sensor.skogsglantan" }
{ name: "William Engelbrektsskolan", entity: "sensor.william_lunch" },
{ name: "Louise - Nyeds skolan", entity: "sensor.louise_lunch" },
{ name: "Ludwig - Skogsgläntan", entity: "sensor.ludwig_lunch" }
];
$scope.schoolMealsBySchool = [];