diff --git a/nbgrader/docs/source/conf.py b/nbgrader/docs/source/conf.py index b1f53fe1a..d127214e5 100644 --- a/nbgrader/docs/source/conf.py +++ b/nbgrader/docs/source/conf.py @@ -288,6 +288,10 @@ # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False +linkcheck_ignore = [ + # Assume GitHub contributor search links for this repo are always valid + r"https://github.com/search\?q=repo%3Ajupyter%2Fnbgrader\+involves%3A.*type=Issues", +] # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'python': ('http://docs.python.org/', None)} diff --git a/nbgrader/server_extensions/formgrader/base.py b/nbgrader/server_extensions/formgrader/base.py index b6854ea24..37254d137 100644 --- a/nbgrader/server_extensions/formgrader/base.py +++ b/nbgrader/server_extensions/formgrader/base.py @@ -4,6 +4,7 @@ from tornado import web from jupyter_server.base.handlers import JupyterHandler +from jupyter_server.utils import url_path_join, url_is_absolute from ...api import Gradebook from ...apps.api import NbGraderAPI @@ -41,7 +42,10 @@ def gradebook(self): @property def mathjax_url(self): - return self.settings['mathjax_url'] + url = self.settings.get("mathjax_url", "") + if not url or url_is_absolute(url): + return url + return url_path_join(self.base_url or "/", url) @property def exporter(self): diff --git a/nbgrader/server_extensions/formgrader/handlers.py b/nbgrader/server_extensions/formgrader/handlers.py index fbe55c85a..70f974c0d 100644 --- a/nbgrader/server_extensions/formgrader/handlers.py +++ b/nbgrader/server_extensions/formgrader/handlers.py @@ -145,7 +145,6 @@ def get(self, submission_id): 'base_url': self.base_url, 'student': student_id, 'last_name': submission.student.last_name, - 'last_name': submission.student.last_name, 'first_name': submission.student.first_name, 'notebook_path': self.url_prefix + '/' + relative_path } diff --git a/nbgrader/server_extensions/formgrader/static/js/jupyterlab_utils.js b/nbgrader/server_extensions/formgrader/static/js/jupyterlab_utils.js deleted file mode 100644 index 7e9bb9783..000000000 --- a/nbgrader/server_extensions/formgrader/static/js/jupyterlab_utils.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Module of data to send to Jupyterlab's nbgrader extension to perform actions. - */ - -var jlab_go_to_path = function(directory_path){ - return JSON.stringify({ - "command": "filebrowser:go-to-path", - "arguments": {"path": directory_path} - }); -} \ No newline at end of file diff --git a/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js b/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js index cd8632bc9..e0dd3c5de 100644 --- a/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js +++ b/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js @@ -96,22 +96,14 @@ var AssignmentUI = Backbone.View.extend({ render: function () { this.clear(); - var this_assignment = this; + // assignment name var name = this.model.get("name") this.$name.attr("data-order", name); - // Append link with a listener to send message to iframe parent. - // NOTE: the formgrade UI is embedded in an iframe. this.$name.append($("") .text(name) - .attr("href", "#") - .click(function() { - window.parent.postMessage( - jlab_go_to_path(url_prefix + "/" + this_assignment.model.get("source_path")), - '*' - ); - }) + .map(linkTo("directory", url_prefix + "/" + this.model.get("source_path"))) ); // duedate @@ -157,16 +149,8 @@ var AssignmentUI = Backbone.View.extend({ // preview student version var release_path = this.model.get("release_path"); if (release_path) { - // Append link with a listener to send message to iframe parent. - // NOTE: the formgrade UI is embedded in an iframe. this.$preview.append($("") - .attr("href", "#") - .click(function() { - window.parent.postMessage( - jlab_go_to_path(url_prefix + "/" + release_path), - '*' - ); - }) + .map(linkTo("directory", url_prefix + "/" + release_path)) .append($("") .addClass("glyphicon glyphicon-search") .attr("aria-hidden", "true") @@ -620,7 +604,6 @@ var loadAssignments = function () { var models = undefined; var views = []; - $(window).on('load', function () { loadAssignments(); }); diff --git a/nbgrader/server_extensions/formgrader/static/js/utils.js b/nbgrader/server_extensions/formgrader/static/js/utils.js index e5adf5fa8..05c50aec1 100644 --- a/nbgrader/server_extensions/formgrader/static/js/utils.js +++ b/nbgrader/server_extensions/formgrader/static/js/utils.js @@ -87,3 +87,44 @@ var insertDataTable = function (tbl) { }] }); }; + +var linkTo = function (type, path) { + /* + * Connect a link in the appropriate manner for the context. + * - If we're in the outermost frame, assume notebook and use an href. + * - If we're in an iframe, assume lab and send a message. + */ + if (window === window.top) { + var prefix = { + notebook: "/notebooks/", + file: "/edit/", + directory: "/tree/" + }[type]; + + return (_, el) => { + return $(el) + .attr("href", prefix + path) + .attr("target", "_blank")[0]; + }; + } else { + var command = { + notebook: "docmanager:open", + file: "docmanager:open", + directory: "filebrowser:go-to-path", + }[type]; + + return (_, el) => { + return $(el) + .attr("href", "#") + .click(() => { + window.parent.postMessage( + JSON.stringify({ + "command": command, + "arguments": {"path": path} + }), + "*" + ); + })[0]; + } + } +} diff --git a/nbgrader/server_extensions/formgrader/templates/base.tpl b/nbgrader/server_extensions/formgrader/templates/base.tpl index 56eb423fb..b2c6168f9 100644 --- a/nbgrader/server_extensions/formgrader/templates/base.tpl +++ b/nbgrader/server_extensions/formgrader/templates/base.tpl @@ -10,7 +10,6 @@ - diff --git a/nbgrader/server_extensions/formgrader/templates/formgrade/formgrade_macros.html.j2 b/nbgrader/server_extensions/formgrader/templates/formgrade/formgrade_macros.html.j2 index cf8a9475e..b5a3133f9 100644 --- a/nbgrader/server_extensions/formgrader/templates/formgrade/formgrade_macros.html.j2 +++ b/nbgrader/server_extensions/formgrader/templates/formgrade/formgrade_macros.html.j2 @@ -20,6 +20,7 @@ var base_url = "{{ resources.base_url }}/formgrader"; + @@ -64,12 +64,12 @@ function jlab_open_notebook(notebook_path) {
  • {{ resources.notebook_id }}
  • Submission #{{ resources.index + 1 }} {%- if resources.last_name and resources.first_name -%} {{ resources.last_name }}, {{ resources.first_name }} @@ -99,4 +99,4 @@ function jlab_open_notebook(notebook_path) { $('span.glyphicon.name-hidden').tooltip({title: "Show student name", placement: "bottom", trigger: "hover"}); $('span.glyphicon.name-shown').tooltip({title: "Hide student name", placement: "bottom", trigger: "hover"}); -{% endmacro %} \ No newline at end of file +{% endmacro %}