Skip to content

Commit

Permalink
#6214 use saved ui_options
Browse files Browse the repository at this point in the history
  • Loading branch information
piorek committed Feb 7, 2018
1 parent f0348ed commit 608b99e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/notebook/src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ define([
'./plot/plotApi',
'./shared/bkCoreManager',
'big.js',
'./extension/gistPublish/index'
'./extension/gistPublish/index',
'./tree/Utils/UIOptionsHelper'
], function(
configmod,
comm,
Expand All @@ -62,7 +63,8 @@ define([
plotApi,
bkCoreManager,
big,
GistPublish
GistPublish,
UIOptionsHelper
) {
"use strict";

Expand All @@ -76,6 +78,7 @@ define([
var initCellUtils = require('./extension/initializationCells');

GistPublish.registerFeature();
UIOptionsHelper.registerFeature(base_url);

function installKernelHandler() {
var kernel = Jupyter.notebook.kernel;
Expand Down
66 changes: 66 additions & 0 deletions js/notebook/src/tree/Utils/UIOptionsHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import './../../global.env';

import BeakerXApi from "./BeakerXApi";


export function registerFeature(baseUrl: string): void {
if (!!Jupyter.NotebookList) {
return;
}

const api = new BeakerXApi(baseUrl);
api.loadSettings()
.then((data) => {

setupAutoCloseBrackets(data.ui_options.auto_close);
setupWideCells(data.ui_options.wide_cells);
setupImproveFonts(data.ui_options.improve_fonts);
setupShowPublication(data.ui_options.show_publication);

})
.catch((e) => {
console.log(e);
});
}

function setupAutoCloseBrackets(autoCloseBrackets: boolean): void {
// new cells
Jupyter.CodeCell.options_default.cm_config.autoCloseBrackets = autoCloseBrackets;

// existing
const code_cells = Jupyter.notebook.get_cells().filter((cell) => {
return cell.cell_type = 'code';
});

const patch = {
CodeCell: {
cm_config: {
autoCloseBrackets: autoCloseBrackets
}
}
};

for (let cell of code_cells) {
cell.config.update(patch);
}

}

function setupWideCells(wideCells: boolean): void {
if (!wideCells) {
return;
}

let s = document.createElement('style');
s.innerText = `.container { width:100% !important; }`;

document.body.appendChild(s);
}

function setupImproveFonts(improveFonts: boolean) {
console.log('handle improve fonts', improveFonts);
}

function setupShowPublication(showPublication: boolean) {
console.log('handle show publication', showPublication);
}

0 comments on commit 608b99e

Please sign in to comment.