Skip to content

Commit

Permalink
Fix formgrader link from course_list (jupyter#1848)
Browse files Browse the repository at this point in the history
* Fix local formgrader link

* Automatically open the formgrader tab if 'formgrader=true' in URL search params
  • Loading branch information
brichet authored and AlirezaT99 committed Aug 6, 2024
1 parent 0d6a184 commit 8935faf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nbgrader/server_extensions/course_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check_for_local_formgrader(self, config):
if status:
raise gen.Return([{
'course_id': coursedir.course_id,
'url': base_url + '/lab',
'url': base_url + '/formgrader',
'kind': 'local'
}])

Expand Down 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
17 changes: 13 additions & 4 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 @@ -178,7 +178,6 @@ const courseListExtension: JupyterFrontEndPlugin<void> = {
id: pluginIDs.coursesList,
autoStart: true,
optional: [ILayoutRestorer, INotebookTree],

activate: (
app: JupyterFrontEnd,
restorer: ILayoutRestorer | null,
Expand Down Expand Up @@ -240,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 @@ -290,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 8935faf

Please sign in to comment.