diff --git a/nbgrader/docs/source/conf.py b/nbgrader/docs/source/conf.py index 30e61a1f6..b5356823a 100644 --- a/nbgrader/docs/source/conf.py +++ b/nbgrader/docs/source/conf.py @@ -287,6 +287,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 = {'http://docs.python.org/': None} diff --git a/nbgrader/server_extensions/formgrader/base.py b/nbgrader/server_extensions/formgrader/base.py index d5bf2ec4d..1593b0ef2 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/formgrader.py b/nbgrader/server_extensions/formgrader/formgrader.py index d5806dfb6..f49a777c6 100644 --- a/nbgrader/server_extensions/formgrader/formgrader.py +++ b/nbgrader/server_extensions/formgrader/formgrader.py @@ -107,9 +107,6 @@ def load_jupyter_server_extension(nbapp): nbapp.log.info("Loading the formgrader nbgrader serverextension") webapp = nbapp.web_app - # Save which kind of application is running : Jupyterlab like or classic Notebook - webapp.settings['is_jlab'] = not (nbapp.name == 'jupyter-notebook') - formgrader = FormgradeExtension(parent=nbapp) # compatibility between notebook.notebookapp.NotebookApp and jupyter_server.serverapp.ServerApp diff --git a/nbgrader/server_extensions/formgrader/handlers.py b/nbgrader/server_extensions/formgrader/handlers.py index 0fa8a9404..7fff1b3d5 100644 --- a/nbgrader/server_extensions/formgrader/handlers.py +++ b/nbgrader/server_extensions/formgrader/handlers.py @@ -17,7 +17,6 @@ def get(self): "manage_assignments.tpl", url_prefix=self.url_prefix, base_url=self.base_url, - is_lab=int(self.settings['is_jlab']), windows=(sys.prefix == 'win32'), course_id=self.api.course_id, exchange=self.api.exchange_root, @@ -108,10 +107,9 @@ def get(self, submission_id): 'index': ix, 'total': len(indices), 'base_url': self.base_url, - 'my_mathjax_url': self.mathjax_url if self.settings['is_jlab'] else self.base_url + '/' + self.mathjax_url, + 'my_mathjax_url': self.mathjax_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 531c64eb8..41e8ed0ed 100644 --- a/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js +++ b/nbgrader/server_extensions/formgrader/static/js/manage_assignments.js @@ -34,7 +34,6 @@ var AssignmentUI = Backbone.View.extend({ this.listenTo(this.model, "request", this.animateSaving); this.listenTo(this.model, "sync", this.closeModal); - this.is_lab = options.is_lab || false; this.render(); }, @@ -97,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 : - * - href if this is a Notebook<7 environment - * - click listener to send message to iframe parent if this is Jupyter Lab environment - */ this.$name.append($("") .text(name) - .attr("target", self.is_lab ? undefined : "_blank") - .attr("href", self.is_lab ? undefined : base_url + "/tree/" + url_prefix + "/" + this.model.get("source_path")) - .click(self.is_lab ? function(){ - window.parent.postMessage(jlab_go_to_path(url_prefix + "/" + this_assignment.model.get("source_path")), '*'); - } : undefined) + .map(linkTo("directory", url_prefix + "/" + this.model.get("source_path"))) ); // duedate @@ -154,16 +145,8 @@ var AssignmentUI = Backbone.View.extend({ // preview student version var release_path = this.model.get("release_path"); if (release_path) { - /* Append link with : - * - href if this is a Notebook<7 environment - * - click listener to send message to iframe parent if this is Jupyter Lab environment - */ this.$preview.append($("") - .attr("target", self.is_lab ? undefined : "_blank") - .attr("href", self.is_lab ? undefined : base_url + "/tree/" + url_prefix + "/" + release_path) - .click(self.is_lab ? function(){ - window.parent.postMessage(jlab_go_to_path(url_prefix + "/" + release_path), '*'); - } : undefined) + .map(linkTo("directory", url_prefix + "/" + release_path)) .append($("") .addClass("glyphicon glyphicon-search") .attr("aria-hidden", "true"))); @@ -215,20 +198,20 @@ var AssignmentUI = Backbone.View.extend({ // generate feedback if (num_submissions > 0) { this.$generate_feedback.append($("") - .attr("href", "#") + .attr("href", "#") .click(_.bind(this.generate_feedback, this)) - .append($("") - .addClass("glyphicon glyphicon-comment") + .append($("") + .addClass("glyphicon glyphicon-comment") .attr("aria-hidden", "true"))); } // feedback if (num_submissions > 0) { this.$release_feedback.append($("") - .attr("href", "#") + .attr("href", "#") .click(_.bind(this.release_feedback, this)) - .append($("") - .addClass("glyphicon glyphicon-envelope") + .append($("") + .addClass("glyphicon glyphicon-envelope") .attr("aria-hidden", "true"))); } @@ -579,7 +562,7 @@ var createAssignmentModal = function () { modal = createModal("add-assignment-modal", "Add New Assignment", body, footer); }; -var loadAssignments = function (is_lab=false) { +var loadAssignments = function () { var tbl = $("#main-table"); models = new Assignments(); @@ -592,7 +575,6 @@ var loadAssignments = function (is_lab=false) { var view = new AssignmentUI({ "model": model, "el": insertRow(tbl), - "is_lab": is_lab }); views.push(view); }); @@ -605,8 +587,6 @@ var loadAssignments = function (is_lab=false) { var models = undefined; var views = []; -var is_lab = is_lab || false; - $(window).on('load', function () { - loadAssignments(is_lab); + 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 e014b1f2e..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,20 +64,12 @@ function jlab_open_notebook(notebook_path) {