Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sections with floating resources in scheduler #3270

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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