Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add save as menu option#3289

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
takluyver merged 7 commits intojupyter:masterfromMadhu94:add-save-as-menu-option
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Add basic selenium test case
  • Loading branch information
@Madhu94
Madhu94 committedMay 13, 2018
commiteab1e709eb2e597d0b95ab40a727891a901ea6c9
4 changes: 3 additions & 1 deletionnotebook/static/notebook/js/notebook.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2858,6 +2858,7 @@ define([
$('<br/>')
).append(
$('<input/>').attr('type','text').attr('size','25')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This input area doesn't show up well for me. I think you're missing theform-control class that the rename dialog uses:

$('<input/>').attr('type','text').attr('size','25').addClass('form-control')

Also, I hope we can get rid of the inline styling a couple of lines below.

.attr('data-testid', 'save-as')
.addClass('form-control')
);

Expand DownExpand Up@@ -2894,7 +2895,8 @@ define([
that.events.trigger('notebook_renamed.Notebook', data);

},function(error) {
console.error(i18n.msg._(error.message || 'Unknown error saving notebook'));
const msg = i18n.msg._(error.message || 'Unknown error saving notebook');
$('.save-message').html(`<span style='color:red;'>${msg}</span>`);
});
}
that.contents.get(nb_path, {type: 'notebook'}).then(function(data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This should at least usecontent: false to avoid getting the full content of the other notebook if it does exist. It's also not great in that it assumes any error getting a model means that the file is not there.

The right way to do this is probably to add a parameter when saving, to ask the server to throw an error if the filename already exists. Maybe this way of doing it is good enough for now, though. I'd like to get some other opinions on it.

Copy link
ContributorAuthor

@Madhu94Madhu94Jun 17, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This should at least use content: false to avoid getting the full content of the other notebook if it does exist.

This is done, thank you.

It's also not great in that it assumes any error getting a model means that the file is not there.

I will try to think of a better way. Maybe we go back to something like my original implementation which used a flag to toggle between copy/save on the server..

Expand Down
40 changes: 40 additions & 0 deletionsnotebook/tests/selenium/test_save_as_notebook.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
from notebook.tests.selenium.utils import wait_for_selector
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait

def wait_for_rename(browser, nbname, timeout=10):
wait = WebDriverWait(browser, timeout)
def notebook_renamed(browser):
elem = browser.find_element_by_id('notebook_name')
current_name = browser.execute_script('return arguments[0].innerText', elem)
return current_name == nbname
return wait.until(notebook_renamed)

def save_as(nb):
JS = 'Jupyter.notebook.save_notebook_as()'
return nb.browser.execute_script(JS)

def get_notebook_name(nb):
JS = 'return Jupyter.notebook.notebook_name'
return nb.browser.execute_script(JS)

def set_notebook_name(nb, name):
JS = 'Jupyter.notebook.rename("{}")'.format(name)
nb.browser.execute_script(JS)

def test_save_notebook_as(notebook):
# Set a name for comparison later
set_notebook_name(notebook, name="nb1.ipynb")
wait_for_rename(notebook.browser, "nb1")
assert get_notebook_name(notebook) == "nb1.ipynb"
# Wait for Save As modal, save
save_as(notebook)
wait_for_selector(notebook.browser, '.save-message')
inp = notebook.browser.find_element_by_xpath('//input[@data-testid="save-as"]')
inp.send_keys('new_notebook.ipynb')
inp.send_keys(Keys.RETURN)
wait_for_rename(notebook.browser, "new_notebook")
# Test that the name changed
assert get_notebook_name(notebook) == "new_notebook.ipynb"
# Test that address bar was updated (TODO: get the base url)
assert "new_notebook.ipynb" in notebook.browser.current_url

[8]ページ先頭

©2009-2025 Movatter.jp