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

Persist header and toolbar toggle status in nbconfig #1769

Merged
merged 4 commits into from Oct 6, 2016

Conversation

3 participants
@gnestor
Contributor

gnestor commented Sep 16, 2016

A first stab at #1661

Define `header` and `toolbar` properties for notebook
If `notebook.header` or `notebook.toolbar` are `false`, hide them on
load
@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 16, 2016

Contributor

@Carreau I am following your lead from c040464. However, neither the header or toolbar properties are being persisted in notebook.config.data after refresh. I don't fully understand how nbconfig works so I would appreciate your input here (I've enabled "Allow edits from maintainers" so you should be able to push to this PR).

Contributor

gnestor commented Sep 16, 2016

@Carreau I am following your lead from c040464. However, neither the header or toolbar properties are being persisted in notebook.config.data after refresh. I don't fully understand how nbconfig works so I would appreciate your input here (I've enabled "Allow edits from maintainers" so you should be able to push to this PR).

@gnestor gnestor added this to the 5.0 milestone Sep 16, 2016

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Sep 19, 2016

Member

Yeah, nbconfig thing is complex. let me have a look. Thanks for that.

Member

Carreau commented Sep 19, 2016

Yeah, nbconfig thing is complex. let me have a look. Thanks for that.

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Sep 19, 2016

Member

So it seem you get the config right, the problem is the asynchronicity and the config return defaults before being completly loaded.

if you cat ~/.jupyter/nbconfig/notebook.json you can see the values get changed.

You might want to add a this.config.loaded.then(function(){stuff(that.config.data)}

The resolve part of the promise does not get passed the new config apparently, but that should be fixable in notebook/services/config.js around line 34:

 ConfigSection.prototype._load_done = function() {
        if (!this._one_load_finished) {
            this._one_load_finished = true;
            this._finish_firstload();  // might want to pass self.data here. 
        }
    };

Does that make sens ?

Member

Carreau commented Sep 19, 2016

So it seem you get the config right, the problem is the asynchronicity and the config return defaults before being completly loaded.

if you cat ~/.jupyter/nbconfig/notebook.json you can see the values get changed.

You might want to add a this.config.loaded.then(function(){stuff(that.config.data)}

The resolve part of the promise does not get passed the new config apparently, but that should be fixable in notebook/services/config.js around line 34:

 ConfigSection.prototype._load_done = function() {
        if (!this._one_load_finished) {
            this._one_load_finished = true;
            this._finish_firstload();  // might want to pass self.data here. 
        }
    };

Does that make sens ?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Sep 19, 2016

Member

The idea with the config is that you can create a ConfigWithDefaults object, and then you have a choice of:

// Get a value immediately, using the defaults if real values aren't loaded yet
visible = c.get_sync('toolbar_visible');

// Wait for the value if necessary
c.get('toolbar_visible').then(function(visible) {...});
Member

takluyver commented Sep 19, 2016

The idea with the config is that you can create a ConfigWithDefaults object, and then you have a choice of:

// Get a value immediately, using the defaults if real values aren't loaded yet
visible = c.get_sync('toolbar_visible');

// Wait for the value if necessary
c.get('toolbar_visible').then(function(visible) {...});
@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 20, 2016

Contributor

@Carreau Your this.config.loaded.then() suggestion worked great...

Two questions:

  1. Is there a place to define default config values so that I don't have to wonder if this.config.data.Header is defined or not?
  2. Is there a better place to check the config values and hide/show the header/toolbar than in the initialization of the Notebook class (e.g. Notebook.load_notebook)?
Contributor

gnestor commented Sep 20, 2016

@Carreau Your this.config.loaded.then() suggestion worked great...

Two questions:

  1. Is there a place to define default config values so that I don't have to wonder if this.config.data.Header is defined or not?
  2. Is there a better place to check the config values and hide/show the header/toolbar than in the initialization of the Notebook class (e.g. Notebook.load_notebook)?
@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Sep 20, 2016

Member

Is there a place to define default config values so that I don't have to wonder if this.config.data.Header is defined or not?

There's a ConfigWithDefaults class, used like this:

configwd = ConfigWithDefaults(this.config, {
    header: true,
    toolbar: true,
});
configwd.get('header').then(function(header) {
    if (!header) {
        $('#header-container').hide();
        ...
    }
});
Member

takluyver commented Sep 20, 2016

Is there a place to define default config values so that I don't have to wonder if this.config.data.Header is defined or not?

There's a ConfigWithDefaults class, used like this:

configwd = ConfigWithDefaults(this.config, {
    header: true,
    toolbar: true,
});
configwd.get('header').then(function(header) {
    if (!header) {
        $('#header-container').hide();
        ...
    }
});
Access config via `ConfigWithDefaults` vs. `ConfigSection`
Move toggle logic to `notebook.js` vs. `actions.js` to be consistent
with `notebook.line_numbers`
@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 20, 2016

Contributor

Thanks @takluyver! I think this is ready for review...

Contributor

gnestor commented Sep 20, 2016

Thanks @takluyver! I think this is ready for review...

@gnestor

Let's give the Review feature a try...

}
});
this.class_config.get('Header').then(function(header) {

This comment has been minimized.

@gnestor

gnestor Sep 20, 2016

Contributor

To revisit my other question: Is there a better place to put this (like Notebook.load_notebook)?

@gnestor

gnestor Sep 20, 2016

Contributor

To revisit my other question: Is there a better place to put this (like Notebook.load_notebook)?

Object.defineProperty(this, 'header', {
get: function() {
return that.class_config.get_sync('Header');

This comment has been minimized.

@gnestor

gnestor Sep 20, 2016

Contributor

I switched from ConfigSection to ConfigWithDefaults to take advantage of defaults.

@gnestor

gnestor Sep 20, 2016

Contributor

I switched from ConfigSection to ConfigWithDefaults to take advantage of defaults.

Show outdated Hide outdated notebook/static/notebook/js/actions.js
Show outdated Hide outdated notebook/static/notebook/js/notebook.js
@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 22, 2016

Contributor

@Carreau Would you care to review? It's working for me and I think it's quite a bit cleaner given @takluyver's feedback. Two questions for you:

  1. I would like notebook.line_numbers to use ConfigWithDefaults as well to keep these properties consistent. I tried it and the issue is this: ConfigWithDefaults (or notebook.class_config.set) saves the line numbers toggle state at Notebook.Cell.cm_config.lineNumbers and ConfigSection (or notebook.config.update) saves it at Cell.cm_config.lineNumbers. After switching to ConfigWithDefaults, the cells no longer reflected the state in Notebook.Cell.cm_config.lineNumbers after refresh. However, if I manually changed the value of Cell.cm_config.lineNumbers in notebook.json, then they would reflect that. Sooo, the cells are not accessing the line numbers toggle state from notebook.line_numbers but appear to accessing it via notebook.config.data.Cell.cm_config.lineNumbers. My question for you: where does Codemirror look to determine whether a cell should display line numbers or not (specifically on load)?
  2. Is there a better place to put the "check nbconfig for header/toolbar toggle state and hide/show them accordingly" behavior than in the initialization of the notebook class (like notebook.load_notebook for example)?
Contributor

gnestor commented Sep 22, 2016

@Carreau Would you care to review? It's working for me and I think it's quite a bit cleaner given @takluyver's feedback. Two questions for you:

  1. I would like notebook.line_numbers to use ConfigWithDefaults as well to keep these properties consistent. I tried it and the issue is this: ConfigWithDefaults (or notebook.class_config.set) saves the line numbers toggle state at Notebook.Cell.cm_config.lineNumbers and ConfigSection (or notebook.config.update) saves it at Cell.cm_config.lineNumbers. After switching to ConfigWithDefaults, the cells no longer reflected the state in Notebook.Cell.cm_config.lineNumbers after refresh. However, if I manually changed the value of Cell.cm_config.lineNumbers in notebook.json, then they would reflect that. Sooo, the cells are not accessing the line numbers toggle state from notebook.line_numbers but appear to accessing it via notebook.config.data.Cell.cm_config.lineNumbers. My question for you: where does Codemirror look to determine whether a cell should display line numbers or not (specifically on load)?
  2. Is there a better place to put the "check nbconfig for header/toolbar toggle state and hide/show them accordingly" behavior than in the initialization of the notebook class (like notebook.load_notebook for example)?
@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Sep 23, 2016

Member

I'm giving a seminar today and will talk to a lot of people before and
after so won't be online a lot. I'll have a look ASAP.

On Thu, Sep 22, 2016 at 12:54 PM, Grant Nestor notifications@github.com
wrote:

@Carreau https://github.com/Carreau Would you care to review? It's
working for me and I think it's quite a bit cleaner given @takluyver
https://github.com/takluyver's feedback. Two questions for you:

  1. I would like notebook.line_numbers to use ConfigWithDefaults as
    well to keep these properties consistent. I tried it and the issue is this:
    ConfigWithDefaults (or notebook.class_config.set) saves the line
    numbers toggle state at Notebook.Cell.cm_config.lineNumbers and
    ConfigSection (or notebook.config.update) saves it at
    Cell.cm_config.lineNumbers. After switching to ConfigWithDefaults, the
    cells no longer reflected the state in Notebook.Cell.cm_config.
    lineNumbers after refresh. However, if I manually changed the value of
    Cell.cm_config.lineNumbers in notebook.json, then they would reflect
    that. Sooo, the cells are not accessing the line numbers toggle state
    from notebook.line_numbers but appear to accessing it via
    notebook.config.data.Cell.cm_config.lineNumbers. My question for you: where
    does Codemirror look to determine whether a cell should display line
    numbers or not (specifically on load)?
  2. Is there a better place to put the "check nbconfig for
    header/toolbar toggle state and hide/show them accordingly" behavior than
    in the initialization of the notebook class (like
    notebook.load_notebook for example)?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1769 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAUez2t4sDZ71KaM56Al57PNjhchdlrxks5qstzogaJpZM4J_FhF
.

Member

Carreau commented Sep 23, 2016

I'm giving a seminar today and will talk to a lot of people before and
after so won't be online a lot. I'll have a look ASAP.

On Thu, Sep 22, 2016 at 12:54 PM, Grant Nestor notifications@github.com
wrote:

@Carreau https://github.com/Carreau Would you care to review? It's
working for me and I think it's quite a bit cleaner given @takluyver
https://github.com/takluyver's feedback. Two questions for you:

  1. I would like notebook.line_numbers to use ConfigWithDefaults as
    well to keep these properties consistent. I tried it and the issue is this:
    ConfigWithDefaults (or notebook.class_config.set) saves the line
    numbers toggle state at Notebook.Cell.cm_config.lineNumbers and
    ConfigSection (or notebook.config.update) saves it at
    Cell.cm_config.lineNumbers. After switching to ConfigWithDefaults, the
    cells no longer reflected the state in Notebook.Cell.cm_config.
    lineNumbers after refresh. However, if I manually changed the value of
    Cell.cm_config.lineNumbers in notebook.json, then they would reflect
    that. Sooo, the cells are not accessing the line numbers toggle state
    from notebook.line_numbers but appear to accessing it via
    notebook.config.data.Cell.cm_config.lineNumbers. My question for you: where
    does Codemirror look to determine whether a cell should display line
    numbers or not (specifically on load)?
  2. Is there a better place to put the "check nbconfig for
    header/toolbar toggle state and hide/show them accordingly" behavior than
    in the initialization of the notebook class (like
    notebook.load_notebook for example)?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1769 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAUez2t4sDZ71KaM56Al57PNjhchdlrxks5qstzogaJpZM4J_FhF
.

@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 23, 2016

Contributor

@Carreau Ok no problem!

Contributor

gnestor commented Sep 23, 2016

@Carreau Ok no problem!

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Sep 23, 2016

Member

Notebook.Cell.cm_config.lineNumbers

this is due to the fact that line number could be toggle per-cell.
I think this is/was a mistake, and I'm fine not storing this config there anymore.

Currently here is how it seem to work...:

Codemirror instances are created on the create_element methods of codecell.js, and textcell.js (this.code_mirror = new CodeMirror(input_area.get(0), this._options.cm_config); lines.

this._options.cm_config contain likely the lineNumber field which is set on the parent class Cell (from cell.js) generated on the line this._options = utils.mergeopt({}, cell_config_data, class_config_data);, and class_config_data get the config synchronously class_config_data = this.class_config.get_sync();.

Does that make (some) sens ?

Member

Carreau commented Sep 23, 2016

Notebook.Cell.cm_config.lineNumbers

this is due to the fact that line number could be toggle per-cell.
I think this is/was a mistake, and I'm fine not storing this config there anymore.

Currently here is how it seem to work...:

Codemirror instances are created on the create_element methods of codecell.js, and textcell.js (this.code_mirror = new CodeMirror(input_area.get(0), this._options.cm_config); lines.

this._options.cm_config contain likely the lineNumber field which is set on the parent class Cell (from cell.js) generated on the line this._options = utils.mergeopt({}, cell_config_data, class_config_data);, and class_config_data get the config synchronously class_config_data = this.class_config.get_sync();.

Does that make (some) sens ?

@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Sep 23, 2016

Contributor

Yep, it makes perfect sense. The culprit was https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/notebook.js#L1185. I ran into a little error but it's almost there...

Contributor

gnestor commented Sep 23, 2016

Yep, it makes perfect sense. The culprit was https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/notebook.js#L1185. I ran into a little error but it's almost there...

@gnestor

This comment has been minimized.

Show comment
Hide comment
@gnestor

gnestor Oct 1, 2016

Contributor

@Carreau Let's merge this and I will work off of another branch to try to get notebook.line_numbers to use ConfigWithDefaults.

Contributor

gnestor commented Oct 1, 2016

@Carreau Let's merge this and I will work off of another branch to try to get notebook.line_numbers to use ConfigWithDefaults.

@gnestor gnestor changed the title from [WIP] Persist header and toolbar toggle status in nbconfig to Persist header and toolbar toggle status in nbconfig Oct 5, 2016

@Carreau Carreau merged commit 558ed9a into jupyter:master Oct 6, 2016

4 checks passed

codecov/patch Coverage not affected when comparing 179bb24...6c1fe1f
Details
codecov/project 74.20% (+0.00%) compared to 179bb24
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Oct 6, 2016

Member

You are right, let's try ! Thanks !

Member

Carreau commented Oct 6, 2016

You are right, let's try ! Thanks !

@gnestor gnestor deleted the gnestor:persist-header-toggle branch Oct 6, 2016

@gnestor gnestor moved this from Open PRs to Merged PRs in 5.0 Feb 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment