Skip to content

Commit

Permalink
Automatically open the formgrader tab if 'formgrader=true' in URL sea…
Browse files Browse the repository at this point in the history
…rch params
  • Loading branch information
brichet committed Nov 29, 2023
1 parent c2c28a3 commit 2359912
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions nbgrader/server_extensions/course_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def check_for_noauth_jupyterhub_formgraders(self, config):

courses = [{
'course_id': coursedir.course_id,
'url': url + "/lab",
'url': url + "/lab?formgrader=true",
'kind': 'jupyterhub'
}]
raise gen.Return(courses)
Expand Down Expand Up @@ -156,7 +156,7 @@ def check_for_jupyterhub_formgraders(self, config):
service = services[course]
courses.append({
'course_id': course,
'url': self.get_base_url() + service['prefix'].rstrip('/') + "/lab",
'url': self.get_base_url() + service['prefix'].rstrip('/') + "/lab?formgrader=true",
'kind': 'jupyterhub'
})

Expand Down
2 changes: 1 addition & 1 deletion src/course_list/courselist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function createElementFromCourse(data: any, app: JupyterFrontEnd, isNotebook:boo
} else {
const url = data['url'] as string;
if (isNotebook) {
anchor.href = URLExt.join(url.replace(/lab\/?$/, 'tree'));
anchor.href = url.replace(/\/lab(\/|\?)?/, '/tree$1');
} else {
anchor.href = url
}
Expand Down
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ILabShell, ILayoutRestorer, JupyterFrontEnd, JupyterFrontEndPlugin } from "@jupyterlab/application";
import { ILabShell, ILayoutRestorer, IRouter, JupyterFrontEnd, JupyterFrontEndPlugin } from "@jupyterlab/application";
import { ICommandPalette, MainAreaWidget, WidgetTracker } from "@jupyterlab/apputils";
import { PageConfig, URLExt } from "@jupyterlab/coreutils";
import { IMainMenu } from '@jupyterlab/mainmenu';
Expand Down Expand Up @@ -239,11 +239,12 @@ const courseListExtension: JupyterFrontEndPlugin<void> = {
const formgraderExtension: JupyterFrontEndPlugin<void> = {
id: pluginIDs.formgrader,
autoStart: true,
optional: [ILayoutRestorer, INotebookTree],
optional: [ILayoutRestorer, INotebookTree, IRouter],
activate: (
app: JupyterFrontEnd,
restorer: ILayoutRestorer | null,
notebookTree: INotebookTree | null
notebookTree: INotebookTree | null,
router: IRouter | null
) => {
// Declare a widget variable
let widget: MainAreaWidget<FormgraderWidget>;
Expand Down Expand Up @@ -289,6 +290,15 @@ const formgraderExtension: JupyterFrontEndPlugin<void> = {
}
});

// Open formgrader from URL.
if (router) {
const formgraderPattern = /(\?|&)formgrader=true/;
router.register({
command: commandIDs.openFormgrader,
pattern: formgraderPattern
});
}

// Restore the widget state
if (restorer != null){
restorer.restore(tracker, {
Expand Down

0 comments on commit 2359912

Please sign in to comment.