Budget, admin och lite css
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,81 +1,352 @@
|
||||
/* Budget Container */
|
||||
.budget-container {
|
||||
:root {
|
||||
--text-main: #1E293B;
|
||||
--text-sub: #64748B;
|
||||
--bg-main: #f9fafb;
|
||||
--bg-card: #f1f5f9;
|
||||
--border-color: #e5e7eb;
|
||||
--card-income: #f97316;
|
||||
--card-expense: #ef4444;
|
||||
--card-savings: #facc15;
|
||||
--card-leftover: #86efac;
|
||||
--btn-edit: #3b82f6;
|
||||
--btn-check: #10b981;
|
||||
--btn-delete: #ef4444;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg-main);
|
||||
color: var(--text-main);
|
||||
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 {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px; /* Reduced gap for tighter layout */
|
||||
padding: 0; /* Removed padding */
|
||||
margin: 0; /* Removed margin */
|
||||
gap: 12px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
/* Category Block */
|
||||
.category-block {
|
||||
flex: 1 1 300px;
|
||||
max-width: 230px;
|
||||
min-width: 180px;
|
||||
margin: 0; /* Removed margin */
|
||||
}
|
||||
|
||||
.category-header {
|
||||
display: flex;
|
||||
justify-content: space-between; /* Aligns the category name and total */
|
||||
align-items: center; /* Center vertically */
|
||||
padding: 5px; /* Retain padding */
|
||||
background-color: #4A6572; /* Muted blue-gray */
|
||||
color: #ffffff;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
max-width: 100%; /* Ensures the header doesn't exceed the width of its container */
|
||||
box-sizing: border-box; /* Include padding in width calculation */
|
||||
}
|
||||
|
||||
.total {
|
||||
font-weight: bold;
|
||||
color: #ffffff; /* White for visibility */
|
||||
background-color: rgba(74, 101, 114, 0.7); /* Semi-transparent muted blue-gray */
|
||||
padding: 5px 10px; /* Add some padding for spacing */
|
||||
border-radius: 5px; /* Rounded corners */
|
||||
}
|
||||
|
||||
/* Items Layout */
|
||||
.items-wrapper {
|
||||
display: flex;
|
||||
min-width: 200px;
|
||||
flex-direction: column;
|
||||
padding: 0; /* Removed padding */
|
||||
margin: 0; /* Removed margin */
|
||||
}
|
||||
|
||||
/* Item Styles */
|
||||
.item {
|
||||
.month-nav-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 5px; /* Space between items */
|
||||
gap: 5px; /* Reduced gap between item components */
|
||||
gap: 6px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Input Styles */
|
||||
.item-name input {
|
||||
flex: 1; /* Compact size for amount field */
|
||||
max-width: 20ch; /* Allow up to 7 characters */
|
||||
padding: 6px; /* Slightly reduced padding */
|
||||
.month-label {
|
||||
padding: 4px 10px;
|
||||
background-color: #e2e8f0;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
min-width: 90px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.menu-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.month-picker-dropdown select,
|
||||
.month-picker-dropdown input {
|
||||
font-size: 13px;
|
||||
padding: 5px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-color);
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.nav-button {
|
||||
background-color: #e2e8f0;
|
||||
color: var(--text-main);
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||
background-color: #f9f9f9;
|
||||
transition: background-color 0.3s;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
transition: background 0.2s;
|
||||
font-size: 16px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.item-amount input {
|
||||
flex: 1; /* Compact size for amount field */
|
||||
max-width: 7ch; /* Allow up to 7 characters */
|
||||
padding: 6px; /* Slightly reduced padding */
|
||||
.nav-button:hover {
|
||||
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;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.budget-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 350px;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
overflow-y: visible;
|
||||
}
|
||||
|
||||
.item-list {
|
||||
flex: 1 1 auto;
|
||||
overflow-y: auto;
|
||||
padding: 8px 12px;
|
||||
background: rgba(255, 0, 0, 0.05); /* tillfällig bakgrund för felsökning */
|
||||
}
|
||||
|
||||
|
||||
|
||||
.card-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 3; /* högre än total-row */
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 12px;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.card-header.income {
|
||||
background-color: var(--card-income);
|
||||
}
|
||||
|
||||
.card-header.expense {
|
||||
background-color: var(--card-expense);
|
||||
}
|
||||
|
||||
.card-header.savings {
|
||||
background-color: var(--card-savings);
|
||||
}
|
||||
|
||||
.card-header.leftover {
|
||||
background-color: var(--card-leftover);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.item-row input[type="text"],
|
||||
.item-row input[type="number"] {
|
||||
flex: 1;
|
||||
padding: 5px 6px;
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
background-color: #ffffff;
|
||||
color: var(--text-main);
|
||||
font-weight: 500;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.amount {
|
||||
min-width: 70px;
|
||||
text-align: right;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.total-row {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
padding: 8px 12px;
|
||||
font-weight: bold;
|
||||
font-size: 13px;
|
||||
background: var(--bg-card);
|
||||
border-top: 1px solid var(--border-color);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.icon-button {
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||
background-color: #f9f9f9;
|
||||
transition: background-color 0.3s;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
padding: 4px;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
/* Focus Effect */
|
||||
.item-name input:focus
|
||||
.icon-button:hover {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.icon-button.danger {
|
||||
color: var(--btn-delete);
|
||||
}
|
||||
|
||||
.icon-button.danger:hover {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.icon-button.edit {
|
||||
color: var(--btn-edit);
|
||||
}
|
||||
|
||||
.icon-button.confirm {
|
||||
color: var(--btn-check);
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: calc(100% + 6px);
|
||||
background-color: #ffffff;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
||||
z-index: 1000;
|
||||
padding: 6px;
|
||||
display: none;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.menu-container.open .dropdown-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.dropdown-menu button {
|
||||
padding: 5px 8px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #ddd;
|
||||
background: #f3f4f6;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.dropdown-menu button:hover {
|
||||
background-color: #e5e7eb;
|
||||
}
|
||||
|
||||
.no-data {
|
||||
text-align: center;
|
||||
padding: 16px;
|
||||
font-size: 14px;
|
||||
color: var(--text-sub);
|
||||
border: 1px dashed var(--border-color);
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
margin-top: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
background: #10B981;
|
||||
color: white;
|
||||
padding: 10px 16px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
transition: opacity 0.3s, transform 0.3s;
|
||||
z-index: 9999;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
background: #ef4444;
|
||||
}
|
||||
|
||||
|
||||
/* === Dropzones === */
|
||||
|
||||
.drop-placeholder {
|
||||
height: 12px;
|
||||
transition: background-color 0.2s ease;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.drop-placeholder.drag-over {
|
||||
border-top: 3px solid #3B82F6; /* blå rand */
|
||||
background-color: rgba(59, 130, 246, 0.15); /* ljusblå fyllning */
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
|
||||
/* Gör att man ser var man kan släppa */
|
||||
.drop-zone.active-drop-target {
|
||||
background-color: rgba(34, 197, 94, 0.15); /* svagt grön basfärg */
|
||||
}
|
||||
|
||||
.drop-zone.drag-over {
|
||||
border: 2px dashed #16a34a; /* grön */
|
||||
background-color: rgba(22, 163, 74, 0.1);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
--text: #2D3748;
|
||||
--accent: #3182CE;
|
||||
--card-bg: #ffffff;
|
||||
--border-radius: 10px;
|
||||
--spacing: 20px;
|
||||
--font-size: 1rem;
|
||||
--border-radius: 6px;
|
||||
--spacing: 12px;
|
||||
--font-size: 0.9rem;
|
||||
--faint-text: #718096;
|
||||
--subtle-text: #4A5568;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ body {
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: var(--spacing);
|
||||
text-align: center;
|
||||
color: var(--accent);
|
||||
@@ -56,7 +56,7 @@ h1 {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: var(--spacing);
|
||||
font-size: var(--font-size);
|
||||
color: var(--subtle-text);
|
||||
@@ -65,12 +65,13 @@ h1 {
|
||||
.date-picker button {
|
||||
background: var(--accent);
|
||||
border: none;
|
||||
padding: 0.5rem 1rem;
|
||||
padding: 0.3rem 0.8rem;
|
||||
border-radius: var(--border-radius);
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
transition: background 0.2s ease;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.date-picker button:hover {
|
||||
@@ -83,7 +84,7 @@ h1 {
|
||||
right: var(--spacing);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.view-selector select {
|
||||
@@ -95,8 +96,8 @@ h1 {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text);
|
||||
font-size: 1.2rem;
|
||||
padding: 6px;
|
||||
font-size: 1rem;
|
||||
padding: 4px;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.2s;
|
||||
@@ -109,23 +110,26 @@ h1 {
|
||||
|
||||
.list-view .day-item {
|
||||
background: var(--card-bg);
|
||||
margin-bottom: var(--spacing);
|
||||
padding: var(--spacing);
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
border-radius: var(--border-radius);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
font-size: 1.4rem;
|
||||
font-size: 1.1rem;
|
||||
color: var(--accent);
|
||||
margin-bottom: 8px;
|
||||
margin-bottom: 4px;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.day-header::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -4px;
|
||||
left: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 40px;
|
||||
height: 3px;
|
||||
background: var(--accent);
|
||||
@@ -133,8 +137,8 @@ h1 {
|
||||
}
|
||||
|
||||
.meal-selection {
|
||||
margin: 6px 0;
|
||||
font-size: 1rem;
|
||||
margin: 2px 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.meal-selection a {
|
||||
@@ -149,28 +153,38 @@ h1 {
|
||||
.not-assigned {
|
||||
color: var(--faint-text);
|
||||
font-style: italic;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.card-view .card-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: var(--spacing);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.meal-card {
|
||||
position: relative;
|
||||
height: 200px;
|
||||
height: 160px;
|
||||
width: 100%;
|
||||
color: #fff;
|
||||
max-height: 200px;
|
||||
background-color: #4A5568; /* fallback-bakgrund */
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
border-radius: var(--border-radius);
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s ease;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.meal-card:hover {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.meal-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -187,18 +201,30 @@ h1 {
|
||||
|
||||
.card-content {
|
||||
position: relative;
|
||||
padding: 12px;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
padding: 12px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.card-content .day {
|
||||
font-size: 1.2rem;
|
||||
font-size: 1rem;
|
||||
font-weight: bold;
|
||||
margin-bottom: 6px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.card-content .meal {
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.2;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.3;
|
||||
margin-bottom: 2px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
231
Aberwyn/wwwroot/js/budget-dragdrop.js
Normal file
231
Aberwyn/wwwroot/js/budget-dragdrop.js
Normal file
@@ -0,0 +1,231 @@
|
||||
// Drag & Drop directives for Budget Page
|
||||
|
||||
app.directive('draggableItem', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
item: '=',
|
||||
category: '=',
|
||||
onItemDrop: '&'
|
||||
},
|
||||
link: function (scope, element) {
|
||||
function isEditing() {
|
||||
return scope.category && scope.category.editing;
|
||||
}
|
||||
|
||||
function updateDraggableAttr() {
|
||||
element[0].setAttribute('draggable', isEditing() ? 'true' : 'false');
|
||||
element[0].classList.toggle('draggable-enabled', isEditing());
|
||||
}
|
||||
|
||||
updateDraggableAttr();
|
||||
scope.$watch('category.editing', updateDraggableAttr);
|
||||
|
||||
element[0].addEventListener('dragstart', function (e) {
|
||||
if (!isEditing()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
e.dataTransfer.setData('text/plain', JSON.stringify({
|
||||
type: 'item',
|
||||
fromCategoryId: scope.category.id,
|
||||
itemId: scope.item.id
|
||||
}));
|
||||
|
||||
const ghost = element[0].cloneNode(true);
|
||||
ghost.style.position = 'absolute';
|
||||
ghost.style.top = '-9999px';
|
||||
ghost.style.left = '-9999px';
|
||||
ghost.style.width = element[0].offsetWidth + 'px';
|
||||
ghost.style.opacity = '0.7';
|
||||
document.body.appendChild(ghost);
|
||||
e.dataTransfer.setDragImage(ghost, 0, 0);
|
||||
|
||||
setTimeout(() => document.body.removeChild(ghost), 0);
|
||||
|
||||
document.querySelectorAll('.drop-zone').forEach(el => el.classList.add('active-drop-target'));
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragend', function () {
|
||||
document.querySelectorAll('.drop-zone').forEach(el => el.classList.remove('active-drop-target'));
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.directive('dropPlaceholder', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
category: '=',
|
||||
index: '=',
|
||||
onDropItem: '&'
|
||||
},
|
||||
link: function (scope, element) {
|
||||
function isEditing() {
|
||||
return scope.category && scope.category.editing;
|
||||
}
|
||||
|
||||
element.addClass('drop-zone');
|
||||
element.addClass('drop-placeholder');
|
||||
|
||||
const label = document.createElement('div');
|
||||
label.innerText = 'DROP HERE';
|
||||
label.style.textAlign = 'center';
|
||||
label.style.fontSize = '12px';
|
||||
label.style.color = '#166534';
|
||||
label.style.display = 'none';
|
||||
element[0].appendChild(label);
|
||||
|
||||
element[0].addEventListener('dragover', function (e) {
|
||||
if (!isEditing()) return;
|
||||
const rawData = e.dataTransfer.getData('text/plain');
|
||||
if (!rawData.includes('"type":"item"')) return;
|
||||
|
||||
e.preventDefault();
|
||||
element[0].classList.add('drag-over');
|
||||
label.style.display = 'block';
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragleave', function () {
|
||||
element[0].classList.remove('drag-over');
|
||||
label.style.display = 'none';
|
||||
});
|
||||
|
||||
element[0].addEventListener('drop', function (e) {
|
||||
if (!isEditing()) return;
|
||||
e.preventDefault();
|
||||
element[0].classList.remove('drag-over');
|
||||
label.style.display = 'none';
|
||||
|
||||
const dataText = e.dataTransfer.getData('text/plain');
|
||||
try {
|
||||
const data = JSON.parse(dataText);
|
||||
if (data.type !== 'item') return;
|
||||
|
||||
scope.$apply(() => {
|
||||
scope.onDropItem({
|
||||
data: data,
|
||||
targetCategory: scope.category,
|
||||
targetIndex: scope.index
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error parsing drop data:", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.directive('dropFallback', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
category: '=',
|
||||
onDropItem: '&'
|
||||
},
|
||||
link: function (scope, element) {
|
||||
element.addClass('drop-zone');
|
||||
|
||||
const label = document.createElement('div');
|
||||
label.innerText = 'DROP HERE';
|
||||
label.style.textAlign = 'center';
|
||||
label.style.fontSize = '12px';
|
||||
label.style.color = '#166534';
|
||||
label.style.display = 'none';
|
||||
element[0].appendChild(label);
|
||||
|
||||
element[0].addEventListener('dragover', function (e) {
|
||||
const data = e.dataTransfer.getData('text/plain');
|
||||
if (!data.includes('"type":"item"')) return;
|
||||
e.preventDefault();
|
||||
element[0].classList.add('drag-over');
|
||||
label.style.display = 'block';
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragleave', function () {
|
||||
element[0].classList.remove('drag-over');
|
||||
label.style.display = 'none';
|
||||
});
|
||||
|
||||
element[0].addEventListener('drop', function (e) {
|
||||
e.preventDefault();
|
||||
element[0].classList.remove('drag-over');
|
||||
label.style.display = 'none';
|
||||
|
||||
const data = JSON.parse(e.dataTransfer.getData('text/plain'));
|
||||
if (data.type !== 'item') return;
|
||||
|
||||
scope.$apply(() => {
|
||||
scope.onDropItem({
|
||||
data: data,
|
||||
targetCategory: scope.category,
|
||||
targetIndex: scope.category.items.length
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.directive('draggableCategory', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
category: '=',
|
||||
onCategoryDrop: '&'
|
||||
},
|
||||
link: function (scope, element) {
|
||||
const header = element[0].querySelector('.card-header');
|
||||
if (!header) return;
|
||||
|
||||
function updateDraggableAttr() {
|
||||
header.setAttribute('draggable', scope.category.allowDrag ? 'true' : 'false');
|
||||
}
|
||||
|
||||
scope.$watch('category.allowDrag', updateDraggableAttr);
|
||||
updateDraggableAttr();
|
||||
|
||||
header.addEventListener('dragstart', function (e) {
|
||||
if (!scope.category.allowDrag) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
e.dataTransfer.setData('text/plain', JSON.stringify({
|
||||
type: 'category',
|
||||
categoryId: scope.category.id
|
||||
}));
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
element[0].addEventListener('drop', function (e) {
|
||||
e.preventDefault();
|
||||
element[0].classList.remove('drag-over');
|
||||
const data = JSON.parse(e.dataTransfer.getData('text/plain'));
|
||||
if (data.type !== 'category') return;
|
||||
|
||||
scope.$apply(() => {
|
||||
scope.onCategoryDrop({
|
||||
data: data,
|
||||
targetCategory: scope.category
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragenter', function (e) {
|
||||
e.preventDefault();
|
||||
element[0].classList.add('drag-over');
|
||||
});
|
||||
|
||||
element[0].addEventListener('dragleave', function (e) {
|
||||
e.preventDefault();
|
||||
element[0].classList.remove('drag-over');
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
430
Aberwyn/wwwroot/js/budget.js
Normal file
430
Aberwyn/wwwroot/js/budget.js
Normal file
@@ -0,0 +1,430 @@
|
||||
var app = angular.module('budgetApp', []);
|
||||
console.log("budget.js loaded");
|
||||
app.controller('BudgetController', function ($scope, $http) {
|
||||
$scope.budget = null;
|
||||
$scope.loading = false;
|
||||
$scope.error = null;
|
||||
$scope.menuOpen = false;
|
||||
|
||||
const today = new Date();
|
||||
$scope.selectedYear = today.getFullYear();
|
||||
$scope.selectedMonth = today.getMonth() + 1;
|
||||
$scope.tempMonth = $scope.monthNames?.[today.getMonth()] || "";
|
||||
$scope.tempYear = $scope.selectedYear;
|
||||
|
||||
$scope.monthNames = ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"];
|
||||
|
||||
$scope.getMonthName = function (month) {
|
||||
return $scope.monthNames[month - 1] || "";
|
||||
};
|
||||
|
||||
$scope.selectedMonthName = $scope.getMonthName($scope.selectedMonth);
|
||||
|
||||
$scope.toggleMenu = function (e) {
|
||||
e.stopPropagation();
|
||||
$scope.menuOpen = !$scope.menuOpen;
|
||||
};
|
||||
|
||||
document.addEventListener('click', function () {
|
||||
$scope.$apply(() => {
|
||||
$scope.menuOpen = false;
|
||||
});
|
||||
});
|
||||
|
||||
$scope.showToast = function (message, isError = false) {
|
||||
const toast = document.createElement("div");
|
||||
toast.className = "toast" + (isError ? " error" : "") + " show";
|
||||
toast.innerText = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.remove("show");
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
$scope.loadBudget = function () {
|
||||
$scope.loading = true;
|
||||
$scope.error = null;
|
||||
$scope.budget = null;
|
||||
|
||||
$http.get(`/api/budget/${$scope.selectedYear}/${$scope.selectedMonth}`)
|
||||
.then(function (response) {
|
||||
const raw = response.data;
|
||||
if (raw && raw.Categories) {
|
||||
const categories = raw.Categories.map(cat => ({
|
||||
id: cat.Id,
|
||||
name: cat.Name,
|
||||
color: cat.Color,
|
||||
editing: false,
|
||||
allowDrag: false,
|
||||
items: (cat.Items || []).map((item, index) => ({
|
||||
id: item.Id,
|
||||
name: item.Name,
|
||||
amount: parseFloat(item.Amount),
|
||||
isExpense: item.IsExpense === true,
|
||||
includeInSummary: item.IncludeInSummary === true,
|
||||
order: item.Order ?? index
|
||||
})).sort((a, b) => a.order - b.order)
|
||||
}));
|
||||
|
||||
$scope.budget = {
|
||||
id: raw.Id,
|
||||
year: raw.Year,
|
||||
month: raw.Month,
|
||||
categories: categories.sort((a, b) => a.order - b.order)
|
||||
};
|
||||
} else {
|
||||
$scope.budget = { categories: [] };
|
||||
}
|
||||
$scope.selectedMonthName = $scope.getMonthName($scope.selectedMonth);
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (error.status === 404) {
|
||||
$scope.budget = { categories: [] };
|
||||
} else {
|
||||
$scope.error = "Kunde inte ladda budgetdata.";
|
||||
$scope.showToast("Fel vid laddning av budgetdata", true);
|
||||
console.error("Budget API error:", error);
|
||||
}
|
||||
})
|
||||
.finally(function () {
|
||||
$scope.loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.saveCategory = function (category) {
|
||||
if (category.newItemName && category.newItemAmount) {
|
||||
const newItem = {
|
||||
name: category.newItemName,
|
||||
amount: parseFloat(category.newItemAmount),
|
||||
isExpense: true,
|
||||
includeInSummary: true,
|
||||
budgetCategoryId: category.id,
|
||||
};
|
||||
|
||||
$http.post("/api/budget/item", newItem)
|
||||
.then(res => {
|
||||
if (res.data && res.data.id) {
|
||||
newItem.id = res.data.id;
|
||||
category.items.push(newItem);
|
||||
category.newItemName = "";
|
||||
category.newItemAmount = "";
|
||||
$scope.showToast("Post sparad!");
|
||||
} else {
|
||||
$scope.showToast("Fel vid sparande av ny post", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
category.editing = false;
|
||||
|
||||
const payload = {
|
||||
id: category.id,
|
||||
name: category.name,
|
||||
color: category.color,
|
||||
items: category.items.map((item, index) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
amount: item.amount,
|
||||
isExpense: item.isExpense,
|
||||
includeInSummary: item.includeInSummary,
|
||||
budgetCategoryId: category.id,
|
||||
order: index
|
||||
}))
|
||||
};
|
||||
|
||||
$http.put(`/api/budget/category/${category.id}`, payload)
|
||||
.then(() => $scope.showToast("Kategori sparad!"))
|
||||
.catch(() => $scope.showToast("Fel vid sparande av kategori", true));
|
||||
};
|
||||
|
||||
$scope.deleteCategory = function (category) {
|
||||
if (!confirm("Vill du verkligen ta bort kategorin och alla dess poster?")) return;
|
||||
|
||||
$http.delete(`/api/budget/category/${category.id}`)
|
||||
.then(() => {
|
||||
$scope.budget.categories = $scope.budget.categories.filter(c => c.id !== category.id);
|
||||
$scope.showToast("Kategori borttagen!");
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Fel vid borttagning av kategori:", err);
|
||||
$scope.showToast("Kunde inte ta bort kategori", true);
|
||||
});
|
||||
};
|
||||
$scope.copyPreviousMonthSafe = function () {
|
||||
console.log("click OK");
|
||||
|
||||
$scope.menuOpen = false;
|
||||
setTimeout(function () {
|
||||
$scope.copyPreviousMonth();
|
||||
}, 10);
|
||||
};
|
||||
$scope.deleteMonth = function () {
|
||||
if (!confirm("Vill du verkligen ta bort alla data för denna månad?")) return;
|
||||
|
||||
const year = $scope.selectedYear;
|
||||
const month = $scope.selectedMonth;
|
||||
|
||||
$http.delete(`/api/budget/${year}/${month}`)
|
||||
.then(() => {
|
||||
$scope.showToast("Månad borttagen!");
|
||||
$scope.loadBudget(); // tömmer sidan
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Kunde inte ta bort månad:", err);
|
||||
$scope.showToast("Fel vid borttagning av månad", true);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.copyPreviousMonth = function () {
|
||||
if (!confirm("Vill du kopiera föregående månad till den aktuella?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Försöker kopiera föregående månad...");
|
||||
|
||||
const year = $scope.selectedYear;
|
||||
const month = $scope.selectedMonth;
|
||||
|
||||
$http.post(`/api/budget/copy/${year}/${month}`)
|
||||
.then(() => {
|
||||
$scope.showToast("Föregående månad kopierad!");
|
||||
$scope.loadBudget();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Kunde inte kopiera föregående månad:", err);
|
||||
if (err.status === 404) {
|
||||
$scope.showToast("Ingen föregående månad att kopiera från", true);
|
||||
} else if (err.status === 400) {
|
||||
$scope.showToast("Data finns redan för denna månad", true);
|
||||
} else {
|
||||
$scope.showToast("Kunde inte kopiera", true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cancelCategoryEdit = function (category) {
|
||||
category.editing = false;
|
||||
};
|
||||
|
||||
function getItemsFlat() {
|
||||
if (!$scope.budget || !$scope.budget.categories) return [];
|
||||
return $scope.budget.categories.flatMap(c => c.items || []);
|
||||
}
|
||||
|
||||
$scope.getCategorySum = function (category) {
|
||||
return (category.items || []).reduce((sum, i) => sum + i.amount, 0);
|
||||
};
|
||||
|
||||
$scope.getTotalIncome = function () {
|
||||
return getItemsFlat().filter(i => !i.isExpense && i.includeInSummary).reduce((sum, i) => sum + i.amount, 0);
|
||||
};
|
||||
|
||||
$scope.getTotalExpense = function () {
|
||||
return getItemsFlat().filter(i => i.isExpense && i.includeInSummary).reduce((sum, i) => sum + i.amount, 0);
|
||||
};
|
||||
|
||||
$scope.getTotalSaving = function () {
|
||||
return getItemsFlat().filter(i => !i.isExpense && !i.includeInSummary).reduce((sum, i) => sum + i.amount, 0);
|
||||
};
|
||||
|
||||
$scope.getLeftover = function () {
|
||||
return $scope.getTotalIncome() - $scope.getTotalExpense();
|
||||
};
|
||||
|
||||
$scope.applyMonthSelection = function () {
|
||||
const monthIndex = $scope.monthNames.indexOf($scope.tempMonth);
|
||||
if (monthIndex >= 0 && $scope.tempYear) {
|
||||
$scope.selectedMonth = monthIndex + 1;
|
||||
$scope.selectedYear = parseInt($scope.tempYear);
|
||||
$scope.selectedMonthName = $scope.getMonthName($scope.selectedMonth);
|
||||
$scope.showMonthPicker = false;
|
||||
$scope.loadBudget();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.previousMonth = function () {
|
||||
if ($scope.selectedMonth === 1) {
|
||||
$scope.selectedMonth = 12;
|
||||
$scope.selectedYear--;
|
||||
} else {
|
||||
$scope.selectedMonth--;
|
||||
}
|
||||
$scope.tempMonth = $scope.getMonthName($scope.selectedMonth);
|
||||
$scope.tempYear = $scope.selectedYear;
|
||||
$scope.selectedMonthName = $scope.getMonthName($scope.selectedMonth);
|
||||
$scope.loadBudget();
|
||||
};
|
||||
|
||||
$scope.nextMonth = function () {
|
||||
if ($scope.selectedMonth === 12) {
|
||||
$scope.selectedMonth = 1;
|
||||
$scope.selectedYear++;
|
||||
} else {
|
||||
$scope.selectedMonth++;
|
||||
}
|
||||
$scope.tempMonth = $scope.getMonthName($scope.selectedMonth);
|
||||
$scope.tempYear = $scope.selectedYear;
|
||||
$scope.selectedMonthName = $scope.getMonthName($scope.selectedMonth);
|
||||
$scope.loadBudget();
|
||||
};
|
||||
|
||||
$scope.handleCategoryDrop = function (data, targetCategory) {
|
||||
if (data.type !== 'category') return; // ⛔ stoppa om det är ett item-drag
|
||||
|
||||
const categories = $scope.budget.categories;
|
||||
const draggedIndex = categories.findIndex(c => c.id === data.categoryId);
|
||||
const targetIndex = categories.findIndex(c => c.id === targetCategory.id);
|
||||
|
||||
if (draggedIndex === -1 || targetIndex === -1 || draggedIndex === targetIndex) return;
|
||||
|
||||
const moved = categories.splice(draggedIndex, 1)[0];
|
||||
categories.splice(targetIndex, 0, moved);
|
||||
|
||||
categories.forEach((cat, i) => {
|
||||
cat.order = i;
|
||||
});
|
||||
|
||||
const payload = $scope.budget.categories.map(cat => ({
|
||||
id: cat.id,
|
||||
name: cat.name,
|
||||
color: cat.color,
|
||||
order: cat.order,
|
||||
year: $scope.selectedYear,
|
||||
month: $scope.selectedMonth,
|
||||
items: [] // tom lista – backend kräver den, men vi använder den inte här
|
||||
}));
|
||||
|
||||
|
||||
$http.put("/api/budget/category/order", payload)
|
||||
.then(() => $scope.showToast("Kategorier omordnade!"))
|
||||
.catch(() => $scope.showToast("Fel vid uppdatering av ordning", true));
|
||||
};
|
||||
|
||||
$scope.handleItemDrop = function ({ data, targetCategory, targetIndex }) {
|
||||
const sourceCategory = $scope.budget.categories.find(c => c.id === data.fromCategoryId);
|
||||
const draggedItem = sourceCategory?.items.find(i => i.id === data.itemId);
|
||||
|
||||
if (!draggedItem || !targetCategory) return;
|
||||
|
||||
// Ta bort från ursprung
|
||||
const draggedIndex = sourceCategory.items.findIndex(i => i.id === draggedItem.id);
|
||||
if (draggedIndex !== -1) {
|
||||
sourceCategory.items.splice(draggedIndex, 1);
|
||||
}
|
||||
|
||||
// Uppdatera värden
|
||||
draggedItem.budgetCategoryId = targetCategory.id;
|
||||
const indexToInsert = typeof targetIndex === 'number' ? targetIndex : targetCategory.items.length;
|
||||
targetCategory.items.splice(indexToInsert, 0, draggedItem);
|
||||
|
||||
// Uppdatera ordning
|
||||
targetCategory.items.forEach((item, i) => {
|
||||
item.order = i;
|
||||
});
|
||||
|
||||
// ✅ Skicka PUT för det flyttade itemet
|
||||
const payload = {
|
||||
id: draggedItem.id,
|
||||
name: draggedItem.name,
|
||||
amount: draggedItem.amount,
|
||||
isExpense: draggedItem.isExpense,
|
||||
includeInSummary: draggedItem.includeInSummary,
|
||||
order: draggedItem.order,
|
||||
budgetCategoryId: draggedItem.budgetCategoryId
|
||||
};
|
||||
|
||||
$http.put(`/api/budget/item/${draggedItem.id}`, payload)
|
||||
.then(() => {
|
||||
console.log(">>> Sparad!");
|
||||
$scope.showToast("Post omplacerad!");
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Kunde inte uppdatera post:", err);
|
||||
$scope.showToast("Fel vid omplacering", true);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.handleItemPreciseDrop = function (data, targetCategory, targetIndex) {
|
||||
if (data.type !== 'item') return;
|
||||
|
||||
const sourceCategory = $scope.budget.categories.find(c => c.id === data.fromCategoryId);
|
||||
const draggedItem = sourceCategory?.items.find(i => i.id === data.itemId);
|
||||
|
||||
if (!draggedItem || !targetCategory) return;
|
||||
|
||||
// Ta bort från ursprung
|
||||
const draggedIndex = sourceCategory.items.findIndex(i => i.id === draggedItem.id);
|
||||
if (draggedIndex !== -1) {
|
||||
sourceCategory.items.splice(draggedIndex, 1);
|
||||
}
|
||||
|
||||
// Uppdatera kategori och lägg till på exakt plats
|
||||
draggedItem.budgetCategoryId = targetCategory.id;
|
||||
targetCategory.items.splice(targetIndex, 0, draggedItem);
|
||||
|
||||
// Uppdatera ordning
|
||||
targetCategory.items.forEach((item, i) => {
|
||||
item.order = i;
|
||||
});
|
||||
|
||||
// ✅ PUT för det flyttade itemet
|
||||
const payload = {
|
||||
id: draggedItem.id,
|
||||
name: draggedItem.name,
|
||||
amount: draggedItem.amount,
|
||||
isExpense: draggedItem.isExpense,
|
||||
includeInSummary: draggedItem.includeInSummary,
|
||||
order: draggedItem.order,
|
||||
budgetCategoryId: draggedItem.budgetCategoryId
|
||||
};
|
||||
|
||||
$http.put(`/api/budget/item/${draggedItem.id}`, payload)
|
||||
.then(() => {
|
||||
console.log(">>> Sparad!");
|
||||
$scope.showToast("Post omplacerad!");
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Kunde inte uppdatera post:", err);
|
||||
$scope.showToast("Fel vid omplacering", true);
|
||||
});
|
||||
};
|
||||
$scope.createNewCategory = function () {
|
||||
const defaultName = "Ny kategori";
|
||||
const newOrder = $scope.budget.categories.length; // sist i listan
|
||||
|
||||
const newCategory = {
|
||||
name: defaultName,
|
||||
color: "#666666",
|
||||
year: $scope.selectedYear,
|
||||
month: $scope.selectedMonth,
|
||||
order: newOrder
|
||||
};
|
||||
|
||||
$http.post("/api/budget/category", newCategory)
|
||||
.then(res => {
|
||||
if (res.data && res.data.id) {
|
||||
$scope.budget.categories.push({
|
||||
id: res.data.id,
|
||||
name: defaultName,
|
||||
color: "#666666",
|
||||
order: newOrder,
|
||||
items: [],
|
||||
editing: true,
|
||||
allowDrag: false
|
||||
});
|
||||
$scope.showToast("Kategori skapad!");
|
||||
} else {
|
||||
$scope.showToast("Misslyckades med att skapa kategori", true);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Fel vid skapande av kategori:", err);
|
||||
$scope.showToast("Fel vid skapande av kategori", true);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.loadBudget();
|
||||
});
|
||||
Reference in New Issue
Block a user