|
3 | 3 | <div class="calendar-container" ref="calendarContainer">
|
4 | 4 | <div class="time-slots">
|
5 | 5 | <!-- Generate time slots (24 hours) -->
|
6 |
| - <div |
7 |
| - v-for="hour in 24" |
8 |
| - :key="hour" |
9 |
| - class="time-slot" |
10 |
| - :style="{ top: calculateTopPosition(hour) }" |
11 |
| - > |
| 6 | + <div v-for="hour in 24" :key="hour" class="time-slot" :style="{ top: calculateTopPosition(hour) }"> |
12 | 7 | {{ formatHour(hour) }}
|
13 | 8 | </div>
|
14 | 9 | </div>
|
15 | 10 |
|
16 | 11 | <div class="events">
|
17 |
| - <!-- Render pending and completed tasks dynamically from different lists --> |
18 |
| - <div |
19 |
| - v-for="(task, index) in combinedEvents" |
20 |
| - :key="task.id" |
21 |
| - class="event" |
22 |
| - :style="getEventStyle(task)" |
23 |
| - @click="handleEventClick(task, index)" |
24 |
| - > |
25 |
| - <span :class="{ completed: task.completed }">{{ task.title }}</span> |
| 12 | + <!-- Render events dynamically --> |
| 13 | + <div v-for="(event, index) in combinedEvents" :key="`${event.listType}-${index}`" class="event" |
| 14 | + :style="getEventStyle(event)" @click="handleEventClick(event, index)"> |
| 15 | + <span>{{ event.textString }}</span> |
26 | 16 | </div>
|
27 | 17 | </div>
|
28 | 18 | </div>
|
|
31 | 21 |
|
32 | 22 | <script>
|
33 | 23 | export default {
|
34 |
| - name: 'DailyCalendar', |
| 24 | + name: "DailyCalendar", |
35 | 25 | props: {
|
36 |
| - completedAllTasks: { |
| 26 | + list1: { |
37 | 27 | type: Array,
|
38 |
| - required: true |
| 28 | + required: true, |
| 29 | + default: () => [], |
39 | 30 | },
|
40 |
| - pendingAllTasks: { |
| 31 | + list2: { |
41 | 32 | type: Array,
|
42 |
| - required: true |
| 33 | + required: true, |
| 34 | + default: () => [], |
43 | 35 | },
|
44 |
| - completedDailyList: { |
45 |
| - type: Array, |
46 |
| - required: true |
47 |
| - }, |
48 |
| - pendingDailyList: { |
49 |
| - type: Array, |
50 |
| - required: true |
51 |
| - } |
52 | 36 | },
|
| 37 | + emits: ["update:list1", "update:list2", "event-clicked"], |
| 38 | +
|
53 | 39 | computed: {
|
54 | 40 | combinedEvents() {
|
55 |
| - // Combine all task arrays and filter by today's date |
56 | 41 | const today = this.getTodayDate();
|
57 |
| - return [ |
58 |
| - ...this.pendingAllTasks.filter(task => task.scheduledDate === today), |
59 |
| - ...this.completedAllTasks.filter(task => task.scheduledDate === today), |
60 |
| - ...this.pendingDailyList.filter(task => task.scheduledDate === today), |
61 |
| - ...this.completedDailyList.filter(task => task.scheduledDate === today) |
| 42 | + const events = [ |
| 43 | + ...this.list1.map((event) => ({ ...event, listType: "list1" })), |
| 44 | + ...this.list2.map((event) => ({ ...event, listType: "list2" })), |
62 | 45 | ];
|
63 |
| - } |
| 46 | +
|
| 47 | + console.log('Computed Combined Events:', events.filter((event) => event.scheduledDate === today)); |
| 48 | +
|
| 49 | + return events.filter((event) => event.scheduledDate === today); |
| 50 | + }, |
| 51 | + }, |
| 52 | +
|
| 53 | + watch: { |
| 54 | + list1(newVal) { |
| 55 | + //console.log('List1 (Backburner) updated:', newVal); |
| 56 | + }, |
| 57 | + list2(newVal) { |
| 58 | + //console.log('List2 (Daily List) updated:', newVal); |
| 59 | + }, |
64 | 60 | },
|
| 61 | +
|
65 | 62 | methods: {
|
66 | 63 | calculateTopPosition(hour) {
|
67 |
| - // Ensure this function works to calculate the top position based on the hour |
68 | 64 | return `${hour * 60}px`;
|
69 | 65 | },
|
70 | 66 | formatHour(hour) {
|
71 |
| - const ampm = hour >= 12 ? 'PM' : 'AM'; |
| 67 | + const ampm = hour >= 12 ? "PM" : "AM"; |
72 | 68 | const formattedHour = hour % 12 || 12;
|
73 | 69 | return `${formattedHour} ${ampm}`;
|
74 | 70 | },
|
75 |
| - getEventStyle(task) { |
76 |
| - const startHour = this.parseTime(task.startTime); |
77 |
| - const endHour = this.parseTime(task.endTime); |
| 71 | +
|
| 72 | + getEventStyle(event) { |
| 73 | + const startHour = this.parseTime(event.scheduledTime); |
| 74 | + let endHour = startHour + event.taskTimeEstimate / 60; |
| 75 | +
|
| 76 | + // Ensure the event doesn't go beyond the last hour of the day (24 hours) and a little less so that it wraps nicely |
| 77 | + if (endHour > 24.75) { |
| 78 | + endHour = 24.75; |
| 79 | + } |
| 80 | +
|
78 | 81 | const topPosition = startHour * 60; // Top position in px
|
79 |
| - const height = (endHour - startHour) * 60; // Event height in px |
| 82 | + let height = (endHour - startHour) * 60; // Event height in px |
| 83 | +
|
| 84 | + const minHeight = 25; |
| 85 | + if (height < minHeight) { |
| 86 | + height = minHeight; |
| 87 | + } |
80 | 88 |
|
81 | 89 | return {
|
82 | 90 | top: `${topPosition}px`,
|
83 | 91 | height: `${height}px`,
|
84 |
| - backgroundColor: task.completed ? '#888888' : '#4caf50' // Gray if completed |
| 92 | + backgroundColor: "#4caf50", // Default color |
85 | 93 | };
|
| 94 | +
|
86 | 95 | },
|
87 |
| - handleEventClick(task, index) { |
88 |
| - // Emit the task's index and its list type to the parent (Dashboard) |
89 |
| - const listType = this.getListType(task); |
90 |
| - this.$emit('task-clicked', { taskIndex: index, listType }); |
91 |
| - }, |
92 |
| - getListType(task) { |
93 |
| - if (this.pendingAllTasks.includes(task)) return 'pendingAllTasks'; |
94 |
| - if (this.completedAllTasks.includes(task)) return 'completedAllTasks'; |
95 |
| - if (this.pendingDailyList.includes(task)) return 'pendingDailyList'; |
96 |
| - if (this.completedDailyList.includes(task)) return 'completedDailyList'; |
97 |
| - return ''; |
| 96 | +
|
| 97 | + handleEventClick(event, index) { |
| 98 | + this.$emit("event-clicked", { event, listType: event.listType, index }); |
98 | 99 | },
|
| 100 | +
|
99 | 101 | getTodayDate() {
|
100 | 102 | const today = new Date();
|
101 | 103 | const year = today.getFullYear();
|
102 |
| - const month = (today.getMonth() + 1).toString().padStart(2, '0'); |
103 |
| - const day = today.getDate().toString().padStart(2, '0'); |
| 104 | + const month = (today.getMonth() + 1).toString().padStart(2, "0"); |
| 105 | + const day = today.getDate().toString().padStart(2, "0"); |
104 | 106 | return `${year}-${month}-${day}`; // Format: YYYY-MM-DD
|
105 | 107 | },
|
| 108 | +
|
| 109 | + // Updated parseTime method to handle various formats like '2:00pm', '09:59am', '9:59am' |
106 | 110 | parseTime(time) {
|
107 |
| - const [hours, minutes] = time.split(':').map(Number); |
| 111 | + const regex = /(\d{1,2}):(\d{2})(am|pm)/i; |
| 112 | + const match = time.trim().match(regex); |
| 113 | + if (!match) return 0; // Default if time format is invalid |
| 114 | +
|
| 115 | + let [_, hours, minutes, period] = match; |
| 116 | + hours = parseInt(hours, 10); |
| 117 | + minutes = parseInt(minutes, 10); |
| 118 | +
|
| 119 | + // Convert to 24-hour time format |
| 120 | + if (period.toLowerCase() === 'pm' && hours !== 12) { |
| 121 | + hours += 12; |
| 122 | + } else if (period.toLowerCase() === 'am' && hours === 12) { |
| 123 | + hours = 0; |
| 124 | + } |
| 125 | +
|
| 126 | + // Return the time in hours (decimal format) |
108 | 127 | return hours + minutes / 60;
|
109 | 128 | },
|
| 129 | +
|
110 | 130 | scrollToDefaultTime() {
|
111 | 131 | const currentTime = new Date();
|
112 | 132 | const defaultScrollTime = currentTime.getHours() - 1; // 1 hour before current time
|
113 | 133 | const scrollPosition = defaultScrollTime * 60; // Scroll to this position (in px)
|
114 | 134 |
|
115 | 135 | // Scroll the container to the desired position
|
116 | 136 | this.$refs.calendarContainer.scrollTop = scrollPosition;
|
117 |
| - } |
| 137 | + }, |
118 | 138 | },
|
| 139 | +
|
119 | 140 | mounted() {
|
120 | 141 | this.scrollToDefaultTime();
|
121 |
| - } |
| 142 | + }, |
122 | 143 | };
|
123 | 144 | </script>
|
124 | 145 |
|
125 | 146 | <style scoped>
|
| 147 | +/* Styles remain the same */ |
126 | 148 | .daily-calendar {
|
127 | 149 | position: relative;
|
128 | 150 | height: 100%;
|
@@ -163,22 +185,19 @@ export default {
|
163 | 185 | position: absolute;
|
164 | 186 | left: 20%;
|
165 | 187 | width: 60%;
|
166 |
| - background-color: #4caf50; |
| 188 | + background-color: blue; |
167 | 189 | color: white;
|
168 | 190 | border-radius: 4px;
|
169 |
| - padding: 10px; |
| 191 | + padding-left: 10px; |
| 192 | + padding-top:5px; |
170 | 193 | box-sizing: border-box;
|
171 | 194 | cursor: pointer;
|
172 | 195 | overflow: hidden;
|
173 | 196 | white-space: nowrap;
|
174 | 197 | text-overflow: ellipsis;
|
175 | 198 | }
|
176 | 199 |
|
177 |
| -.event:hover { |
178 |
| - background-color: #388e3c; |
179 |
| -} |
180 |
| -
|
181 |
| -.completed { |
182 |
| - text-decoration: line-through; |
| 200 | +.event:hover { |
| 201 | + background-color: blue; |
183 | 202 | }
|
184 | 203 | </style>
|
0 commit comments