Skip to content

Update notebook routes and services to include get_notebook_by_path f… #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/app/routes/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def notebook():
def get_all_notebooks():
return Notebook.get_all_notebooks()

@notebook_blueprint.route('/notebook/<path:notebook_path>', methods=['GET'])
def get_notebook_by_path(notebook_path):
return Notebook.get_notebook_by_path(notebook_path=notebook_path)

@notebook_blueprint.route('/notebook', methods=['POST'])
def create_notebook():
data = request.get_json()
Expand Down
9 changes: 9 additions & 0 deletions server/app/services/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def get_all_notebooks():
notebooks_json = json.dumps(notebooks_dict)

return notebooks_json

@staticmethod
def get_notebook_by_path(notebook_path: str = None):
jupyter_server_path = os.environ.get("JUPYTER_SERVER_PATH", "http://localhost:8888")

path = f"{jupyter_server_path}/api/contents/{notebook_path}"
response = requests.get(path)

return response.json()

@staticmethod
def create_notebook(notebook_name: str = None) -> None:
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const App = () => {
const handleNewNotebookClick = () => {
if (handleUnsavedChanges()) {
NotebookModel.createNotebook(`${baseUrl}work`, '').then((data) => {
const notebookPath = `${baseUrl}${data.path}`
const notebookPath = `${data.path}`
NotebookModel.fetchNotebook(notebookPath).then((data) => {
setNotebook(data);
setShowHistoryServer(false);
Expand All @@ -93,7 +93,7 @@ const App = () => {

const handleExistingNotebookClick = (path) => {
if (handleUnsavedChanges()) {
NotebookModel.fetchNotebook(`${baseUrl}${path}`).then((data) => {
NotebookModel.fetchNotebook(`${path}`).then((data) => {
console.log('Fetched notebook:', data);
setNotebook(data);
setShowHistoryServer(false);
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/models/NotebookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ class NotebookModel {
};

static async fetchNotebook(path = '') {
const url = new URL(path);
url.searchParams.append('t', Date.now()); // Append current timestamp as query parameter
const response = await fetch(url, {
const response = await fetch("http://localhost:5002/notebook/" + path, {
method: 'GET',
redirect: "follow",
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
}
});

if (!response.ok) {
throw new Error('Failed to fetch notebook');
}
const data = await response.json();
return data;
}
Expand Down
Loading