Skip to content

Commit 80545e6

Browse files
committed
add hour indicator
1 parent a7adb4b commit 80545e6

File tree

3 files changed

+75
-13
lines changed

3 files changed

+75
-13
lines changed

timetable/static/bundled/timetable/generator-index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ document.addEventListener("alpine:init", () => {
8282
displayedWeekdays: [] as WeekDay[],
8383
courses: [] as TimetableSlot[],
8484
startSlot: 0,
85+
endSlot: 0,
8586
table: {
8687
height: 0,
8788
width: 0,
@@ -150,6 +151,25 @@ document.addEventListener("alpine:init", () => {
150151
};
151152
},
152153

154+
getHours(): [string, object][] {
155+
let hour: number = Number.parseInt(
156+
this.courses
157+
.map((c: TimetableSlot) => c.startHour)
158+
.reduce((res: string, hour: string) => (hour < res ? hour : res), "24:00")
159+
.split(":")[0],
160+
);
161+
const res: [string, object][] = [];
162+
for (let i = 0; i <= this.endSlot - this.startSlot; i += 60 / MINUTES_PER_SLOT) {
163+
res.push([`${hour}:00`, { top: `${i * SLOT_HEIGHT}px` }]);
164+
hour += 1;
165+
}
166+
return res;
167+
},
168+
169+
getWidth() {
170+
return this.displayedWeekdays.length * SLOT_WIDTH + 20;
171+
},
172+
153173
async savePng() {
154174
const elem = document.getElementById("timetable");
155175
const img = (await html2canvas(elem)).toDataURL();

timetable/static/timetable/css/generator.scss

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
@import "core/static/core/colors";
2+
13
#timetable {
4+
--hour-side-width: 60px;
5+
26
display: block;
3-
margin: 2em auto ;
7+
margin: 2em auto;
48
.header {
5-
background-color: white;
9+
background-color: $white-color;
10+
font-weight: bold;
611
box-shadow: none;
7-
width: 100%;
12+
width: calc(100% - var(--hour-side-width) - 10px);
13+
margin-left: var(--hour-side-width);
14+
padding-left: 0;
815
display: flex;
916
flex-direction: row;
1017
gap: 0;
@@ -15,7 +22,32 @@
1522
}
1623
.content {
1724
position: relative;
25+
}
26+
.hours {
27+
position: absolute;
28+
width: 40px;
29+
left: 0;
30+
top: -.5em;
31+
32+
.hour {
33+
position: absolute;
34+
35+
.hour-bar {
36+
content: "";
37+
position: absolute;
38+
height: 1px;
39+
background: lightgray;
40+
top: 50%;
41+
left: 100%;
42+
margin-left: 10px;
43+
}
44+
}
45+
}
46+
.courses {
47+
position: absolute;
1848
text-align: center;
49+
top: 0;
50+
left: var(--hour-side-width);
1951

2052
.slot {
2153
background-color: cadetblue;

timetable/templates/timetable/generator.jinja

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,33 @@
2828
<div
2929
id="timetable"
3030
x-show="table.height > 0 && table.width > 0"
31-
:style="{width: `${table.width}px`, height: `${table.height+40}px`}"
31+
:style="{width: `${table.width+80}px`, height: `${table.height+40}px`}"
3232
>
3333
<div class="header">
3434
<template x-for="weekday in displayedWeekdays">
3535
<span x-text="weekday"></span>
3636
</template>
3737
</div>
3838
<div class="content">
39-
<template x-for="course in courses">
40-
<div class="slot" :style="getStyle(course)">
41-
<span class="course-type" x-text="course.courseType"></span>
42-
<span x-text="course.ueCode"></span>
43-
<span x-text="`${course.startHour} - ${course.endHour}`"></span>
44-
<span x-text="(course.weekGroup ? `\nGroupe ${course.weekGroup}` : '')"></span>
45-
<span x-text="course.room"></span>
46-
</div>
47-
</template>
39+
<div class="hours" :height="(endSlot - endSlot%4) - (startSlot - startSlot%4)">
40+
<template x-for="[hour, style] in getHours()">
41+
<div class="hour" :style="style">
42+
<div x-text="hour"></div>
43+
<div class="hour-bar" :style="{width: `${getWidth()}px`}"></div>
44+
</div>
45+
</template>
46+
</div>
47+
<div class="courses">
48+
<template x-for="course in courses">
49+
<div class="slot" :style="getStyle(course)">
50+
<span class="course-type" x-text="course.courseType"></span>
51+
<span x-text="course.ueCode"></span>
52+
<span x-text="`${course.startHour} - ${course.endHour}`"></span>
53+
<span x-text="(course.weekGroup ? `\nGroupe ${course.weekGroup}` : '')"></span>
54+
<span x-text="course.room"></span>
55+
</div>
56+
</template>
57+
</div>
4858
</div>
4959
</div>
5060
<button

0 commit comments

Comments
 (0)