This commit is contained in:
@@ -44,7 +44,54 @@ angular.module('mealMenuApp', ['ngSanitize'])
|
||||
});
|
||||
|
||||
}).catch(err => console.error("Fel vid hämtning av meny:", err));
|
||||
$scope.loadSchoolMeals(); // Lägg till här
|
||||
|
||||
};
|
||||
$scope.schoolMeals = [];
|
||||
$scope.schoolMealsBySchool = [];
|
||||
|
||||
$scope.schoolSensors = [
|
||||
{ name: "William – Engelbrektsskolan", entity: "sensor.engelbrektsskolan" },
|
||||
{ name: "Louise - Nyeds skolan", entity: "sensor.nyedsskola" },
|
||||
{ name: "Ludwig - Skogsgläntan", entity: "sensor.skogsglantan" }
|
||||
];
|
||||
|
||||
$scope.schoolMealsBySchool = [];
|
||||
|
||||
$scope.loadSchoolMeals = function () {
|
||||
const savedExpanded = JSON.parse(localStorage.getItem("expandedSchools") || "{}");
|
||||
|
||||
$scope.schoolMealsBySchool = $scope.schoolSensors.map(sensor => ({
|
||||
name: sensor.name,
|
||||
entity: sensor.entity,
|
||||
days: [],
|
||||
expanded: savedExpanded[sensor.entity] || false
|
||||
}));
|
||||
|
||||
$scope.schoolMealsBySchool.forEach(school => {
|
||||
$http.get(`/api/mealmenuapi/skolmat?week=${$scope.selectedWeek}&sensor=${school.entity}`)
|
||||
.then(res => {
|
||||
school.days = res.data;
|
||||
})
|
||||
.catch(() => {
|
||||
school.days = [];
|
||||
});
|
||||
});
|
||||
};
|
||||
$scope.toggleSchoolExpanded = function (school) {
|
||||
school.expanded = !school.expanded;
|
||||
|
||||
const expandedState = {};
|
||||
$scope.schoolMealsBySchool.forEach(s => {
|
||||
expandedState[s.entity] = s.expanded;
|
||||
});
|
||||
|
||||
localStorage.setItem("expandedSchools", JSON.stringify(expandedState));
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$scope.openMeal = function (mealId) {
|
||||
if (!mealId) return;
|
||||
|
||||
Reference in New Issue
Block a user