@@ -508,28 +508,34 @@ def edit_meeting_schedule(request, num=None, owner=None, name=None):
508508 for a in assignments :
509509 assignments_by_session [a .session_id ].append (a )
510510
511- # Prepare timeslot layout. We arrange time slots in columns per
512- # room where everything inside is grouped by day. Things inside
513- # the days are then layouted proportionally to the actual time of
514- # day, to ensure that everything lines up, even if the time slots
515- # are not the same in the different rooms.
511+ # Prepare timeslot layout, making a timeline per day scaled in
512+ # browser em units to ensure that everything lines up even if the
513+ # timeslots are not the same in the different rooms
516514
517515 def timedelta_to_css_ems (timedelta ):
518- css_ems_per_hour = 1.8
516+ css_ems_per_hour = 5
519517 return timedelta .seconds / 60.0 / 60.0 * css_ems_per_hour
520518
521- # time labels column
522519 timeslots_by_day = defaultdict (list )
523520 for t in timeslots_qs :
524521 timeslots_by_day [t .time .date ()].append (t )
525522
526523 day_min_max = []
527524 for day , timeslots in sorted (timeslots_by_day .iteritems ()):
528525 day_min_max .append ((day , min (t .time for t in timeslots ), max (t .end_time () for t in timeslots )))
529-
530- time_labels = []
526+
527+ timeslots_by_room_and_day = defaultdict (list )
528+ room_has_timeslots = set ()
529+ for t in timeslots_qs :
530+ room_has_timeslots .add (t .location_id )
531+ timeslots_by_room_and_day [(t .location_id , t .time .date ())].append (t )
532+
533+ days = []
531534 for day , day_min_time , day_max_time in day_min_max :
532535 day_labels = []
536+ day_width = timedelta_to_css_ems (day_max_time - day_min_time )
537+
538+ label_width = 4 # em
533539
534540 hourly_delta = 2
535541
@@ -540,47 +546,42 @@ def timedelta_to_css_ems(timedelta):
540546 end = day_max_time .replace (hour = last_hour , minute = 0 , second = 0 , microsecond = 0 )
541547
542548 while t <= end :
543- day_labels .append ((t , 'top' , timedelta_to_css_ems (t - day_min_time ), 'left' ))
549+ left_offset = timedelta_to_css_ems (t - day_min_time )
550+ right_offset = day_width - left_offset
551+ if right_offset > label_width :
552+ # there's room for the label
553+ day_labels .append ((t , 'left' , left_offset ))
554+ else :
555+ day_labels .append ((t , 'right' , right_offset ))
556+
544557 t += datetime .timedelta (seconds = hourly_delta * 60 * 60 )
545558
546559 if not day_labels :
547- day_labels .append ((day_min_time , 'top' , 0 , 'left' ))
548-
549- time_labels .append ({
550- 'day' : day ,
551- 'height' : timedelta_to_css_ems (day_max_time - day_min_time ),
552- 'labels' : day_labels ,
553- })
554-
555- # room columns
556- timeslots_by_room_and_day = defaultdict (list )
557- for t in timeslots_qs :
558- timeslots_by_room_and_day [(t .location_id , t .time .date ())].append (t )
560+ day_labels .append ((day_min_time , 'left' , 0 ))
559561
560- room_columns = []
561- for r in rooms :
562- room_days = []
562+ room_timeslots = []
563+ for r in rooms :
564+ if r .pk not in room_has_timeslots :
565+ continue
563566
564- for day , day_min_time , day_max_time in day_min_max :
565- day_timeslots = []
567+ timeslots = []
566568 for t in timeslots_by_room_and_day .get ((r .pk , day ), []):
567- day_timeslots .append ({
569+ timeslots .append ({
568570 'timeslot' : t ,
569571 'offset' : timedelta_to_css_ems (t .time - day_min_time ),
570- 'height ' : timedelta_to_css_ems (t .end_time () - t .time ),
572+ 'width ' : timedelta_to_css_ems (t .end_time () - t .time ),
571573 })
572574
573- room_days .append ({
574- 'day' : day ,
575- 'timeslots' : day_timeslots ,
576- 'height' : timedelta_to_css_ems (day_max_time - day_min_time ),
577- })
575+ room_timeslots .append ((r , timeslots ))
578576
579- if any (d ['timeslots' ] for d in room_days ):
580- room_columns .append ({
581- 'room' : r ,
582- 'days' : room_days ,
583- })
577+ days .append ({
578+ 'day' : day ,
579+ 'width' : day_width ,
580+ 'time_labels' : day_labels ,
581+ 'room_timeslots' : room_timeslots ,
582+ })
583+
584+ room_labels = [[r for r in rooms if r .pk in room_has_timeslots ] for i in range (len (days ))]
584585
585586 # prepare sessions
586587 for ts in timeslots_qs :
@@ -701,7 +702,7 @@ def add_group_constraints(g1_pk, g2_pk, name_id, person_id):
701702 s .requested_duration_in_hours = s .requested_duration .seconds / 60.0 / 60.0
702703
703704 session_layout_margin = 0.2
704- s .layout_height = timedelta_to_css_ems (s .requested_duration ) - 2 * session_layout_margin
705+ s .layout_width = timedelta_to_css_ems (s .requested_duration ) - 2 * session_layout_margin
705706 s .parent_acronym = s .group .parent .acronym if s .group and s .group .parent else ""
706707 s .historic_group_ad_name = ad_names .get (s .group_id )
707708
@@ -744,9 +745,8 @@ def add_group_constraints(g1_pk, g2_pk, name_id, person_id):
744745 'schedule' : schedule ,
745746 'can_edit' : can_edit ,
746747 'js_data' : json .dumps (js_data , indent = 2 ),
747- 'time_labels' : time_labels ,
748- 'rooms' : rooms ,
749- 'room_columns' : room_columns ,
748+ 'days' : days ,
749+ 'room_labels' : room_labels ,
750750 'unassigned_sessions' : unassigned_sessions ,
751751 'session_parents' : session_parents ,
752752 'hide_menu' : True ,
0 commit comments