Skip to content

Commit

Permalink
feat: platform accounts for conn; connector dropdown is sticky on rel…
Browse files Browse the repository at this point in the history
…oad.
  • Loading branch information
chrisparnin committed Sep 7, 2020
1 parent fb48269 commit 56647b1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions docs/examples/tutorials/figlet.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Install `figlet`. (Mac):
brew install figlet
```

(Linux):
```bash|{type: 'command', platform: 'linux'}
apt-get install -y figlet
```

(Windows):

```bash|{type: 'command', privileged: true, platform: 'win32'}
Expand Down
18 changes: 16 additions & 2 deletions lib/notebook/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ Default set of rules and behaviors for notebooks.
class Policy
{

isExecutable($cell)
isExecutable($cell, setup)
{
let properties = $cell.data();
let isDocable = properties.docable;
if( properties.platform )
{
return require('os').platform == properties.platform && isDocable;
return this._getCurrentPlatform(setup) == properties.platform && isDocable;
}
return isDocable;
}

_getCurrentPlatform(setup)
{
if( setup.local )
{
return require('os').platform;
}
if( setup.docker || setup.ssh )
{
return "linux";
}

return "unknown";
}

}

module.exports = new Policy();
4 changes: 2 additions & 2 deletions lib/notebook/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var uuid = require('uuid');

class NotebookRender
{
async notebookRender(rootDir, md, ir) {
async notebookRender(session, rootDir, md, ir) {

let neededVariables = new Set();
let IR;
Expand All @@ -22,7 +22,7 @@ class NotebookRender
const $ = cheerio.load(IR);
$('[data-docable="true"]').each(function (index, elem) {

let cell = self.renderCell($(elem), $, policy.isExecutable($(elem)) );
let cell = self.renderCell($(elem), $, policy.isExecutable($(elem), session.notebooks.setup) );

// getting list of used variables in this notebook
let vars = $(elem).data('variables');
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.editCell = async function(req, res) {
let ir = await docable.transformers.inline.transform(Buffer.from(req.body.text, 'utf-8'));
const $ = cheerio.load(ir);
const elem = $('[data-docable="true"]');
let newCell = notebookRender.renderCell(elem, $, policy.isExecutable(elem));
let newCell = notebookRender.renderCell(elem, $, policy.isExecutable(elem, req.session.notebooks.setup));

res.send($.html());
};
Expand All @@ -78,7 +78,7 @@ async function run(text, stepIndex, session, res)
let html = "";
$$('[data-docable=true]').each( function(index, element)
{
if( policy.isExecutable($$(element) ) )
if( policy.isExecutable($$(element), session.notebooks.setup ) )
{
html+= $$(element).parent().html();
}
Expand Down
5 changes: 3 additions & 2 deletions lib/routes/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ async function _get_notebook(req, res, notebook_dir, slug, cwd) {
logger.info(`Setuping for notebook: ${notebook_dir}/${name}`);

let stepper = new docable.Stepper();
let setupStanza = await stepper.getSetupFromDocument(path.join(notebook_dir, name));
let setupStanza = (req.session.notebooks && req.session.notebooks.setup) ||
await stepper.getSetupFromDocument(path.join(notebook_dir, name));

if( !session.notebooks )
{
Expand All @@ -52,7 +53,7 @@ async function _get_notebook(req, res, notebook_dir, slug, cwd) {
session.notebooks.docDir = path.resolve(notebook_dir);

logger.info(`Rendering notebook: ${notebook_dir}/${name}`);
const { html, IR, md, neededVariables } = await notebookRender.notebookRender(path.dirname(name), nb);
const { html, IR, md, neededVariables } = await notebookRender.notebookRender(session, path.dirname(name), nb);

// return needed and missing variables which are used in this notebook
const sessionVariables = (req.session.variables || [])
Expand Down
2 changes: 2 additions & 0 deletions public/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $("#environment-dropdown").change(function () {
setEnvironment(selectedEnvironment).then(function(response)
{
envSpinToggle();
// Reload page so we can re-render cells that are platform specific.
location.reload();
}).catch( function(err) {
$('#docable-error').append( err );
envSpinToggle();
Expand Down

0 comments on commit 56647b1

Please sign in to comment.