Skip to content

Commit

Permalink
Fix sections with floating resources in scheduler (#3270)
Browse files Browse the repository at this point in the history
* Fix sections with floating resources

* remove unused import
  • Loading branch information
willgearty committed Apr 30, 2021
1 parent a45a660 commit ce5146c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
23 changes: 13 additions & 10 deletions esp/esp/program/modules/handlers/jsondatamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,23 @@ def resource_types(prog):
resource_types.cached_function.depend_on_model(ResourceType)

@aux_call
@json_response({'resourceassignment__resource__name': 'room_name', 'resourceassignment__resource__id': 'room_id'})
@json_response()
@needs_admin
@cached_module_view
def schedule_assignments(prog):
data = ClassSection.objects.filter(status__gte=0, parent_class__status__gte=0, parent_class__parent_program=prog).select_related('resourceassignment__resource__name', 'resourceassignment__resource__event').extra({'timeslots': 'ARRAY(SELECT resources_resource.event_id FROM resources_resource, resources_resourceassignment WHERE resources_resource.id = resources_resourceassignment.resource_id AND resources_resourceassignment.target_id = program_classsection.id)'}).values('id', 'resourceassignment__resource__name', 'resourceassignment__resource__id', 'timeslots').distinct()
sections = prog.sections().prefetch_related('meeting_times')
data_list = []
for i in range(len(data)):
if data[i]['resourceassignment__resource__id'] != None:
res = Resource.objects.get(id=data[i]['resourceassignment__resource__id'])
# Ignore anything that isn't a classroom
if res.res_type.name != "Classroom":
continue
data[i]['resourceassignment__resource__id'] = res.identical_id(prog)
data_list.append(data[i])
for section in sections:
room = None
rooms = section.initial_rooms()
if rooms.count() > 0:
room = rooms[0]
data_list.append({
'id': section.id,
'room_id': room.identical_id(prog) if room else None,
'room_name': room.name if room else None,
'timeslots': [time.id for time in section.get_meeting_times()]
})
return {'schedule_assignments': data_list}
schedule_assignments.method.cached_function.depend_on_row(ClassSection, lambda sec: {'prog': sec.parent_class.parent_program})
schedule_assignments.method.cached_function.depend_on_row(ResourceAssignment, lambda ra: {'prog': ra.target.parent_class.parent_program})
Expand Down
56 changes: 29 additions & 27 deletions esp/public/media/scripts/ajaxschedulingmodule/ESP/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,34 +342,36 @@ function Matrix(
this.initSections = function() {
// Associated already scheduled classes with rooms
$j.each(this.sections.scheduleAssignments, function(class_id, assignmentData){
$j.each(assignmentData.timeslots, function(j, timeslot_id){
var cell = this.getCell(assignmentData.room_id, timeslot_id);
if(cell && !cell.disabled) {
cell.addSection(sections.getById(class_id));
} else {
if(!cell) {
var errorMessage = "Error: Could not find cell with room with id "
+ assignmentData.room_id
+ " and timeslot with id "
+ timeslot_id
+ " to schedule section with id "
+ class_id;
console.log(errorMessage);
messagePanel.addMessage(errorMessage);
}
else {
var errorMessage = "Error: Room with id "
+ assignmentData.room_id
+ " appears to be unavailable during timeslot with id "
+ timeslot_id
+ " but section with id "
+ class_id
+ " is scheduled there.";
console.log(errorMessage);
messagePanel.addMessage(errorMessage);
if(assignmentData.room_id){
$j.each(assignmentData.timeslots, function(j, timeslot_id){
var cell = this.getCell(assignmentData.room_id, timeslot_id);
if(cell && !cell.disabled) {
cell.addSection(sections.getById(class_id));
} else {
if(!cell) {
var errorMessage = "Error: Could not find cell with room with id "
+ assignmentData.room_id
+ " and timeslot with id "
+ timeslot_id
+ " to schedule section with id "
+ class_id;
console.log(errorMessage);
messagePanel.addMessage(errorMessage);
}
else {
var errorMessage = "Error: Room with id "
+ assignmentData.room_id
+ " appears to be unavailable during timeslot with id "
+ timeslot_id
+ " but section with id "
+ class_id
+ " is scheduled there.";
console.log(errorMessage);
messagePanel.addMessage(errorMessage);
}
}
}
}.bind(this));
}.bind(this));
}
}.bind(this));
};

Expand Down
4 changes: 2 additions & 2 deletions esp/public/media/scripts/ajaxschedulingmodule/ESP/Sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ function Sections(sections_data, section_details_data, categories_data, teacher_
this.filtered_sections = function(allowScheduled){
var returned_sections = [];
$j.each(this.sections_data, function(section_id, section) {
if (!this.scheduleAssignments[section.id]) {
// filter out rejected sections
if (section.status < 0) {
// filter out rejected and cancelled sections
return;
}
if (this.isScheduled(section) && !allowScheduled) {
Expand Down

0 comments on commit ce5146c

Please sign in to comment.