Skip to content

Commit a600daf

Browse files
authored
Edit Scheduled plan date/time input (both on one row) (#3048)
1 parent 7287b2c commit a600daf

File tree

1 file changed

+63
-24
lines changed

1 file changed

+63
-24
lines changed

packages/modules/web_themes/koala/source/src/components/ChargePointScheduledPlanDetails.vue

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@
2222
color="positive"
2323
/>
2424
</div>
25-
<div class="row items-center q-mb-md">
26-
<q-input
27-
v-model="planTime.value"
28-
type="time"
29-
label="Ziel-Termin"
30-
class="col"
31-
/>
32-
</div>
25+
<q-separator />
3326
<div class="q-mb-sm">
3427
<div class="text-subtitle2 q-mb-sm q-mt-sm">Wiederholungen</div>
3528
<q-btn-group spread>
@@ -52,18 +45,10 @@
5245
label="Wöchentlich"
5346
/>
5447
</q-btn-group>
55-
<div v-if="planFrequency.value === 'once'" class="q-mt-sm">
56-
<q-input
57-
v-model="planOnceDate.value"
58-
type="date"
59-
label="Datum"
60-
:min="new Date().toISOString().split('T')[0]"
61-
/>
62-
</div>
6348
<!-- Weekly buttons -->
6449
<div
6550
v-if="planFrequency.value === 'weekly'"
66-
class="q-mt-sm row items-center q-gutter-sm justify-center no-wrap"
51+
class="row items-center q-gutter-sm justify-center no-wrap q-mt-xs"
6752
>
6853
<div v-for="(day, index) in weekDays" :key="day">
6954
<q-btn
@@ -78,9 +63,36 @@
7863
/>
7964
</div>
8065
</div>
66+
<div class="text-subtitle2 q-mt-sm">Ziel-Termin</div>
67+
<div class="row items-center q-mb-md">
68+
<q-input
69+
v-if="planFrequency.value === 'once'"
70+
class="q-mr-lg col"
71+
v-model="planOnceDate.value"
72+
type="date"
73+
label="Ziel-Datum"
74+
:min="new Date().toISOString().split('T')[0]"
75+
/>
76+
<q-input
77+
v-else
78+
class="q-mr-lg col"
79+
:model-value="
80+
planFrequency.value === 'daily' ? today : firstSelectedWeekday
81+
"
82+
label="Ziel-Datum"
83+
readonly
84+
/>
85+
<q-input
86+
v-model="planTime.value"
87+
type="time"
88+
label="Ziel-Uhrzeit"
89+
class="col"
90+
/>
91+
</div>
8192
</div>
93+
<q-separator />
8294
<SliderStandard
83-
class="q-mb-sm"
95+
class="q-my-sm"
8496
:title="planDcChargingEnabled ? 'Ladestrom (AC)' : 'Ladestrom'"
8597
:min="6"
8698
:max="32"
@@ -237,20 +249,47 @@ const emit = defineEmits(['close']);
237249
const mqttStore = useMqttStore();
238250
const $q = useQuasar();
239251
252+
const formatDateDayMonthYear = (dateString: string): string => {
253+
if (!dateString) return '';
254+
const [year, month, day] = dateString.split('-');
255+
return `${day}.${month}.${year}`;
256+
};
257+
const today = formatDateDayMonthYear(new Date().toISOString().split('T')[0]);
240258
const weekDays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
241259
242-
const phaseOptions = [
243-
{ value: 1, label: '1' },
244-
{ value: 3, label: 'Maximum' },
245-
{ value: 0, label: 'Automatik' },
246-
];
247-
248260
const selectDay = (index: number) => {
249261
const newArray = [...selectedWeekDays.value];
250262
newArray[index] = !newArray[index];
251263
selectedWeekDays.value = newArray;
252264
};
253265
266+
const firstSelectedWeekday = computed(() => {
267+
const today = new Date();
268+
// 0=Sonntag, ..., 6=Samstag >> 0=Montag, ..., 6=Sonntag
269+
const todayIndex = (today.getDay() + 6) % 7;
270+
const userSelection = selectedWeekDays.value
271+
.map((isSelected, index) => (isSelected ? index : -1))
272+
.filter((index) => index !== -1);
273+
if (userSelection.length === 0) return '';
274+
// For all selected days, calculate the distance to today
275+
const daysUntilSelected = userSelection.map((idx) => {
276+
let daysUntil = idx - todayIndex;
277+
if (daysUntil < 0) daysUntil += 7;
278+
return daysUntil;
279+
});
280+
// Take the smallest distance (this is the next day)
281+
const nearestDay = Math.min(...daysUntilSelected);
282+
const dateNextDay = new Date(today);
283+
dateNextDay.setDate(today.getDate() + nearestDay);
284+
return formatDateDayMonthYear(dateNextDay.toISOString().split('T')[0]);
285+
});
286+
287+
const phaseOptions = [
288+
{ value: 1, label: '1' },
289+
{ value: 3, label: 'Maximum' },
290+
{ value: 0, label: 'Automatik' },
291+
];
292+
254293
const planActive = computed(() =>
255294
mqttStore.vehicleScheduledChargingPlanActive(
256295
props.chargePointId,

0 commit comments

Comments
 (0)