Skip to content

Commit

Permalink
Added error messages for fetch/fetch_feedback when something goes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncbkose committed Jul 12, 2023
1 parent 649d655 commit b30b1b1
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 8 deletions.
58 changes: 56 additions & 2 deletions nbgrader/nbextensions/assignment_list/assignment_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,25 @@ define([
return container;
};

Assignment.prototype.fetch_error = function (data) {
var body = $('<div/>').attr('id', 'fetch-message');

body.append(
$('<div/>').append(
$('<p/>').text('Assignment not fetched:')
)
);
body.append(
$('<pre/>').text(data.value)
);

dialog.modal({
title: "Fetch failed",
body: body,
buttons: { OK: { class : "btn-primary" } }
});
};

Assignment.prototype.submit_error = function (data) {
var body = $('<div/>').attr('id', 'submission-message');

Expand All @@ -400,6 +419,25 @@ define([
});
};

Assignment.prototype.fetchfeedback_error = function (data) {
var body = $('<div/>').attr('id', 'fetchfeedback-message');

body.append(
$('<div/>').append(
$('<p/>').text('Feedback not fetched:')
)
);
body.append(
$('<pre/>').text(data.value)
);

dialog.modal({
title: "Fetch Feedback failed",
body: body,
buttons: { OK: { class : "btn-primary" } }
});
};

Assignment.prototype.make_button = function () {
var that = this;
var container = $('<span/>').addClass('item_status col-sm-4');
Expand All @@ -417,7 +455,15 @@ define([
},
type : "POST",
dataType : "json",
success : $.proxy(that.on_refresh, that),
success : function (data, status, xhr) {
if (!data.success) {
that.fetch_error(data);
button.text('Fetch');
button.removeAttr('disabled');
} else {
that.on_refresh(data, status, xhr);
}
},
error : function (xhr, status, error) {
container.empty().text("Error fetching assignment.");
utils.log_ajax_error(xhr, status, error);
Expand Down Expand Up @@ -479,7 +525,15 @@ define([
},
type : "POST",
dataType : "json",
success : $.proxy(that.on_refresh, that),
success : function (data, status, xhr) {
if (!data.success) {
that.fetchfeedback_error(data);
button.text('Fetch Feedback');
button.removeAttr('disabled');
} else {
that.on_refresh(data, status, xhr);
}
},
error : function (xhr, status, error) {
container.empty().text("Error fetching feedback.");
utils.log_ajax_error(xhr, status, error);
Expand Down
14 changes: 10 additions & 4 deletions nbgrader/server_extensions/assignment_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ def post(self, action):
if action == 'fetch':
assignment_id = data['assignment_id']
course_id = data['course_id']
self.manager.fetch_assignment(course_id, assignment_id)
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
output = self.manager.fetch_assignment(course_id, assignment_id)
if output["success"]:
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
else:
self.finish(json.dumps(output))
elif action == 'submit':
assignment_id = data['assignment_id']
course_id = data['course_id']
Expand All @@ -326,8 +329,11 @@ def post(self, action):
elif action == 'fetch_feedback':
assignment_id = data['assignment_id']
course_id = data['course_id']
self.manager.fetch_feedback(course_id, assignment_id)
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
output = self.manager.fetch_feedback(course_id, assignment_id)
if output["success"]:
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
else:
self.finish(json.dumps(output))


class CourseListHandler(BaseAssignmentHandler):
Expand Down
46 changes: 44 additions & 2 deletions src/assignment_list/assignmentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ class Assignment {
return container;
};

private fetch_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Assignment not fetched:');
const body_content = React.createElement('pre', null, data.value);
const body = React.createElement("div", {'id': 'fetch-message'}, [body_title, body_content]);

showNbGraderDialog({
title: "Fetch Failed",
body: body,
buttons: [Dialog.okButton()]
}, true);


};

private submit_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Assignment not submitted:');
Expand All @@ -260,6 +275,21 @@ class Assignment {
}, true);


};

private fetchfeedback_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Feedback not fetched:');
const body_content = React.createElement('pre', null, data.value);
const body = React.createElement("div", {'id': 'fetchfeedback-message'}, [body_title, body_content]);

showNbGraderDialog({
title: "Fetch Failed",
body: body,
buttons: [Dialog.okButton()]
}, true);


};

private make_button(): HTMLSpanElement{
Expand All @@ -282,7 +312,13 @@ class Assignment {
method: 'POST'
});

that.on_refresh(reply);
if(!reply.success){
that.fetch_error(reply);
button.innerText = 'Fetch'
button.removeAttribute('disabled')
}else{
that.on_refresh(reply);
}
} catch (reason) {
remove_children(container);
container.innerText = 'Error fetching assignment.';
Expand Down Expand Up @@ -335,7 +371,13 @@ class Assignment {
method: 'POST'
});

that.on_refresh(reply);
if(!reply.success){
that.fetchfeedback_error(reply);
button.innerText = 'Fetch Feedback'
button.removeAttribute('disabled')
}else{
that.on_refresh(reply);
}

} catch (reason) {
remove_children(container);
Expand Down
4 changes: 4 additions & 0 deletions style/validation_message.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#fetch-message p,
#submission-message p,
#fetchfeedback-message p,
#validation-message p {
margin-bottom: 1em;
padding-top: 1em;
}

#fetch-message pre,
#submission-message pre,
#fetchfeedback-message pre,
#validation-message pre {
border: solid var(--jp-border-color2) 1px;
padding: 5px;
Expand Down

0 comments on commit b30b1b1

Please sign in to comment.