Skip to content

Commit 4f3dfb6

Browse files
authored
Update fast-search-card.js
1 parent dc9b059 commit 4f3dfb6

File tree

1 file changed

+120
-19
lines changed

1 file changed

+120
-19
lines changed

dist/fast-search-card.js

Lines changed: 120 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,32 @@ class FastSearchCard extends HTMLElement {
28142814
background: rgba(255,255,255,0.05);
28152815
border-radius: 12px;
28162816
}
2817+
2818+
.timer-actions {
2819+
display: flex;
2820+
gap: 8px;
2821+
align-items: center;
2822+
}
2823+
2824+
.timer-edit,
2825+
.timer-delete {
2826+
width: 32px;
2827+
height: 32px;
2828+
background: rgba(255,255,255,0.1);
2829+
border: none;
2830+
border-radius: 50%;
2831+
cursor: pointer;
2832+
display: flex;
2833+
align-items: center;
2834+
justify-content: center;
2835+
transition: all 0.2s ease;
2836+
flex-shrink: 0;
2837+
}
2838+
2839+
.timer-edit:hover {
2840+
background: rgba(0, 122, 255, 0.2);
2841+
transform: scale(1.1);
2842+
}
28172843

28182844
.quick-timer-title {
28192845
font-size: 14px;
@@ -9023,11 +9049,21 @@ class FastSearchCard extends HTMLElement {
90239049
return;
90249050
}
90259051

9026-
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9027-
90289052
try {
9029-
// Verwende deine bestehende Timer-Erstellung
9030-
await this.createActionTimer(item, action, totalMinutes);
9053+
// NEU: Prüfen ob Edit-Modus
9054+
if (this.editingTimer) {
9055+
console.log(`🔧 Timer bearbeiten: ${this.editingTimer.id} - ${totalMinutes} Minuten`);
9056+
9057+
// Timer bearbeiten (Sie müssen diese Funktion implementieren)
9058+
await this.updateTimerTime(this.editingTimer.id, totalMinutes);
9059+
9060+
// Edit-Modus zurücksetzen
9061+
this.editingTimer = null;
9062+
} else {
9063+
// Normal: Neuen Timer erstellen
9064+
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9065+
await this.createActionTimer(item, action, totalMinutes);
9066+
}
90319067

90329068
// Schließe den Picker
90339069
const parentContainer = this.shadowRoot.querySelector('.minimal-time-picker').closest('.shortcuts-tab-content');
@@ -9039,10 +9075,39 @@ class FastSearchCard extends HTMLElement {
90399075
}, 500);
90409076

90419077
} catch (error) {
9042-
console.error('❌ Fehler beim Erstellen des Timers:', error);
9078+
console.error('❌ Fehler beim Timer:', error);
90439079
}
90449080
}
90459081

9082+
// NEU: Timer by ID laden
9083+
async getTimerById(timerId) {
9084+
// Implementierung je nach Ihrem Backend
9085+
// Beispiel für Home Assistant Scheduler:
9086+
try {
9087+
const schedules = await this._hass.callWS({
9088+
type: 'scheduler/items'
9089+
});
9090+
return schedules.find(s => s.schedule_id === timerId);
9091+
} catch (error) {
9092+
console.error('Fehler beim Laden des Timers:', error);
9093+
return null;
9094+
}
9095+
}
9096+
9097+
// NEU: Timer-Zeit aktualisieren
9098+
async updateTimerTime(timerId, newTotalMinutes) {
9099+
const future = new Date(Date.now() + newTotalMinutes * 60 * 1000);
9100+
const timeString = future.toTimeString().slice(0, 5);
9101+
9102+
await this._hass.callService('scheduler', 'edit', {
9103+
entity_id: `schedule.${timerId}`,
9104+
timeslots: [{
9105+
start: timeString,
9106+
// Weitere Timer-Daten beibehalten...
9107+
}]
9108+
});
9109+
}
9110+
90469111
closeMinimalTimePicker(parentContainer) {
90479112
const timePickerContainer = parentContainer.querySelector('.minimal-time-picker');
90489113
if (timePickerContainer) {
@@ -9558,20 +9623,27 @@ class FastSearchCard extends HTMLElement {
95589623
<span class="timer-time">${timeUntil}</span>
95599624
</div>
95609625
</div>
9561-
9562-
<button class="timer-delete" data-timer-id="${timer.schedule_id}" title="Timer löschen">
9563-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9564-
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
9565-
<path d="M4 7l16 0" />
9566-
<path d="M10 11l0 6" />
9567-
<path d="M14 11l0 6" />
9568-
<path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" />
9569-
<path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
9570-
</svg>
9571-
</button>
9572-
9626+
<div class="timer-actions">
9627+
<button class="timer-edit" data-timer-id="${timer.schedule_id}" title="Timer bearbeiten">
9628+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9629+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
9630+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
9631+
</svg>
9632+
</button>
9633+
<button class="timer-delete" data-timer-id="${timer.schedule_id}" title="Timer löschen">
9634+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9635+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
9636+
<path d="M4 7l16 0" />
9637+
<path d="M10 11l0 6" />
9638+
<path d="M14 11l0 6" />
9639+
<path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" />
9640+
<path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
9641+
</svg>
9642+
</button>
9643+
</div>
95739644
</div>
95749645
`;
9646+
95759647
}).join('');
95769648

95779649
container.innerHTML = `
@@ -9580,14 +9652,43 @@ class FastSearchCard extends HTMLElement {
95809652
`;
95819653

95829654
// Event Listeners für Delete Buttons
9583-
container.querySelectorAll('.timer-delete').forEach(btn => {
9655+
container.querySelectorAll('.timer-edit').forEach(btn => {
95849656
btn.addEventListener('click', () => {
95859657
const timerId = btn.dataset.timerId;
9586-
this.deleteTimer(timerId, entityId);
9658+
this.editTimer(timerId, entityId);
95879659
});
95889660
});
95899661
}
95909662

9663+
async editTimer(timerId, entityId) {
9664+
console.log(`🔧 Timer bearbeiten: ${timerId}`);
9665+
9666+
try {
9667+
// Timer-Daten laden (Sie müssen diese Funktion ggf. implementieren)
9668+
const timer = await this.getTimerById(timerId);
9669+
if (!timer) {
9670+
console.error('Timer nicht gefunden');
9671+
return;
9672+
}
9673+
9674+
// Edit-Modus setzen
9675+
this.editingTimer = {
9676+
id: timerId,
9677+
action: timer.action || 'turn_off',
9678+
entityId: entityId
9679+
};
9680+
9681+
// Container finden
9682+
const parentContainer = this.shadowRoot.querySelector(`#timer-section-${entityId}`);
9683+
9684+
// Bestehenden Minimal Time Picker anzeigen
9685+
this.showMinimalTimePicker(parentContainer, timer.action || 'turn_off', entityId, false);
9686+
9687+
} catch (error) {
9688+
console.error('❌ Fehler beim Bearbeiten:', error);
9689+
}
9690+
}
9691+
95919692
getNextExecution(timer) {
95929693
// Zuerst prüfen ob next_execution Attribut vorhanden ist
95939694
if (timer.next_execution) {

0 commit comments

Comments
 (0)